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 ifneq ($(CONFIG_FILE_OK),y)
64 CONFIG_FILE := $(MAKERULES_DIR)/config.omk
66 ifneq ($(wildcard $(CONFIG_FILE)-default),)
67 -include $(CONFIG_FILE)-default
69 ifneq ($(MAKECMDGOALS),default-config)
70 $(warning Please, run "make default-config" first)
74 -include $(MAKERULES_DIR)/config.target
76 ifneq ($(wildcard $(CONFIG_FILE)),)
77 include $(CONFIG_FILE)
80 endif #$(CONFIG_FILE_OK)
82 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
83 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
84 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
85 # must to be serialized only in the toplevel make.
88 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
90 #$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
91 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
92 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
93 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
94 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
95 #$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
97 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
98 #$(warning MAKERULES_DIR = "$(MAKERULES_DIR)")
99 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
101 # We have to use RELATIVE_PREFIX because of mingw
102 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
103 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
105 #vpath %.c $(SOURCES_DIR)
106 #vpath %.cc $(SOURCES_DIR)
107 #vpath %.cxx $(SOURCES_DIR)
109 # Define srcdir for Automake compatibility
110 srcdir = $(SOURCES_DIR)
112 # Defines for quiet compilation
114 ifeq ("$(origin V)", "command line")
121 ifneq ($(OMK_VERBOSE),0)
126 ifneq ($(findstring s,$(MAKEFLAGS)),)
127 QUIET_CMD_ECHO = true
130 QUIET_CMD_ECHO = echo
133 MAKEFILE_OMK=Makefile.omk
134 # All subdirectories (even linked ones) containing Makefile.omk
135 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
136 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
138 # ===================================================================
139 # We have set up all important variables, so we can check and include
140 # real OCERA style Makefile.omk now
142 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
147 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
148 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
149 echo "Your make program version is too old and does not support OMK system." ; \
150 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
153 distclean dist-clean:
154 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
155 @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME) $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
157 # Common OMK templates
158 # ====================
160 # Syntax: $(call mkdir,<dir name>)
162 [ -d $(1) ] || mkdir -p $(1) || exit 1
166 NO_PRINT_DIRECTORY := --no-print-directory
169 ifeq ($(USE_LEAF_MAKEFILES),n)
170 export USE_LEAF_MAKEFILES
171 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
172 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
174 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
175 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
180 # Call a pass in a subdirectory
181 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
182 define omk_pass_subdir_template
183 .PHONY: $(pass)-$(3)-subdir
184 $(pass)-submakes: $(pass)-$(3)-subdir
186 @$(call mkdir_def,$(2)/$(3))
187 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
188 RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
189 -f $(SUBDIR_MAKEFILE) $(pass)-submakes
190 # In subdirectories we can call submakes directly since passes are
191 # already searialized on the toplevel make.
195 check-target = $(1:%=%-check)
198 # Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
199 define omk_pass_template
200 .PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
201 $(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
203 # Submakes have to be called this way and not as dependecies for pass
204 # serialization to work
205 +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR) --no-print-directory \
206 RELATIVE_DIR=$(RELATIVE_DIR) \
207 -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
209 @true # Do not emit "nothing to be done" messages
212 $(pass)-submakes: $(pass)-this-dir
213 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
214 +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
215 @$(call mkdir_def,$(2))
216 +@$(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
217 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
221 # =======================
222 # DEFAULT CONFIG PASS
225 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
226 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
227 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
228 @echo >> "$(CONFIG_FILE)-default"
229 @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
230 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
231 -f $(MAKERULES_DIR)/Makefile default-config-pass
233 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
235 default-config-pass-local:
236 # @echo Default config for $(RELATIVE_DIR)
237 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
238 @$(foreach x, $(default_CONFIG), echo '$(x)' | \
239 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
243 $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
244 echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
246 $(Q)for i in `find -L . -name Makefile.omk` ; do \
248 if ! test -f "$${d}/Makefile.rules" && ( ! test -f "$${d}/Makefile" || ! cmp --silent Makefile "$${d}/Makefile" ); then \
249 rm -f "$${d}/Makefile"; \
250 cp -v Makefile "$${d}/Makefile"; \