2021-07-26 09:05:34 +01:00
|
|
|
SRCS = mongoose.c test/unit_test.c test/packed_fs.c
|
2020-12-05 11:26:32 +00:00
|
|
|
HDRS = $(wildcard src/*.h)
|
2021-08-04 11:38:32 +01:00
|
|
|
DEFS ?= -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1
|
2021-12-21 18:16:12 +00:00
|
|
|
WARN ?= -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef
|
2021-05-28 18:30:42 +01:00
|
|
|
OPTS ?= -O3 -g3
|
|
|
|
INCS ?= -Isrc -I.
|
2020-12-05 11:26:32 +00:00
|
|
|
SSL ?= MBEDTLS
|
2021-07-26 11:00:37 +01:00
|
|
|
CWD ?= $(realpath $(CURDIR))
|
2021-07-26 18:18:29 +01:00
|
|
|
DOCKER ?= docker run --rm -e Tmp=. -e WINEDEBUG=-all -v $(CWD):$(CWD) -w $(CWD)
|
2020-12-05 11:26:32 +00:00
|
|
|
VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS)
|
2020-12-22 10:16:31 +00:00
|
|
|
IPV6 ?= 1
|
2022-01-23 06:10:14 +00:00
|
|
|
ASAN ?= -fsanitize=address,undefined
|
|
|
|
ASAN_OPTIONS ?= detect_leaks=1
|
2020-12-05 11:26:32 +00:00
|
|
|
EXAMPLES := $(wildcard examples/*)
|
2021-06-02 02:09:55 +02:00
|
|
|
PREFIX ?= /usr/local
|
2021-09-30 13:34:55 +01:00
|
|
|
VERSION ?= $(shell cut -d'"' -f2 src/version.h)
|
2022-01-23 06:10:14 +00:00
|
|
|
CFLAGS ?= $(OPTS) $(WARN) $(INCS) $(DEFS) $(ASAN) -DMG_ENABLE_IPV6=$(IPV6) $(TFLAGS) $(EXTRA)
|
2021-07-29 14:21:20 +01:00
|
|
|
.PHONY: examples test
|
2020-12-05 11:26:32 +00:00
|
|
|
|
|
|
|
ifeq "$(SSL)" "MBEDTLS"
|
2022-01-24 02:20:45 +00:00
|
|
|
MBEDTLS ?= /usr/local
|
2021-07-13 17:28:07 +01:00
|
|
|
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLS)/include -I/usr/include
|
2020-12-07 18:52:40 +00:00
|
|
|
LDFLAGS ?= -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509
|
2020-12-05 11:26:32 +00:00
|
|
|
endif
|
|
|
|
ifeq "$(SSL)" "OPENSSL"
|
2022-01-24 02:20:45 +00:00
|
|
|
OPENSSL ?= /usr/local
|
2021-07-13 17:28:07 +01:00
|
|
|
CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include
|
2020-12-20 21:50:46 +00:00
|
|
|
LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto
|
2020-12-05 11:26:32 +00:00
|
|
|
endif
|
|
|
|
|
2022-01-18 17:11:02 +00:00
|
|
|
all: mg_prefix unamalgamated unpacked test test++ arm examples vc98 vc2017 mingw mingw++ linux linux++ fuzz
|
2020-12-05 11:26:32 +00:00
|
|
|
|
2021-07-29 14:21:20 +01:00
|
|
|
examples:
|
2022-01-27 12:10:03 +00:00
|
|
|
@for X in $(EXAMPLES); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
|
2020-12-05 11:26:32 +00:00
|
|
|
|
2022-02-12 14:28:02 +00:00
|
|
|
test/packed_fs.c:
|
2021-07-30 13:19:20 +01:00
|
|
|
$(CC) $(CFLAGS) test/pack.c -o pack
|
2022-02-12 14:28:02 +00:00
|
|
|
./pack Makefile src/ssi.h test/fuzz.c test/data/a.txt -z 'gzip -c' test/data/range.txt > $@
|
2021-07-26 09:05:34 +01:00
|
|
|
|
2022-02-14 17:44:43 +00:00
|
|
|
DIR ?= test/data/
|
|
|
|
OUT ?= gui.c
|
|
|
|
ZIP ?= -z 'gzip -c'
|
|
|
|
mkfs:
|
|
|
|
$(CC) $(CFLAGS) test/pack.c -o pack
|
|
|
|
./pack $(ZIP) -s $(DIR) `find $(DIR) -type f` > $(OUT)
|
|
|
|
# find $(DIR) -type f | sed -e s,^$(DIR),,g -e s,^/,,g
|
|
|
|
|
2020-12-05 11:26:32 +00:00
|
|
|
# Check that all external (exported) symbols have "mg_" prefix
|
|
|
|
mg_prefix: mongoose.c mongoose.h
|
2021-07-26 09:05:34 +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
|
|
|
|
|
|
|
# C++ build
|
2021-07-26 09:05:34 +01:00
|
|
|
test++: CC = g++
|
2021-05-28 18:57:47 +01:00
|
|
|
test++: WARN += -Wno-shadow -Wno-missing-field-initializers -Wno-deprecated
|
2021-07-13 06:58:34 +01:00
|
|
|
test++: test
|
2020-12-05 11:26:32 +00:00
|
|
|
|
|
|
|
# Make sure we can build from an unamalgamated sources
|
2021-09-14 12:27:02 +01: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 11:00:37 +01:00
|
|
|
|
2021-07-30 13:19:20 +01:00
|
|
|
unpacked:
|
|
|
|
$(CC) -I. mongoose.c test/unit_test.c -o unit_test
|
|
|
|
|
2021-07-26 11:00:37 +01:00
|
|
|
fuzzer: mongoose.c mongoose.h Makefile test/fuzz.c
|
2021-07-30 13:19:20 +01:00
|
|
|
clang mongoose.c test/fuzz.c $(WARN) $(INCS) -DMG_ENABLE_LINES -DMG_ENABLE_LOG=0 -fsanitize=fuzzer,signed-integer-overflow,address -g -o $@
|
2021-07-26 11:00:37 +01:00
|
|
|
|
|
|
|
fuzz: fuzzer
|
|
|
|
$(RUN) ./fuzzer
|
2020-12-05 11:26:32 +00:00
|
|
|
|
2021-07-26 09:05:34 +01:00
|
|
|
# make CC=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1
|
|
|
|
test: mongoose.h Makefile $(SRCS)
|
|
|
|
$(CC) $(SRCS) $(CFLAGS) -coverage $(LDFLAGS) -g -o unit_test
|
2022-02-14 17:44:43 +00:00
|
|
|
ASAN1OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test
|
2020-12-05 11:26:32 +00:00
|
|
|
|
|
|
|
coverage: test
|
|
|
|
gcov -l -n *.gcno | sed '/^$$/d' | sed 'N;s/\n/ /'
|
2020-12-11 22:58:50 +00:00
|
|
|
gcov mongoose.gcno >/dev/null
|
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
|
|
|
|
|
2020-12-05 11:26:32 +00:00
|
|
|
infer:
|
2020-12-05 11:34:58 +00: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 11:26:32 +00:00
|
|
|
|
2021-07-26 11:00:37 +01:00
|
|
|
arm: mongoose.h $(SRCS)
|
2021-07-30 13:19:20 +01:00
|
|
|
$(DOCKER) mdashnet/armgcc arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb $(SRCS) test/mongoose_custom.c -Itest -DMG_ARCH=MG_ARCH_CUSTOM $(OPTS) $(WARN) $(INCS) $(DEFS) -o unit_test -nostartfiles --specs nosys.specs -e 0
|
2021-07-26 11:00:37 +01:00
|
|
|
|
|
|
|
riscv: mongoose.h $(SRCS)
|
2021-07-30 13:19:20 +01:00
|
|
|
$(DOCKER) mdashnet/riscv riscv-none-elf-gcc -march=rv32imc -mabi=ilp32 $(SRCS) test/mongoose_custom.c -Itest -DMG_ARCH=MG_ARCH_CUSTOM $(OPTS) $(WARN) $(INCS) $(DEFS) -o unit_test
|
2021-07-26 11:00:37 +01:00
|
|
|
|
2020-12-05 11:26:32 +00:00
|
|
|
#vc98: VCFLAGS += -DMG_ENABLE_IPV6=1
|
2021-07-30 13:19:20 +01:00
|
|
|
vc98: Makefile mongoose.h $(SRCS)
|
|
|
|
$(DOCKER) mdashnet/vc98 wine cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
|
2021-07-26 11:00:37 +01:00
|
|
|
$(DOCKER) mdashnet/vc98 wine $@.exe
|
2020-12-05 11:26:32 +00:00
|
|
|
|
2020-12-22 09:44:59 +00:00
|
|
|
#vc2017: VCFLAGS += -DMG_ENABLE_IPV6=1
|
2021-07-30 13:19:20 +01:00
|
|
|
vc2017: Makefile mongoose.h $(SRCS)
|
|
|
|
$(DOCKER) mdashnet/vc2017 wine64 cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
|
2021-07-26 11:00:37 +01:00
|
|
|
$(DOCKER) mdashnet/vc2017 wine64 $@.exe
|
2020-12-05 11:26:32 +00:00
|
|
|
|
2021-07-30 13:19:20 +01:00
|
|
|
mingw: Makefile mongoose.h $(SRCS)
|
|
|
|
$(DOCKER) mdashnet/mingw i686-w64-mingw32-gcc $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -o test.exe
|
2021-07-26 11:00:37 +01:00
|
|
|
$(DOCKER) mdashnet/vc98 wine test.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 i686-w64-mingw32-g++ $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -o test.exe
|
2020-12-25 19:24:51 +00:00
|
|
|
# Note: for some reason, a binary built with mingw g++, fails to run
|
|
|
|
|
2022-02-19 16:17:03 +00:00
|
|
|
linux: IPV6=0
|
2021-07-30 13:19:20 +01:00
|
|
|
linux: Makefile mongoose.h $(SRCS)
|
|
|
|
$(DOCKER) mdashnet/cc2 gcc $(SRCS) $(CFLAGS) $(LDFLAGS) -o unit_test_gcc
|
2021-07-26 11:00:37 +01:00
|
|
|
$(DOCKER) mdashnet/cc2 ./unit_test_gcc
|
2020-12-05 11:26:32 +00:00
|
|
|
|
2021-05-28 18:45:35 +01:00
|
|
|
linux++: CC = g++
|
2021-07-15 02:18:32 +01:00
|
|
|
linux++: WARN += -Wno-missing-field-initializers
|
2020-12-07 03:47:37 +00:00
|
|
|
linux++: linux
|
|
|
|
|
2021-06-02 02:09:55 +02:00
|
|
|
linux-libs: CFLAGS += -fPIC
|
|
|
|
linux-libs: mongoose.o
|
2021-09-30 13:34:55 +01:00
|
|
|
$(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION)
|
2021-06-02 02:09:55 +02:00
|
|
|
$(AR) rcs libmongoose.a mongoose.o
|
|
|
|
|
|
|
|
install: linux-libs
|
2021-09-30 13:34:55 +01:00
|
|
|
install -Dm644 libmongoose.a libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib
|
|
|
|
ln -s libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libmongoose.so
|
2021-06-30 21:46:58 +02:00
|
|
|
install -Dm644 mongoose.h $(DESTDIR)$(PREFIX)/include/mongoose.h
|
2021-06-02 02:09:55 +02:00
|
|
|
|
|
|
|
uninstall:
|
2021-09-30 13:34:55 +01: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 02:09:55 +02:00
|
|
|
|
2021-07-26 09:15:17 +01:00
|
|
|
mongoose.c: Makefile $(wildcard src/*)
|
2021-10-22 14:00:31 +01:00
|
|
|
(cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.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
|
2022-01-18 17:11:02 +00: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/config.h src/str.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 | sed -e 's,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
|
2020-12-05 11:26:32 +00:00
|
|
|
|
2021-07-29 14:21:20 +01:00
|
|
|
clean:
|
2021-07-26 09:05:34 +01: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-* test/packed_fs.c pack
|
2022-01-24 13:07:56 +00:00
|
|
|
@for X in $(EXAMPLES); do test -f $$X/Makefile && $(MAKE) -C $$X clean; done
|