mongoose/test/Makefile

270 lines
13 KiB
Makefile
Raw Normal View History

2024-04-19 18:28:13 -03:00
SRCS = mongoose.c unit_test.c packed_fs.c
HDRS = $(wildcard ../src/*.h) $(wildcard ../src/drivers/*.h)
2023-02-12 20:30:18 +00:00
DEFS ?= -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -DMG_ENABLE_SSI=1 -DMG_ENABLE_ASSERT=1
2022-09-22 10:34:38 +01:00
WARN ?= -pedantic -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef
OPTS ?= -O3 -g3
INCS ?= -Isrc -I.
2022-10-28 15:35:40 +01:00
SSL ?=
2021-07-26 11:00:37 +01:00
CWD ?= $(realpath $(CURDIR))
ROOT_DIR = $(realpath $(CWD)/..)
ENV ?= -e Tmp=. -e WINEDEBUG=-all
DOCKER_BIN ?= docker
DOCKER ?= $(DOCKER_BIN) run --platform linux/amd64 --rm $(ENV) -v $(ROOT_DIR):$(ROOT_DIR) -w $(CWD)
2022-05-23 15:27:19 +01:00
VCFLAGS = /nologo /W3 /O2 /MD /I. $(DEFS) $(TFLAGS)
2020-12-22 10:16:31 +00:00
IPV6 ?= 1
2022-09-22 21:05:30 +01:00
ASAN ?= -fsanitize=address,undefined,alignment -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common
ASAN_OPTIONS ?= detect_leaks=1
2024-04-19 18:28:13 -03:00
EXAMPLES := $(dir $(wildcard ../examples/*/Makefile))
2024-04-29 10:15:53 -03:00
EXAMPLES_QUICK := $(filter-out ../examples/micropython/, $(EXAMPLES))
EXAMPLES_MAC := $(filter-out ../examples/micropython/, $(EXAMPLES))
2024-04-19 18:28:13 -03:00
EXAMPLES_WIN := $(dir $(wildcard ../examples/device-dashboard/Makefile) $(wildcard ../examples/file-*/Makefile) $(wildcard ../examples/http-*/Makefile) $(wildcard ../examples/mqtt-*/Makefile) $(wildcard ../examples/websocket-*/Makefile) $(wildcard ../examples/webui-*/Makefile))
EXAMPLES_EMBEDDED := $(filter-out $(wildcard ../examples/zephyr/*/), $(dir $(wildcard ../examples/*/*/Makefile)))
2024-04-24 16:01:25 -03:00
REFPROJS := $(dir $(wildcard ../reference-projects/windows-macos-linux/*/Makefile))
TUTORIALS := $(dir $(wildcard ../tutorials/*/*/Makefile))
2024-04-29 11:23:00 -03:00
TUTORIALS_QUICK := $(filter-out ../tutorials/tcpip/pcap-driver/, $(TUTORIALS))
2024-04-29 10:15:53 -03:00
TUTORIALS_MAC := $(filter-out ../tutorials/tcpip/pcap-driver/ ../tutorials/tcpip/tap-driver/, $(TUTORIALS))
2024-04-29 11:23:00 -03:00
TUTORIALS_WIN := $(dir $(wildcard ../tutorials/http/file-*/Makefile) $(wildcard ../tutorials/http/http-*/Makefile) $(wildcard ../tutorials/mqtt/*/Makefile) $(wildcard ../tutorials/websocket/*/Makefile) $(wildcard ../tutorials/webui/*/Makefile))
PREFIX ?= /usr/local
2023-05-24 15:37:24 -03:00
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
2024-04-19 18:28:13 -03:00
VERSION ?= $(shell cut -d'"' -f2 ../src/version.h)
2023-02-12 20:30:18 +00:00
COMMON_CFLAGS ?= $(C_WARN) $(WARN) $(INCS) $(DEFS) -DMG_ENABLE_IPV6=$(IPV6) $(TFLAGS) -pthread
CFLAGS ?= $(OPTS) $(ASAN) $(COMMON_CFLAGS)
2022-09-03 13:36:08 +01:00
VALGRIND_CFLAGS ?= $(OPTS) $(COMMON_CFLAGS)
2023-02-12 20:30:18 +00:00
VALGRIND_RUN ?= valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --show-leak-kinds=all --leak-resolution=high --track-origins=yes --error-exitcode=1 --exit-on-first-error=yes --fair-sched=yes
2023-02-28 14:18:39 -03:00
.PHONY: clean_examples examples mip_test test valgrind
2022-09-22 10:34:38 +01:00
ifeq "$(findstring ++,$(CC))" ""
2022-09-22 13:42:17 +01:00
# $(CC) does not end with ++, i.e. we're using C. Apply C flags
2022-09-22 10:34:38 +01:00
C_WARN ?= -Wmissing-prototypes -Wstrict-prototypes
else
2022-09-22 13:42:17 +01:00
# $(CC) ends with ++, i.e. we're using C++. Apply C++ flags
2022-09-22 10:34:38 +01:00
C_WARN ?= -Wno-deprecated
endif
2020-12-05 11:26:32 +00:00
2024-05-16 10:56:51 -03:00
ifeq "$(SSL)" "OPENSSL"
ifeq "$(OPENSSL)" ""
CFLAGS += -DMG_TLS=MG_TLS_OPENSSL $(shell pkg-config openssl --cflags)
LDFLAGS += $(shell pkg-config openssl --libs)
else
CFLAGS += -DMG_TLS=MG_TLS_OPENSSL -I$(OPENSSL)/include
LDFLAGS += -L$(OPENSSL)/lib -lssl -lcrypto
endif
endif
2020-12-05 11:26:32 +00:00
ifeq "$(SSL)" "MBEDTLS"
2024-05-16 10:56:51 -03:00
ifeq "$(MBEDTLS)" ""
# Ubuntu 22.04 does not provide 'pc' files for MbedTLS (others may)
#CFLAGS += -DMG_TLS=MG_TLS_MBED $(shell pkg-config mbedtls --cflags) $(shell pkg-config mbedcrypto --cflags) $(shell pkg-config mbedx509 --cflags)
#LDFLAGS += $(shell pkg-config mbedtls --libs) $(shell pkg-config mbedcrypto --libs) $(shell pkg-config mbedx509 --libs)
CFLAGS += -DMG_TLS=MG_TLS_MBED -I/usr/include
LDFLAGS += -lmbedtls -lmbedcrypto -lmbedx509
else
2023-07-25 13:07:28 +01:00
CFLAGS += -DMG_TLS=MG_TLS_MBED -I$(MBEDTLS)/include -I/usr/include
2023-05-24 15:37:24 -03:00
LDFLAGS += -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509
2020-12-05 11:26:32 +00:00
endif
endif
ifeq "$(SSL)" "WOLFSSL"
2024-05-16 10:56:51 -03:00
# WolfSSL requires overriding the include path when used in OpenSSL compatibility mode (we do)
#ifeq "$(WOLFSSL)" ""
#CFLAGS += -DMG_TLS=MG_TLS_WOLFSSL -DEXTERNAL_OPTS_OPENVPN $(shell pkg-config openssl --cflags)
#LDFLAGS += $(shell pkg-config wolfssl --libs)
#else
WOLFSSL ?= $(shell pkg-config wolfssl --variable=prefix)
CFLAGS += -DMG_TLS=MG_TLS_WOLFSSL -DEXTERNAL_OPTS_OPENVPN -I$(WOLFSSL)/include -I$(WOLFSSL)/include/wolfssl
LDFLAGS += -L$(WOLFSSL)/lib -lwolfssl
2024-05-16 10:56:51 -03:00
#endif
endif
2024-03-25 08:34:05 +00:00
ifeq "$(SSL)" "BUILTIN"
CFLAGS += -DMG_TLS=MG_TLS_BUILTIN
endif
2022-10-31 10:40:34 +00:00
all:
2024-05-01 14:15:01 -03:00
$(MAKE) -C ../tutorials/http/http-server
2022-10-31 10:40:34 +00:00
tall: mg_prefix unamalgamated test mip_test arm examples vc98 vc17 vc22 mingw mingw++ fuzz
2020-12-05 11:26:32 +00:00
2024-07-22 17:14:10 -03:00
mip_test: mip_test.c mongoose.c mongoose.h packed_fs.c Makefile
$(CC) mip_test.c packed_fs.c $(CFLAGS) $(LDFLAGS) -o $@
2022-09-03 13:36:08 +01:00
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./$@
2024-07-22 17:14:10 -03:00
mip_tap_test: mip_tap_test.c mongoose.c mongoose.h packed_fs.c Makefile
$(CC) mip_tap_test.c packed_fs.c $(CFLAGS) $(LDFLAGS) -o $@
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./$@
2022-09-03 13:36:08 +01:00
2024-04-19 18:28:13 -03:00
packed_fs.c: Makefile data/ssi.h fuzz.c data/a.txt data/ca.pem certs/ca.crt certs/server.crt certs/server.key
$(CC) $(CFLAGS) pack.c -o pack
$(RUN) ./pack Makefile data/ssi.h fuzz.c data/a.txt data/range.txt data/ca.pem certs/ca.crt certs/server.crt certs/server.key certs/client.key certs/client.crt > $@
2021-07-26 09:05:34 +01:00
2020-12-05 11:26:32 +00:00
# Check that all external (exported) symbols have "mg_" prefix
mg_prefix: mongoose.c mongoose.h
2022-09-22 10:34:38 +01:00
$(CC) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T ' | grep -v 'mg_' ; test $$? = 1
2020-12-05 11:26:32 +00:00
musl: test
musl: ASAN =
musl: WARN += -Wno-sign-conversion
musl: CC = $(DOCKER) mdashnet/cc1 gcc
musl: RUN = $(DOCKER) mdashnet/cc1
2023-07-19 16:21:14 -03:00
# Make sure we can build from unamalgamated sources.
2023-10-13 06:32:12 -04:00
unamalgamated: CFLAGS += -DMG_ENABLE_MD5=1
2024-04-19 18:28:13 -03:00
unamalgamated: $(HDRS) Makefile packed_fs.c
$(CC) ../src/*.c packed_fs.c unit_test.c $(CFLAGS) $(LDFLAGS) -g -o unit_test
2021-07-26 11:00:37 +01:00
2022-09-25 10:19:17 +01:00
fuzz: ASAN = -fsanitize=fuzzer,signed-integer-overflow,address,undefined
2024-04-19 18:28:13 -03:00
fuzz: mongoose.c mongoose.h Makefile fuzz.c
$(CC) fuzz.c $(OPTS) $(WARN) $(INCS) $(TFLAGS) $(ASAN) -o fuzzer
2021-07-26 11:00:37 +01:00
$(RUN) ./fuzzer
2020-12-05 11:26:32 +00:00
2022-11-09 13:11:22 +00:00
FUZZDATA ?= /tmp/fuzzdata
2024-04-19 18:28:13 -03:00
fuzz2: mongoose.c mongoose.h Makefile fuzz.c
$(CC) fuzz.c -DMAIN $(OPTS) $(WARN) $(ASAN) $(INCS) -o fuzzer
2022-11-09 13:11:22 +00:00
$(RUN) ./fuzzer $(FUZZDATA)
2022-09-29 16:53:11 +01:00
2022-09-22 10:34:38 +01:00
test: Makefile mongoose.h $(SRCS)
$(CC) $(SRCS) $(CFLAGS) $(LDFLAGS) -o unit_test
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test
2020-12-05 11:26:32 +00:00
2022-06-10 12:14:42 +01:00
coverage: CFLAGS += -coverage
2020-12-05 11:26:32 +00:00
coverage: test
gcov -l -n *.gcno | sed '/^$$/d' | sed 'N;s/\n/ /'
gcov -t mongoose.c > mongoose.gcov
2020-12-05 11:26:32 +00:00
2020-12-18 11:47:56 +00:00
upload-coverage: coverage
curl -s https://codecov.io/bash | /bin/bash
2024-04-05 15:56:50 -03:00
valgrind: Makefile mongoose.h $(SRCS)
2022-09-22 10:34:38 +01:00
$(CC) $(SRCS) $(VALGRIND_CFLAGS) $(LDFLAGS) -g -o unit_test
$(VALGRIND_RUN) ./unit_test
2024-01-23 10:56:41 +00:00
misra:
cppcheck --addon=misra -DMG_ARCH=MG_ARCH_UNIX -DMG_ENABLE_PACKED_FS=1 -DMG_ENABLE_SSI=1 mongoose.c >/tmp/x 2>&1
cppcheck --addon=misra -DMG_ARCH=MG_ARCH_CUSTOM -DMG_ENABLE_LINES=1 -DTLS=MG_TLS_BUILTIN -DMG_ENABLE_TCPIP=1 mongoose.c >>/tmp/x 2>&1
cppcheck --addon=misra --clang -DMG_ENABLE_LINES=1 -DTLS=MG_TLS_BUILTIN -DMG_ENABLE_TCPIP=1 mongoose.c >>/tmp/x 2>&1
cppcheck --addon=misra --clang -DMG_ENABLE_LINES=1 -DMG_ENABLE_SSI=1 mongoose.c >>/tmp/x 2>&1
less /tmp/x
2022-10-31 10:40:34 +00:00
armhf: ASAN=
armhf: IPV6=0
armhf: CC = $(DOCKER) mdashnet/armhf cc
armhf: RUN = $(DOCKER) mdashnet/armhf
armhf: test
s390: ASAN=
s390: IPV6=0
s390: CC = $(DOCKER) mdashnet/s390 cc
s390: RUN = $(DOCKER) mdashnet/s390
s390: test
2024-03-12 14:03:29 -03:00
arm: DEFS += -DMG_ENABLE_POSIX_FS=0 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_TCPIP_DRIVER_INIT=0 -DMG_ARCH=MG_ARCH_NEWLIB
2021-07-26 11:00:37 +01:00
arm: mongoose.h $(SRCS)
2022-06-12 12:43:01 +01:00
$(DOCKER) mdashnet/armgcc arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb $(SRCS) $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) -o unit_test -nostartfiles --specs nosys.specs -e 0
2021-07-26 11:00:37 +01:00
2024-03-12 14:03:29 -03:00
riscv: DEFS += -DMG_ENABLE_POSIX_FS=0 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_TCPIP_DRIVER_INIT=0 -DMG_ARCH=MG_ARCH_NEWLIB
2021-07-26 11:00:37 +01:00
riscv: mongoose.h $(SRCS)
2022-06-12 12:43:01 +01:00
$(DOCKER) mdashnet/riscv riscv-none-elf-gcc -march=rv32imc -mabi=ilp32 $(SRCS) $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) -o unit_test
2021-07-26 11:00:37 +01:00
2021-07-30 13:19:20 +01:00
vc98: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/vc98 wine cl $(SRCS) $(VCFLAGS) /Fe$@.exe
2021-07-26 11:00:37 +01:00
$(DOCKER) mdashnet/vc98 wine $@.exe
2020-12-05 11:26:32 +00:00
2022-08-09 15:38:25 +01:00
vc17: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/vc17 wine64 cl $(SRCS) $(VCFLAGS) /Fe$@.exe
2022-08-09 15:38:25 +01:00
$(DOCKER) mdashnet/vc17 wine64 $@.exe
2020-12-05 11:26:32 +00:00
2022-05-23 15:27:19 +01:00
vc22: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/vc22 wine64 cl $(SRCS) $(VCFLAGS) /Fe$@.exe
2022-05-23 15:27:19 +01:00
$(DOCKER) mdashnet/vc22 wine64 $@.exe
2021-07-30 13:19:20 +01:00
mingw: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/mingw x86_64-w64-mingw32-gcc $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -lbcrypt -o $@.exe
2022-06-07 00:25:15 +01:00
$(DOCKER) mdashnet/mingw wine64 $@.exe
2020-12-25 19:24:51 +00:00
2021-07-30 13:19:20 +01:00
mingw++: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/mingw x86_64-w64-mingw32-g++ $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -lbcrypt -o $@.exe
2020-12-25 19:24:51 +00:00
linux-libs: CFLAGS += -fPIC
2023-05-24 15:37:24 -03:00
linux-libs: LDFLAGS += -Wl,-soname,libmongoose.so.$(VERSION)
linux-libs: mongoose.o
2021-09-30 13:34:55 +01:00
$(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION)
$(AR) rcs libmongoose.a mongoose.o
install: linux-libs
2023-05-24 15:37:24 -03:00
install -Dm644 libmongoose.a libmongoose.so.$(VERSION) $(DESTDIR)$(LIBDIR)
ln -s libmongoose.so.$(VERSION) $(DESTDIR)$(LIBDIR)/libmongoose.so
install -Dm644 mongoose.h $(DESTDIR)$(INCLUDEDIR)/mongoose.h
uninstall:
2023-05-24 15:37:24 -03:00
rm -rf $(DESTDIR)$(LIBDIR)/libmongoose.a $(DESTDIR)$(LIBDIR)/libmongoose.so.$(VERSION) $(DESTDIR)$(INCLUDEDIR)/mongoose.h $(DESTDIR)$(LIBDIR)/libmongoose.so
2024-04-20 18:24:41 +01:00
mongoose.c: Makefile $(wildcard ../src/*.c) $(wildcard ../src/drivers/*.c)
2024-04-19 18:28:13 -03:00
cd .. && (export LC_ALL=C ; cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.c src/drivers/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@
2020-12-05 11:26:32 +00:00
mongoose.h: $(HDRS) Makefile
2024-10-23 10:02:03 -03:00
cd .. && (cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_ft.h src/net_lwip.h src/net_rl.h src/config.h src/str.h src/queue.h src/fmt.h src/printf.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/sha256.h src/tls_x25519.h src/tls_aes128.h src/tls_uecc.h src/tls_chacha20.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/ota.h src/flash.h src/net_builtin.h src/profile.h src/drivers/*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
2023-02-28 14:18:39 -03:00
2024-04-24 16:01:25 -03:00
clean: clean_examples clean_refprojs clean_tutorials clean_examples_embedded
2024-05-07 14:56:48 -03:00
rm -rf $(PROG) *.exe *.o *.dSYM *_test ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt crash-* packed_fs.c pack
2023-02-28 14:18:39 -03:00
#find examples -maxdepth 3 -name zephyr -prune -o -name Makefile -print | xargs dirname | xargs -n1 make clean -C
2024-04-24 16:01:25 -03:00
examples:
@for X in $(EXAMPLES); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
clean_examples:
for X in $(EXAMPLES); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
examples_essential:
@for X in $(EXAMPLES_QUICK); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
clean_examples_essential:
for X in $(EXAMPLES_QUICK); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
examples_mac:
for X in $(EXAMPLES_MAC); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
clean_examples_mac:
for X in $(EXAMPLES_MAC); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
examples_win:
$(foreach X, $(EXAMPLES_WIN), $(MAKE) -C $(X) example &)
clean_examples_win:
$(foreach X, $(EXAMPLES_WIN), $(MAKE) -C $(X) clean &)
refprojs:
@for X in $(REFPROJS); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
clean_refprojs:
for X in $(REFPROJS); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
refprojs_win:
$(foreach X, $(REFPROJS), $(MAKE) -C $(X) example.exe &)
clean_refprojs_win:
$(foreach X, $(REFPROJS), $(MAKE) -C $(X) clean &)
tutorials:
@for X in $(TUTORIALS); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
clean_tutorials:
for X in $(TUTORIALS); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
tutorials_essential:
@for X in $(TUTORIALS_QUICK); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
clean_tutorials_essential:
for X in $(TUTORIALS_QUICK); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
tutorials_mac:
@for X in $(TUTORIALS_MAC); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
clean_tutorials_mac:
for X in $(TUTORIALS_MAC); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
tutorials_win:
$(foreach X, $(TUTORIALS_WIN), $(MAKE) -C $(X) example &)
clean_tutorials_win:
$(foreach X, $(TUTORIALS_WIN), $(MAKE) -C $(X) clean &)
examples_embedded:
@for X in $(EXAMPLES_EMBEDDED); do test -f $$X/Makefile || continue; $(MAKE) -C $$X build || exit 1; done
clean_examples_embedded:
2023-02-28 14:18:39 -03:00
for X in $(EXAMPLES_EMBEDDED); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done