Merge pull request #1750 from cesanta/make

Optimize makefile
This commit is contained in:
Sergey Lyubka authored and GitHub committed 2022-09-22 13:26:57 +01:00
commit f9ad870ff0
3 files changed
+50 -58

No files matched your search

+19 -10
View File
@@ -6,8 +6,8 @@ jobs:
strategy:
fail-fast: false
matrix:
cc: [gcc, clang]
target: [test, mip_test, test++, valgrind]
cc: [gcc, clang, g++, clang++]
target: [test, mip_test]
ssl: [MBEDTLS, OPENSSL]
name: linux ${{ matrix.target }} CC=${{ matrix.cc }} SSL=${{ matrix.ssl }}
env:
@@ -16,12 +16,16 @@ jobs:
SSL: ${{ matrix.ssl }}
steps:
- uses: actions/checkout@v3
- name: Install packages
run: sudo apt-get update ; sudo apt-get install libmbedtls-dev valgrind
- name: test
run: make ${{ matrix.target }}
- name: unamalgamated
run: make unamalgamated
- run: sudo apt-get update ; sudo apt-get install libmbedtls-dev
- run: make ${{ matrix.target }}
linux2:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sudo apt-get update ; sudo apt-get install libmbedtls-dev valgrind
- run: make unamalgamated SSL=
- run: make valgrind IPV6=0
- run: make mg_prefix
examples:
runs-on: ubuntu-latest
steps:
@@ -34,8 +38,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: HOMEBREW_NO_AUTO_UPDATE=1 brew install jq mbedtls openssl
- run: make test++ upload-coverage IPV6=0 ASAN_OPTIONS=
- run: make test SSL=OPENSSL IPV6=0 ASAN_OPTIONS= OPENSSL=`echo /usr/local/Cellar/openssl*/*`
- run: make test upload-coverage SSL=OPENSSL IPV6=0 ASAN_OPTIONS= OPENSSL=`echo /usr/local/Cellar/openssl*/*`
- run: make test SSL=MBEDTLS IPV6=0 ASAN_OPTIONS= MBEDTLS=`echo /usr/local/Cellar/mbedtls*/*`
- run: make mip_test ASAN_OPTIONS=
- run: make mg_prefix
windows:
@@ -52,6 +56,11 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: make arm
riscv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: make riscv
matrix_examples:
runs-on: ubuntu-latest
strategy:
+22 -44
View File
@@ -1,8 +1,7 @@
SRCS = mongoose.c test/unit_test.c test/packed_fs.c
HDRS = $(wildcard src/*.h) $(wildcard mip/*.h)
DEFS ?= -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -DMG_ENABLE_SSI=1
C_WARN ?= -Wmissing-prototypes -Wstrict-prototypes
WARN ?= -pedantic -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef $(C_WARN)
WARN ?= -pedantic -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef
OPTS ?= -O3 -g3
INCS ?= -Isrc -I.
SSL ?= MBEDTLS
@@ -16,11 +15,17 @@ ASAN_OPTIONS ?= detect_leaks=1
EXAMPLES := $(dir $(wildcard examples/*/Makefile)) $(wildcard examples/stm32/nucleo-*)
PREFIX ?= /usr/local
VERSION ?= $(shell cut -d'"' -f2 src/version.h)
COMMON_CFLAGS ?= $(WARN) $(INCS) $(DEFS) -DMG_ENABLE_IPV6=$(IPV6) $(TFLAGS)
COMMON_CFLAGS ?= $(C_WARN) $(WARN) $(INCS) $(DEFS) -DMG_ENABLE_IPV6=$(IPV6) $(TFLAGS)
CFLAGS ?= $(OPTS) $(ASAN) $(COMMON_CFLAGS)
VALGRIND_CFLAGS ?= $(OPTS) $(COMMON_CFLAGS)
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
.PHONY: examples test valgrind
.PHONY: examples test valgrind mip_test
ifeq "$(findstring ++,$(CC))" ""
C_WARN ?= -Wmissing-prototypes -Wstrict-prototypes
else
C_WARN ?= -Wno-deprecated
endif
ifeq "$(SSL)" "MBEDTLS"
MBEDTLS ?= /usr/local
@@ -34,16 +39,12 @@ CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include
LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto
endif
all: mg_prefix unamalgamated unpacked test test++ mip_test arm examples vc98 vc17 vc22 mingw mingw++ linux linux++ fuzz
all: mg_prefix unamalgamated test mip_test arm examples vc98 vc17 vc22 mingw mingw++ fuzz
mip_test: test/mip_test.c mongoose.c mongoose.h Makefile
$(CC) test/mip_test.c $(INCS) $(WARN) $(OPTS) -g -o $@
$(CC) test/mip_test.c $(INCS) $(WARN) $(OPTS) $(C_WARN) -o $@
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./$@
mip_test++: mip_test
mip_test++: C_WARN = -Wno-deprecated
mip_test++: CC = g++
examples:
@for X in $(EXAMPLES); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
@@ -60,12 +61,7 @@ mkfs:
# Check that all external (exported) symbols have "mg_" prefix
mg_prefix: mongoose.c mongoose.h
$(CC) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T' | grep -v 'mg_' ; test $$? = 1
# C++ build
test++: test
test++: CC = g++
test++: C_WARN = -std=c++2a -Wno-vla -Wno-shadow -Wno-missing-field-initializers -Wno-deprecated
$(CC) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T ' | grep -v 'mg_' ; test $$? = 1
musl: test
musl: ASAN =
@@ -77,23 +73,16 @@ musl: RUN = $(DOCKER) mdashnet/cc1
unamalgamated: $(HDRS) Makefile test/packed_fs.c
$(CC) src/*.c test/packed_fs.c test/unit_test.c $(CFLAGS) $(LDFLAGS) -g -o unit_test
unpacked:
$(CC) -I. mongoose.c test/unit_test.c -o $@
fuzzer: WARN += -Wno-missing-field-initializers
fuzzer: mongoose.c mongoose.h Makefile test/fuzz.c
$(CXX) test/fuzz.c $(WARN) $(INCS) $(TFLAGS) -fsanitize=fuzzer,signed-integer-overflow,address -Wno-deprecated -Wno-vla-extension -o $@
fuzz: fuzzer
fuzz: mongoose.c mongoose.h Makefile test/fuzz.c
$(CXX) test/fuzz.c $(WARN) $(INCS) $(TFLAGS) -Wno-missing-field-initializers -fsanitize=fuzzer,signed-integer-overflow,address -Wno-deprecated -Wno-vla-extension -o fuzzer
$(RUN) ./fuzzer
unit_test: Makefile mongoose.h $(SRCS)
$(CC) $(SRCS) $(CFLAGS) $(LDFLAGS) -g -o unit_test
# make CC=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1
test: unit_test
test: Makefile mongoose.h $(SRCS)
$(CC) $(SRCS) $(CFLAGS) $(LDFLAGS) -o unit_test
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test
# $(CXX) $(SRCS) $(CFLAGS) $(LDFLAGS) $(CXX_WARN) -g -o unit_test
coverage: CFLAGS += -coverage
coverage: test
gcov -l -n *.gcno | sed '/^$$/d' | sed 'N;s/\n/ /'
@@ -102,11 +91,9 @@ coverage: test
upload-coverage: coverage
curl -s https://codecov.io/bash | /bin/bash
valgrind_unit_test: Makefile mongoose.h $(SRCS)
$(CC) $(SRCS) $(VALGRIND_CFLAGS) $(LDFLAGS) -g -o valgrind_unit_test
valgrind: valgrind_unit_test
$(VALGRIND_RUN) ./valgrind_unit_test
valgrind: Makefile mongoose.h mongoose.c
$(CC) $(SRCS) $(VALGRIND_CFLAGS) $(LDFLAGS) -g -o unit_test
$(VALGRIND_RUN) ./unit_test
arm: DEFS += -DMG_ENABLE_FILE=0 -DMG_ENABLE_MIP=1 -DMG_ARCH=MG_ARCH_NEWLIB
arm: mongoose.h $(SRCS)
@@ -137,15 +124,6 @@ mingw: Makefile mongoose.h $(SRCS)
mingw++: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/mingw x86_64-w64-mingw32-g++ $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -o $@.exe
linux: IPV6=0
linux: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/cc2 gcc $(SRCS) $(CFLAGS) $(LDFLAGS) -o unit_test_gcc
$(DOCKER) mdashnet/cc2 ./unit_test_gcc
linux++: CC = g++
linux++: WARN += -Wno-missing-field-initializers
linux++: linux
linux-libs: CFLAGS += -fPIC
linux-libs: mongoose.o
$(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION)
@@ -166,5 +144,5 @@ mongoose.h: $(HDRS) Makefile
(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/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 mip/mip.h mip/driver_*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
clean:
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 unpacked
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
@for X in $(EXAMPLES); do $(MAKE) -C $$X clean; done
+9 -4
View File
@@ -926,9 +926,13 @@ static void test_http_404(void) {
static void test_tls(void) {
#if MG_ENABLE_MBEDTLS || MG_ENABLE_OPENSSL
struct mg_tls_opts opts = {.ca = "./test/data/ss_ca.pem",
.cert = "./test/data/ss_server.pem",
.certkey = "./test/data/ss_server.pem"};
struct mg_tls_opts opts = {"./test/data/ss_ca.pem",
NULL,
"./test/data/ss_server.pem",
"./test/data/ss_server.pem",
NULL,
{0, 0},
NULL};
struct mg_mgr mgr;
struct mg_connection *c;
const char *url = "https://127.0.0.1:12347";
@@ -981,7 +985,8 @@ static void test_http_client(void) {
{
const char *url = "https://cesanta.com";
struct mg_str host = mg_url_host(url);
struct mg_tls_opts opts = {.ca = "./test/data/ca.pem", .srvname = host};
struct mg_tls_opts opts = {
"./test/data/ca.pem", NULL, NULL, NULL, NULL, host, NULL};
c = mg_http_connect(&mgr, url, f3, &ok);
ASSERT(c != NULL);
mg_tls_init(c, &opts);