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