3 # Released into the public domain.
5 # dean [at] fourwalledcubicle [dot] com
6 # www.fourwalledcubicle.com
9 DMBS_BUILD_MODULES
+= CORE
10 DMBS_BUILD_TARGETS
+= help list_targets list_modules list_mandatory list_optional list_provided list_macros
11 DMBS_BUILD_MANDATORY_VARS
+=
12 DMBS_BUILD_OPTIONAL_VARS
+=
13 DMBS_BUILD_PROVIDED_VARS
+= DMBS_VERSION
14 DMBS_BUILD_PROVIDED_MACROS
+= DMBS_CHECK_VERSION ERROR_IF_UNSET ERROR_IF_EMPTY ERROR_IF_NONBOOL
18 # Current DMBS release version
19 DMBS_VERSION
:= 20160403
21 # Macro to check the DMBS version, aborts if the given DMBS version is below the current version
22 DMBS_CHECK_VERSION ?
= $(if
$(filter-out 0, $(shell test $(DMBS_VERSION
) -lt
$(1); echo
$$?
)), , $(error DMBS version
$(1) or newer required
, current version is
$(DMBS_VERSION
)))
24 # Macros to use in other modules to check various conditions
25 ERROR_IF_UNSET ?
= $(if
$(filter undefined
, $(origin $(strip $(1)))), $(error Makefile
$(strip $(1)) value not set
))
26 ERROR_IF_EMPTY ?
= $(if
$(strip $($(strip $(1)))), , $(error Makefile
$(strip $(1)) option cannot be blank
))
27 ERROR_IF_NONBOOL ?
= $(if
$(filter Y N
, $($(strip $(1)))), , $(error Makefile
$(strip $(1)) option must be Y or N
))
29 # Converts a given input to a printable output using "(None)" if no items are in the list
30 CONVERT_TO_PRINTABLE
= $(if
$(strip $(1)), $(1), (None
))
32 # Build sorted and filtered lists of the included build module data
33 SORTED_DMBS_BUILD_MODULES
= $(sort $(DMBS_BUILD_MODULES
))
34 SORTED_DMBS_BUILD_TARGETS
= $(sort $(DMBS_BUILD_TARGETS
))
35 SORTED_DMBS_MANDATORY_VARS
= $(sort $(DMBS_BUILD_MANDATORY_VARS
))
36 SORTED_DMBS_OPTIONAL_VARS
= $(filter-out $(SORTED_DMBS_MANDATORY_VARS
), $(sort $(DMBS_BUILD_OPTIONAL_VARS
)))
37 SORTED_DMBS_PROVIDED_VARS
= $(sort $(DMBS_BUILD_PROVIDED_VARS
))
38 SORTED_DMBS_PROVIDED_MACROS
= $(sort $(DMBS_BUILD_PROVIDED_MACROS
))
40 # Create printable versions of the sorted build module data (use "(None)" when no data is available)
41 PRINTABLE_DMBS_BUILD_MODULES
= $(call CONVERT_TO_PRINTABLE
, $(SORTED_DMBS_BUILD_MODULES
))
42 PRINTABLE_DMBS_BUILD_TARGETS
= $(call CONVERT_TO_PRINTABLE
, $(SORTED_DMBS_BUILD_TARGETS
))
43 PRINTABLE_DMBS_MANDATORY_VARS
= $(call CONVERT_TO_PRINTABLE
, $(SORTED_DMBS_MANDATORY_VARS
))
44 PRINTABLE_DMBS_OPTIONAL_VARS
= $(call CONVERT_TO_PRINTABLE
, $(SORTED_DMBS_OPTIONAL_VARS
))
45 PRINTABLE_DMBS_PROVIDED_VARS
= $(call CONVERT_TO_PRINTABLE
, $(SORTED_DMBS_PROVIDED_VARS
))
46 PRINTABLE_DMBS_PROVIDED_MACROS
= $(call CONVERT_TO_PRINTABLE
, $(SORTED_DMBS_PROVIDED_MACROS
))
49 @echo
"==================================================================="
50 @echo
" The DMBS Build System "
51 @echo
" By Dean Camera { dean @ fourwalledcubicle . com } "
52 @echo
"==================================================================="
54 @echo
" This build system is a set of makefile modules for (GNU) Make, to "
55 @echo
" provide a simple system for building DMBS powered applications. "
56 @echo
" Each makefile module can be included from within a user makefile, "
57 @echo
" to expose the build rules documented in the comments at the top of"
58 @echo
" each build module. "
61 @echo
" To execute a rule, define all variables indicated in the desired "
62 @echo
" module as a required parameter before including the build module "
63 @echo
" in your project makefile. Parameters marked as optional will "
64 @echo
" assume a default value in the modules if not user-assigned. "
66 @echo
" By default the target output shows both a friendly summary, as "
67 @echo
" well as the actual invoked command. To suppress the output of the "
68 @echo
" invoked commands and show only the friendly command output, run "
69 @echo
" make with the \"-s\" switch added before the target(s). "
70 @echo
"==================================================================="
72 @echo
" Currently used build system modules in this application: "
74 @printf
" %b" "$(PRINTABLE_DMBS_BUILD_MODULES:%= - %\n)"
77 @echo
" Currently available build targets in this application: "
79 @printf
" %b" "$(PRINTABLE_DMBS_BUILD_TARGETS:%= - %\n)"
82 @echo
" Mandatory variables required by the selected build Modules: "
84 @printf
" %b" "$(PRINTABLE_DMBS_MANDATORY_VARS:%= - %\n)"
87 @echo
" Optional variables required by the selected build Modules: "
89 @printf
" %b" "$(PRINTABLE_DMBS_OPTIONAL_VARS:%= - %\n)"
92 @echo
" Variables provided by the selected build Modules: "
94 @printf
" %b" "$(PRINTABLE_DMBS_PROVIDED_VARS:%= - %\n)"
97 @echo
" Macros provided by the selected build Modules: "
99 @printf
" %b" "$(PRINTABLE_DMBS_PROVIDED_MACROS:%= - %\n)"
101 @echo
"==================================================================="
102 @echo
" The DMBS Build System $(DMBS_VERSION) - Making MAKE easier."
103 @echo
"==================================================================="
105 # Lists build modules included by the project makefile, in alphabetical order
107 @echo Currently Used Build System Modules
:
108 @printf
" %b" "$(PRINTABLE_DMBS_BUILD_MODULES:%= - %\n)"
110 # Lists build targets included by the project makefile, in alphabetical order
112 @echo Currently Available Build Targets
:
113 @printf
" %b" "$(PRINTABLE_DMBS_BUILD_TARGETS:%= - %\n)"
115 # Lists mandatory variables that must be set by the project makefile, in alphabetical order
117 @echo Mandatory Variables for Included Modules
:
118 @printf
" %b" "$(PRINTABLE_DMBS_MANDATORY_VARS:%= - %\n)"
120 # Lists optional variables that must be set by the project makefile, in alphabetical order
122 @echo Optional Variables for Included Modules
:
123 @printf
" %b" "$(PRINTABLE_DMBS_OPTIONAL_VARS:%= - %\n)"
125 # Lists variables provided by the included build modules, in alphabetical order
127 @echo Variables Provided by the Included Modules
:
128 @printf
" %b" "$(PRINTABLE_DMBS_PROVIDED_VARS:%= - %\n)"
130 # Lists macros provided by the included build modules, in alphabetical order
132 @echo Macros Provided by the Included Modules
:
133 @printf
" %b" "$(PRINTABLE_DMBS_PROVIDED_MACROS:%= - %\n)"
135 # Debugging; "make print-VARNAME" will output the variable VARNAME's value
137 @printf
"%s = %s" $(@
:print-
%=%) $($(@
:print-
%=%))
139 # Disable default in-built make rules (those that are needed are explicitly
140 # defined, and doing so has performance benefits when recursively building)
141 ifeq ($(filter -r
,$(MAKEFLAGS
)),)
146 # Phony build targets for this module
147 .PHONY
: $(DMBS_BUILD_TARGETS
)