From 1f1ec28dcec025b811861c3f9789bec33f893671 Mon Sep 17 00:00:00 2001 From: Alon Bar-Lev Date: Sat, 15 Oct 2022 21:24:27 +0300 Subject: [PATCH] examples: build: support mingw build Currently cygwin build is supported, while cygwin is actually mingw, it has its own flags and settings to build native windows executables. This change adds minimal support for mingw build keeping backward compatibility. Changes: * Case sensitive paths, the SDK uses Include and Lib directories, while build had include and lib. * Move -mno-cygwin flag to CYGWIN_FLAGS so that it can be overridden, default remains the same. * Add LIBARCH make variable to be able to link against a specific variant of library. * Add missing winsock linkage when needed and convert existing to winsock2. Build using mingw-w64 is supported using: make CC=x86_64-w64-mingw32-gcc CYGWIN_FLAGS= LIBARCH=/x64 Signed-off-by: Alon Bar-Lev --- Examples-pcap/UDPdump/GNUmakefile | 7 ++++--- Examples-pcap/basic_dump/GNUmakefile | 5 +++-- Examples-pcap/basic_dump_ex/GNUmakefile | 5 +++-- Examples-pcap/iflist/GNUmakefile | 7 ++++--- Examples-pcap/pcap_filter/GNUmakefile | 5 +++-- Examples-pcap/pktdump_ex/GNUmakefile | 5 +++-- Examples-pcap/readfile/GNUmakefile | 5 +++-- Examples-pcap/readfile_ex/GNUmakefile | 5 +++-- Examples-pcap/savedump/GNUmakefile | 5 +++-- Examples-pcap/sendpack/GNUmakefile | 5 +++-- 10 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Examples-pcap/UDPdump/GNUmakefile b/Examples-pcap/UDPdump/GNUmakefile index 21f42ad9..1c7b9c93 100644 --- a/Examples-pcap/UDPdump/GNUmakefile +++ b/Examples-pcap/UDPdump/GNUmakefile @@ -1,11 +1,12 @@ # Makefile for cygwin gcc # Loris Degioanni -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = udpdump.o -LIBS = -L ${PCAP_PATH} -lwpcap -lwsock32 +LIBS = -L ${PCAP_PATH} -lwpcap -lws2_32 all: ${OBJS} ${CC} ${CFLAGS} -o udpdump.exe ${OBJS} ${LIBS} diff --git a/Examples-pcap/basic_dump/GNUmakefile b/Examples-pcap/basic_dump/GNUmakefile index e10ff285..61a8a031 100644 --- a/Examples-pcap/basic_dump/GNUmakefile +++ b/Examples-pcap/basic_dump/GNUmakefile @@ -1,8 +1,9 @@ # Makefile for cygwin gcc # Nate Lawson -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = basic_dump.o LIBS = -L ${PCAP_PATH} -lwpcap diff --git a/Examples-pcap/basic_dump_ex/GNUmakefile b/Examples-pcap/basic_dump_ex/GNUmakefile index 708acd4b..d1586232 100644 --- a/Examples-pcap/basic_dump_ex/GNUmakefile +++ b/Examples-pcap/basic_dump_ex/GNUmakefile @@ -1,8 +1,9 @@ # Makefile for cygwin gcc # Nate Lawson -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = basic_dump_ex.o LIBS = -L ${PCAP_PATH} -lwpcap diff --git a/Examples-pcap/iflist/GNUmakefile b/Examples-pcap/iflist/GNUmakefile index 30c70138..320a8d47 100644 --- a/Examples-pcap/iflist/GNUmakefile +++ b/Examples-pcap/iflist/GNUmakefile @@ -1,11 +1,12 @@ # Makefile for cygwin gcc # Nate Lawson -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = iflist.o -LIBS = -L ${PCAP_PATH} -lwpcap +LIBS = -L ${PCAP_PATH} -lwpcap -lws2_32 all: ${OBJS} ${CC} ${CFLAGS} -o iflist.exe ${OBJS} ${LIBS} diff --git a/Examples-pcap/pcap_filter/GNUmakefile b/Examples-pcap/pcap_filter/GNUmakefile index ca84d01a..d8f3c71a 100644 --- a/Examples-pcap/pcap_filter/GNUmakefile +++ b/Examples-pcap/pcap_filter/GNUmakefile @@ -1,8 +1,9 @@ # Makefile for cygwin gcc # Nate Lawson -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = pcap_filter.o LIBS = -L ${PCAP_PATH} -lwpcap diff --git a/Examples-pcap/pktdump_ex/GNUmakefile b/Examples-pcap/pktdump_ex/GNUmakefile index f649ce3c..e5b846e5 100644 --- a/Examples-pcap/pktdump_ex/GNUmakefile +++ b/Examples-pcap/pktdump_ex/GNUmakefile @@ -1,5 +1,6 @@ -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = pktdump_ex.o LIBS = -L ${PCAP_PATH} -lwpcap diff --git a/Examples-pcap/readfile/GNUmakefile b/Examples-pcap/readfile/GNUmakefile index fe4bae3a..35ba8dee 100644 --- a/Examples-pcap/readfile/GNUmakefile +++ b/Examples-pcap/readfile/GNUmakefile @@ -1,8 +1,9 @@ # Makefile for cygwin gcc # Nate Lawson -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = readfile.o LIBS = -L ${PCAP_PATH} -lwpcap diff --git a/Examples-pcap/readfile_ex/GNUmakefile b/Examples-pcap/readfile_ex/GNUmakefile index 34087211..f750dadd 100644 --- a/Examples-pcap/readfile_ex/GNUmakefile +++ b/Examples-pcap/readfile_ex/GNUmakefile @@ -1,8 +1,9 @@ # Makefile for cygwin gcc # Nate Lawson -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = readfile_ex.o LIBS = -L ${PCAP_PATH} -lwpcap diff --git a/Examples-pcap/savedump/GNUmakefile b/Examples-pcap/savedump/GNUmakefile index fd98a3ab..b6f0c77d 100644 --- a/Examples-pcap/savedump/GNUmakefile +++ b/Examples-pcap/savedump/GNUmakefile @@ -1,8 +1,9 @@ # Makefile for cygwin gcc # Nate Lawson -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = savedump.o LIBS = -L ${PCAP_PATH} -lwpcap diff --git a/Examples-pcap/sendpack/GNUmakefile b/Examples-pcap/sendpack/GNUmakefile index 54939a6f..f7b2695e 100644 --- a/Examples-pcap/sendpack/GNUmakefile +++ b/Examples-pcap/sendpack/GNUmakefile @@ -1,8 +1,9 @@ # Makefile for cygwin gcc # Nate Lawson -PCAP_PATH = ../../lib -CFLAGS = -g -O -mno-cygwin -I ../../include +CYGWIN_FLAGS = -mno-cygwin +PCAP_PATH = ../../Lib$(LIBARCH) +CFLAGS = -g -O $(CYGWIN_FLAGS) -I ../../Include OBJS = sendpack.o LIBS = -L ${PCAP_PATH} -lwpcap