c9d6e21b5ec51d7459d050a56521a24ba8ac4647
[pub/USBasp.git] / LUFA / Build / DMBS / DMBS / core.mk
1 # Include Guard
2 ifeq ($(filter CORE, $(DMBS_BUILD_MODULES)),)
3
4 #
5 # DMBS Build System
6 # Released into the public domain.
7 #
8 # dean [at] fourwalledcubicle [dot] com
9 # www.fourwalledcubicle.com
10 #
11
12 DMBS_BUILD_MODULES += CORE
13 DMBS_BUILD_TARGETS += help list_targets list_modules list_mandatory list_optional list_provided list_macros
14 DMBS_BUILD_MANDATORY_VARS +=
15 DMBS_BUILD_OPTIONAL_VARS +=
16 DMBS_BUILD_PROVIDED_VARS += DMBS_VERSION
17 DMBS_BUILD_PROVIDED_MACROS += DMBS_CHECK_VERSION ERROR_IF_UNSET ERROR_IF_EMPTY ERROR_IF_NONBOOL
18
19 SHELL = /bin/sh
20
21 # Current DMBS release version
22 DMBS_VERSION := 20200719
23
24 # Macro to check the DMBS version, aborts if the given DMBS version is below the current version
25 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)))
26
27 # Macros to use in other modules to check various conditions
28 ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
29 ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
30 ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
31
32 # Converts a given input to a printable output using "(None)" if no items are in the list
33 CONVERT_TO_PRINTABLE = $(if $(strip $(1)), $(1), (None))
34
35 # Build sorted and filtered lists of the included build module data
36 SORTED_DMBS_BUILD_MODULES = $(sort $(DMBS_BUILD_MODULES))
37 SORTED_DMBS_BUILD_TARGETS = $(sort $(DMBS_BUILD_TARGETS))
38 SORTED_DMBS_MANDATORY_VARS = $(sort $(DMBS_BUILD_MANDATORY_VARS))
39 SORTED_DMBS_OPTIONAL_VARS = $(filter-out $(SORTED_DMBS_MANDATORY_VARS), $(sort $(DMBS_BUILD_OPTIONAL_VARS)))
40 SORTED_DMBS_PROVIDED_VARS = $(sort $(DMBS_BUILD_PROVIDED_VARS))
41 SORTED_DMBS_PROVIDED_MACROS = $(sort $(DMBS_BUILD_PROVIDED_MACROS))
42
43 # Create printable versions of the sorted build module data (use "(None)" when no data is available)
44 PRINTABLE_DMBS_BUILD_MODULES = $(call CONVERT_TO_PRINTABLE, $(SORTED_DMBS_BUILD_MODULES))
45 PRINTABLE_DMBS_BUILD_TARGETS = $(call CONVERT_TO_PRINTABLE, $(SORTED_DMBS_BUILD_TARGETS))
46 PRINTABLE_DMBS_MANDATORY_VARS = $(call CONVERT_TO_PRINTABLE, $(SORTED_DMBS_MANDATORY_VARS))
47 PRINTABLE_DMBS_OPTIONAL_VARS = $(call CONVERT_TO_PRINTABLE, $(SORTED_DMBS_OPTIONAL_VARS))
48 PRINTABLE_DMBS_PROVIDED_VARS = $(call CONVERT_TO_PRINTABLE, $(SORTED_DMBS_PROVIDED_VARS))
49 PRINTABLE_DMBS_PROVIDED_MACROS = $(call CONVERT_TO_PRINTABLE, $(SORTED_DMBS_PROVIDED_MACROS))
50
51 help:
52 @echo "==================================================================="
53 @echo " The DMBS Build System "
54 @echo " By Dean Camera { dean @ fourwalledcubicle . com } "
55 @echo "==================================================================="
56 @echo "DESCRIPTION: "
57 @echo " This build system is a set of makefile modules for (GNU) Make, to "
58 @echo " provide a simple system for building DMBS powered applications. "
59 @echo " Each makefile module can be included from within a user makefile, "
60 @echo " to expose the build rules documented in the comments at the top of"
61 @echo " each build module. "
62 @echo " "
63 @echo "USAGE: "
64 @echo " To execute a rule, define all variables indicated in the desired "
65 @echo " module as a required parameter before including the build module "
66 @echo " in your project makefile. Parameters marked as optional will "
67 @echo " assume a default value in the modules if not user-assigned. "
68 @echo " "
69 @echo " By default the target output shows both a friendly summary, as "
70 @echo " well as the actual invoked command. To suppress the output of the "
71 @echo " invoked commands and show only the friendly command output, run "
72 @echo " make with the \"-s\" switch added before the target(s). "
73 @echo "==================================================================="
74 @echo " "
75 @echo " Currently used build system modules in this application: "
76 @echo " "
77 @printf " %b" "$(PRINTABLE_DMBS_BUILD_MODULES:%= - %\n)"
78 @echo " "
79 @echo " "
80 @echo " Currently available build targets in this application: "
81 @echo " "
82 @printf " %b" "$(PRINTABLE_DMBS_BUILD_TARGETS:%= - %\n)"
83 @echo " "
84 @echo " "
85 @echo " Mandatory variables required by the selected build Modules: "
86 @echo " "
87 @printf " %b" "$(PRINTABLE_DMBS_MANDATORY_VARS:%= - %\n)"
88 @echo " "
89 @echo " "
90 @echo " Optional variables required by the selected build Modules: "
91 @echo " "
92 @printf " %b" "$(PRINTABLE_DMBS_OPTIONAL_VARS:%= - %\n)"
93 @echo " "
94 @echo " "
95 @echo " Variables provided by the selected build Modules: "
96 @echo " "
97 @printf " %b" "$(PRINTABLE_DMBS_PROVIDED_VARS:%= - %\n)"
98 @echo " "
99 @echo " "
100 @echo " Macros provided by the selected build Modules: "
101 @echo " "
102 @printf " %b" "$(PRINTABLE_DMBS_PROVIDED_MACROS:%= - %\n)"
103 @echo " "
104 @echo "==================================================================="
105 @echo " The DMBS Build System $(DMBS_VERSION) - Making MAKE easier."
106 @echo "==================================================================="
107
108 # Lists build modules included by the project makefile, in alphabetical order
109 list_modules:
110 @echo Currently Used Build System Modules:
111 @printf " %b" "$(PRINTABLE_DMBS_BUILD_MODULES:%= - %\n)"
112
113 # Lists build targets included by the project makefile, in alphabetical order
114 list_targets:
115 @echo Currently Available Build Targets:
116 @printf " %b" "$(PRINTABLE_DMBS_BUILD_TARGETS:%= - %\n)"
117
118 # Lists mandatory variables that must be set by the project makefile, in alphabetical order
119 list_mandatory:
120 @echo Mandatory Variables for Included Modules:
121 @printf " %b" "$(PRINTABLE_DMBS_MANDATORY_VARS:%= - %\n)"
122
123 # Lists optional variables that must be set by the project makefile, in alphabetical order
124 list_optional:
125 @echo Optional Variables for Included Modules:
126 @printf " %b" "$(PRINTABLE_DMBS_OPTIONAL_VARS:%= - %\n)"
127
128 # Lists variables provided by the included build modules, in alphabetical order
129 list_provided:
130 @echo Variables Provided by the Included Modules:
131 @printf " %b" "$(PRINTABLE_DMBS_PROVIDED_VARS:%= - %\n)"
132
133 # Lists macros provided by the included build modules, in alphabetical order
134 list_macros:
135 @echo Macros Provided by the Included Modules:
136 @printf " %b" "$(PRINTABLE_DMBS_PROVIDED_MACROS:%= - %\n)"
137
138 # Debugging; "make print-VARNAME" will output the variable VARNAME's value
139 print-%:
140 @printf "%s = %s" $(@:print-%=%) $($(@:print-%=%))
141
142 # Disable default in-built make rules (those that are needed are explicitly
143 # defined, and doing so has performance benefits when recursively building)
144 ifeq ($(filter -r,$(MAKEFLAGS)),)
145 MAKEFLAGS += -r
146 endif
147 .SUFFIXES:
148
149 # Phony build targets for this module
150 .PHONY: $(DMBS_BUILD_TARGETS)
151
152 endif