-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (128 loc) · 5.27 KB
/
Makefile
File metadata and controls
154 lines (128 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/make
APP_VERSION ?= 0.0.0
CC := musl-gcc
C_SIZE_FLAGS = -Os -ffunction-sections -fdata-sections -fmerge-all-constants
C_SECURITY_FLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2
C_WARNING_FLAGS = -Wall -Wextra -Werror -Wpedantic -Wformat=2 -Wformat-security -Wnull-dereference \
-Wstack-protector -Wstrict-overflow=3 -Wwrite-strings -Wconversion -Wshadow
C_STRIP_FLAGS = -fno-asynchronous-unwind-tables -fno-ident
C_LDFLAGS_EXTRA ?= -static
C_LDFLAGS = -Wl,--gc-sections -Wl,--as-needed -Wl,-O1 \
-Wl,--build-id=none -Wl,--hash-style=gnu $(C_LDFLAGS_EXTRA)
STRIP_FLAGS = -s -R .comment -R .gnu.version -R .note -R .note.ABI-tag \
-R .note.gnu.build-id -R .gnu.hash -R .eh_frame -R .eh_frame_hdr
ifeq ($(shell uname -s),Darwin) # macOS linker flags (https://github.com/tarampampam/microcheck/issues/11)
C_LDFLAGS = -Wl,-dead_strip
STRIP_FLAGS = -x
endif
CFLAGS = -std=c99 -D_POSIX_C_SOURCE=200809L
CFLAGS += $(C_SIZE_FLAGS) $(C_SECURITY_FLAGS) $(C_WARNING_FLAGS) $(C_STRIP_FLAGS)
LDFLAGS = $(C_LDFLAGS)
.DEFAULT_GOAL: all
all: \
build/bin/httpcheck \
build/bin/httpscheck \
build/bin/portcheck \
build/bin/parallel \
build/bin/pidcheck
## Download mbedtls4 library
lib/mbedtls4:
$(SHELL) ./lib/install-mbedtls4.sh $@
## Build mbedtls4 library
lib/mbedtls4/build: lib/mbedtls4
mkdir -p $@
CC=$(CC) CFLAGS="" cmake -S ./lib/mbedtls4 -B ./lib/mbedtls4/build \
-DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_C_FLAGS="-Os -ffunction-sections -fdata-sections" \
-DENABLE_TESTING=OFF -DENABLE_PROGRAMS=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF
cmake --build ./lib/mbedtls4/build --target lib -j$(shell nproc)
## Compile CLI module source files
build/obj/%.o: lib/cli/%.c lib/cli/cli.h
mkdir -p $(dir $@)
$(CC) -c $(CFLAGS) -o $@ $<
## Build CLI module static library
build/lib/cli.a: $(patsubst lib/cli/%.c,build/obj/%.o,$(wildcard lib/cli/*.c))
mkdir -p $(dir $@)
ar rcs $@ $^
## Build CLI module test binary
build/bin/cli_test: tests/unit/cli/cli_test.c build/lib/cli.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a
## Compile COMMAND module source files
build/obj/%.o: lib/command/%.c lib/command/command.h
mkdir -p $(dir $@)
$(CC) -c $(CFLAGS) -o $@ $<
## Build COMMAND module static library
build/lib/command.a: $(patsubst lib/command/%.c,build/obj/%.o,$(wildcard lib/command/*.c))
mkdir -p $(dir $@)
ar rcs $@ $^
## Build COMMAND module test binary
build/bin/command_test: tests/unit/command/command_test.c build/lib/command.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/command.a
## Compile HTTP module source files
build/obj/%.o: lib/http/%.c lib/http/http.h
mkdir -p $(dir $@)
$(CC) -c $(CFLAGS) -o $@ $<
## Build HTTP module static library
build/lib/http.a: $(patsubst lib/http/%.c,build/obj/%.o,$(wildcard lib/http/*.c))
mkdir -p $(dir $@)
ar rcs $@ $^
## Build HTTP module test binary
build/bin/http_test: tests/unit/http/http_test.c build/lib/http.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/http.a
.PHONY: apps/version.h
apps/version.h:
@printf '// Code generated by make; DO NOT EDIT.\n\n\
#ifndef VERSION_H\n#define VERSION_H\n#define APP_VERSION "%s"\n#endif\n' "$(APP_VERSION)" > $@
build/bin/httpscheck: apps/httpcheck.c apps/version.h build/lib/cli.a build/lib/http.a lib/mbedtls4/build
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -DWITH_TLS \
-Ilib/mbedtls4/include \
-Ilib/mbedtls4/tf-psa-crypto/include \
-Ilib/mbedtls4/tf-psa-crypto/drivers/builtin/include \
$(LDFLAGS) -Llib/mbedtls4/build/library \
-o $@ $< build/lib/cli.a build/lib/http.a \
-lmbedtls -lmbedx509 -ltfpsacrypto
strip $(STRIP_FLAGS) $@
build/bin/httpcheck: apps/httpcheck.c apps/version.h build/lib/cli.a build/lib/http.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a build/lib/http.a
strip $(STRIP_FLAGS) $@
build/bin/portcheck: apps/portcheck.c apps/version.h build/lib/cli.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a
strip $(STRIP_FLAGS) $@
build/bin/parallel: apps/parallel.c apps/version.h build/lib/cli.a build/lib/command.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a build/lib/command.a
strip $(STRIP_FLAGS) $@
build/bin/pidcheck: apps/pidcheck.c apps/version.h build/lib/cli.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a
strip $(STRIP_FLAGS) $@
SRC_FILES := $(shell find ./apps ./lib -type f \( -name '*.c' -o -name '*.h' \) ! -path '*/apps/version.h' ! -path '*/lib/mbedtls4/*')
fmt: $(SRC_FILES)
clang-format -i $^
test: build/bin/httpcheck \
build/bin/httpscheck \
build/bin/portcheck \
build/bin/parallel \
build/bin/pidcheck \
build/bin/cli_test \
build/bin/command_test \
build/bin/http_test
./build/bin/cli_test
./build/bin/command_test
./build/bin/http_test
python3 ./tests/feature/httpcheck.py --bin ./build/bin/httpcheck
python3 ./tests/feature/httpcheck.py --bin ./build/bin/httpscheck --https
python3 ./tests/feature/httpcheck.py --bin ./build/bin/httpscheck --fallback
python3 ./tests/feature/portcheck.py --bin ./build/bin/portcheck
python3 ./tests/feature/parallel.py --bin ./build/bin/parallel
python3 ./tests/feature/pidcheck.py --bin ./build/bin/pidcheck
#.PHONY: clean
clean:
-rm ./apps/version.h
-rm -r ./build
-rm -r ./lib/mbedtls4/build