1 # Makefile.rules - OCERA make framework common project rules -*- makefile -*-
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/
8 # The OMK build system is distributed under the GNU General Public
9 # License. See file COPYING for details.
12 # V .. if set to 1, full command text is shown else short form is used
13 # W .. whole tree - if set to 1, make is always called from the top-level directory
14 # SUBDIRS .. list of subdirectories intended for make from actual directory
15 # default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ...
17 # We need to ensure definition of sources directory first
19 # Only shell built-in pwd understands -L
20 SOURCES_DIR := $(shell ( pwd -L ) )
23 # If we are not called by OMK leaf Makefile...
25 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
28 .PHONY: all default check-make-ver omkize
31 ifeq ("$(origin W)", "command line")
39 ifneq ($(OMK_WHOLE_TREE),1)
40 all: check-make-ver default
41 @echo "Compilation finished"
43 # Run make in the top-level directory
45 @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
49 # Usage: $(call canttest,<error message>)
51 ( echo "$(1)" > $(MAKERULES_DIR)/_canttest; echo "$(1)"; exit 1 )
59 #=========================
60 # Include the config file
62 # FIXME: I think CONFIG_FILE_OK variable is useless. We have three
63 # config files and it is not clearly defined to which file is this
65 ifneq ($(CONFIG_FILE_OK),y)
67 CONFIG_FILE := $(MAKERULES_DIR)/config.omk
69 ifneq ($(wildcard $(CONFIG_FILE)-default),)
70 -include $(CONFIG_FILE)-default
72 ifneq ($(MAKECMDGOALS),default-config)
73 $(warning Please, run "make default-config" first)
77 -include $(MAKERULES_DIR)/config.target
79 ifneq ($(wildcard $(CONFIG_FILE)),)
80 -include $(CONFIG_FILE)
83 endif #$(CONFIG_FILE_OK)
86 CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(MAKERULES_DIR)/config.target) $(wildcard $(CONFIG_FILE))
89 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
90 export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
91 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
92 # must to be serialized only in the toplevel make.
95 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
97 #$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
98 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
99 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
100 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
101 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
102 #$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
104 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
105 #$(warning MAKERULES_DIR = "$(MAKERULES_DIR)")
106 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
108 # We have to use RELATIVE_PREFIX because of mingw
109 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
110 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
112 #vpath %.c $(SOURCES_DIR)
113 #vpath %.cc $(SOURCES_DIR)
114 #vpath %.cxx $(SOURCES_DIR)
116 # Define srcdir for Automake compatibility
117 srcdir = $(SOURCES_DIR)
119 # Defines for quiet compilation
121 ifeq ("$(origin V)", "command line")
128 ifneq ($(OMK_VERBOSE),0)
133 ifneq ($(findstring s,$(MAKEFLAGS)),)
134 QUIET_CMD_ECHO = true
137 QUIET_CMD_ECHO = echo
140 MAKEFILE_OMK=Makefile.omk
141 # All subdirectories (even linked ones) containing Makefile.omk
142 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
143 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
145 # ===================================================================
146 # We have set up all important variables, so we can check and include
147 # real OCERA style Makefile.omk now
149 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
150 ifeq ($(AUTOMATIC_SUBDIRS),y)
151 SUBDIRS?=$(ALL_OMK_SUBDIRS)
157 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
158 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
159 echo "Your make program version is too old and does not support OMK system." ; \
160 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
163 distclean dist-clean:
164 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
165 @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME) $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
167 # Common OMK templates
168 # ====================
170 # Syntax: $(call mkdir,<dir name>)
172 [ -d $(1) ] || mkdir -p $(1) || exit 1
176 NO_PRINT_DIRECTORY := --no-print-directory
179 ifeq ($(USE_LEAF_MAKEFILES),n)
180 export USE_LEAF_MAKEFILES
181 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
182 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
184 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
185 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
190 # Call a pass in a subdirectory
191 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
192 define omk_pass_subdir_template
193 .PHONY: $(pass)-$(3)-subdir
194 $(pass)-submakes: $(pass)-$(3)-subdir
196 @$(call mkdir_def,$(2)/$(3))
197 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
198 RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
199 -f $(SUBDIR_MAKEFILE) $(pass)-submakes
200 # In subdirectories we can call submakes directly since passes are
201 # already searialized on the toplevel make.
205 check-target = $(1:%=%-check)
208 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
209 define omk_pass_template
210 .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
211 $(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
213 # Submakes have to be called this way and not as dependecies for pass
214 # serialization to work
215 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR) --no-print-directory \
216 RELATIVE_DIR=$(RELATIVE_DIR) \
217 -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
219 @true # Do not emit "nothing to be done" messages
221 ifneq ($(4)$($(pass)_HOOKS),)
222 $(pass)-submakes: $(pass)-this-dir
223 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
224 +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
225 @$(call mkdir_def,$(2))
226 +@$(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
227 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
228 $(pass)-local: $($(pass)_HOOKS)
232 # =======================
233 # DEFAULT CONFIG PASS
236 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
237 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
238 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
239 @echo >> "$(CONFIG_FILE)-default"
240 @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
241 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
242 -f $(MAKERULES_DIR)/Makefile default-config-pass
244 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
246 default-config-pass-local:
247 # @echo Default config for $(RELATIVE_DIR)
248 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
249 @$(foreach x, $(default_CONFIG), echo '$(x)' | \
250 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
254 $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
255 echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
257 $(Q)for i in `find -L . -name Makefile.omk` ; do \
259 if ! test -f "$${d}/Makefile.rules" && ( ! test -f "$${d}/Makefile" || ! cmp --silent Makefile "$${d}/Makefile" ); then \
260 rm -f "$${d}/Makefile"; \
261 cp -v Makefile "$${d}/Makefile"; \