1 # Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*-
3 # (C) Copyright 2003 by Pavel Pisa - OCERA team member
4 # (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
6 # Homepage: http://rtime.felk.cvut.cz/omk/
7 # Version: @git-describe@
9 # Adapted by Tommaso Cucinotta, Scuola Superiore Sant'Anna, Pisa, Italy, for the
10 # Project Adaptive Quality of Service Architecture (AQuoSA)
11 # More information at: http://aquosa.sourceforge.net
13 # The OMK build system is distributed under the GNU General Public
14 # License. See file COPYING for details.
18 # V .. if set to 1, full command text is shown else short form is used
19 # W .. whole tree - if set to 1, make is always called from the top-level directory
20 # SUBDIRS .. list of subdirectories intended for make from actual directory
21 # kernel_SUBDIRS .. subdirectories within which to propagate kernel targets
22 # library_SUBDIRS .. list of subdirectories within which to propagate library targets
23 # include_SUBDIRS .. list of subdirectories within which to propagate include pass (defaults to kernel_SUBDIRS + library_SUBDIRS)
24 # binary_SUBDIRS .. list of subdirectories within which to propagate binary targets
25 # docs_SUBDIRS .. list of subdirectories within which to propagate docs target
26 # clean_SUBDIRS .. list of subdirectories within which to propagate clean targets
27 # default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ...
29 # We need to ensure definition of sources directory first
31 # Only shell built-in pwd understands -L
32 SOURCES_DIR := $(shell ( pwd -L ) )
35 include $(MAKERULES_DIR)/variables.mk
37 # If we are not called by OMK leaf Makefile...
39 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
42 # OUTPUT_DIR is the place where _compiled, _build and possible other
43 # files/directories are created. By default is the same as
46 OUTPUT_DIR := $(MAKERULES_DIR)
49 .PHONY: all default check-make-ver omkize
52 ifeq ("$(origin W)", "command line")
60 ifneq ($(OMK_WHOLE_TREE),1)
61 all: check-make-ver default
62 @echo "Compilation finished"
64 # Run make in the top-level directory
66 @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
70 # Usage: $(call canttest,<error message>)
72 ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 )
80 #=========================
81 # Include the config file
83 # FIXME: I think CONFIG_FILE_OK variable is useless. We have three
84 # config files and it is not clearly defined to which file is this
86 ifneq ($(CONFIG_FILE_OK),y)
88 CONFIG_FILE := $(OUTPUT_DIR)/config.omk
90 ifneq ($(wildcard $(CONFIG_FILE)-default),)
91 -include $(CONFIG_FILE)-default
93 #ifneq ($(MAKECMDGOALS),default-config)
94 #$(warning Please, run "make default-config" first)
98 -include $(OUTPUT_DIR)/config.target
99 -include $(MAKERULES_DIR)/variables.mk
101 ifneq ($(wildcard $(CONFIG_FILE)),)
102 -include $(CONFIG_FILE)
105 endif #$(CONFIG_FILE_OK)
108 CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE)) $(wildcard $(MAKERULES_DIR)/variables.mk)
111 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
112 export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
113 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
114 # must to be serialized only in the toplevel make.
117 RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
119 #$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
120 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
121 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
122 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
123 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
124 #$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
126 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
127 #$(warning MAKERULES_DIR = "$(OUTPUT_DIR)")
128 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
130 # We have to use RELATIVE_PREFIX because of mingw
131 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
132 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
134 #vpath %.c $(SOURCES_DIR)
135 #vpath %.cc $(SOURCES_DIR)
136 #vpath %.cxx $(SOURCES_DIR)
138 # Define srcdir for Automake compatibility
139 srcdir = $(SOURCES_DIR)
141 # Defines for quiet compilation
143 ifeq ("$(origin V)", "command line")
150 ifneq ($(OMK_VERBOSE),0)
155 ifneq ($(findstring s,$(MAKEFLAGS)),)
156 QUIET_CMD_ECHO = true
159 QUIET_CMD_ECHO = echo
162 MAKEFILE_OMK=Makefile.omk
163 # All subdirectories (even linked ones) containing Makefile.omk
164 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
165 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
167 # ===================================================================
168 # We have set up all important variables, so we can check and include
169 # real OCERA style Makefile.omk now
171 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
172 ifeq ($(AUTOMATIC_SUBDIRS),y)
173 SUBDIRS?=$(ALL_OMK_SUBDIRS)
178 all_SUBDIRS=$(kernel_SUBDIRS) $(library_SUBDIRS) $(binary_SUBDIRS) $(docs_SUBDIRS) $(clean_SUBDIRS) $(include_SUBDIRS) $(QT_SUBDIRS)
179 include_SUBDIRS+=$(kernel_SUBDIRS) $(library_SUBDIRS)
182 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
183 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
184 echo "Your make program version is too old and does not support OMK system." ; \
185 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
188 distclean dist-clean:
189 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
190 @rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME) $(OUTPUT_DIR)/$(BUILD_DIR_NAME) autom4te.cache config.log config.log config.status
192 # Common OMK templates
193 # ====================
195 # Syntax: $(call mkdir,<dir name>)
197 [ -d $(1) ] || mkdir -p $(1) || exit 1
200 ifneq ($(OMK_VERBOSE),2)
201 NO_PRINT_DIRECTORY := --no-print-directory
204 ifeq ($(USE_LEAF_MAKEFILES),n)
205 export USE_LEAF_MAKEFILES
206 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
207 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
209 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
210 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
215 # Call a pass in a subdirectory
216 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
217 define omk_pass_subdir_template
218 .PHONY: $(pass)-$(3)-subdir
219 $(pass)-submakes: $(pass)-$(3)-subdir
221 @$(call mkdir_def,$(2)/$(3))
222 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
223 RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
224 -f $(SUBDIR_MAKEFILE) $(pass)-submakes
225 # In subdirectories we can call submakes directly since passes are
226 # already serialized on the toplevel make.
230 check-target = $(1:%=%-check)
233 # Call a pass in a subdirectory
234 # Usage: $(call extra_rules_subdir_template,<subdir>)
235 define extra_rules_subdir_template
236 extra-rules-subdirs: extra-rules-$(1)
238 +@$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \
239 SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1)
242 .PHONY: extra-rules-subdirs
245 $(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir))))
247 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>],[<pass directories>])
248 define omk_pass_template
249 .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
250 # Produce in SUBDIRS_NODUPS a set of directories without duplicates
252 $(foreach x,$(SUBDIRS) $(5),$(eval SUBDIRS_NODUPS:=$(SUBDIRS_NODUPS:$(x)=) $(x)))
253 $(foreach subdir,$(SUBDIRS_NODUPS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
255 # Submakes have to be called this way and not as dependecies for pass
256 # serialization to work
257 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
258 RELATIVE_DIR=$(RELATIVE_DIR) \
259 -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
261 @true # Do not emit "nothing to be done" messages
263 ifneq ($(4)$($(pass)_HOOKS),)
264 $(pass)-submakes: $(pass)-this-dir
265 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS_NODUPS),$(pass)-$(subdir)-subdir)
266 +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
267 @$(call mkdir_def,$(2))
268 +@$(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
269 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
270 $(pass)-local: $($(pass)_HOOKS)
274 # =======================
275 # DEFAULT CONFIG PASS
278 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
279 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
280 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
281 @echo >> "$(CONFIG_FILE)-default"
282 @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \
283 RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \
284 -f $(OUTPUT_DIR)/Makefile default-config-pass
286 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always,))
288 default-config-pass-local:
289 # @echo Default config for $(RELATIVE_DIR)
290 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
291 @$(foreach x, $(default_CONFIG), echo '$(x)' | \
292 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
296 $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
297 echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
299 $(Q)for i in `find -L . -name Makefile.omk` ; do \
301 if ! test -f "$${d}/Makefile.rules" && ( test -f "$${d}/Makefile" && ! cmp --silent Makefile "$${d}/Makefile" ); then \
302 rm -f "$${d}/Makefile"; \
303 cp -v Makefile "$${d}/Makefile"; \