2021-07-26 16:05:34 +08:00
|
|
|
SRCS = mongoose.c test/unit_test.c test/packed_fs.c
|
2023-02-08 05:16:42 +08:00
|
|
|
HDRS = $(wildcard src/*.h) $(wildcard src/tcpip/*.h)
|
2023-02-13 04:30:18 +08: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 17:34:38 +08:00
|
|
|
WARN ?= -pedantic -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef
|
2021-05-29 01:30:42 +08:00
|
|
|
OPTS ?= -O3 -g3
|
|
|
|
INCS ?= -Isrc -I.
|
2022-10-28 22:35:40 +08:00
|
|
|
SSL ?=
|
2021-07-26 18:00:37 +08:00
|
|
|
CWD ?= $(realpath $(CURDIR))
|
2022-06-30 00:02:37 +08:00
|
|
|
ENV ?= -e Tmp=. -e WINEDEBUG=-all
|
2022-08-26 21:19:13 +08:00
|
|
|
DOCKER ?= docker run --platform linux/amd64 --rm $(ENV) -v $(CWD):$(CWD) -w $(CWD)
|
2022-05-23 22:27:19 +08:00
|
|
|
VCFLAGS = /nologo /W3 /O2 /MD /I. $(DEFS) $(TFLAGS)
|
2020-12-22 18:16:31 +08:00
|
|
|
IPV6 ?= 1
|
2022-09-23 04:05:30 +08:00
|
|
|
ASAN ?= -fsanitize=address,undefined,alignment -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common
|
2022-01-23 14:10:14 +08:00
|
|
|
ASAN_OPTIONS ?= detect_leaks=1
|
2023-01-03 02:16:50 +08:00
|
|
|
EXAMPLES := $(dir $(wildcard examples/*/Makefile))
|
2023-03-01 01:04:02 +08: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))
|
2021-06-02 08:09:55 +08:00
|
|
|
PREFIX ?= /usr/local
|
2021-09-30 20:34:55 +08:00
|
|
|
VERSION ?= $(shell cut -d'"' -f2 src/version.h)
|
2023-02-13 04:30:18 +08:00
|
|
|
COMMON_CFLAGS ?= $(C_WARN) $(WARN) $(INCS) $(DEFS) -DMG_ENABLE_IPV6=$(IPV6) $(TFLAGS) -pthread
|
|
|
|
CFLAGS ?= $(OPTS) $(ASAN) $(COMMON_CFLAGS)
|
2022-09-03 20:36:08 +08:00
|
|
|
VALGRIND_CFLAGS ?= $(OPTS) $(COMMON_CFLAGS)
|
2023-02-13 04:30:18 +08: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
|
2022-09-22 17:34:38 +08:00
|
|
|
.PHONY: examples test valgrind mip_test
|
|
|
|
|
|
|
|
ifeq "$(findstring ++,$(CC))" ""
|
2022-09-22 20:42:17 +08:00
|
|
|
# $(CC) does not end with ++, i.e. we're using C. Apply C flags
|
2022-09-22 17:34:38 +08:00
|
|
|
C_WARN ?= -Wmissing-prototypes -Wstrict-prototypes
|
|
|
|
else
|
2022-09-22 20:42:17 +08:00
|
|
|
# $(CC) ends with ++, i.e. we're using C++. Apply C++ flags
|
2022-09-22 17:34:38 +08:00
|
|
|
C_WARN ?= -Wno-deprecated
|
|
|
|
endif
|
2020-12-05 19:26:32 +08:00
|
|
|
|
|
|
|
ifeq "$(SSL)" "MBEDTLS"
|
2022-01-24 10:20:45 +08:00
|
|
|
MBEDTLS ?= /usr/local
|
2021-07-14 00:28:07 +08:00
|
|
|
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLS)/include -I/usr/include
|
2020-12-08 02:52:40 +08:00
|
|
|
LDFLAGS ?= -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509
|
2020-12-05 19:26:32 +08:00
|
|
|
endif
|
2022-09-03 20:36:08 +08:00
|
|
|
|
2020-12-05 19:26:32 +08:00
|
|
|
ifeq "$(SSL)" "OPENSSL"
|
2022-01-24 10:20:45 +08:00
|
|
|
OPENSSL ?= /usr/local
|
2021-07-14 00:28:07 +08:00
|
|
|
CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include
|
2020-12-21 05:50:46 +08:00
|
|
|
LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto
|
2020-12-05 19:26:32 +08:00
|
|
|
endif
|
|
|
|
|
2022-10-31 18:40:34 +08:00
|
|
|
all:
|
|
|
|
$(MAKE) -C examples/http-server
|
|
|
|
|
|
|
|
tall: mg_prefix unamalgamated test mip_test arm examples vc98 vc17 vc22 mingw mingw++ fuzz
|
2020-12-05 19:26:32 +08:00
|
|
|
|
2022-12-19 19:43:25 +08:00
|
|
|
mip_test: test/mip_test.c mongoose.c mongoose.h Makefile mip_tap_test
|
2022-09-23 04:05:30 +08:00
|
|
|
$(CC) test/mip_test.c $(INCS) $(WARN) $(OPTS) $(C_WARN) $(ASAN) -o $@
|
2022-09-03 20:36:08 +08:00
|
|
|
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./$@
|
2022-12-03 00:40:46 +08:00
|
|
|
|
|
|
|
mip_tap_test: test/mip_tap_test.c mongoose.c mongoose.h Makefile
|
|
|
|
$(CC) test/mip_tap_test.c $(INCS) $(WARN) $(OPTS) $(C_WARN) $(ASAN) -o $@
|
|
|
|
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./$@
|
2022-09-03 20:36:08 +08:00
|
|
|
|
2021-07-29 21:21:20 +08:00
|
|
|
examples:
|
2022-01-27 20:10:03 +08:00
|
|
|
@for X in $(EXAMPLES); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
|
2020-12-05 19:26:32 +08:00
|
|
|
|
2023-03-01 01:04:02 +08:00
|
|
|
examples_win:
|
|
|
|
$(foreach X, $(EXAMPLES_WIN), $(MAKE) -C $(X) example &)
|
|
|
|
clean_examples_win:
|
|
|
|
$(foreach X, $(EXAMPLES_WIN), $(MAKE) -C $(X) clean &)
|
|
|
|
|
2022-03-03 01:12:42 +08:00
|
|
|
test/packed_fs.c: Makefile src/ssi.h test/fuzz.c test/data/a.txt
|
2021-07-30 20:19:20 +08:00
|
|
|
$(CC) $(CFLAGS) test/pack.c -o pack
|
2022-08-26 21:19:13 +08:00
|
|
|
$(RUN) ./pack Makefile src/ssi.h test/fuzz.c test/data/a.txt test/data/range.txt > $@
|
2021-07-26 16:05:34 +08:00
|
|
|
|
2022-09-03 20:36:08 +08:00
|
|
|
DIR ?= test/data
|
|
|
|
OUT ?= packed_fs.c
|
2022-02-15 01:44:43 +08:00
|
|
|
mkfs:
|
|
|
|
$(CC) $(CFLAGS) test/pack.c -o pack
|
2022-08-26 21:19:13 +08:00
|
|
|
$(RUN) ./pack -s $(DIR) `find $(DIR) -type f` > $(OUT)
|
2022-02-15 01:44:43 +08:00
|
|
|
# find $(DIR) -type f | sed -e s,^$(DIR),,g -e s,^/,,g
|
|
|
|
|
2020-12-05 19:26:32 +08:00
|
|
|
# Check that all external (exported) symbols have "mg_" prefix
|
|
|
|
mg_prefix: mongoose.c mongoose.h
|
2022-09-22 17:34:38 +08:00
|
|
|
$(CC) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T ' | grep -v 'mg_' ; test $$? = 1
|
2020-12-05 19:26:32 +08:00
|
|
|
|
2022-03-30 16:06:00 +08:00
|
|
|
musl: test
|
|
|
|
musl: ASAN =
|
|
|
|
musl: WARN += -Wno-sign-conversion
|
|
|
|
musl: CC = $(DOCKER) mdashnet/cc1 gcc
|
2022-08-26 21:19:13 +08:00
|
|
|
musl: RUN = $(DOCKER) mdashnet/cc1
|
2022-03-30 16:06:00 +08:00
|
|
|
|
2020-12-05 19:26:32 +08:00
|
|
|
# Make sure we can build from an unamalgamated sources
|
2021-09-14 19:27:02 +08:00
|
|
|
unamalgamated: $(HDRS) Makefile test/packed_fs.c
|
|
|
|
$(CC) src/*.c test/packed_fs.c test/unit_test.c $(CFLAGS) $(LDFLAGS) -g -o unit_test
|
2021-07-26 18:00:37 +08:00
|
|
|
|
2022-09-25 17:19:17 +08:00
|
|
|
fuzz: ASAN = -fsanitize=fuzzer,signed-integer-overflow,address,undefined
|
2022-09-22 17:34:38 +08:00
|
|
|
fuzz: mongoose.c mongoose.h Makefile test/fuzz.c
|
2022-09-30 18:44:50 +08:00
|
|
|
$(CC) test/fuzz.c $(OPTS) $(WARN) $(INCS) $(TFLAGS) $(ASAN) -o fuzzer
|
2021-07-26 18:00:37 +08:00
|
|
|
$(RUN) ./fuzzer
|
2020-12-05 19:26:32 +08:00
|
|
|
|
2022-11-09 21:11:22 +08:00
|
|
|
FUZZDATA ?= /tmp/fuzzdata
|
2022-09-29 23:53:11 +08:00
|
|
|
fuzz2: mongoose.c mongoose.h Makefile test/fuzz.c
|
2022-09-30 02:31:52 +08:00
|
|
|
$(CC) test/fuzz.c -DMAIN $(OPTS) $(WARN) $(ASAN) $(INCS) -o fuzzer
|
2022-11-09 21:11:22 +08:00
|
|
|
$(RUN) ./fuzzer $(FUZZDATA)
|
2022-09-29 23:53:11 +08:00
|
|
|
|
2022-09-22 17:34:38 +08:00
|
|
|
test: Makefile mongoose.h $(SRCS)
|
|
|
|
$(CC) $(SRCS) $(CFLAGS) $(LDFLAGS) -o unit_test
|
2022-03-18 16:52:54 +08:00
|
|
|
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test
|
2020-12-05 19:26:32 +08:00
|
|
|
|
2022-06-10 19:14:42 +08:00
|
|
|
coverage: CFLAGS += -coverage
|
2020-12-05 19:26:32 +08:00
|
|
|
coverage: test
|
|
|
|
gcov -l -n *.gcno | sed '/^$$/d' | sed 'N;s/\n/ /'
|
2022-03-22 20:46:55 +08:00
|
|
|
gcov -t mongoose.c > mongoose.gcov
|
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
|
|
|
|
|
2022-09-22 17:34:38 +08:00
|
|
|
valgrind: Makefile mongoose.h mongoose.c
|
|
|
|
$(CC) $(SRCS) $(VALGRIND_CFLAGS) $(LDFLAGS) -g -o unit_test
|
|
|
|
$(VALGRIND_RUN) ./unit_test
|
2022-03-18 16:52:54 +08:00
|
|
|
|
2022-10-31 18:40:34 +08: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
|
|
|
|
|
2023-02-08 05:16:42 +08:00
|
|
|
arm: DEFS += -DMG_ENABLE_FILE=0 -DMG_ENABLE_TCPIP=1 -DMG_ARCH=MG_ARCH_NEWLIB
|
2021-07-26 18:00:37 +08:00
|
|
|
arm: mongoose.h $(SRCS)
|
2022-06-12 19:43:01 +08: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 18:00:37 +08:00
|
|
|
|
2023-02-08 05:16:42 +08:00
|
|
|
riscv: DEFS += -DMG_ENABLE_FILE=0 -DMG_ENABLE_TCPIP=1 -DMG_ARCH=MG_ARCH_NEWLIB
|
2021-07-26 18:00:37 +08:00
|
|
|
riscv: mongoose.h $(SRCS)
|
2022-06-12 19:43:01 +08:00
|
|
|
$(DOCKER) mdashnet/riscv riscv-none-elf-gcc -march=rv32imc -mabi=ilp32 $(SRCS) $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) -o unit_test
|
2021-07-26 18:00:37 +08:00
|
|
|
|
2021-07-30 20:19:20 +08:00
|
|
|
vc98: Makefile mongoose.h $(SRCS)
|
|
|
|
$(DOCKER) mdashnet/vc98 wine cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
|
2021-07-26 18:00:37 +08:00
|
|
|
$(DOCKER) mdashnet/vc98 wine $@.exe
|
2020-12-05 19:26:32 +08:00
|
|
|
|
2022-08-09 22:38:25 +08:00
|
|
|
vc17: Makefile mongoose.h $(SRCS)
|
|
|
|
$(DOCKER) mdashnet/vc17 wine64 cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
|
|
|
|
$(DOCKER) mdashnet/vc17 wine64 $@.exe
|
2020-12-05 19:26:32 +08:00
|
|
|
|
2022-05-23 22:27:19 +08:00
|
|
|
vc22: Makefile mongoose.h $(SRCS)
|
|
|
|
$(DOCKER) mdashnet/vc22 wine64 cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
|
|
|
|
$(DOCKER) mdashnet/vc22 wine64 $@.exe
|
|
|
|
|
2021-07-30 20:19:20 +08:00
|
|
|
mingw: Makefile mongoose.h $(SRCS)
|
2022-06-07 07:25:15 +08:00
|
|
|
$(DOCKER) mdashnet/mingw x86_64-w64-mingw32-gcc $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -o $@.exe
|
|
|
|
$(DOCKER) mdashnet/mingw wine64 $@.exe
|
2020-12-26 03:24:51 +08:00
|
|
|
|
2022-11-11 16:50:57 +08:00
|
|
|
arduino: ENV = -v $(CWD)/arduino:/root
|
|
|
|
arduino:
|
|
|
|
curl -sL http://downloads.arduino.cc/arduino-1.8.19-linux64.tar.xz | unxz | tar -xf -
|
|
|
|
mv arduino-* $@
|
|
|
|
$(DOCKER) mdashnet/cc2 ./arduino/arduino --pref "boardsmanager.additional.urls=https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json" --save-prefs
|
|
|
|
$(DOCKER) mdashnet/cc2 ./arduino/arduino --pref "compiler.warning_level=all" --save-prefs
|
|
|
|
$(DOCKER) mdashnet/cc2 ./arduino/arduino --install-boards Seeeduino:samd
|
|
|
|
|
|
|
|
arduino-xiao: ENV = -v $(CWD)/arduino:/root
|
|
|
|
arduino-xiao: arduino
|
|
|
|
rm -rf tmp; mkdir tmp
|
|
|
|
cp examples/arduino/w5500/w5500.ino tmp/tmp.ino
|
|
|
|
cp mongoose.c mongoose.h examples/arduino/w5500/mongoose_custom.h tmp/
|
|
|
|
$(DOCKER) mdashnet/cc2 ./arduino/arduino --verbose --verify --board Seeeduino:samd:seeed_XIAO_m0 tmp/tmp.ino
|
|
|
|
|
2021-07-30 20:19:20 +08:00
|
|
|
mingw++: Makefile mongoose.h $(SRCS)
|
2022-06-07 07:25:15 +08:00
|
|
|
$(DOCKER) mdashnet/mingw x86_64-w64-mingw32-g++ $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -o $@.exe
|
2020-12-26 03:24:51 +08:00
|
|
|
|
2021-06-02 08:09:55 +08:00
|
|
|
linux-libs: CFLAGS += -fPIC
|
|
|
|
linux-libs: mongoose.o
|
2021-09-30 20:34:55 +08:00
|
|
|
$(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION)
|
2021-06-02 08:09:55 +08:00
|
|
|
$(AR) rcs libmongoose.a mongoose.o
|
|
|
|
|
|
|
|
install: linux-libs
|
2021-09-30 20:34:55 +08:00
|
|
|
install -Dm644 libmongoose.a libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib
|
|
|
|
ln -s libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libmongoose.so
|
2021-07-01 03:46:58 +08:00
|
|
|
install -Dm644 mongoose.h $(DESTDIR)$(PREFIX)/include/mongoose.h
|
2021-06-02 08:09:55 +08:00
|
|
|
|
|
|
|
uninstall:
|
2021-09-30 20:34:55 +08:00
|
|
|
rm -rf $(DESTDIR)$(PREFIX)/lib/libmongoose.a $(DESTDIR)$(PREFIX)/lib/libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/include/mongoose.h $(DESTDIR)$(PREFIX)/lib/libmongoose.so
|
2021-06-02 08:09:55 +08:00
|
|
|
|
2023-02-08 05:16:42 +08:00
|
|
|
mongoose.c: Makefile $(wildcard src/*.c) $(wildcard src/tcpip/*.c)
|
|
|
|
(cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.c src/tcpip/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@
|
2020-12-05 19:26:32 +08:00
|
|
|
|
|
|
|
mongoose.h: $(HDRS) Makefile
|
2023-02-08 23:00:04 +08:00
|
|
|
(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_*.h src/config.h src/str.h src/queue.h src/fmt.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/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/tcpip/tcpip.h src/tcpip/driver_*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
|
2020-12-05 19:26:32 +08:00
|
|
|
|
2021-07-29 21:21:20 +08:00
|
|
|
clean:
|
2022-11-11 16:50:57 +08: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-* test/packed_fs.c pack arduino tmp
|
2023-01-20 22:19:20 +08:00
|
|
|
find examples -maxdepth 3 -name zephyr -prune -o -name Makefile -print | xargs dirname | xargs -n1 make clean -C
|