xref: /freebsd/share/mk/bsd.sys.mk (revision 5b56413d04e608379c9a306373554a8e4d321bc0)
1#
2# This file contains common settings used for building FreeBSD
3# sources.
4
5# Enable various levels of compiler warning checks.  These may be
6# overridden (e.g. if using a non-gcc compiler) by defining MK_WARNS=no.
7
8# for GCC:   https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
9# for clang: https://clang.llvm.org/docs/DiagnosticsReference.html
10
11.include <bsd.compiler.mk>
12
13# the default is gnu99 for now
14CSTD?=		gnu99
15
16.if ${CSTD} == "c89" || ${CSTD} == "c90"
17CFLAGS+=	-std=iso9899:1990
18.elif ${CSTD} == "c94" || ${CSTD} == "c95"
19CFLAGS+=	-std=iso9899:199409
20.elif ${CSTD} == "c99"
21CFLAGS+=	-std=iso9899:1999
22.else # CSTD
23CFLAGS+=	-std=${CSTD}
24.endif # CSTD
25
26.if !empty(CXXSTD)
27CXXFLAGS+=	-std=${CXXSTD}
28.endif
29
30# This gives the Makefile we're evaluating at the top-level a chance to set
31# WARNS.  If it doesn't do so, we may freely pull a DEFAULTWARNS if it's set
32# and use that.  This allows us to default WARNS to 6 for src builds without
33# needing to set the default in various Makefile.inc.
34.if !defined(WARNS) && defined(DEFAULTWARNS)
35WARNS=	${DEFAULTWARNS}
36.endif
37
38# -pedantic is problematic because it also imposes namespace restrictions
39#CFLAGS+=	-pedantic
40.if defined(WARNS)
41.if ${WARNS} >= 1
42CWARNFLAGS+=	-Wsystem-headers
43.if ${MK_WERROR} != "no" && ${MK_WERROR.${COMPILER_TYPE}:Uyes} != "no"
44CWARNFLAGS+=	-Werror
45.endif # ${MK_WERROR} != "no" && ${MK_WERROR.${COMPILER_TYPE}:Uyes} != "no"
46.endif # WARNS >= 1
47.if ${WARNS} >= 2
48CWARNFLAGS+=	-Wall -Wno-format-y2k
49.endif # WARNS >= 2
50.if ${WARNS} >= 3
51CWARNFLAGS+=	-W -Wno-unused-parameter
52.if ${COMPILER_TYPE} == "clang"
53CWARNFLAGS+=	-Wstrict-prototypes
54.endif
55CWARNFLAGS+=	-Wmissing-prototypes -Wpointer-arith
56.endif # WARNS >= 3
57.if ${WARNS} >= 4
58CWARNFLAGS+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
59		-Wunused-parameter
60.if !defined(NO_WCAST_ALIGN) && !defined(NO_WCAST_ALIGN.${COMPILER_TYPE})
61CWARNFLAGS+=	-Wcast-align
62.endif # !NO_WCAST_ALIGN !NO_WCAST_ALIGN.${COMPILER_TYPE}
63.endif # WARNS >= 4
64.if ${WARNS} >= 6
65CWARNFLAGS+=	-Wchar-subscripts -Wnested-externs \
66		-Wold-style-definition
67.if !defined(NO_WMISSING_VARIABLE_DECLARATIONS)
68CWARNFLAGS.clang+=	-Wmissing-variable-declarations
69.endif
70.if !defined(NO_WTHREAD_SAFETY)
71CWARNFLAGS.clang+=	-Wthread-safety
72.endif
73.endif # WARNS >= 6
74.if ${WARNS} >= 2 && ${WARNS} <= 4
75# XXX Delete -Wuninitialized by default for now -- the compiler doesn't
76# XXX always get it right.
77CWARNFLAGS+=	-Wno-uninitialized
78.endif # WARNS >=2 && WARNS <= 4
79CWARNFLAGS+=	-Wno-pointer-sign
80.if !defined(NO_WDATE_TIME)
81CWARNFLAGS+=	-Wdate-time
82.endif # NO_WDATE_TIME
83# Clang has more warnings enabled by default, and when using -Wall, so if WARNS
84# is set to low values, these have to be disabled explicitly.
85.if ${WARNS} <= 6
86CWARNFLAGS.clang+=	-Wno-empty-body -Wno-string-plus-int
87CWARNFLAGS.clang+=	-Wno-unused-const-variable
88.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 150000
89CWARNFLAGS.clang+=	-Wno-error=unused-but-set-parameter
90.endif
91.endif # WARNS <= 6
92.if ${WARNS} <= 3
93CWARNFLAGS.clang+=	-Wno-tautological-compare -Wno-unused-value\
94		-Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion
95CWARNFLAGS.clang+=	-Wno-unused-local-typedef
96CWARNFLAGS.clang+=	-Wno-address-of-packed-member
97.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 90100
98CWARNFLAGS.gcc+=	-Wno-address-of-packed-member
99.endif
100.endif # WARNS <= 3
101.if ${WARNS} <= 2
102CWARNFLAGS.clang+=	-Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter
103.endif # WARNS <= 2
104.if ${WARNS} <= 1
105CWARNFLAGS.clang+=	-Wno-parentheses
106.endif # WARNS <= 1
107.if defined(NO_WARRAY_BOUNDS)
108CWARNFLAGS.clang+=	-Wno-array-bounds
109.endif # NO_WARRAY_BOUNDS
110.if defined(NO_WMISLEADING_INDENTATION) && \
111    ((${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 100000) || \
112      ${COMPILER_TYPE} == "gcc")
113CWARNFLAGS+=		-Wno-misleading-indentation
114.endif # NO_WMISLEADING_INDENTATION
115.if ${COMPILER_VERSION} >= 130000
116NO_WUNUSED_BUT_SET_VARIABLE=	-Wno-unused-but-set-variable
117.endif
118.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 140000
119NO_WBITWISE_INSTEAD_OF_LOGICAL=	-Wno-bitwise-instead-of-logical
120.endif
121.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 150000
122NO_WARRAY_PARAMETER=	-Wno-array-parameter
123NO_WSTRICT_PROTOTYPES=	-Wno-strict-prototypes
124NO_WDEPRECATED_NON_PROTOTYPE=-Wno-deprecated-non-prototype
125.endif
126.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 50200
127NO_WUNUSED_BUT_SET_VARIABLE=-Wno-unused-but-set-variable
128.endif
129.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 100100
130NO_WZERO_LENGTH_BOUNDS=	-Wno-zero-length-bounds
131.endif
132.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 110100
133NO_WARRAY_PARAMETER=	-Wno-array-parameter
134.endif
135.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 120100
136NO_WUSE_AFTER_FREE=	-Wno-use-after-free
137NO_WDANGLING_POINTER=	-Wno-dangling-pointer
138.endif
139.endif # WARNS
140
141.if defined(FORMAT_AUDIT)
142WFORMAT=	1
143.endif # FORMAT_AUDIT
144.if defined(WFORMAT)
145.if ${WFORMAT} > 0
146#CWARNFLAGS+=	-Wformat-nonliteral -Wformat-security -Wno-format-extra-args
147CWARNFLAGS+=	-Wformat=2 -Wno-format-extra-args
148.if ${WARNS:U0} <= 3
149CWARNFLAGS.clang+=	-Wno-format-nonliteral
150.endif # WARNS <= 3
151.if ${MK_WERROR} != "no" && ${MK_WERROR.${COMPILER_TYPE}:Uyes} != "no"
152CWARNFLAGS+=	-Werror
153.endif # ${MK_WERROR} != "no" && ${MK_WERROR.${COMPILER_TYPE}:Uyes} != "no"
154.endif # WFORMAT > 0
155.endif # WFORMAT
156.if defined(NO_WFORMAT) || defined(NO_WFORMAT.${COMPILER_TYPE})
157CWARNFLAGS+=	-Wno-format
158.endif # NO_WFORMAT || NO_WFORMAT.${COMPILER_TYPE}
159
160# GCC
161# We should clean up warnings produced with these flags.
162# They were originally added as a quick hack to enable gcc5/6.
163# The base system requires at least GCC 6.4, but some ports
164# use this file with older compilers.  Request an exprun
165# before changing these.
166.if ${COMPILER_TYPE} == "gcc"
167# GCC 5.2.0
168.if ${COMPILER_VERSION} >= 50200
169CWARNFLAGS+=	-Wno-error=address			\
170		-Wno-error=array-bounds			\
171		-Wno-error=attributes			\
172		-Wno-error=bool-compare			\
173		-Wno-error=cast-align			\
174		-Wno-error=clobbered			\
175		-Wno-error=deprecated-declarations	\
176		-Wno-error=enum-compare			\
177		-Wno-error=extra			\
178		-Wno-error=logical-not-parentheses	\
179		-Wno-error=strict-aliasing		\
180		-Wno-error=uninitialized		\
181		-Wno-error=unused-function		\
182		-Wno-error=unused-value
183.endif
184
185# GCC 6.1.0
186.if ${COMPILER_VERSION} >= 60100
187CWARNFLAGS+=	-Wno-error=empty-body			\
188		-Wno-error=maybe-uninitialized		\
189		-Wno-error=nonnull-compare		\
190		-Wno-error=shift-negative-value		\
191		-Wno-error=tautological-compare		\
192		-Wno-error=unused-const-variable
193.endif
194
195# GCC 7.1.0
196.if ${COMPILER_VERSION} >= 70100
197CWARNFLAGS+=	-Wno-error=bool-operation		\
198		-Wno-error=deprecated			\
199		-Wno-error=expansion-to-defined		\
200		-Wno-error=format-overflow		\
201		-Wno-error=format-truncation		\
202		-Wno-error=implicit-fallthrough		\
203		-Wno-error=int-in-bool-context		\
204		-Wno-error=memset-elt-size		\
205		-Wno-error=noexcept-type		\
206		-Wno-error=nonnull			\
207		-Wno-error=pointer-compare		\
208		-Wno-error=stringop-overflow
209.endif
210
211# GCC 8.1.0
212.if ${COMPILER_VERSION} >= 80100
213CWARNFLAGS+=	-Wno-error=aggressive-loop-optimizations	\
214		-Wno-error=cast-function-type			\
215		-Wno-error=catch-value				\
216		-Wno-error=multistatement-macros		\
217		-Wno-error=restrict				\
218		-Wno-error=sizeof-pointer-memaccess		\
219		-Wno-error=stringop-truncation
220.endif
221
222# GCC 9.2.0
223.if ${COMPILER_VERSION} >= 90200
224.if ${MACHINE_ARCH} == "i386"
225CWARNFLAGS+=	-Wno-error=overflow
226.endif
227.endif
228
229# GCC 12.1.0
230.if ${COMPILER_VERSION} >= 120100
231# These warnings are raised by headers in libc++ so are disabled
232# globally for all C++
233CXXWARNFLAGS+=	-Wno-literal-suffix 			\
234		-Wno-error=unknown-pragmas
235.endif
236
237# GCC 13.1.0
238.if ${COMPILER_VERSION} >= 130100
239# These warnings are raised by headers in libc++ so are disabled
240# globally for all C++
241CXXWARNFLAGS+=	-Wno-dangling-reference
242.endif
243
244# GCC produces false positives for functions that switch on an
245# enum (GCC bug 87950)
246CWARNFLAGS+=	-Wno-return-type
247
248# GCC's own arm_neon.h triggers various warnings
249.if ${MACHINE_CPUARCH} == "aarch64"
250CWARNFLAGS+=	-Wno-system-headers
251.endif
252.endif	# gcc
253
254# How to handle FreeBSD custom printf format specifiers.
255.if ${COMPILER_TYPE} == "clang" || \
256    (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 120100)
257FORMAT_EXTENSIONS=	-D__printf__=__freebsd_kprintf__
258.else
259FORMAT_EXTENSIONS=	-fformat-extensions
260.endif
261
262.if defined(IGNORE_PRAGMA)
263CWARNFLAGS+=	-Wno-unknown-pragmas
264.endif # IGNORE_PRAGMA
265
266# This warning is utter nonsense
267CFLAGS+=	-Wno-format-zero-length
268
269.if ${COMPILER_TYPE} == "clang"
270# The headers provided by clang are incompatible with the FreeBSD headers.
271# If the version of clang is not one that has been patched to omit the
272# incompatible headers, we need to compile with -nobuiltininc and add the
273# resource dir to the end of the search paths. This ensures that headers such as
274# immintrin.h are still found but stddef.h, etc. are picked up from FreeBSD.
275#
276# XXX: This is a hack to support complete external installs of clang while
277# we work to synchronize our decleration guards with those in the clang tree.
278.if ${MK_CLANG_BOOTSTRAP:Uno} == "no" && \
279    ${COMPILER_RESOURCE_DIR} != "unknown" && !defined(BOOTSTRAPPING)
280CFLAGS+=-nobuiltininc -idirafter ${COMPILER_RESOURCE_DIR}/include
281.endif
282.endif
283
284CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3
285.if ${COMPILER_VERSION} < 130000
286CLANG_OPT_SMALL+= -mllvm -simplifycfg-dup-ret
287.endif
288CLANG_OPT_SMALL+= -mllvm -enable-load-pre=false
289CFLAGS.clang+=	 -Qunused-arguments
290# The libc++ headers use c++11 extensions.  These are normally silenced because
291# they are treated as system headers, but we explicitly disable that warning
292# suppression when building the base system to catch bugs in our headers.
293# Eventually we'll want to start building the base system C++ code as C++11,
294# but not yet.
295CXXFLAGS.clang+=	 -Wno-c++11-extensions
296
297# XXX This should be defaulted to 2 when WITH_SSP is in use after further
298# testing and soak time.
299FORTIFY_SOURCE?=	0
300.if ${MK_SSP} != "no"
301# Don't use -Wstack-protector as it breaks world with -Werror.
302SSP_CFLAGS?=	-fstack-protector-strong
303CFLAGS+=	${SSP_CFLAGS}
304.endif # SSP
305.if ${FORTIFY_SOURCE} > 0
306CFLAGS+=	-D_FORTIFY_SOURCE=${FORTIFY_SOURCE}
307CXXFLAGS+=	-D_FORTIFY_SOURCE=${FORTIFY_SOURCE}
308.endif
309
310# Additional flags passed in CFLAGS and CXXFLAGS when MK_DEBUG_FILES is
311# enabled.
312DEBUG_FILES_CFLAGS?= -g -gz=zlib
313
314# Allow user-specified additional warning flags, plus compiler and file
315# specific flag overrides, unless we've overridden this...
316.if ${MK_WARNS} != "no"
317CFLAGS+=	${CWARNFLAGS:M*} ${CWARNFLAGS.${COMPILER_TYPE}}
318CFLAGS+=	${CWARNFLAGS.${.IMPSRC:T}}
319CXXFLAGS+=	${CXXWARNFLAGS:M*} ${CXXWARNFLAGS.${COMPILER_TYPE}}
320CXXFLAGS+=	${CXXWARNFLAGS.${.IMPSRC:T}}
321.endif
322
323CFLAGS+=	 ${CFLAGS.${COMPILER_TYPE}}
324CXXFLAGS+=	 ${CXXFLAGS.${COMPILER_TYPE}}
325
326AFLAGS+=	${AFLAGS.${.IMPSRC:T}}
327AFLAGS+=	${AFLAGS.${.TARGET:T}}
328ACFLAGS+=	${ACFLAGS.${.IMPSRC:T}}
329ACFLAGS+=	${ACFLAGS.${.TARGET:T}}
330CFLAGS+=	${CFLAGS.${.IMPSRC:T}}
331CXXFLAGS+=	${CXXFLAGS.${.IMPSRC:T}}
332
333LDFLAGS+=	${LDFLAGS.${LINKER_TYPE}}
334
335# Only allow .TARGET when not using PROGS as it has the same syntax
336# per PROG which is ambiguous with this syntax. This is only needed
337# for PROG_VARS vars.
338#
339# Some directories (currently just clang) also need to disable this since
340# CFLAGS.${COMPILER_TYPE}, CFLAGS.${.IMPSRC:T} and CFLAGS.${.TARGET:T} all live
341# in the same namespace, meaning that, for example, GCC builds of clang pick up
342# CFLAGS.clang via CFLAGS.${.TARGET:T} and thus try to pass Clang-specific
343# flags. Ideally the different sources of CFLAGS would be namespaced to avoid
344# collisions.
345.if !defined(_RECURSING_PROGS) && !defined(NO_TARGET_FLAGS)
346.if ${MK_WARNS} != "no"
347CFLAGS+=	${CWARNFLAGS.${.TARGET:T}}
348.endif
349CFLAGS+=	${CFLAGS.${.TARGET:T}}
350CXXFLAGS+=	${CXXFLAGS.${.TARGET:T}}
351LDFLAGS+=	${LDFLAGS.${.TARGET:T}}
352LDADD+=		${LDADD.${.TARGET:T}}
353LIBADD+=	${LIBADD.${.TARGET:T}}
354.endif
355
356.if defined(SRCTOP)
357# Prevent rebuilding during install to support read-only objdirs.
358.if ${.TARGETS:M*install*} == ${.TARGETS} && empty(.MAKE.MODE:Mmeta)
359CFLAGS+=	ERROR-tried-to-rebuild-during-make-install
360.endif
361.endif
362
363# Please keep this if in sync with kern.mk
364.if ${LD} != "ld" && (${CC:[1]:H} != ${LD:[1]:H} || ${LD:[1]:T} != "ld")
365# Add -fuse-ld=${LD} if $LD is in a different directory or not called "ld".
366.if ${COMPILER_TYPE} == "clang"
367# Note: Clang does not like relative paths for ld so we map ld.lld -> lld.
368.if ${COMPILER_VERSION} >= 120000
369LDFLAGS+=	--ld-path=${LD:[1]:S/^ld.//1W}
370.else
371LDFLAGS+=	-fuse-ld=${LD:[1]:S/^ld.//1W}
372.endif
373.elif ${COMPILER_TYPE} == "gcc"
374# GCC does not support an absolute path for -fuse-ld so we just print this
375# warning instead and let the user add the required symlinks.
376# However, we can avoid this warning if -B is set appropriately (e.g. for
377# CROSS_TOOLCHAIN=...-gcc).
378.if !(${LD:[1]:T} == "ld" && ${CC:tw:M-B${LD:[1]:H}/})
379.warning LD (${LD}) is not the default linker for ${CC} but -fuse-ld= is not supported
380.endif
381.endif
382.endif
383
384# Tell bmake not to mistake standard targets for things to be searched for
385# or expect to ever be up-to-date.
386PHONY_NOTMAIN = analyze afterdepend afterinstall all beforedepend beforeinstall \
387		beforelinking build build-tools buildconfig buildfiles \
388		buildincludes check checkdpadd clean cleandepend cleandir \
389		cleanobj configure depend distclean distribute exe \
390		files html includes install installconfig installdirs \
391		installfiles installincludes lint obj objlink objs objwarn \
392		realinstall tags whereobj
393
394# we don't want ${PROG} to be PHONY
395.PHONY: ${PHONY_NOTMAIN:N${PROG:U}}
396.NOTMAIN: ${PHONY_NOTMAIN:Nall}
397
398.if ${MK_STAGING} != "no"
399.if defined(_SKIP_BUILD) || (!make(all) && !make(clean*) && !make(*clean))
400_SKIP_STAGING?= yes
401.endif
402.if ${_SKIP_STAGING:Uno} == "yes"
403staging stage_libs stage_files stage_as stage_links stage_symlinks:
404.else
405# allow targets like beforeinstall to be leveraged
406DESTDIR= ${STAGE_OBJTOP}
407.export DESTDIR
408
409.if target(beforeinstall)
410.if !empty(_LIBS) || (${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG))
411staging: beforeinstall
412.endif
413.endif
414
415# normally only libs and includes are staged
416.if ${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG)
417STAGE_DIR.prog= ${STAGE_OBJTOP}${BINDIR}
418
419.if !empty(PROG)
420.if defined(PROGNAME)
421STAGE_AS_SETS+= prog
422STAGE_AS_${PROG}= ${PROGNAME}
423stage_as.prog: ${PROG}
424.else
425STAGE_SETS+= prog
426stage_files.prog: ${PROG}
427STAGE_TARGETS+= stage_files
428.endif
429.endif
430.endif
431
432.if !empty(_LIBS) && !defined(INTERNALLIB)
433.if defined(SHLIBDIR) && ${SHLIBDIR} != ${LIBDIR} && ${_LIBS:Uno:M*.so.*} != ""
434STAGE_SETS+= shlib
435STAGE_DIR.shlib= ${STAGE_OBJTOP}${SHLIBDIR}
436STAGE_FILES.shlib+= ${_LIBS:M*.so.*}
437stage_files.shlib: ${_LIBS:M*.so.*}
438.endif
439
440.if defined(SHLIB_LINK) && commands(${SHLIB_LINK:R}.ld)
441STAGE_AS_SETS+= ldscript
442STAGE_AS.ldscript+= ${SHLIB_LINK:R}.ld
443stage_as.ldscript: ${SHLIB_LINK:R}.ld
444STAGE_DIR.ldscript = ${STAGE_LIBDIR}
445STAGE_AS_${SHLIB_LINK:R}.ld:= ${SHLIB_LINK}
446NO_SHLIB_LINKS=
447.endif
448
449.if defined(STATIC_LDSCRIPT) && target(lib${LIB}.ald)
450STAGE_AS_SETS+= ald
451STAGE_DIR.ald = ${STAGE_LIBDIR}
452STAGE_AS.ald+= lib${LIB}.ald
453STAGE_AS_lib${LIB}.ald = lib${LIB}.a
454stage_as.ald: lib${LIB}.ald
455.endif
456
457.if target(stage_files.shlib)
458stage_libs: ${_LIBS}
459.if defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols)
460stage_files.shlib: ${SHLIB_NAME}.symbols
461.endif
462.else
463stage_libs: ${_LIBS}
464.endif
465.if defined(SHLIB_NAME) && defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols)
466stage_libs: ${SHLIB_NAME}.symbols
467.endif
468
469.endif
470
471.if !empty(INCS) || !empty(INCSGROUPS) && target(buildincludes)
472.if !defined(NO_BEFOREBUILD_INCLUDES)
473stage_includes: buildincludes
474beforebuild: stage_includes
475.endif
476.endif
477
478.for t in stage_libs stage_files stage_as
479.if target($t)
480STAGE_TARGETS+= $t
481.endif
482.endfor
483
484.if !empty(STAGE_AS_SETS)
485STAGE_TARGETS+= stage_as
486.endif
487
488.if !empty(STAGE_TARGETS) || (${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG))
489
490.if !empty(LINKS)
491STAGE_TARGETS+= stage_links
492.if ${MAKE_VERSION} < 20131001
493stage_links.links: ${_LIBS} ${PROG}
494.endif
495STAGE_SETS+= links
496STAGE_LINKS.links= ${LINKS}
497.endif
498
499.if !empty(SYMLINKS)
500STAGE_TARGETS+= stage_symlinks
501STAGE_SETS+= links
502STAGE_SYMLINKS.links= ${SYMLINKS}
503.endif
504
505.endif
506
507.include <meta.stage.mk>
508.endif
509.endif
510
511.if defined(META_TARGETS)
512.for _tgt in ${META_TARGETS}
513.if target(${_tgt})
514${_tgt}: ${META_DEPS}
515.endif
516.endfor
517.endif
518
519# we are generally the last makefile read
520CFLAGS+= ${CFLAGS_LAST}
521CXXFLAGS+= ${CXXFLAGS_LAST}
522LDFLAGS+= ${LDFLAGS_LAST}
523