blob: 9b958ddb50b28af35291c68b67f53c0f39c36a49 [file] [log] [blame]
Pascal Brandb0104772014-06-12 15:56:20 +02001# Input
2#
3# The output from mk/sub.mk
4# base-prefix
Jerome Forissierfe52b1f2014-11-06 17:54:51 +01005# conf-file [optional] if set, all objects will depend on $(conf-file)
Pascal Brandb0104772014-06-12 15:56:20 +02006#
7# Output
8#
9# set objs
10# update cleanfiles
11#
12# Generates explicit rules for all objs
13
14objs :=
15
16# Disable all builtin rules
17.SUFFIXES:
18
19comp-cflags$(sm) = -std=gnu99
20comp-aflags$(sm) =
21comp-cppflags$(sm) =
22
23ifndef NOWERROR
24comp-cflags$(sm) += -Werror
25endif
26comp-cflags$(sm) += -fdiagnostics-show-option
27
28comp-cflags-warns-high = \
29 -Wall -Wcast-align \
30 -Werror-implicit-function-declaration -Wextra -Wfloat-equal \
31 -Wformat-nonliteral -Wformat-security -Wformat=2 -Winit-self \
32 -Wmissing-declarations -Wmissing-format-attribute \
33 -Wmissing-include-dirs -Wmissing-noreturn \
34 -Wmissing-prototypes -Wnested-externs -Wpointer-arith \
35 -Wshadow -Wstrict-prototypes -Wswitch-default \
36 -Wwrite-strings \
37 -Wno-missing-field-initializers -Wno-format-zero-length
38comp-cflags-warns-medium = \
39 -Waggregate-return -Wredundant-decls
40comp-cflags-warns-low = \
Pascal Brandb0104772014-06-12 15:56:20 +020041 -Wold-style-definition -Wstrict-aliasing=2 \
42 -Wundef -pedantic \
43 -Wdeclaration-after-statement
44
45comp-cflags-warns-1:= $(comp-cflags-warns-high)
46comp-cflags-warns-2:= $(comp-cflags-warns-1) $(comp-cflags-warns-medium)
47comp-cflags-warns-3:= $(comp-cflags-warns-2) $(comp-cflags-warns-low)
48
49WARNS ?= 3
50
51comp-cflags$(sm) += $(comp-cflags-warns-$(WARNS))
52
53.PHONY: FORCE
54FORCE:
55
56define process_srcs
57objs += $2
58comp-dep-$2 := $$(dir $2).$$(notdir $2).d
Pascal Brandb0104772014-06-12 15:56:20 +020059comp-cmd-file-$2:= $$(dir $2).$$(notdir $2).cmd
60comp-sm-$2 := $(sm)
Jerome Forissier73dc7282014-09-25 16:04:03 +020061comp-lib-$2 := $(libname)
Pascal Brandb0104772014-06-12 15:56:20 +020062
63cleanfiles := $$(cleanfiles) $$(comp-dep-$2) $$(comp-cmd-file-$2) $2
64
65ifeq ($$(filter %.c,$1),$1)
Jerome Forissier76f59872014-11-03 17:03:28 +010066comp-q-$2 := CC
Pascal Brandb0104772014-06-12 15:56:20 +020067comp-flags-$2 = $$(filter-out $$(CFLAGS_REMOVE) $$(cflags-remove) \
68 $$(cflags-remove-$2), \
69 $$(CFLAGS) $$(CFLAGS_WARNS) \
70 $$(comp-cflags$$(comp-sm-$2)) $$(cflags$$(comp-sm-$2)) \
Jerome Forissier3d34e122014-10-30 17:37:42 +010071 $$(cflags-lib$$(comp-lib-$2)) $$(cflags-$2))
Pascal Brandb0104772014-06-12 15:56:20 +020072else ifeq ($$(filter %.S,$1),$1)
Jerome Forissier76f59872014-11-03 17:03:28 +010073comp-q-$2 := AS
Pascal Brandb0104772014-06-12 15:56:20 +020074comp-flags-$2 = -DASM=1 $$(filter-out $$(AFLAGS_REMOVE) $$(aflags-remove) \
75 $$(aflags-remove-$2), \
76 $$(AFLAGS) $$(comp-aflags$$(comp-sm-$2)) \
77 $$(aflags$$(comp-sm-$2)) $$(aflags-$2))
78else
79$$(error "Don't know what to do with $1")
80endif
81
Jerome Forissieraaac0982014-08-18 19:19:36 +020082comp-flags-$2 += -MD -MF $$(comp-dep-$2) -MT $$@ \
Pascal Brandb0104772014-06-12 15:56:20 +020083 $$(filter-out $$(CPPFLAGS_REMOVE) $$(cppflags-remove) \
84 $$(cppflags-remove-$2), \
Jens Wiklander1b4eb4f2015-02-02 09:19:18 +010085 $$(nostdinc$$(comp-sm-$2)) $$(CPPFLAGS) \
Pascal Brandb0104772014-06-12 15:56:20 +020086 $$(addprefix -I,$$(incdirs$$(comp-sm-$2))) \
Jerome Forissier73dc7282014-09-25 16:04:03 +020087 $$(addprefix -I,$$(incdirs-lib$$(comp-lib-$2))) \
88 $$(addprefix -I,$$(incdirs-$2)) \
89 $$(cppflags$$(comp-sm-$2)) \
90 $$(cppflags-lib$$(comp-lib-$2)) $$(cppflags-$2))
Pascal Brandb0104772014-06-12 15:56:20 +020091
Jens Wiklander1b4eb4f2015-02-02 09:19:18 +010092comp-cmd-$2 = $$(CC$(sm)) $$(comp-flags-$2) -c $$< -o $$@
93comp-objcpy-cmd-$2 = $$(OBJCOPY$(sm)) \
Jens Wiklander6d6ea542014-12-02 11:06:01 +010094 --rename-section .rodata=.rodata.$1 \
95 --rename-section .rodata.str1.1=.rodata.str1.1.$1 \
96 $2
Pascal Brandb0104772014-06-12 15:56:20 +020097
98-include $$(comp-cmd-file-$2)
99-include $$(comp-dep-$2)
100
101
102$2: $1 FORCE
103# Check if any prerequisites are newer than the target and
104# check if command line has changed
Jerome Forissier313ead42015-01-22 18:17:54 +0100105 $$(if $$(strip $$(filter-out FORCE, $$?) \
106 $$(filter-out $$(comp-cmd-$2), $$(old-cmd-$2)) \
Pascal Brandb0104772014-06-12 15:56:20 +0200107 $$(filter-out $$(old-cmd-$2), $$(comp-cmd-$2))), \
108 @set -e ;\
109 mkdir -p $$(dir $2) ;\
Jens Wiklander62428632015-04-29 15:05:19 +0200110 $(cmd-echo-silent) ' $$(comp-q-$2) $$@' ;\
Pascal Brandb0104772014-06-12 15:56:20 +0200111 $(cmd-echo) $$(subst \",\\\",$$(comp-cmd-$2)) ;\
112 $$(comp-cmd-$2) ;\
Jens Wiklander6d6ea542014-12-02 11:06:01 +0100113 $(cmd-echo) $$(comp-objcpy-cmd-$2) ;\
114 $$(comp-objcpy-cmd-$2) ;\
Pascal Brandb0104772014-06-12 15:56:20 +0200115 echo "old-cmd-$2 := $$(subst \",\\\",$$(comp-cmd-$2))" > \
116 $$(comp-cmd-file-$2) ;\
117 )
118
119endef
120
121$(foreach f, $(srcs), $(eval $(call \
Jerome Forissier4334e8d2014-09-08 10:53:42 +0200122 process_srcs,$(f),$(out-dir)/$(base-prefix)$$(basename $f).o)))
Jerome Forissierfe52b1f2014-11-06 17:54:51 +0100123
124$(objs): $(conf-file)