Make tls-psk-identity available during request processing
[freeradius.git] / scripts / boiler.mk
1 # boilermake: A reusable, but flexible, boilerplate Makefile.
2 #
3 # Copyright 2008, 2009, 2010 Dan Moulding, Alan T. DeKok
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 # Caution: Don't edit this Makefile! Create your own main.mk and other
19 #          submakefiles, which will be included by this Makefile.
20 #          Only edit this if you need to modify boilermake's behavior (fix
21 #          bugs, add features, etc).
22
23 # Note: Parameterized "functions" in this makefile that are marked with
24 #       "USE WITH EVAL" are only useful in conjuction with eval. This is
25 #       because those functions result in a block of Makefile syntax that must
26 #       be evaluated after expansion. Since they must be used with eval, most
27 #       instances of "$" within them need to be escaped with a second "$" to
28 #       accomodate the double expansion that occurs when eval is invoked.
29
30 #
31 #  You can watch what it's doing by:
32 #
33 #       $ VERBOSE=1 make ... args ...
34 #
35 ifeq "${VERBOSE}" ""
36     Q=@
37 else
38     Q=
39 endif
40
41 # ADD_CLEAN_RULE - Parameterized "function" that adds a new rule and phony
42 #   target for cleaning the specified target (removing its build-generated
43 #   files).
44 #
45 #   USE WITH EVAL
46 #
47 define ADD_CLEAN_RULE
48     clean: clean_$(notdir ${1})
49     .PHONY: clean_$(notdir ${1})
50     clean_$(notdir ${1}):
51         $(Q)$(strip rm -f ${${1}_BUILD}/${1} $${${1}_OBJS} $${${1}_DEPS} $${${1}_OBJS:%.${OBJ_EXT}=%.[do]}) $(if ${TARGET_DIR},$${TARGET_DIR}/$(notdir ${1}))
52         $${${1}_POSTCLEAN}
53
54 endef
55
56 # FILTER_DEPENDS: function to turn a *.d file into a *.mk file.
57 #   We start off with the dependencies as created by the compiler,
58 #   CPP, or makedepend.  We then ensure that there is an empty dependency
59 #   for each header file.  The blank target ensures that the build
60 #   can proceed even if the header file has been deleted.
61 #
62 #  COMMON filters:
63 #       remove comments
64 #       remove dependencies on global include files
65 #       remove empty dependencies
66 #       remove CPP hacks like "foo: <built-in>"
67 #
68 #  1) Filter the .d file to remove unnecessary cruft
69 #
70 #       COMMON
71 #       Replace ".o" with "${OBJ_EXT}"
72 #       delete empty continuation lines
73 #       delete blank lines
74 #       replace "build/" with "${BUILD_DIR}/" when it's at the start of a line
75 #       delete references to ${BUILD_DIR}/make/include, the "config.mk"
76 #       file adds these dependencies automatically.
77 #       replace "build/" with "${BUILD_DIR}/" when it's in the middle of a line
78 #
79 #       remove sequential duplicate lines
80 #
81 #  2) Create empty dependencies from the files
82 #
83 #       COMMON
84 #       remove existing targets
85 #       remove continuations (to make the targets stand by themselves)
86 #       delete blank lines
87 #       add in empty dependency for each file.
88 #       remove sequential duplicate lines
89 #
90 define FILTER_DEPENDS
91         $(Q)mkdir -p $$(dir $${BUILD_DIR}/make/src/$$*)
92         $(Q)mkdir -p $$(dir $${BUILD_DIR}/objs/$$*)
93         $(Q)sed  -e 's/#.*//' \
94           -e 's,^$${top_srcdir},$$$${top_srcdir},' \
95           -e 's, $${top_srcdir}, $$$${top_srcdir},' \
96           -e 's,^$${BUILD_DIR},$$$${BUILD_DIR},' \
97           -e 's, $${BUILD_DIR}/make/include/[^ :]*,,' \
98           -e 's, $${BUILD_DIR}, $$$${BUILD_DIR},' \
99           -e 's, /[^: ]*,,g' \
100           -e 's,^ *[^:]* *: *$$$$,,' \
101           -e '/: </ d' \
102           -e 's/\.o: /.$$$${OBJ_EXT}: /' \
103           -e '/^ *\\$$$$/ d' \
104           < $${BUILD_DIR}/objs/$$*.d | sed -e '$$$$!N; /^\(.*\)\n\1$$$$/!P; D' \
105           >  $${BUILD_DIR}/make/src/$$*.mk
106         $(Q)sed -e 's/#.*//' \
107           -e 's, $${BUILD_DIR}/make/include/[^ :]*,,' \
108           -e 's, /[^: ]*,,g' \
109           -e 's,^ *[^:]* *: *$$$$,,' \
110           -e '/: </ d' \
111           -e 's/^[^:]*: *//' \
112           -e 's/ *\\$$$$//' \
113           -e 's/$$$$/ :/' \
114           < $${BUILD_DIR}/objs/$$*.d | sed -e '$$$$!N; /^\(.*\)\n\1$$$$/!P; D' \
115          >> $${BUILD_DIR}/make/src/$$*.mk
116          @rm -f $${BUILD_DIR}/objs/$$*.d
117 endef
118
119 # ADD_OBJECT_RULE - Parameterized "function" that adds a pattern rule, using
120 #   the commands from the second argument, for building object files from
121 #   source files with the filename extension specified in the first argument.
122 #
123 #   This function assumes that the C/C++ sources files have filenames
124 #   *relative* to the source root.  If they have absolute pathnames, it
125 #   creates the wrong filenames...
126 #
127 #   USE WITH EVAL
128 #
129 ifeq "${CPP_MAKEDEPEND}" "yes"
130 define ADD_OBJECT_RULE
131 $${BUILD_DIR}/objs/%.${OBJ_EXT} $${BUILD_DIR}/objs/%.d: ${1} ${JLIBTOOL}
132         ${2}
133         $${CPP} $${CPPFLAGS} $${SRC_INCDIRS} $${SRC_DEFS} $$< | sed \
134           -n 's,^\# *[0-9][0-9]* *"\([^"]*\)".*,$$@: \1,p' > $${BUILD_DIR}/objs/$$*.d
135 ${FILTER_DEPENDS}
136 endef
137
138 else
139 define ADD_OBJECT_RULE
140 $${BUILD_DIR}/objs/%.${OBJ_EXT} $${BUILD_DIR}/objs/%.d: ${1} ${JLIBTOOL}
141         ${2}
142 ${FILTER_DEPENDS}
143 endef
144 endif
145
146 define ADD_ANALYZE_RULE
147 $${BUILD_DIR}/plist/%.plist: ${1} ${JLIBTOOL}
148         ${2}
149 endef
150
151 # ADD_TARGET_DIR - Parameterized "function" that makes a link from
152 #   TARGET_DIR to the executable or library in the BUILD_DIR directory.
153 #
154 #   USE WITH EVAL
155 #
156 ifneq "${TARGET_DIR}" ""
157     define ADD_TARGET_DIR
158         all: $${TARGET_DIR}/$$(notdir ${1})
159
160         $${TARGET_DIR}/$$(notdir ${1}): ${1}
161             [ -f $${TARGET_DIR}/$$(notdir ${1}) ] || ln -s ${1} $${TARGET_DIR}/$$(notdir ${1})
162
163     endef
164 endif
165
166 # ADD_TARGET_TO_ALL - Parameterized "function" that adds the target,
167 #   and makes "all" depend on it.
168 #
169 #   USE WITH EVAL
170 #
171 define ADD_TARGET_TO_ALL
172     all: ${1}
173
174 endef
175
176 # ADD_TARGET_RULE.* - Parameterized "functions" that adds a new target to the
177 #   Makefile.  There should be one ADD_TARGET_RULE definition for each
178 #   type of target that is used in the build.
179 #
180 #   New rules can be added by copying one of the existing ones, and
181 #   replacing the line after the "mkdir"
182 #
183
184 # ADD_TARGET_RULE.exe - Build an executable target.
185 #
186 #   USE WITH EVAL
187 #
188 define ADD_TARGET_RULE.exe
189     # So "make ${1}" works
190     .PHONY: ${1}
191     ${1}: $${${1}_BUILD}/${1}
192
193     # Create executable ${1}
194     $${${1}_BUILD}/${1}: $${${1}_OBJS} $${${1}_PRBIN} $${${1}_PRLIBS}
195             $(Q)$(strip mkdir -p $(dir $${${1}_BUILD}/${1}))
196             $(Q)$(ECHO) LINK $${${1}_BUILD}/${1}
197             $(Q)$${${1}_LINKER} -o $${${1}_BUILD}/${1} $${RPATH_FLAGS} $${LDFLAGS} \
198                 $${${1}_LDFLAGS} $${${1}_OBJS} $${${1}_PRLIBS} \
199                 $${LDLIBS} $${${1}_LDLIBS}
200             $(Q)$${${1}_POSTMAKE}
201
202     ifneq "${ANALYZE.c}" ""
203         scan.${1}: $${${1}_PLISTS}
204     endif
205 endef
206
207 # ADD_TARGET_RULE.a - Build a static library target.
208 #
209 #   USE WITH EVAL
210 #
211 define ADD_TARGET_RULE.a
212     # So "make ${1}" works
213     .PHONY: ${1}
214     ${1}: $${${1}_BUILD}/${1}
215
216     # Create static library ${1}
217     $${${1}_BUILD}/${1}: $${${1}_OBJS} $${${1}_PRLIBS}
218             $(Q)$(strip mkdir -p $(dir $${${1}_BUILD}/${1}))
219             $(Q)$(ECHO) LINK $${${1}_BUILD}/${1}
220             $(Q)$${AR} $${ARFLAGS} $${${1}_BUILD}/${1} $${${1}_OBJS}
221             $(Q)$${${1}_POSTMAKE}
222
223     ifneq "${ANALYZE.c}" ""
224         scan.${1}: $${${1}_PLISTS}
225     endif
226 endef
227
228 # ADD_TARGET_RULE.so - Build a ".so" target.
229 #
230 #   USE WITH EVAL
231 #
232 define ADD_TARGET_RULE.so
233 $(error Please add rules to build a ".so" file.)
234 endef
235
236 # ADD_TARGET_RULE.dll - Build a ".dll" target.
237 #
238 #   USE WITH EVAL
239 #
240 define ADD_TARGET_RULE.dll
241 $(error Please add rules to build a ".dll" file.)
242 endef
243
244 # ADD_TARGET_RULE.dylib - Build a ".dylib" target.
245 #
246 #   USE WITH EVAL
247 #
248 define ADD_TARGET_RULE.dylib
249 $(error Please add rules to build a ".dylib" file.)
250 endef
251
252 # CANONICAL_PATH - Given one or more paths, converts the paths to the canonical
253 #   form. The canonical form is the path, relative to the project's top-level
254 #   directory (the directory from which "make" is run), and without
255 #   any "./" or "../" sequences. For paths that are not  located below the
256 #   top-level directory, the canonical form is the absolute path (i.e. from
257 #   the root of the filesystem) also without "./" or "../" sequences.
258 define CANONICAL_PATH
259 $(patsubst ${CURDIR}/%,%,$(abspath ${1}))
260 endef
261
262 # COMPILE_C_CMDS - Commands for compiling C source code.
263 define COMPILE_C_CMDS
264         $(Q)mkdir -p $(dir $@)
265         $(Q)$(ECHO) CC $<
266         $(Q)$(strip ${COMPILE.c} -o $@ -c -MD ${CPPFLAGS} ${CFLAGS} ${SRC_CFLAGS} ${INCDIRS} \
267             ${SRC_INCDIRS} ${SRC_DEFS} ${DEFS} $<)
268 endef
269
270 # ANALYZE_C_CMDS - Commands for analyzing C source code with clang.
271 define ANALYZE_C_CMDS
272         $(Q)mkdir -p $(dir $@)
273         $(Q)$(ECHO) SCAN $<
274         ${Q}$(strip ${ANALYZE.c} --analyze -Xanalyzer -analyzer-output=html -c $< -o $@ ${CPPFLAGS} \
275             ${CFLAGS} ${SRC_CFLAGS} ${INCDIRS} ${SRC_INCDIRS} ${SRC_DEFS} ${DEFS}) || (rm -f $@ && false)
276         $(Q)touch $@
277 endef
278
279 # COMPILE_CXX_CMDS - Commands for compiling C++ source code.
280 define COMPILE_CXX_CMDS
281         $(Q)mkdir -p $(dir $@)
282         $(Q)$(strip ${COMPILE.cxx} -o $@ -c -MD ${CPPFLAGS} ${CXXFLAGS} ${SRC_CXXFLAGS} ${INCDIRS} \
283             ${SRC_INCDIRS} ${SRC_DEFS} ${DEFS} $<)
284 endef
285
286 # INCLUDE_SUBMAKEFILE - Parameterized "function" that includes a new
287 #   "submakefile" fragment into the overall Makefile. It also recursively
288 #   includes all submakefiles of the specified submakefile fragment.
289 #
290 #   USE WITH EVAL
291 #
292 define INCLUDE_SUBMAKEFILE
293     # Initialize all variables that can be defined by a makefile fragment, then
294     # include the specified makefile fragment.
295     TARGET :=
296     TGT_LDFLAGS :=
297     TGT_LDLIBS :=
298     TGT_LINKER :=
299     TGT_POSTCLEAN :=
300     TGT_POSTMAKE :=
301     TGT_PREREQS :=
302     TGT_POSTINSTALL :=
303     TGT_INSTALLDIR := ..
304     TGT_CHECK_HEADERS :=
305     TGT_CHECK_LIBS :=
306
307     SOURCES :=
308     SRC_CFLAGS :=
309     SRC_CXXFLAGS :=
310     SRC_DEFS :=
311     SRC_INCDIRS :=
312     MAN :=
313
314     SUBMAKEFILES :=
315
316     # A directory stack is maintained so that the correct paths are used as we
317     # recursively include all submakefiles. Get the makefile's directory and
318     # push it onto the stack.
319     DIR := $(call CANONICAL_PATH,$(dir ${1}))
320     DIR_STACK := $$(call PUSH,$${DIR_STACK},$${DIR})
321
322     include ${1}
323
324     # Initialize internal local variables.
325     OBJS :=
326
327     # Determine which target this makefile's variables apply to. A stack is
328     # used to keep track of which target is the "current" target as we
329     # recursively include other submakefiles.
330     ifneq "$$(strip $${TARGET})" ""
331         # This makefile defined a new target. Target variables defined by this
332         # makefile apply to this new target. Initialize the target's variables.
333
334         # libs go into ${BUILD_DIR}/lib
335         # everything else goes into ${BUILD_DIR}/bin
336 #        TGT := $$(strip $$(if $$(suffix $${TARGET}),$${BUILD_DIR}/lib,$${BUILD_DIR}/bin)/$${TARGET})
337         TGT := $${TARGET}
338
339         # A "hook" to rewrite "libfoo.a" -> "libfoo.la" when using libtool
340         $$(eval $$(call ADD_LIBTOOL_SUFFIX))
341
342         ALL_TGTS += $${TGT}
343         $${TGT}_LDFLAGS := $${TGT_LDFLAGS}
344         $${TGT}_LDLIBS := $${TGT_LDLIBS}
345         $${TGT}_LINKER := $${TGT_LINKER}
346         $${TGT}_POSTMAKE := $${TGT_POSTMAKE}
347         $${TGT}_POSTCLEAN := $${TGT_POSTCLEAN}
348         $${TGT}_POSTINSTALL := $${TGT_POSTINSTALL}
349         $${TGT}_PREREQS := $${TGT_PREREQS}
350         $${TGT}_PRBIN := $$(addprefix $${BUILD_DIR}/bin/,$$(filter-out %.a %.so %.la,$${TGT_PREREQS}))
351         $${TGT}_PRLIBS := $$(addprefix $${BUILD_DIR}/lib/,$$(filter %.a %.so %.la,$${TGT_PREREQS}))
352         $${TGT}_DEPS :=
353         $${TGT}_OBJS :=
354         $${TGT}_SOURCES :=
355         $${TGT}_MAN := $${MAN}
356         $${TGT}_SUFFIX := $$(if $$(suffix $${TGT}),$$(suffix $${TGT}),.exe)
357
358         # If it's an EXE, ensure that transitive library linking works.
359         # i.e. we build libfoo.a which in turn requires -lbar.  So, the executable
360         # has to be linked to both libfoo.a and -lbar.
361         ifeq "$${$${TGT}_SUFFIX}" ".exe"
362                 $${TGT}_LDLIBS += $$(filter-out %.a %.so %.la,$${$${TGT_PREREQS}_LDLIBS})
363         endif
364
365         $${TGT}_BUILD := $$(if $$(suffix $${TGT}),$${BUILD_DIR}/lib,$${BUILD_DIR}/bin)
366         $${TGT}_MAKEFILES += ${1}
367         $${TGT}_CHECK_HEADERS := $${TGT_CHECK_HEADERS}
368         $${TGT}_CHECK_LIBS := $${TGT_CHECK_LIBS}
369     else
370         # The values defined by this makefile apply to the the "current" target
371         # as determined by which target is at the top of the stack.
372         TGT := $$(strip $$(call PEEK,$${TGT_STACK}))
373         $${TGT}_LDFLAGS   += $${TGT_LDFLAGS}
374         $${TGT}_LDLIBS    += $${TGT_LDLIBS}
375         $${TGT}_POSTCLEAN += $${TGT_POSTCLEAN}
376         $${TGT}_POSTMAKE  += $${TGT_POSTMAKE}
377         $${TGT}_PREREQS   += $${TGT_PREREQS}
378     endif
379
380     # Push the current target onto the target stack.
381     TGT_STACK := $$(call PUSH,$${TGT_STACK},$${TGT})
382
383     # If there's no target, don't build the sources.
384     ifneq "$$(strip $${TARGET})" ""
385
386     # if there's no sources, don't do the automatic object build
387     ifneq "$$(strip $${SOURCES})" ""
388         # This makefile builds one or more objects from source. Validate the
389         # specified sources against the supported source file types.
390         BAD_SRCS := $$(strip $$(filter-out $${ALL_SRC_EXTS},$${SOURCES}))
391         ifneq "$${BAD_SRCS}" ""
392             $$(error Unsupported source file(s) found in ${1} [$${BAD_SRCS}])
393         endif
394
395         # Qualify and canonicalize paths.
396         SOURCES     := $$(call QUALIFY_PATH,$${DIR},$${SOURCES})
397         SOURCES     := $$(call CANONICAL_PATH,$${SOURCES})
398         SRC_INCDIRS := $$(call QUALIFY_PATH,$${DIR},$${SRC_INCDIRS})
399         SRC_INCDIRS := $$(call CANONICAL_PATH,$${SRC_INCDIRS})
400
401         # Save the list of source files for this target.
402         $${TGT}_SOURCES += $${SOURCES}
403
404         # Convert the source file names to their corresponding object file
405         # names.
406         OBJS := $$(addprefix $${BUILD_DIR}/objs/,\
407                    $$(addsuffix .${OBJ_EXT},$$(basename $${SOURCES})))
408
409         PLISTS := $$(addprefix $${BUILD_DIR}/plist/,\
410                    $$(addsuffix .plist,$$(basename $${SOURCES})))
411         ALL_PLISTS += ${PLISTS}
412
413         # Add the objects to the current target's list of objects, and create
414         # target-specific variables for the objects based on any source
415         # variables that were defined.
416         $${TGT}_OBJS += $${OBJS}
417         $${TGT}_PLISTS += $${PLISTS}
418         $${TGT}_DEPS += $$(addprefix $${BUILD_DIR}/make/src/,\
419                    $$(addsuffix .mk,$$(basename $${SOURCES})))
420
421         # A "hook" to define variables needed by the "legacy" makefiles.
422         $$(eval $$(call ADD_LEGACY_VARIABLES,$$(dir ${1}),$${TGT}))
423
424         $${OBJS}: SRC_CFLAGS := $${SRC_CFLAGS}
425         $${OBJS}: SRC_CXXFLAGS := $${SRC_CXXFLAGS}
426         $${OBJS}: SRC_DEFS := $$(addprefix -D,$${SRC_DEFS})
427         $${OBJS}: SRC_INCDIRS := $$(addprefix -I,$${SRC_INCDIRS})
428         $${OBJS}: ${1}
429
430         $${PLISTS}: SRC_CFLAGS := $${SRC_CFLAGS}
431         $${PLISTS}: SRC_CXXFLAGS := $${SRC_CXXFLAGS}
432         $${PLISTS}: SRC_DEFS := $$(addprefix -D,$${SRC_DEFS})
433         $${PLISTS}: SRC_INCDIRS := $$(addprefix -I,$${SRC_INCDIRS})
434         $${PLISTS}: ${1}
435     endif
436     endif
437
438     ifneq "$$(strip $${SUBMAKEFILES})" ""
439         # This makefile has submakefiles. Recursively include them.
440         $$(foreach MK,$${SUBMAKEFILES},\
441            $$(eval $$(call INCLUDE_SUBMAKEFILE,\
442                       $$(call CANONICAL_PATH,\
443                          $$(call QUALIFY_PATH,$${DIR},$${MK})))))
444     endif
445
446     # Reset the "current" target to it's previous value.
447     TGT_STACK := $$(call POP,$${TGT_STACK})
448     # If we're about to change targets, create the rules for the target
449     ifneq "$${TGT}" "$$(call PEEK,$${TGT_STACK})"
450         # add rules to build the target, and have "all" depend on it.
451         $$(eval $$(call ADD_TARGET_TO_ALL,$${TGT}))
452
453         # A "hook" to add rules for ${TARGET_DIR}/foo, if TARGET_DIR
454         # is defined.  Otherwise, we leave the source directory untouched.
455         $$(eval $$(call ADD_TARGET_DIR,$${TGT}))
456
457         # A "hook" to build the libtool target.
458         $$(eval $$(call ADD_LIBTOOL_TARGET))
459
460         # Choose the correct linker.
461         ifeq "$$(strip $$(filter $${CXX_SRC_EXTS},$${$${TGT}_SOURCES}))" ""
462             ifeq "$${$${TGT}_LINKER}" ""
463                 $${TGT}_LINKER := ${LL}$${LINK.c}
464             endif
465         else
466             ifeq "$${$${TGT}_LINKER}" ""
467                 $${TGT}_LINKER := ${LL}$${LINK.cxx}
468             endif
469         endif
470
471         # add rules to build the target
472         $$(eval $$(call ADD_TARGET_RULE$${$${TGT}_SUFFIX},$${TGT}))
473
474         # generate the clean rule for this target.
475         $$(eval $$(call ADD_CLEAN_RULE,$${TGT}))
476
477         # Hook to add an installation target
478         $$(eval $$(call ADD_INSTALL_TARGET,$${TGT}))
479
480         # Hook to add a configuration target
481         $$(eval $$(call ADD_TARGET_CONFIG,$${TGT}))
482
483         # "hook" for legacy Makefiles
484         $$(eval $$(call ADD_LEGACY_RULE,$${TGT}))
485     endif
486
487     TGT := $$(call PEEK,$${TGT_STACK})
488
489     # Reset the "current" directory to it's previous value.
490     DIR_STACK := $$(call POP,$${DIR_STACK})
491     DIR := $$(call PEEK,$${DIR_STACK})
492 endef
493
494 # MIN - Parameterized "function" that results in the minimum lexical value of
495 #   the two values given.
496 define MIN
497 $(firstword $(sort ${1} ${2}))
498 endef
499
500 # PEEK - Parameterized "function" that results in the value at the top of the
501 #   specified colon-delimited stack.
502 define PEEK
503 $(lastword $(subst :, ,${1}))
504 endef
505
506 # POP - Parameterized "function" that pops the top value off of the specified
507 #   colon-delimited stack, and results in the new value of the stack. Note that
508 #   the popped value cannot be obtained using this function; use peek for that.
509 define POP
510 ${1:%:$(lastword $(subst :, ,${1}))=%}
511 endef
512
513 # PUSH - Parameterized "function" that pushes a value onto the specified colon-
514 #   delimited stack, and results in the new value of the stack.
515 define PUSH
516 ${2:%=${1}:%}
517 endef
518
519 # QUALIFY_PATH - Given a "root" directory and one or more paths, qualifies the
520 #   paths using the "root" directory (i.e. appends the root directory name to
521 #   the paths) except for paths that are absolute.
522 define QUALIFY_PATH
523 $(addprefix ${1}/,$(filter-out /%,${2})) $(filter /%,${2})
524 endef
525
526 ###############################################################################
527 #
528 # Start of Makefile Evaluation
529 #
530 ###############################################################################
531
532 # Older versions of GNU Make lack capabilities needed by boilermake.
533 # With older versions, "make" may simply output "nothing to do", likely leading
534 # to confusion. To avoid this, check the version of GNU make up-front and
535 # inform the user if their version of make doesn't meet the minimum required.
536 MIN_MAKE_VERSION := 3.81
537 MIN_MAKE_VER_MSG := boilermake requires GNU Make ${MIN_MAKE_VERSION} or greater
538 ifeq "${MAKE_VERSION}" ""
539     $(info GNU Make not detected)
540     $(error ${MIN_MAKE_VER_MSG})
541 endif
542 ifneq "${MIN_MAKE_VERSION}" "$(call MIN,${MIN_MAKE_VERSION},${MAKE_VERSION})"
543     $(info This is GNU Make version ${MAKE_VERSION})
544     $(error ${MIN_MAKE_VER_MSG})
545 endif
546
547 # Define the source file extensions that we know how to handle.
548 OBJ_EXT := o
549 C_SRC_EXTS := %.c
550 CXX_SRC_EXTS := %.C %.cc %.cp %.cpp %.CPP %.cxx %.c++
551 ALL_SRC_EXTS := ${C_SRC_EXTS} ${CXX_SRC_EXTS}
552
553 # Initialize global variables.
554 ALL_TGTS :=
555 DEFS :=
556 DIR_STACK :=
557 INCDIRS :=
558 TGT_STACK :=
559
560 ifeq "${top_builddir}" ""
561     top_builddir := .
562 endif
563
564 # Ensure that valid values are set for BUILD_DIR
565 ifeq "$(strip ${BUILD_DIR})" ""
566     ifeq "${top_builddir}" "${PWD}"
567         BUILD_DIR := build
568     else
569         BUILD_DIR := ${top_builddir}/build
570     endif
571 else
572     BUILD_DIR := $(call CANONICAL_PATH,${BUILD_DIR})
573 endif
574
575 # Define compilers and linkers
576 #
577 COMPILE.c = ${CC}
578 COMPILE.cxx = ${CXX}
579 CPP = cc -E
580 LINK.c = ${CC}
581 LINK.cxx = ${CXX}
582
583 # Set ECHO to "true" for *very* quiet builds
584 ECHO = echo
585
586 # Define the "all" target (which simply builds all user-defined targets) as the
587 # default goal.
588 .PHONY: all
589 all:
590
591 # Add "clean" rules to remove all build-generated files.
592 .PHONY: clean
593 clean:
594
595 top_makedir := $(dir $(lastword ${MAKEFILE_LIST}))
596
597 -include ${top_makedir}/install.mk
598 -include ${top_makedir}/libtool.mk
599
600 # Include the main user-supplied submakefile. This also recursively includes
601 # all other user-supplied submakefiles.
602 $(eval $(call INCLUDE_SUBMAKEFILE,${top_builddir}/main.mk))
603
604 # Perform post-processing on global variables as needed.
605 DEFS := $(addprefix -D,${DEFS})
606 INCDIRS := $(addprefix -I,$(call CANONICAL_PATH,${INCDIRS}))
607
608 # Add pattern rule(s) for creating compiled object code from C source.
609 $(foreach EXT,${C_SRC_EXTS},\
610   $(eval $(call ADD_OBJECT_RULE,${EXT},$${COMPILE_C_CMDS})))
611
612 ifneq "${ANALYZE.c}" ""
613 $(foreach EXT,${C_SRC_EXTS},\
614   $(eval $(call ADD_ANALYZE_RULE,${EXT},$${ANALYZE_C_CMDS})))
615 endif
616
617 # Add pattern rule(s) for creating compiled object code from C++ source.
618 $(foreach EXT,${CXX_SRC_EXTS},\
619   $(eval $(call ADD_OBJECT_RULE,${EXT},$${COMPILE_CXX_CMDS})))
620
621 # Don't include the target dependencies if we're doing a "make clean"
622 # Future: have a list of targets that don't require dependency generation,
623 #  and see if MAKECMDGOALS is one of them.
624 ifneq "$(MAKECMDGOALS)" "clean"
625     $(foreach TGT,${ALL_TGTS},\
626       $(eval -include ${${TGT}_DEPS}))
627 endif
628
629 scan: ${ALL_PLISTS}
630
631 .PHONY: clean.scan
632 clean.scan:
633         $(Q)rm -f ${ALL_PLISTS}
634
635 clean: clean.scan