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