Skip to content

Instantly share code, notes, and snippets.

@sgeto
Forked from gvanem/Makefile.Windows
Created December 9, 2017 23:27
Show Gist options
  • Save sgeto/12c45d0fc671021920e580f7b9e80695 to your computer and use it in GitHub Desktop.
Save sgeto/12c45d0fc671021920e580f7b9e80695 to your computer and use it in GitHub Desktop.
GNU-make files for Windump
#
# This is Common.Windows.
#
# Include this from Makefile.MingW or Makefile.MSVC to generate
# a *common* config.h file for both MingW and MSVC.
# It also generates a version_*.c file.
#
# By G. Vanem <[email protected]> 2003 - 2015.
#
.SUFFIXES: .rc
VPATH = missing win32/src
MAKE_FILE = $(firstword $(MAKEFILE_LIST))
COMMON_FILE = $(realpath Common.Windows)
BUILD_DATE = $(shell date +%d-%B-%Y)
MAJOR_VER = $(word 1, $(subst ., ,$(MAKE_VERSION)))
ifneq ($(CC),gcc)
ifneq ($(CC),cl)
ifneq ($(CC),clang-cl)
$(error "Unsupported compiler: $$(CC) = $(CC).")
endif
endif
endif
#
# $(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
#
# Comment this out in order NOT to rebuild everything when either
# $(COMMON_FILE) or $(MAKE_FILE) changes. And delete .depend.Windows.
#
MDEPEND = $(COMMON_FILE) $(MAKE_FILE)
#
# 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 of your AirPcap root (must not includes spaces).
#
AIRPCAP_ROOT = $(PCAP_ROOT)/AirPcap
#
# Location of OpenSSL.
#
OPENSSL_ROOT = ../../Crypto/OpenSSL
#
# Use System Management lib for SNMP.
#
LIBSMI_ROOT = ../../libsmi-0.4.8
#
# 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
#
# 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 ?= 0
#
# Put only generic CFLAGS here. All cl/gcc specific CFLAGS should be set
# in the including Makefile. E.g. Makefile.MSVC before or after this
# file gets included.
#
CFLAGS += -DHAVE_CONFIG_H \
-DLIBPCAP_NO_EXTRAS \
-DWIN32_COLOR_PRINTF \
-I. \
-I$(PCAP_ROOT) \
-I$(PCAP_ROOT)/Win32/Include \
-I$(WINPCAP_ROOT)/Include \
-I$(WINPCAP_ROOT)/PacketNtx/Dll
ifeq ($(CC),gcc)
CFLAGS += -D_U_='__attribute__((unused))'
else
#
# 'cl' + 'clang-cl'
#
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))' \
-Wno-unused-parameter \
-Wno-unused-function \
-Wno-unused-variable
else
CFLAGS += -D_U_='' -wd4456 \
# -Fp./windump$(X64_SUFFIX).pch
endif
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 \
no_need_for_this_HAVE_PCAP_DUMP_FTELL \
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_SNPRINTF \
HAVE_STRDUP \
HAVE_STRFTIME \
HAVE_STDINT_H \
HAVE_VSNPRINTF
ifeq ($(USE_REMOTE),1)
CFLAGS += -DHAVE_PCAP_FINDALLDEVS_EX -DHAVE_PCAP_OPEN
endif
ifeq ($(USE_AIRPCAP),1)
CFLAGS += -DHAVE_AIRPCAP_API
RCFLAGS += -DHAVE_AIRPCAP_API
endif
ifeq ($(USE_OPENSSL),1)
CFLAGS += -DHAVE_LIBCRYPTO -DHAVE_OPENSSL -DHAVE_OPENSSL_EVP_H \
-DHAVE_EVP_CIPHER_CTX_NEW -DHAVE_EVP_CIPHERINIT_EX
RCFLAGS += -DHAVE_OPENSSL
HAVE_WHAT += HAVE_LIBCRYPTO
endif
ifeq ($(USE_LIBSMI),1)
CFLAGS += -DUSE_LIBSMI
RCFLAGS += -DUSE_LIBSMI
endif
ifeq ($(USE_STATIC_LIBPCAP),1)
CFLAGS += -DPCAP_STATIC
endif
ifeq ($(USE_PCAP_DEBUG),1)
CFLAGS += -DHAVE_PCAP_DEBUG -DHAVE_YYDEBUG
endif
VERSION = $(shell cat ./VERSION)
SOURCES := $(filter print-%.c, $(shell cat Makefile.in))
#
# print-pflog.c is no point on Windows:
#
SOURCES := $(filter-out print-pflog.c, $(SOURCES))
SOURCES += print-xtp.c
SOURCES += addrtoname.c \
addrtostr.c \
af.c \
ascii_strcasecmp.c \
checksum.c \
cpack.c \
gmpls.c \
gmt2local.c \
in_cksum.c \
ipproto.c \
l2vpn.c \
machdep.c \
netdissect.c \
nlpid.c \
oui.c \
parsenfsfh.c \
print.c \
signature.c \
smbutil.c \
strtoaddr.c \
tcpdump.c \
util-print.c \
version.c \
win32-stuff.c \
$(addprefix missing/, \
getopt_long.c \
getservent.c \
strlcpy.c \
strlcat.c strsep.c) \
win32/src/ether_ntohost.c \
# bpf_dump.c
SOURCES := $(sort $(SOURCES))
OBJECTS += $(addprefix $(OBJ_DIR)/, $(notdir $(SOURCES:.c=.$(O))))
######################################################################################
define CONFIG_H
/*
* config.h generated by $(COMMON_FILE).
* DO NOT EDIT!
*/
#if !defined(RC_INVOKED)
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0601
#endif
#include <inttypes.h> /* Will include <stdint.h> */
#if 0
/* "netdissect-stdinc.h" defines a 'uint64_t' as 'unsigned _int64'.
* This doesn't work with gcc (only MSVC). Hence:
*/
#define uint64_t unsigned __int64
#define uint unsigned int
#if defined(__MINGW32__) || 1
/*
* Avoid redefining 'u_int64_t' in $(WINPCAP_ROOT)/include/bittypes.h.
* This header must be included in "netdissect-stdinc.h".
*/
#define u_int8_t uint8_t
#define u_int16_t uint16_t
#define u_int32_t uint32_t
#define u_int64_t uint64_t
#define _int64 __int64
#endif
#endif
/* Use the 'I64??' definitions in "netdissect-stdinc.h" for gcc too.
* '_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(_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
##################################################################################
TARGETS = windump$(X64_SUFFIX).exe ascii.exe tcpdump.1
LINK_CRAP += $(TARGETS:.exe=.map) $(TARGETS:.exe=.pdb)
TEST_CMD = TESTrun.py -vvs
ifeq ($(CPU),x64)
TEST_CMD += -6
endif
all: intro ver_check $(OBJ_DIR) config.h $(TARGETS)
@echo 'Welcome to windump$(X64_SUFFIX).exe. Do may need to do a "make -f $(MAKE_FILE) install" too'.
ver_check:
ifneq ($(MAJOR_VER),4)
$(error I need GNUmake 4 or later)
endif
runtests tests: tests_py
tests_py::
export WSOCK_TRACE_LEVEL=0; \
export PCAP_TRACE=0; \
cd ./tests; \
dos2unix -q *.out; \
$(TEST_CMD)
tests_sh::
export WSOCK_TRACE_LEVEL=0; \
export PCAP_TRACE=0; \
cd ./tests; \
dos2unix -q *.out; \
sh TESTrun.sh
intro:
@echo 'Building version "$(VERSION)" with compiler "$(CC)".'
config.h: $(MDEPEND)
@echo 'Generating $@...'
$(file > $@,#ifndef _TCPDUMP_CONFIG_H)
$(file >> $@,#define _TCPDUMP_CONFIG_H)
$(file >> $@,$(CONFIG_H))
@$(foreach what, $(HAVE_WHAT), \
$(file >> $@,#define $(what) 1))
$(file >> $@, )
$(file >> $@,#endif /* _TCPDUMP_CONFIG_H */)
##################################################################################
comma := ,
_RC_VERSION := $(VERSION:-PRE-GIT=)
_RC_VERSION := $(subst .,$(comma),$(_RC_VERSION)),0
define VERSION_C
/*
* This file is generated from $(COMMON_FILE) and
* ./VERSION. DO NOT EDIT!
*/
#include "config.h"
#if defined(__MINGW64_VERSION_MAJOR)
#define HOST "(TDM-GCC)"
#elif defined(__MINGW32__)
#define HOST "(MinGW)"
#elif 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_DEBUG)
#define RC_HOST HOST
#define RC_VERSION_STR "$(VERSION)"
/*
* Replace '.' with ',' and remove the '-PRE-GIT' part
* with the $$(_RC_VERSION) value from $(COMMON_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
version.c: ./VERSION $(MDEPEND)
@echo 'Generating $@...'
$(file > $@,$(VERSION_C))
$(OBJ_DIR):
- mkdir $(OBJ_DIR)
$(OBJ_DIR)/pch.obj: $(MDEPEND) config.h
$(file > pch.c, /*)
$(file >>pch.c, * pch.c: source file that includes just the standard includes.)
$(file >>pch.c, * windump.pch will be the pre-compiled header.)
$(file >>pch.c, * $$(OBJ_DIR)/pch.obj will contain the pre-compiled type information.)
$(file >>pch.c, */)
$(file >>pch.c, #pragma once)
$(file >>pch.c, #define NETDISSECT_REWORKED 1)
$(file >>pch.c, #include "config.h")
$(file >>pch.c, #include <netdissect-stdinc.h>)
$(CC) -c pch.c $(CFLAGS) -Fo./$@ -Yc"config.h"
ifeq ($(CC),cl)
# CFLAGS += -Yu"config.h"
endif
$(OBJ_DIR)/%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
@echo
#
# Rule to create a nicer preprocessed .i file from a .c file.
# Uses the Python script 'cpp_filter.py' (generated below) and
# GNU-indent on PATH.
#
%.i: %.c FORCE cpp_filter.py
$(CC) -E $(CFLAGS) $< | python cpp_filter.py | indent -st > $@
@echo
FORCE:
$(OBJ_DIR)/windump.res: $(MDEPEND) $(OBJ_DIR)/windump.rc
$(RC) $@ $(RCFLAGS) $(OBJ_DIR)/windump.rc
@echo
$(OBJ_DIR)/windump.rc: $(MDEPEND) version.c
@echo 'Generating $@...'
$(file > $@,$(WINDUMP_RC))
define WINDUMP_RC
/*
* windump.rc generated by $(COMMON_FILE).
* DO NOT EDIT!
*/
#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_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 <[email protected]>"
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
#
# @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)/* config.h cpp_filter.py
vclean realclean: clean tests_clean
- rm -f $(TARGETS) version.c .depend.Windows $(LINK_CRAP) vc1*.pdb
- rmdir $(OBJ_DIR)
tests_clean:
-cd ./tests; \
rm -f NEW/* DIFF/* .passed .failed failure-outputs.txt; \
rmdir NEW DIFF
REPLACE = sed -e 's/\(.*\)\.o: /\n$$(OBJ_DIR)\/\1.$$(O): /'
depend: config.h version.c
gcc -MM $(filter -I% -D%, $(CFLAGS)) $(SOURCES) | $(REPLACE) > .depend.Windows
#
# For cpp_filter.py used in '*.c -> *.i' rule.
#
define CPP_FILTER_PY
import sys, os
try:
import ntpath
except ImportError, 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
# print ("orig: \"%s\"" % line)
line = line.replace ("\\\\", "/")
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),
last_line = line
if empty_lines > 0:
sys.stderr.write ("Removed %d empty lines." % empty_lines)
endef
cpp_filter.py: $(COMMON_FILE)
@echo 'Generating $@...'
$(file > $@,#!/usr/env/python)
$(file >> $@,#)
$(file >> $@,# DO NOT EDIT! This file was generated automatically)
$(file >> $@,# from $(COMMON_FILE). Edit that file instead.)
$(file >> $@,#)
$(file >> $@,if 1:)
$(file >> $@,$(CPP_FILTER_PY))
CC = clang-cl
include ./Makefile.MSVC
#
# tcpdump/windump Makefile for MinGW 32/64-bit gcc
# By Gisle Vanem <[email protected]> 2003.
#
MAKE_FILE = $(firstword $(MAKEFILE_LIST))
#
# Options:
#
# Do a 'make -f Makefile.MinGW vclean' after changing any of these.
#
USE_AIRPCAP = 1
USE_DEBUG = 0
USE_PCH = 0
USE_LIBSMI = 0
USE_OPENSSL = 0
USE_STATIC_LIBPCAP = 0
#
# Target a X86 or X64 CPU.
# Say "make CPU=X64 -f Makefile.MinGW all" to build a
# 64-bit version of windump.exe
#
CPU ?= X86
OBJ_DIR = MinGW_obj
O = o
CC = gcc
RC = windres -D__MINGW32__
ifeq ($(CPU),x64)
RC += --target=pe-x86-64
else
RC += --target=pe-i386
endif
RC += -O COFF -I. -o
include Common.Windows
CFLAGS += -m$(BITS) -Wall -W -Wno-unused-but-set-variable -Wno-unused-function \
-Wno-strict-aliasing -Wno-type-limits -D_WIN32_WINNT=0x601
LDFLAGS = -m$(BITS)
ifeq ($(USE_DEBUG),1)
CFLAGS += -O0
else
CFLAGS += -O2 -g
LDFLAGS += -s
endif
LDFLAGS += -Wl,--print-map,--sort-common
ifeq ($(USE_STATIC_LIBPCAP),1)
ifeq ($(USER),gv)
EX_LIBS += $(PCAP_ROOT)/$(LIB_SUFFIX)libwpcap2_static.a
else
EX_LIBS += $(PCAP_ROOT)/$(LIB_SUFFIX)libwpcap_static.a
endif
else
ifeq ($(USER),gv)
EX_LIBS += $(PCAP_ROOT)/$(LIB_SUFFIX)libwpcap2.a
else
EX_LIBS += $(PCAP_ROOT)/$(LIB_SUFFIX)libwpcap.a
endif
endif
ifeq ($(USE_AIRPCAP),1)
CFLAGS += -I$(AIRPCAP_ROOT)/include
EX_LIBS += $(AIRPCAP_ROOT)/lib/libairpcap.a
endif
ifeq ($(USE_OPENSSL),1)
CFLAGS += -I$(OPENSSL_ROOT)/include
ifeq ($(CPU),X64)
EX_LIBS += $(OPENSSL_ROOT)/lib64/libcrypto.dll.a
else
EX_LIBS += $(OPENSSL_ROOT)/lib32/libcrypto.dll.a
endif
endif
ifeq ($(USE_LIBSMI),1)
CFLAGS += -I$(LIBSMI_ROOT)/lib
EX_LIBS += $(LIBSMI_ROOT)/win/libsmi.a
endif
ifeq ($(USER),gv)
EX_LIBS += -liphlpapi
endif
EX_LIBS += -lws2_32 -lversion
windump.exe: $(OBJECTS) $(OBJ_DIR)/windump.res
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(EX_LIBS) > $(@:.exe=.map)
@echo
ascii.exe: print-ascii.c
$(CC) -o $@ -DMAIN $(LDFLAGS) $(CFLAGS) $^ > $(@:.exe=.map)
@echo
espdecrypt.exe: espdecrypt.c
$(CC) -o $@ $(LDFLAGS) $(CFLAGS) -DDEBUG -I$(PCAP_ROOT)/bpf $^ $(EX_LIBS) > $(@:.exe=.map)
@echo
-include .depend.Windows
#
# tcpdump/windump Makefile for MSVC.
# NB! Needs GNU make.
#
# By Gisle Vanem <[email protected]> 2004 - 2017.
#
#
# Options:
#
# Do a 'make -f Makefile.MSVC vclean' after changing any of these.
#
MULTI_COMPILE = 0
USE_AIRPCAP = 1
USE_DEBUG = 0
USE_LIBSMI = 1
USE_REMOTE = 1
USE_OPENSSL = 1
USE_STATIC_LIBPCAP = 0
USE_PCAP_DEBUG = 2
#
# If this file is included from Makefile.clang
#
ifeq ($(CC),clang-cl)
OBJ_DIR = clang_obj
RC = rc -nologo -D__clang__ -Fo
#
# In case %CL is set, undefine it.
#
export CL=
else
OBJ_DIR = MSVC_obj
CC = cl
RC = rc -nologo -D_MSC_VER -Fo
endif
O = obj
LINK_CRAP = windump$(X64_SUFFIX).idb link.tmp
CFLAGS = -nologo -W4 -Zi -GF -D_WINSOCK_DEPRECATED_NO_WARNINGS
ifeq ($(CC),cl)
CFLAGS += -Gs # -arch:IA32
else
CFLAGS += -fms-compatibility
endif
LDFLAGS = -nologo -debug -subsystem:console \
-incremental:no -map -verbose -machine:$(CPU)
#
# These roots assumes "Visual-Studio 2017 Update" is used.
#
VC_ROOT = $(realpath $(VCHOME))
CRT_DIR = $(VC_ROOT)/lib/$(CPU)
CL_CC = $(VC_ROOT)/bin/HostX86/$(CPU)/cl.exe
CL_LINK = $(VC_ROOT)/bin/HostX86/$(CPU)/link.exe
ifeq ($(CC),clang-cl)
MULTI_COMPILE = 0
CL_CC = clang-cl
else
#
# The path for the CRT library (msvcrt.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))
endif
include Common.Windows
ifeq ($(CC),clang-cl)
ifeq ($(CPU),x64)
$(error 'x64' with 'clang-cl' is untested.)
endif
endif
ifeq ($(USE_DEBUG),1)
CFLAGS += -MDd -Od -Oi- -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_DEBUG),0)
LDFLAGS += -nodefaultlib:msvcrtd.lib
endif
ifeq ($(USE_AIRPCAP),1)
CFLAGS += -I$(AIRPCAP_ROOT)/include
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
ifeq ($(USER),gv)
# EX_LIBS += iphlpapi.lib
endif
ifneq ($(USER),gv)
EX_LIBS += $(PCAP_ROOT)/WinPcap/lib/$(LIB_SUBDIR)packet.lib
endif
ifeq ($(USE_STATIC_LIBPCAP),1)
EX_LIBS += advapi32.lib version.lib
endif
EX_LIBS += ws2_32.lib
#
# Compiling multiple .c-files (with -MP) is really much faster
# than the single rule in Common.Windows.
#
ifeq ($(MULTI_COMPILE),1)
$(OBJECTS): $(SOURCES)
$(CL_CC) -MP -FS $(CFLAGS) -Fo./$(OBJ_DIR)\\ -c $(SOURCES)
@echo
endif
windump$(X64_SUFFIX).exe: $(OBJECTS) $(OBJ_DIR)/windump.res
$(CL_LINK) $(LDFLAGS) -out:$@ $^ $(EX_LIBS) > link.tmp
cat link.tmp >> windump$(X64_SUFFIX).map
@echo
ascii.exe: print-ascii.c
$(CL_CC) -c -Fo./$(OBJ_DIR)/print-ascii-test.obj -DMAIN $(CFLAGS) $^
$(CL_LINK) -out:$@ $(LDFLAGS) $(OBJ_DIR)/print-ascii-test.obj ws2_32.lib > link.tmp
cat link.tmp >> ascii.map
@echo
espdecrypt.exe: espdecrypt.c
$(CL_CC) -c -Fo./$(OBJ_DIR)\\ -DDEBUG -Dstrncasecmp=strnicmp $(CFLAGS) -I$(PCAP_ROOT)/bpf $^
$(CL_LINK) -out:$@ $(LDFLAGS) $(OBJ_DIR)/espdecrypt.obj $(EX_LIBS) > link.tmp
cat link.tmp >> espdecrypt.map
@echo
$(OBJ_DIR)/%.obj: %.c
$(CL_CC) $(CFLAGS) -Fo./$@ -c $<
@echo
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