Last active
July 11, 2020 15:36
-
-
Save gvanem/a6eaf29bda43b82fdd8556ed7f6efe2a to your computer and use it in GitHub Desktop.
GNU-makefile for Windump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# tcpdump/windump Makefile for MSVC or clang-cl. | |
# NB! Needs GNU make 4.x. | |
# | |
# By Gisle Vanem <gvanem@yahoo.no> 2004 - 2019. | |
# | |
THIS_FILE = Makefile.Windows | |
BUILD_DATE = $(shell date +%d-%B-%Y) | |
PYTHON ?= py -3 | |
VPATH = missing win32 | |
# | |
# Comment this out in order NOT to rebuild everything when $(THIS_FILE) changes. | |
# And delete .depend.Windows. | |
# | |
MDEPEND ?= $(THIS_FILE) | |
# Options: | |
# | |
# Do a 'make -f Makefile.Windows CC=cl vclean' after changing any of these | |
# (except 'USE_MULTI_COMPILE'). | |
# | |
# Compile several .c-files at once (much faster, but with MSVC only). | |
# | |
USE_MULTI_COMPILE ?= 1 | |
# | |
# Include code for sniffing WiFi using an USB AirPcap adapter. | |
# | |
USE_AIRPCAP ?= 1 | |
AIRPCAP_ROOT ?= $(PCAP_ROOT)/AirPcap | |
# | |
# Include code for "System Management Information" to handle SNMP / MIB stuff. | |
# | |
USE_LIBSMI ?= 0 | |
LIBSMI_ROOT ?= ../../libsmi-0.4.8 | |
# | |
# Include support for capturing from Remote interfaces. | |
# | |
USE_REMOTE ?= 1 | |
# | |
# Include OpenSSL library to verify MD5 signatures, decode ESP | |
# packets ("Encapsulated Security Payload") etc. | |
# | |
USE_OPENSSL ?= 1 | |
OPENSSL_ROOT ?= ../../Crypto/OpenSSL | |
# | |
# Use "Visual Leak Detector" for all programs: | |
# https://kinddragon.github.io/vld/ | |
# https://github.com/KindDragon/vld/ | |
# | |
USE_VLD ?= 0 | |
VLD_ROOT ?= f:/ProgramFiler/VisualLeakDetector | |
# | |
# Generate and compile a 'oui-generated.c' file with "Organizationally Unique Identifiers" | |
# using the 'make-oui.py' script. These OUI values are most commonly used as MAC-address prefixes. | |
# | |
# But enabling this will cause many 'runtests' cases to fail. | |
# | |
USE_OUI_GENERATED ?= 0 | |
# | |
# Link to the static libpcap library | |
# (as opposed to the wpcap.dll). | |
# | |
USE_STATIC_LIBPCAP ?= 0 | |
# | |
# Define 'HAVE_PCAP_DEBUG=1'. | |
# MUST match what libpcap was built with. | |
# | |
USE_PCAP_DEBUG ?= 2 | |
# | |
# Use Wsock-Trace | |
# | |
USE_WSOCK_TRACE ?= 0 | |
# | |
# Build using a debug CRT (-MDd). | |
# This has no relation to 'USE_PCAP_DEBUG' above. | |
# | |
USE_CRT_DEBUG ?= 0 | |
# | |
# See '%.i: %.c' rule below. | |
# | |
USE_CLANG_FORMAT ?= 1 | |
USE_GNU_INDENT ?= 0 | |
# | |
# Location of your libpcap root (must not includes spaces). | |
# | |
PCAP_ROOT ?= ../../libpcap | |
# | |
# Location of your WinPcap root (must not includes spaces). | |
# | |
WINPCAP_ROOT ?= $(PCAP_ROOT)/WinPcap | |
# | |
# Location for 'make install' target: | |
# $(INSTALL_BIN_DIR): location for 'windump$(X64_SUFFIX).exe'. | |
# $(INSTALL_DOC_DIR): location for 'tcpdump.1'. | |
# | |
MINGW_ROOT = $(realpath $(MINGW32)) | |
INSTALL_BIN_DIR = $(MINGW_ROOT)/bin | |
INSTALL_DOC_DIR = $(MINGW_ROOT)/share/man/man1 | |
# | |
# These roots assumes "Visual-Studio 2017" (or later) is used. | |
# | |
VC_ROOT = $(realpath $(VCToolkitInstallDir)) | |
CRT_DIR = $(VC_ROOT)/lib/$(CPU) | |
CL_CC = $(VC_ROOT)/bin/HostX86/$(CPU)/cl.exe | |
CL_LINK = $(VC_ROOT)/bin/HostX86/$(CPU)/link.exe | |
comma := , | |
# | |
# In case %CL is set, undefine it. | |
# | |
export CL= | |
OBJ_DIR = objects | |
GENERATED = config.h version.c | |
CFLAGS = -nologo -W4 -GF -D_WINSOCK_DEPRECATED_NO_WARNINGS | |
LDFLAGS = -nologo -subsystem:console -incremental:no -map -verbose -debug -machine:$(CPU) | |
ifeq ($(CC),clang-cl) | |
CFLAGS += -fms-compatibility | |
RCFLAGS = -D__clang__ | |
else ifeq ($(CC),cl) | |
CFLAGS += -Gs # -arch:IA32 | |
RCFLAGS = -D_MSC_VER | |
else | |
$(error "Only 'cl' and 'clang-cl' are supported.") | |
endif | |
LINK_CRAP = windump$(X64_SUFFIX).idb link.tmp | |
ifeq ($(USE_VLD),1) | |
CFLAGS += -Zi \ | |
-DUSE_VLD -DVLD_FORCE_ENABLE \ | |
-I$(VLD_ROOT)/include | |
VLD_LIB = $(VLD_ROOT)/lib/Win$(BITS)/vld.lib | |
else | |
# | |
# This causes a much faster compile and link using MSVC-2019. | |
# But breaks "Visual Leak Detector". | |
# | |
CFLAGS += -Z7 -Zo | |
endif | |
# | |
# Return a list of .obj-files from .c-files: | |
# | |
c_to_obj = $(addprefix $(OBJ_DIR)/, $(notdir $(1:.c=.obj))) | |
# | |
# No 64-bit version of OpenSSL and 'libsmi' libraries at the moment. | |
# | |
ifeq ($(CPU),x64) | |
USE_OPENSSL = 0 | |
USE_LIBSMI = 0 | |
endif | |
ifeq ($(CC),clang-cl) | |
USE_MULTI_COMPILE = 0 | |
# | |
# I have this clang-cl.bat file on my PATH: | |
# | |
# @echo off | |
# set CLANG_32=f:\ProgramFiler\LLVM-9-32bit | |
# set CLANG_64=f:\ProgramFiler\LLVM-9-64bit | |
# set CL= | |
# | |
# if %1. == -m32. ( | |
# shift | |
# %CLANG_32%\bin\clang-cl.exe %* | |
# ) else if %1. == -m64. ( | |
# shift | |
# %CLANG_64%\bin\clang-cl.exe %* | |
# ) else ( | |
# clang-cl.exe %* | |
# ) | |
# | |
ifeq ($(CPU),x64) | |
CL_CC = clang-cl.bat -m64 | |
else | |
CL_CC = clang-cl.bat -m32 | |
endif | |
endif | |
# | |
# The path for the CRT library ('msvcrt.lib' or 'msvcrtd.lib'): | |
# | |
LDFLAGS += -libpath:$(CRT_DIR) | |
# | |
# 'WindowsKits' root is in $(WK_ROOT) and | |
# 'WindowsKits' version is in $(WK_VER). | |
# | |
# Hence the User-Mode libraries for 'x86' are in: | |
# $(WK_ROOT)/Lib/$(WK_VER)/um/x86/ | |
# | |
LDFLAGS += -libpath:$(realpath $(WK_ROOT)/Lib/$(WK_VER)/um/$(CPU)) | |
# | |
# Ditto mess for the Universal CRT libraries: for 'x86' the UCRT libs are in: | |
# $(WK_ROOT)/Lib/$(WK_VER)/ucrt/x86/ | |
# | |
LDFLAGS += -libpath:$(realpath $(WK_ROOT)/Lib/$(WK_VER)/ucrt/$(CPU)) | |
# | |
# $(LIB_SUBDIR) is to select 64-bit version of Packet.lib when building a | |
# 64-bit WinDump: | |
# $(PCAP_ROOT)/WinPcap/lib/$(LIB_SUBDIR)packet.lib | |
# | |
# If '$(CPU)=x64', build and use 64-bit programs/DLLs. Otherwise 32-bit programs. | |
# | |
ifeq ($(CPU),) | |
CPU := x86 | |
endif | |
# | |
# GNU Make handles environment variables in a case-sensitive manner. | |
# | |
ifeq ($(CPU),X64) | |
BITS = 64 | |
else ifeq ($(CPU),x64) | |
BITS = 64 | |
else ifeq ($(CPU),x86) | |
BITS = 32 | |
else ifeq ($(CPU),X86) | |
BITS = 32 | |
else | |
$(error Unsupported $$(CPU)=$(CPU)) | |
endif | |
ifeq ($(BITS),64) | |
USE_AIRPCAP = 0 | |
X64_SUFFIX = _64 | |
LIB_SUBDIR = x64/ | |
$(message Building for x64) | |
endif | |
# | |
# The following ANSI-codes used in macro 'colour_message' assumes you | |
# have MSys/Cygwin's echo with colour support. | |
# | |
BRIGHT_GREEN = \e[1;32m | |
BRIGHT_YELLOW = \e[1;33m | |
BRIGHT_WHITE = \e[1;37m | |
colour_message = @echo -e "$(1)\e[0m" | |
green_message = $(call colour_message,$(BRIGHT_GREEN)$(strip $(1))) | |
yellow_message = $(call colour_message,$(BRIGHT_YELLOW)$(strip $(1))) | |
CFLAGS += -DHAVE_CONFIG_H \ | |
-DLIBPCAP_NO_EXTRAS \ | |
-DWIN32_COLOR_PRINTF \ | |
-I. -I./win32 \ | |
-I$(PCAP_ROOT) \ | |
-I$(WINPCAP_ROOT)/Include \ | |
-I$(WINPCAP_ROOT)/PacketNtx/Dll | |
CFLAGS += -D_CRT_SECURE_NO_WARNINGS \ | |
-D_CRT_SECURE_NO_WARNINGS_GLOBALS \ | |
-D_CRT_SECURE_NO_DEPRECATE \ | |
-D_CRT_NONSTDC_NO_WARNINGS \ | |
-D_CRT_OBSOLETE_NO_WARNINGS | |
ifeq ($(CC),clang-cl) | |
CFLAGS += # -D_U_='__attribute__((unused))' | |
else | |
CFLAGS += -wd4456 # -D_U_= | |
ifeq ($(BITS),64) | |
# | |
# netdissect.h(226): warning C4324: 'netdissect_options': structure was padded due to alignment specifier | |
# | |
CFLAGS += -wd4324 | |
endif | |
endif | |
# | |
# clang-cl warnings; a lot of them: | |
# | |
ifeq ($(CC),clang-cl) | |
CFLAGS += -Wall \ | |
-Wno-unused-local-typedef \ | |
-Wno-unused-function \ | |
-Wno-ignored-attributes \ | |
-Wno-unknown-pragmas \ | |
-Wno-unused-parameter \ | |
-Wno-sign-compare \ | |
-Wno-pointer-sign \ | |
-Wno-unused-variable \ | |
-Wno-expansion-to-defined \ | |
-Wno-unused-label \ | |
-Wno-double-promotion \ | |
-Wno-zero-length-array \ | |
-Wno-strict-prototypes \ | |
-Wno-assign-enum \ | |
-Wno-switch-enum \ | |
-Wno-bad-function-cast \ | |
-Wno-\#pragma-messages \ | |
-Wno-extra-semi-stmt \ | |
-Wno-implicit-fallthrough \ | |
-Wno-comma | |
# | |
# New warnings in clang-cl v 6.0: | |
# | |
CFLAGS += -Wno-reserved-id-macro -Wno-undef \ | |
-Wno-language-extension-token \ | |
-Wno-nonportable-system-include-path \ | |
-Wno-disabled-macro-expansion \ | |
-Wno-documentation-unknown-command \ | |
-Wno-keyword-macro \ | |
-Wno-sign-conversion \ | |
-Wno-conversion \ | |
-Wno-shorten-64-to-32 \ | |
-Wno-vla \ | |
-Wno-unused-macros \ | |
-Wno-documentation \ | |
-Wno-documentation-pedantic \ | |
-Wno-cast-qual \ | |
-Wno-cast-align \ | |
-Wno-missing-noreturn \ | |
-Wno-covered-switch-default \ | |
-Wno-embedded-directive \ | |
-Wno-format-nonliteral \ | |
-Wno-format-pedantic \ | |
-Wno-unreachable-code-break \ | |
-Wno-used-but-marked-unused \ | |
-Wno-missing-variable-declarations \ | |
-Wno-gnu-zero-variadic-macro-arguments \ | |
-Wno-incompatible-pointer-types-discards-qualifiers | |
# | |
# The warning '-Wbad-function-cast' is pretty important. | |
# Leave that in. | |
# | |
# CFLAGS += -Wno-bad-function-cast | |
endif | |
# | |
# A common HAVE_WHAT section: | |
# | |
HAVE_WHAT = HAVE_BPF_DUMP \ | |
HAVE_FCNTL_H \ | |
HAVE_PCAP_BLUETOOTH_H \ | |
HAVE_PCAP_BREAKLOOP \ | |
HAVE_PCAP_CREATE \ | |
HAVE_PCAP_DATALINK_NAME_TO_VAL \ | |
HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION \ | |
HAVE_PCAP_DUMP_FLUSH \ | |
HAVE_PCAP_DUMP_FTELL64 \ | |
HAVE_PCAP_FINDALLDEVS \ | |
HAVE_PCAP_FREE_DATALINKS \ | |
HAVE_PCAP_IF_T \ | |
HAVE_PCAP_LIB_VERSION \ | |
HAVE_PCAP_LIST_DATALINKS \ | |
HAVE_PCAP_NFLOG_H \ | |
HAVE_PCAP_PCAP_INTTYPES_H \ | |
HAVE_PCAP_SET_DATALINK \ | |
HAVE_PCAP_SET_TSTAMP_TYPE \ | |
HAVE_PCAP_SETDIRECTION \ | |
HAVE_PCAP_SET_IMMEDIATE_MODE \ | |
HAVE_PCAP_SET_OPTIMIZER_DEBUG \ | |
HAVE_PCAP_SET_PARSER_DEBUG \ | |
HAVE_PCAP_VERSION \ | |
HAVE_PCAP_WSOCKINIT \ | |
HAVE_STRDUP \ | |
HAVE_STRFTIME \ | |
HAVE_STDINT_H | |
ifeq ($(USE_AIRPCAP),1) | |
HAVE_WHAT += HAVE_AIRPCAP_API | |
endif | |
ifeq ($(USE_REMOTE),1) | |
HAVE_WHAT += HAVE_PCAP_FINDALLDEVS_EX \ | |
HAVE_PCAP_OPEN | |
endif | |
ifeq ($(USE_OPENSSL),1) | |
HAVE_WHAT += HAVE_LIBCRYPTO \ | |
HAVE_OPENSSL \ | |
HAVE_OPENSSL_EVP_H \ | |
HAVE_EVP_CIPHER_CTX_NEW \ | |
HAVE_EVP_CIPHERINIT_EX \ | |
HAVE_EVP_DECRYPTINIT_EX | |
endif | |
ifeq ($(USE_LIBSMI),1) | |
HAVE_WHAT += USE_LIBSMI | |
endif | |
ifeq ($(USE_PCAP_DEBUG),1) | |
HAVE_WHAT += HAVE_PCAP_DEBUG HAVE_YYDEBUG | |
endif | |
ifeq ($(USE_STATIC_LIBPCAP),1) | |
CFLAGS += -DPCAP_STATIC | |
endif | |
VERSION = $(shell cat ./VERSION) | |
# | |
# Extract the 'print-*.c' files from 'Makefile.in'. | |
# | |
print_SRC := $(filter print-%.c, $(shell cat Makefile.in)) | |
# | |
# print-pflog.c is no point on Windows: | |
# | |
print_SRC := $(filter-out print-pflog.c, $(print_SRC)) | |
# | |
# All the combined .c sources: | |
# | |
SOURCES += $(print_SRC) \ | |
addrtoname.c \ | |
addrtostr.c \ | |
af.c \ | |
ascii_strcasecmp.c \ | |
checksum.c \ | |
cpack.c \ | |
fptype.c \ | |
gmpls.c \ | |
in_cksum.c \ | |
ipproto.c \ | |
l2vpn.c \ | |
machdep.c \ | |
netdissect.c \ | |
netdissect-alloc.c \ | |
nlpid.c \ | |
ntp.c \ | |
parsenfsfh.c \ | |
print.c \ | |
signature.c \ | |
smbutil.c \ | |
strtoaddr.c \ | |
tcpdump.c \ | |
util-print.c \ | |
version.c \ | |
win32/win32-stuff.c \ | |
$(addprefix missing/, \ | |
getopt_long.c \ | |
getservent.c \ | |
strlcpy.c \ | |
strlcat.c \ | |
strsep.c) \ | |
# bpf_dump.c | |
# | |
# Support for reading '%SystemRoot%/drivers/etc/ethers' file to | |
# get sensible hosts names from MAC-addresses. | |
# | |
SOURCES += missing/win_ether_ntohost.c | |
ifeq ($(USE_OUI_GENERATED),1) | |
SOURCES += oui-generated.c | |
CFLAGS += -DUSE_OUI_GENERATED | |
ifeq ($(CC),cl) | |
CFLAGS += -bigobj | |
endif | |
else | |
SOURCES += oui.c | |
endif | |
SOURCES := $(sort $(SOURCES)) | |
OBJECTS = $(call c_to_obj, $(SOURCES)) | |
################################################################################## | |
TARGETS = windump$(X64_SUFFIX).exe ascii.exe tcpdump.1 | |
LINK_CRAP += $(TARGETS:.exe=.map) $(TARGETS:.exe=.pdb) | |
ifeq ($(USE_CRT_DEBUG),1) | |
CFLAGS += -MDd -Od -Ob2 -RTCs -RTCu # -RTC1 | |
else | |
CFLAGS += -MD -O2 | |
endif | |
ifeq ($(USE_STATIC_LIBPCAP),1) | |
ifeq ($(USER),gv) | |
EX_LIBS += $(PCAP_ROOT)/wpcap2$(X64_SUFFIX)_static.lib | |
else | |
EX_LIBS += $(PCAP_ROOT)/wpcap$(X64_SUFFIX)_static.lib | |
endif | |
EX_LIBS += iphlpapi.lib user32.lib | |
else | |
ifeq ($(USER),gv) | |
EX_LIBS += $(PCAP_ROOT)/wpcap2$(X64_SUFFIX).lib | |
else | |
EX_LIBS += $(PCAP_ROOT)/wpcap$(X64_SUFFIX).lib | |
endif | |
endif | |
ifeq ($(USE_CRT_DEBUG),0) | |
# LDFLAGS += -nodefaultlib:msvcrtd.lib | |
endif | |
ifeq ($(USE_AIRPCAP),1) | |
CFLAGS += -I$(AIRPCAP_ROOT)/include \ | |
-I$(AIRPCAP_ROOT)/src | |
EX_LIBS += $(AIRPCAP_ROOT)/lib/airpcap.lib | |
endif | |
ifeq ($(USE_OPENSSL),1) | |
CFLAGS += -I$(OPENSSL_ROOT)/include | |
EX_LIBS += $(OPENSSL_ROOT)/lib$(BITS)/libcrypto_imp.lib | |
endif | |
ifeq ($(USE_LIBSMI),1) | |
CFLAGS += -I$(LIBSMI_ROOT)/lib | |
EX_LIBS += $(LIBSMI_ROOT)/win/smi$(X64_SUFFIX).lib | |
endif | |
ifneq ($(USER),gv) | |
EX_LIBS += $(PCAP_ROOT)/WinPcap/lib/$(LIB_SUBDIR)packet.lib | |
endif | |
ifeq ($(USE_STATIC_LIBPCAP),1) | |
EX_LIBS += version.lib | |
endif | |
EX_LIBS += advapi32.lib | |
ifeq ($(USE_WSOCK_TRACE),1) | |
WS2_32_LIB = wsock_trace.lib | |
else | |
WS2_32_LIB = ws2_32.lib | |
endif | |
EX_LIBS += $(WS2_32_LIB) | |
ifeq ($(CC),cl) | |
# CFLAGS += -Yu"config.h" | |
endif | |
##### Now, we're ready to get to work ############################## | |
all: intro $(OBJ_DIR) $(GENERATED) $(TARGETS) epilogue | |
epilogue: | |
$(call green_message,Welcome to windump$(X64_SUFFIX).exe. \ | |
Do a $(BRIGHT_WHITE)make -f $(THIS_FILE) [install | tests]$(BRIGHT_GREEN) at own risk.) | |
intro: | |
@echo 'Building version "$(VERSION)" with compiler "$(CC)".' | |
config.h: $(MDEPEND) | |
$(call Generate, $@, //) | |
$(file >> $@,$(CONFIG_H)) | |
@$(foreach what, $(HAVE_WHAT), \ | |
$(file >> $@, #define $(what) 1)) | |
$(file >> $@, ) | |
$(file >> $@, #endif /* _TCPDUMP_CONFIG_H */) | |
version.c: ./VERSION $(MDEPEND) | |
$(call Generate, $@, //) | |
$(file >> $@,$(VERSION_C)) | |
$(OBJ_DIR): | |
- mkdir $(OBJ_DIR) | |
$(OBJ_DIR)/pch.obj: $(MDEPEND) config.h $(CC).args | |
$(call Generate, pch.c, //) | |
$(file >> pch.c,$(pch_c)) | |
$(CC) -c pch.c @$(CC).args -Fo./$@ -Yc"config.h" | |
# | |
# Compile a 'print-*.c' files (with -MP) is really much faster | |
# than the single compile rule. | |
# | |
ifeq ($(USE_MULTI_COMPILE),1) | |
print_OBJ = $(call c_to_obj, $(print_SRC)) | |
$(print_OBJ): $(print_SRC) | |
$(CL_CC) -MP -FS $(CFLAGS) -Fo./$(OBJ_DIR)\\ -c $(print_SRC) | |
@echo | |
endif | |
$(OBJ_DIR)/print-ascii-test.obj: print-ascii.c | |
$(CL_CC) -c -DMAIN @$(CC).args -Fo./$@ $< | |
@echo | |
# | |
# Not in 'TARGET'. Will it compile? | |
# | |
$(OBJ_DIR)/espdecrypt.obj: backup/espdecrypt.c | |
$(CL_CC) -c -DDEBUG -Dstrncasecmp=strnicmp @$(CC).args -I$(PCAP_ROOT)/bpf -Fo./$@ $^ | |
@echo | |
$(OBJ_DIR)/%.obj: %.c | $(CC).args | |
$(CL_CC) -c @$(CC).args -Fo./$@ $< | |
@echo | |
windump$(X64_SUFFIX).exe: $(OBJECTS) $(OBJ_DIR)/windump.res | |
$(call make_resp_file, link.args, $^ $(VLD_LIB) $(EX_LIBS)) | |
$(call link_EXE, $@, @link.args) | |
ascii.exe: $(OBJ_DIR)/print-ascii-test.obj | |
$(call link_EXE, $@, $< $(VLD_LIB) $(WS2_32_LIB)) | |
espdecrypt.exe: $(OBJ_DIR)/espdecrypt.obj | |
$(call link_EXE, $@, $< $(VLD_LIB) $(EX_LIBS)) | |
$(CC).args: $(THIS_FILE) | |
$(call make_resp_file, $@, $(CFLAGS)) | |
oui-generated.c: make-oui.py | |
$< | |
%.i: %.c FORCE cpp_filter.py | |
$(CC) -E $(CFLAGS) $< | $(PYTHON) cpp_filter.py $(C_FORMATER) > $@ | |
@echo | |
FORCE: | |
$(OBJ_DIR)/windump.res: $(MDEPEND) $(OBJ_DIR)/windump.rc | |
rc -nologo $(RCFLAGS) -fo $@ $(OBJ_DIR)/windump.rc | |
@echo | |
$(OBJ_DIR)/windump.rc: $(MDEPEND) version.c | |
$(call Generate, $@, //) | |
$(file >> $@,$(WINDUMP_RC)) | |
##### Test what we've just built ################################### | |
# | |
# Use this Python 2/3 script for testing (not the Perl mess in 'tests/TESTrun') | |
# | |
TEST_CMD = TESTrun.py | |
ifeq ($(CPU),x64) | |
TEST_CMD += -6 | |
endif | |
runtests tests: tests_py | |
tests_py:: | |
export WSOCK_TRACE_LEVEL=0; \ | |
export PCAP_TRACE=0; \ | |
cd ./tests; \ | |
$(PYTHON) $(TEST_CMD) | |
tests_sh:: | |
export WSOCK_TRACE_LEVEL=0; \ | |
export PCAP_TRACE=0; \ | |
cd ./tests; \ | |
sh TESTrun.sh | |
# | |
# @MAN_MISC_INFO@ is unimportant on Win32. | |
# | |
MAN_FILE_FORMATS = 1 | |
MAN_MISC_INFO = 7 | |
tcpdump.1: tcpdump.1.in | |
sed -e 's/@MAN_FILE_FORMATS@/$(MAN_FILE_FORMATS)/g' \ | |
-e 's/@MAN_MISC_INFO@/$(MAN_MISC_INFO)/g' < $< > $@ | |
@echo | |
install: all tcpdump.1 | |
cp --update windump$(X64_SUFFIX).exe $(INSTALL_BIN_DIR)/tcpdump$(X64_SUFFIX).exe | |
cp --update windump$(X64_SUFFIX).exe $(INSTALL_BIN_DIR) | |
cp --update tcpdump.1 $(INSTALL_DOC_DIR) | |
uninstall: | |
rm -f $(INSTALL_BIN_DIR)/windump$(X64_SUFFIX).exe | |
rm -f $(INSTALL_BIN_DIR)/tcdump$(X64_SUFFIX).exe | |
rm -f $(INSTALL_DOC_DIR)/tcpdump.1 | |
clean: | |
rm -f $(OBJ_DIR)/* $(GENERATED) cpp_filter.py link.args cl.args clang-cl.args | |
vclean realclean: clean tests_clean | |
- rm -f $(TARGETS) .depend.Windows $(LINK_CRAP) oui-generated.c oui-generated.txt vc1*.pdb | |
- rmdir $(OBJ_DIR) | |
tests_clean: | |
-cd ./tests ; \ | |
rm -f NEW/* NEW_py/* DIFF/* DIFF_py/* .passed .failed failure-outputs.txt failure-outputs_py.txt ; \ | |
rmdir NEW NEW_py DIFF DIFF_py | |
###################################################################################### | |
define Generate | |
$(call green_message, Generating $(1)..) | |
$(file > $(1),$(2)) | |
$(file >> $(1),$(2) Generated by $(THIS_FILE) at $(BUILD_DATE).) | |
$(file >> $(1),$(2) DO NOT EDIT!) | |
$(file >> $(1),$(2)) | |
endef | |
define CONFIG_H | |
#ifndef _TCPDUMP_CONFIG_H | |
#define _TCPDUMP_CONFIG_H | |
#if !defined(RC_INVOKED) | |
#ifndef _WIN32_WINNT | |
#define _WIN32_WINNT 0x0601 | |
#endif | |
#include <inttypes.h> /* Will include <stdint.h> */ | |
/* '_MSC_EXTENSIONS' is a built-in define for '_MSC_VER'. | |
*/ | |
#ifndef _MSC_VER | |
#define _MSC_EXTENSIONS | |
#endif | |
#undef WIN32_LEAN_AND_MEAN | |
#define WIN32_LEAN_AND_MEAN | |
#undef _WINSOCK_DEPRECATED_NO_WARNINGS | |
#define _WINSOCK_DEPRECATED_NO_WARNINGS | |
/* Suppress warnings like: | |
* 'GetVersion': was declared deprecated | |
* | |
* in MS SDK 8+. | |
*/ | |
#undef BUILD_WINDOWS | |
#define BUILD_WINDOWS | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/stat.h> | |
#include <errno.h> | |
#include <string.h> | |
#include <assert.h> | |
#include <winsock2.h> | |
#include <ws2tcpip.h> | |
#if defined(USE_VLD) | |
#include <vld.h> | |
#endif | |
#if defined(_MSC_VER) && !defined(__clang__) | |
#pragma warning (disable:4100) /* unreferenced formal parameter */ | |
#pragma warning (disable:4127) /* conditional expression is constant */ | |
#pragma warning (disable:4244) /* conversion from 'double' to 'float', possible loss of data */ | |
#pragma warning (disable:4305) /* 'initializing' : truncation from 'double' to 'const float' */ | |
#pragma warning (disable:4706) /* assignment within conditional expression */ | |
#if defined(_M_X64) || defined(_M_IA64) || defined(_M_AMD64) | |
#pragma warning (disable:4267) /* conversion from 'size_t' to 'u_int', possible loss of data */ | |
#endif | |
#pragma intrinsic (memcmp, memcpy, memset) | |
#pragma intrinsic (strcat, strcmp, strcpy, strlen) | |
#elif defined(__GNUC__) | |
#define HAVE___ATTRIBUTE__ 1 | |
#endif | |
#define DEBUG 1 /* For parsenfs.c */ | |
#define NBBY 8 | |
#define SIZEOF_LONG_LONG 8 | |
#define USE_ETHER_NTOHOST 1 | |
#define ENABLE_SMB 1 | |
#define OPENSSL_NO_KRB5 1 | |
#endif /* RC_INVOKED */ | |
#define PACKAGE_VERSION "$(VERSION)" | |
/* Our HAVE_WHAT section. Some .sh files in 'tests/' requires that | |
* these '#define' lines starts at position 1. | |
* | |
* Note: this 'HAVE_WHAT' list is common for all compilers. | |
* Thus a 'make clean' shouldn't be needed when switching compilers $(CC). | |
*/ | |
endef | |
################################################################################## | |
_RC_VERSION := $(VERSION:-PRE-GIT=) | |
_RC_VERSION := $(subst .,$(comma),$(_RC_VERSION)),0 | |
define VERSION_C | |
#include "config.h" | |
#if defined(__clang__) | |
#define HOST "(clang)" | |
#elif defined(_MSC_VER) | |
#define HOST "(MSVC)" | |
#else | |
#define HOST "(by ?)" | |
#endif | |
#if defined(RC_INVOKED) | |
/* | |
* This section gets read by the resource-compiler since 'version.c' | |
* gets included in '$$(OBJ_DIR)/windump.rc'. | |
*/ | |
#define RC_DEBUG $(USE_CRT_DEBUG) | |
#define RC_HOST HOST | |
#define RC_VERSION_STR "$(VERSION)" | |
/* | |
* Replace '.' with ',' and remove the '-PRE-GIT' part | |
* with the $$(_RC_VERSION) value from $(THIS_FILE). | |
*/ | |
#define RC_VERSION $(_RC_VERSION) | |
#if defined(HAVE_AIRPCAP_API) | |
#define RC_HAVE_AIRPCAP "AirPcap " | |
#else | |
#define RC_HAVE_AIRPCAP "" | |
#endif | |
#if defined(HAVE_OPENSSL) | |
#define RC_HAVE_SSL "OpenSSL " | |
#else | |
#define RC_HAVE_SSL "" | |
#endif | |
#if defined(USE_LIBSMI) | |
#define RC_HAVE_SMI "SMI library" | |
#else | |
#define RC_HAVE_SMI "" | |
#endif | |
#if RC_DEBUG | |
#define RC_DBG_REL "debug" | |
#else | |
#define RC_DBG_REL "release" | |
#endif | |
#else | |
const char version[] = "$(VERSION) " HOST ; | |
#endif | |
endef | |
define pch_c | |
/* | |
* pch.c: source file that includes just the standard includes. | |
* windump.pch will contain the pre-compiled header data. | |
* $$(OBJ_DIR)/pch.obj will contain the pre-compiled type information. | |
*/ | |
#pragma once | |
#define NETDISSECT_REWORKED 1 | |
#include "config.h" | |
#include <netdissect-stdinc.h> | |
endef | |
# | |
# Rule to generate a nicer C preprocessed output | |
# with the help of 'cpp_filter.py' and optionally 'GNU indent' or 'clang-format'. | |
# | |
ifeq ($(USE_GNU_INDENT),1) | |
C_FORMATER = | indent -st | |
else ifeq ($(USE_CLANG_FORMAT),1) | |
C_FORMATER = | clang-format -style=Mozilla -assume-filename=c | |
else | |
C_FORMATER = | |
endif | |
# | |
# Some handy GNU-make macros | |
# | |
define link_EXE | |
$(CL_LINK) $(LDFLAGS) -out:$(strip $(1)) $(2) > link.tmp | |
@cat link.tmp >> $(1:.exe=.map) | |
@echo | |
endef | |
# | |
# Make a response file using this make-macro instead of relying on | |
# various 'echo' programs. Depending on Cygwin or Msys version, the cmdline | |
# limit can be very low. Besides this macro avoids spawning 'sh'. | |
# | |
# arg1, $(1): The name of the response file | |
# arg2, $(2): The content for the response file. | |
# | |
define make_resp_file | |
$(file > $(1)) | |
$(foreach f, $(2), $(file >> $(1),$(strip $(f))) ) | |
endef | |
define WINDUMP_RC | |
#include <winver.h> | |
#include "version.c" | |
TCPDUMP_ICON ICON "tcpdump.ico" | |
VS_VERSION_INFO VERSIONINFO | |
FILEVERSION RC_VERSION | |
PRODUCTVERSION RC_VERSION | |
FILEFLAGSMASK 0x3FL | |
FILEOS VOS__WINDOWS32 | |
FILETYPE VFT_APP | |
FILESUBTYPE 0 | |
FILEFLAGS $(USE_CRT_DEBUG) | |
BEGIN | |
BLOCK "StringFileInfo" | |
BEGIN | |
BLOCK "040904b0" | |
BEGIN | |
VALUE "Comments", "Build on $(BUILD_DATE)" | |
VALUE "CompanyName", "http://www.tcpdump.org/" | |
VALUE "FileDescription", "Network Packet Analyser " RC_HOST | |
VALUE "FileVersion", RC_VERSION_STR " " RC_DBG_REL | |
VALUE "InternalName", "windump$(X64_SUFFIX)" | |
VALUE "LegalCopyright", "3-clause BSD licence:\r\n" \ | |
"\t\t\thttp://www.opensource.org/licenses/BSD-3-Clause" | |
VALUE "OriginalFilename", "windump$(X64_SUFFIX).exe" | |
VALUE "PrivateBuild", "Private build by <gvanem@yahoo.no>" | |
VALUE "ProductName", "windump$(X64_SUFFIX).exe" | |
VALUE "ProductVersion", RC_VERSION_STR | |
VALUE "SpecialBuild", "With: " RC_HAVE_AIRPCAP RC_HAVE_SSL RC_HAVE_SMI | |
END | |
END | |
BLOCK "VarFileInfo" | |
BEGIN | |
VALUE "Translation", 0x409, 1200 | |
END | |
END | |
endef | |
# | |
# For cpp_filter.py used in '*.c -> *.i' rule. | |
# | |
define CPP_FILTER_PY | |
import sys, os | |
try: | |
import ntpath | |
except ImportError as e: | |
print ("Failed to import ntpath: %s" % e) | |
sys.exit(1) | |
def _win32_abspath (path): | |
path = ntpath.abspath (path) | |
return path.replace ('\\', '/') | |
def skip_cwd (s1, s2): | |
''' Skip the leading part that is in common with s1 and s2 | |
''' | |
i = 0 | |
while i < len(s1) and s1[i] == s2[i]: | |
i += 1 | |
return s2[i:] | |
cwd = _win32_abspath (os.getcwd()) + '/' | |
last_line = '??' | |
last_fname = '??' | |
empty_lines = 0 | |
while True: | |
line = sys.stdin.readline() | |
if not line: | |
break | |
if line.startswith('\n') or line.startswith('\r'): | |
empty_lines += 1 | |
continue | |
if line.lstrip().startswith("#line"): | |
line = line.replace ("\\\\", "/") | |
fname = None | |
quote = line.find ('\"') | |
if line.startswith ("#line ") and quote > 0: | |
fname = _win32_abspath (line[quote:]) | |
last_fname = fname | |
if line.strip() != '' and last_line != '': | |
if fname is None or fname != last_fname: | |
print (line, end="") | |
if line.strip() == '}' or line.strip() == '};': # Print a newline after a functions or structs | |
print ("") | |
last_line = line | |
if empty_lines > 0: | |
sys.stderr.write ("Removed %d empty lines." % empty_lines) | |
endef | |
cpp_filter.py: $(THIS_FILE) | |
$(call Generate, $@, #) | |
$(file >> $@,if 1:) | |
$(file >> $@,$(CPP_FILTER_PY)) | |
DEP_CFLAGS = -MM $(filter -I% -D%, $(CFLAGS)) | |
DEP_REPLACE = sed -e 's|\(.*\)\.o: |\n$$(OBJ_DIR)\/\1.obj: |' \ | |
-e 's|$(OPENSSL_ROOT)|$$(OPENSSL_ROOT)|' | |
depend: $(GENERATED) | |
$(call Generate, .depend.Windows, #) | |
gcc $(DEP_CFLAGS) $(SOURCES) | $(DEP_REPLACE) >> .depend.Windows | |
ifeq ($(findstring $(MAKECMDGOALS),depend),depend) | |
$(warning Not reading .depend.Windows) | |
else | |
-include .depend.Windows | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment