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 SOURCES_DIR := $(shell ( pwd -L ) ) # Only shell built-in pwd understands -L
22 .PHONY: all default check-make-ver omkize
25 ifeq ("$(origin W)", "command line")
33 ifneq ($(OMK_WHOLE_TREE),1)
34 all: check-make-ver default
35 @echo "Compilation finished"
37 # Run make in the top-level directory
39 @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
42 #=========================
43 # Include the config file
45 ifneq ($(CONFIG_FILE_OK),y)
47 CONFIG_FILE := $(MAKERULES_DIR)/config.omk
49 ifneq ($(wildcard $(CONFIG_FILE)-default),)
50 -include $(CONFIG_FILE)-default
52 ifneq ($(MAKECMDGOALS),default-config)
53 $(warning Please, run "make default-config" first)
57 ifneq ($(wildcard $(CONFIG_FILE)),)
58 include $(CONFIG_FILE)
61 endif #$(CONFIG_FILE_OK)
63 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
64 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
65 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
66 # must to be serialized only in the toplevel make.
69 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
71 #$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
72 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
73 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
74 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
75 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
76 #$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
78 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
79 #$(warning MAKERULES_DIR = "$(MAKERULES_DIR)")
80 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
82 # We have to use RELATIVE_PREFIX because of mingw
83 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
84 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
86 #vpath %.c $(SOURCES_DIR)
87 #vpath %.cc $(SOURCES_DIR)
88 #vpath %.cxx $(SOURCES_DIR)
90 VPATH = $(SOURCES_DIR)
91 srcdir = $(SOURCES_DIR)
93 # Defines for quiet compilation
95 ifeq ("$(origin V)", "command line")
102 ifneq ($(OMK_VERBOSE),0)
107 ifneq ($(findstring s,$(MAKEFLAGS)),)
108 QUIET_CMD_ECHO = true
111 QUIET_CMD_ECHO = echo
114 MAKEFILE_OMK=Makefile.omk
115 # All subdirectories (even linked ones) containing Makefile.omk
116 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
117 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
119 # ===================================================================
120 # We have set up all important variables, so we can check and include
121 # real OCERA style Makefile.omk now
123 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
128 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
129 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
130 echo "Your make program version is too old and does not support OMK system." ; \
131 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
134 distclean dist-clean:
135 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
136 @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME) $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
138 # Common OMK templates
139 # ====================
141 # Syntax: $(call mkdir,<dir name>)
143 [ -d $(1) ] || mkdir -p $(1) || exit 1
147 NO_PRINT_DIRECTORY := --no-print-directory
150 # Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>])
151 define omk_pass_template
152 .PHNOY: $(1) $(1)-local
154 +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \
155 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \
156 RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(2)/$(dir) \
157 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) true
159 @echo "make[omk]: $$@ in $(RELATIVE_DIR)"; \
160 $(call mkdir_def,$(2)); \
161 $(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
162 -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local)
166 # =======================
167 # DEFAULT CONFIG PASS
170 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
171 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
172 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
173 @echo >> "$(CONFIG_FILE)-default"
174 @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
175 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
176 -f $(MAKERULES_DIR)/Makefile default-config-pass
178 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
180 default-config-pass-local:
181 # @echo Default config for $(RELATIVE_DIR)
182 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
183 @$(foreach x, $(default_CONFIG), echo '$(x)' | \
184 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
188 $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
189 echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
191 $(Q)for i in `find -L . -name Makefile.omk` ; do \
193 if [ x"$$i" != x"." ]; then \
194 rm -f $${i}/Makefile; \
195 cp Makefile $${i}/Makefile; \