xref: /optee_os/mk/compile.mk (revision 3d34e125a253aad5152b99fd4cce84f6565fa479)
1b0104773SPascal Brand# Input
2b0104773SPascal Brand#
3b0104773SPascal Brand# The output from mk/sub.mk
4b0104773SPascal Brand# base-prefix
5b0104773SPascal Brand#
6b0104773SPascal Brand# Output
7b0104773SPascal Brand#
8b0104773SPascal Brand# set	  objs
9b0104773SPascal Brand# update  cleanfiles
10b0104773SPascal Brand#
11b0104773SPascal Brand# Generates explicit rules for all objs
12b0104773SPascal Brand
13b0104773SPascal Brandobjs		:=
14b0104773SPascal Brand
15b0104773SPascal Brand# Disable all builtin rules
16b0104773SPascal Brand.SUFFIXES:
17b0104773SPascal Brand
18b0104773SPascal Brandcomp-cflags$(sm) = -std=gnu99
19b0104773SPascal Brandcomp-aflags$(sm) =
20b0104773SPascal Brandcomp-cppflags$(sm) =
21b0104773SPascal Brand
22b0104773SPascal Brandifndef NOWERROR
23b0104773SPascal Brandcomp-cflags$(sm)	+= -Werror
24b0104773SPascal Brandendif
25b0104773SPascal Brandcomp-cflags$(sm)  	+= -fdiagnostics-show-option
26b0104773SPascal Brand
27b0104773SPascal Brandcomp-cflags-warns-high = \
28b0104773SPascal Brand	-Wall -Wcast-align  \
29b0104773SPascal Brand	-Werror-implicit-function-declaration -Wextra -Wfloat-equal \
30b0104773SPascal Brand	-Wformat-nonliteral -Wformat-security -Wformat=2 -Winit-self \
31b0104773SPascal Brand	-Wmissing-declarations -Wmissing-format-attribute \
32b0104773SPascal Brand	-Wmissing-include-dirs -Wmissing-noreturn \
33b0104773SPascal Brand	-Wmissing-prototypes -Wnested-externs -Wpointer-arith \
34b0104773SPascal Brand	-Wshadow -Wstrict-prototypes -Wswitch-default \
35b0104773SPascal Brand	-Wwrite-strings \
36b0104773SPascal Brand	-Wno-missing-field-initializers -Wno-format-zero-length
37b0104773SPascal Brandcomp-cflags-warns-medium = \
38b0104773SPascal Brand	-Waggregate-return -Wredundant-decls
39b0104773SPascal Brandcomp-cflags-warns-low = \
40b0104773SPascal Brand	-Wold-style-definition -Wstrict-aliasing=2 \
41b0104773SPascal Brand	-Wundef -pedantic \
42b0104773SPascal Brand	-Wdeclaration-after-statement
43b0104773SPascal Brand
44b0104773SPascal Brandcomp-cflags-warns-1:= $(comp-cflags-warns-high)
45b0104773SPascal Brandcomp-cflags-warns-2:= $(comp-cflags-warns-1) $(comp-cflags-warns-medium)
46b0104773SPascal Brandcomp-cflags-warns-3:= $(comp-cflags-warns-2) $(comp-cflags-warns-low)
47b0104773SPascal Brand
48b0104773SPascal BrandWARNS		?= 3
49b0104773SPascal Brand
50b0104773SPascal Brandcomp-cflags$(sm)	+= $(comp-cflags-warns-$(WARNS))
51b0104773SPascal Brand
52b0104773SPascal Brand.PHONY: FORCE
53b0104773SPascal BrandFORCE:
54b0104773SPascal Brand
55b0104773SPascal Branddefine process_srcs
56b0104773SPascal Brandobjs		+= $2
57b0104773SPascal Brandcomp-dep-$2	:= $$(dir $2).$$(notdir $2).d
58b0104773SPascal Brandcomp-cmd-file-$2:= $$(dir $2).$$(notdir $2).cmd
59b0104773SPascal Brandcomp-sm-$2	:= $(sm)
6073dc728dSJerome Forissiercomp-lib-$2	:= $(libname)
61b0104773SPascal Brand
62b0104773SPascal Brandcleanfiles := $$(cleanfiles) $$(comp-dep-$2) $$(comp-cmd-file-$2) $2
63b0104773SPascal Brand
64b0104773SPascal Brandifeq ($$(filter %.c,$1),$1)
65b0104773SPascal Brandcomp-flags-$2 = $$(filter-out $$(CFLAGS_REMOVE) $$(cflags-remove) \
66b0104773SPascal Brand			      $$(cflags-remove-$2), \
67b0104773SPascal Brand		   $$(CFLAGS) $$(CFLAGS_WARNS) \
68b0104773SPascal Brand		   $$(comp-cflags$$(comp-sm-$2)) $$(cflags$$(comp-sm-$2)) \
69*3d34e125SJerome Forissier		   $$(cflags-lib$$(comp-lib-$2)) $$(cflags-$2))
70b0104773SPascal Brandelse ifeq ($$(filter %.S,$1),$1)
71b0104773SPascal Brandcomp-flags-$2 = -DASM=1 $$(filter-out $$(AFLAGS_REMOVE) $$(aflags-remove) \
72b0104773SPascal Brand				      $$(aflags-remove-$2), \
73b0104773SPascal Brand			   $$(AFLAGS) $$(comp-aflags$$(comp-sm-$2)) \
74b0104773SPascal Brand			   $$(aflags$$(comp-sm-$2)) $$(aflags-$2))
75b0104773SPascal Brandelse
76b0104773SPascal Brand$$(error "Don't know what to do with $1")
77b0104773SPascal Brandendif
78b0104773SPascal Brand
79b0104773SPascal Brand
80aaac0982SJerome Forissiercomp-flags-$2 += -MD -MF $$(comp-dep-$2) -MT $$@ \
81b0104773SPascal Brand	   $$(filter-out $$(CPPFLAGS_REMOVE) $$(cppflags-remove) \
82b0104773SPascal Brand			 $$(cppflags-remove-$2), \
83b0104773SPascal Brand	      $$(nostdinc) $$(CPPFLAGS) \
84b0104773SPascal Brand	      $$(addprefix -I,$$(incdirs$$(comp-sm-$2))) \
8573dc728dSJerome Forissier	      $$(addprefix -I,$$(incdirs-lib$$(comp-lib-$2))) \
8673dc728dSJerome Forissier	      $$(addprefix -I,$$(incdirs-$2)) \
8773dc728dSJerome Forissier	      $$(cppflags$$(comp-sm-$2)) \
8873dc728dSJerome Forissier	      $$(cppflags-lib$$(comp-lib-$2)) $$(cppflags-$2))
89b0104773SPascal Brand
90b0104773SPascal Brandcomp-cmd-$2 = $$(CC) $$(comp-flags-$2) -c $$< -o $$@
91b0104773SPascal Brand
92b0104773SPascal Brand-include $$(comp-cmd-file-$2)
93b0104773SPascal Brand-include $$(comp-dep-$2)
94b0104773SPascal Brand
95b0104773SPascal Brand
96b0104773SPascal Brand$2: $1 FORCE
97b0104773SPascal Brand# Check if any prerequisites are newer than the target and
98b0104773SPascal Brand# check if command line has changed
99b0104773SPascal Brand	$$(if $$(strip $$?  $$(filter-out $$(comp-cmd-$2), $$(old-cmd-$2)) \
100b0104773SPascal Brand	    $$(filter-out $$(old-cmd-$2), $$(comp-cmd-$2))), \
101b0104773SPascal Brand		@set -e ;\
102b0104773SPascal Brand		mkdir -p $$(dir $2) ;\
1030047cb63SJerome Forissier		echo '  CC      $$@' ;\
104b0104773SPascal Brand		$(cmd-echo) $$(subst \",\\\",$$(comp-cmd-$2)) ;\
105b0104773SPascal Brand		$$(comp-cmd-$2) ;\
106b0104773SPascal Brand		echo "old-cmd-$2 := $$(subst \",\\\",$$(comp-cmd-$2))" > \
107b0104773SPascal Brand			$$(comp-cmd-file-$2) ;\
108b0104773SPascal Brand	)
109b0104773SPascal Brand
110b0104773SPascal Brandendef
111b0104773SPascal Brand
112b0104773SPascal Brand$(foreach f, $(srcs), $(eval $(call \
1134334e8d7SJerome Forissier	process_srcs,$(f),$(out-dir)/$(base-prefix)$$(basename $f).o)))
114