-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
119 lines (108 loc) · 2.24 KB
/
Makefile
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
# SPDX-License-Identifier: MIT
PROJECT := mycbor
BASEDIR := $(shell pwd)
BUILDIR := build
VERBOSE ?= 0
V ?= $(VERBOSE)
ifeq ($(V), 0)
Q := @
else
Q :=
endif
export BASEDIR
export BUILDIR
export Q
CBOR_ROOT := ./
include $(CBOR_ROOT)/cbor.mk
SRCS := $(CBOR_SRCS)
INCS := $(CBOR_INCS)
OBJS := $(addprefix $(BUILDIR)/, $(SRCS:.c=.o))
DEPS := $(OBJS:.o=.d)
ifneq ($(CROSS_COMPILE),)
CROSS_COMPILE_PREFIX := $(CROSS_COMPILE)-
endif
CC := $(CROSS_COMPILE_PREFIX)gcc
LD := $(CROSS_COMPILE_PREFIX)ld
SZ := $(CROSS_COMPILE_PREFIX)size
AR := $(CROSS_COMPILE_PREFIX)ar
OC := $(CROSS_COMPILE_PREFIX)objcopy
OD := $(CROSS_COMPILE_PREFIX)objdump
NM := $(CROSS_COMPILE_PREFIX)nm
CFLAGS := \
-std=c99 \
-static \
-ffreestanding \
-fno-builtin \
-fno-common \
-ffunction-sections \
-fdata-sections \
-fstack-usage \
-Os \
\
-Werror \
-Wall \
-Wextra \
-Wc++-compat \
-Wformat=2 \
-Wmissing-prototypes \
-Wstrict-prototypes \
-Wmissing-declarations \
-Wcast-align \
-Wpointer-arith \
-Wbad-function-cast \
-Wcast-qual \
-Wmissing-format-attribute \
-Wmissing-include-dirs \
-Wformat-nonliteral \
-Wdouble-promotion \
-Wfloat-equal \
-Winline \
-Wundef \
-Wunused-macros \
-Wshadow \
-Wwrite-strings \
-Waggregate-return \
-Wredundant-decls \
-Wconversion \
-Wstrict-overflow=5 \
-Wno-long-long \
-Wswitch-default \
-Wpedantic \
\
-Wno-error=pedantic
ifneq ($(CROSS_COMPILE),)
CFLAGS += \
-mcpu=cortex-m0 \
-mthumb \
-mabi=aapcs
endif
VERSION ?= $(shell git describe --long --tags --dirty --always)
version-list := $(subst -, , $(VERSION))
VERSION_TAG := $(strip $(word 1, $(version-list)))
all: $(OBJS)
$(Q)$(SZ) -t --common $(sort $(OBJS))
@echo $(VERSION_TAG) > $(BUILDIR)/version.txt
$(BUILDIR)/%.o: %.c $(MAKEFILE_LIST)
$(info compiling $<)
@mkdir -p $(@D)
$(Q)$(CC) -o $@ -c $*.c -MMD \
$(addprefix -D, $(DEFS)) \
$(addprefix -I, $(INCS)) \
$(CFLAGS)
.PHONY: test fuzz
test:
$(Q)$(MAKE) -C tests
fuzz:
$(Q)clang++ -g -fsanitize=address,fuzzer \
-o tests/build/fuzz_testing \
$(addprefix -D, $(DEFS)) \
$(addprefix -I, $(INCS)) \
$(SRCS) tests/src/parser_fuzz_test.c
$(Q)./tests/build/fuzz_testing
.PHONY: coverage
coverage:
$(Q)$(MAKE) -C tests $@
.PHONY: clean
clean:
$(Q)$(MAKE) -C tests clean
$(Q)rm -rf $(BUILDIR)