mongoose/Makefile

107 lines
4.8 KiB
Makefile
Raw Normal View History

2020-12-05 19:26:32 +08:00
SRCS = $(wildcard src/*.c)
HDRS = $(wildcard src/*.h)
DEFS ?= -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES -DMG_ENABLE_DIRECTORY_LISTING=1 -DMG_ENABLE_SSI=1
2020-12-05 19:26:32 +08:00
CFLAGS ?= -W -Wall -Werror -Isrc -I. -O0 -g $(DEFS) $(TFLAGS) $(EXTRA)
SSL ?= MBEDTLS
CDIR ?= $(realpath $(CURDIR))
VC98 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc98
VC2017 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc2017
2020-12-26 03:24:51 +08:00
MINGW = docker run --rm -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/mingw
2020-12-05 19:26:32 +08:00
GCC = docker run --rm -v $(CDIR):$(CDIR) -w $(CDIR) mdashnet/cc2
VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS)
2020-12-07 07:19:56 +08:00
CLANG ?= clang # /usr/local/opt/llvm\@9/bin/clang
2020-12-22 18:16:31 +08:00
IPV6 ?= 1
2020-12-07 07:19:56 +08:00
ASAN_OPTIONS ?=
2020-12-05 19:26:32 +08:00
EXAMPLES := $(wildcard examples/*)
EXAMPLE_TARGET ?= example
2020-12-07 16:54:58 +08:00
.PHONY: ex test
2020-12-05 19:26:32 +08:00
ifeq "$(SSL)" "MBEDTLS"
2020-12-08 02:52:40 +08:00
MBEDTLS_DIR ?= $(shell brew --cellar mbedtls)
MBEDTLS_VER ?= $(shell brew info mbedtls --json | jq -j .[0].installed[0].version)
MBEDTLS ?= $(MBEDTLS_DIR)/$(MBEDTLS_VER)
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLS)/include -I/usr/include
LDFLAGS ?= -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509
2020-12-05 19:26:32 +08:00
endif
ifeq "$(SSL)" "OPENSSL"
2020-12-21 05:50:46 +08:00
OPENSSL_DIR ?= $(shell brew --cellar openssl)
OPENSSL_VER ?= $(shell brew info openssl --json | jq -j .[0].installed[0].version)
OPENSSL ?= $(OPENSSL_DIR)/$(OPENSSL_VER)
CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include
LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto
2020-12-05 19:26:32 +08:00
endif
2020-12-26 03:24:51 +08:00
all: mg_prefix test test++ ex vc98 vc2017 mingw mingw++ linux linux++ infer fuzz
2020-12-05 19:26:32 +08:00
2020-12-07 09:27:44 +08:00
ex:
@for X in $(EXAMPLES); do $(MAKE) -C $$X $(EXAMPLE_TARGET); done
2020-12-05 19:26:32 +08:00
# Check that all external (exported) symbols have "mg_" prefix
mg_prefix: mongoose.c mongoose.h
$(CLANG) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T' | grep -v 'mg_' ; test $$? = 1
# C++ build
2021-03-17 20:22:19 +08:00
test++: CLANG = g++ -Wno-deprecated -Wno-missing-field-initializers
2020-12-07 11:47:37 +08:00
test++: unamalgamated
2020-12-05 19:26:32 +08:00
# Make sure we can build from an unamalgamated sources
unamalgamated: $(SRCS) $(HDRS) Makefile
2020-12-05 19:34:58 +08:00
$(CLANG) src/*.c test/unit_test.c $(CFLAGS) $(LDFLAGS) -g -o unit_test
2020-12-05 19:26:32 +08:00
2020-12-05 19:34:58 +08:00
fuzz: mongoose.c mongoose.h Makefile test/fuzz.c
2020-12-14 17:31:23 +08:00
$(CLANG) mongoose.c test/fuzz.c $(CFLAGS) -DMG_ENABLE_LINES -DMG_ENABLE_LOG=0 -fsanitize=fuzzer,signed-integer-overflow,address $(LDFLAGS) -g -o fuzzer
2020-12-05 19:26:32 +08:00
$(DEBUGGER) ./fuzzer
2020-12-07 07:19:56 +08:00
# make CLANG=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1
2020-12-22 18:16:31 +08:00
test: CFLAGS += -DMG_ENABLE_IPV6=$(IPV6) -fsanitize=address#,undefined
2020-12-07 13:46:47 +08:00
test: mongoose.c mongoose.h Makefile test/unit_test.c
2020-12-05 19:34:58 +08:00
$(CLANG) mongoose.c test/unit_test.c $(CFLAGS) -coverage $(LDFLAGS) -g -o unit_test
2020-12-07 07:19:56 +08:00
ASAN_OPTIONS=$(ASAN_OPTIONS) $(DEBUGGER) ./unit_test
2020-12-05 19:26:32 +08:00
coverage: test
gcov -l -n *.gcno | sed '/^$$/d' | sed 'N;s/\n/ /'
2020-12-12 06:58:50 +08:00
gcov mongoose.gcno >/dev/null
2020-12-05 19:26:32 +08:00
2020-12-18 19:47:56 +08:00
upload-coverage: coverage
curl -s https://codecov.io/bash | /bin/bash
2020-12-05 19:26:32 +08:00
infer:
2020-12-05 19:34:58 +08:00
infer run -- cc test/unit_test.c -c -W -Wall -Werror -Isrc -I. -O2 -DMG_ENABLE_MBEDTLS=1 -DMG_ENABLE_LINES -I/usr/local/Cellar/mbedtls/2.23.0/include -DMG_ENABLE_IPV6=1 -g -o /dev/null
2020-12-05 19:26:32 +08:00
#vc98: VCFLAGS += -DMG_ENABLE_IPV6=1
2020-12-07 13:46:47 +08:00
vc98: Makefile mongoose.c mongoose.h test/unit_test.c
2020-12-05 19:34:58 +08:00
$(VC98) wine cl mongoose.c test/unit_test.c $(VCFLAGS) ws2_32.lib /Fe$@.exe
2020-12-05 19:26:32 +08:00
$(VC98) wine $@.exe
2020-12-22 17:44:59 +08:00
#vc2017: VCFLAGS += -DMG_ENABLE_IPV6=1
2020-12-07 13:46:47 +08:00
vc2017: Makefile mongoose.c mongoose.h test/unit_test.c
2020-12-05 19:34:58 +08:00
$(VC2017) wine64 cl mongoose.c test/unit_test.c $(VCFLAGS) ws2_32.lib /Fe$@.exe
2020-12-05 19:26:32 +08:00
$(VC2017) wine64 $@.exe
2020-12-26 03:24:51 +08:00
mingw: Makefile mongoose.c mongoose.h test/unit_test.c
$(MINGW) i686-w64-mingw32-gcc mongoose.c test/unit_test.c -W -Wall -Werror -I. $(DEFS) -lwsock32 -o test.exe
$(VC98) wine test.exe
mingw++: Makefile mongoose.c mongoose.h test/unit_test.c
$(MINGW) i686-w64-mingw32-g++ mongoose.c test/unit_test.c -W -Wall -Werror -I. $(DEFS) -lwsock32 -o test.exe
# Note: for some reason, a binary built with mingw g++, fails to run
2020-12-22 18:16:31 +08:00
#linux: CFLAGS += -DMG_ENABLE_IPV6=$(IPV6)
linux: CFLAGS += -fsanitize=address,undefined
2020-12-07 13:46:47 +08:00
linux: Makefile mongoose.c mongoose.h test/unit_test.c
2020-12-07 11:47:37 +08:00
$(GCC) $(CC) mongoose.c test/unit_test.c $(CFLAGS) $(LDFLAGS) -o unit_test_gcc
2020-12-05 19:26:32 +08:00
$(GCC) ./unit_test_gcc
2021-03-17 20:22:19 +08:00
linux++: CC = g++ -Wno-missing-field-initializers
2020-12-07 11:47:37 +08:00
linux++: linux
2020-12-05 19:26:32 +08:00
mongoose.c: $(SRCS) Makefile
(cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/private.h src/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@
mongoose.h: $(HDRS) Makefile
(cat src/license.h src/version.h ; cat src/arch.h src/arch_*.h src/config.h src/str.h src/log.h src/timer.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/ws.h src/sntp.h src/mqtt.h src/dns.h | sed -e 's,#include ".*,,' -e 's,^#pragma once,,')> $@
2020-12-05 19:26:32 +08:00
clean: EXAMPLE_TARGET = clean
2020-12-07 11:47:37 +08:00
clean: ex
2020-12-11 21:16:51 +08:00
rm -rf $(PROG) *.o *.dSYM unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt crash-*