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 # The OMK build system is distributed under the GNU General Public
7 # License. See file COPYING for details.
10 # V .. if set to 1, full command text is shown else short form is used
11 # W .. whole tree - if set to 1, make is always called from the top-level directory
12 # SUBDIRS .. list of subdirectories intended for make from actual directory
13 # default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ...
15 # We need to ensure definition of sources directory first
17 SOURCES_DIR := $(shell ( pwd -L ) )
20 .PHONY: all default check-make-ver
23 ifeq ("$(origin W)", "command line")
31 ifneq ($(OMK_WHOLE_TREE),1)
32 all: check-make-ver default
33 @echo "Compilation finished"
35 # Run make in the top-level directory
37 @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
40 #=========================
41 # Include the config file
43 ifneq ($(CONFIG_FILE_OK),y)
45 CONFIG_FILE := $(MAKERULES_DIR)/config.omk
47 ifneq ($(wildcard $(CONFIG_FILE)-default),)
48 -include $(CONFIG_FILE)-default
50 ifneq ($(MAKECMDGOALS),default-config)
51 $(warning Please, run "make default-config" first)
55 ifneq ($(wildcard $(CONFIG_FILE)),)
56 include $(CONFIG_FILE)
59 endif #$(CONFIG_FILE_OK)
61 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
62 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
63 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
64 # must to be serialized only in the toplevel make.
67 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
69 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
70 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
71 #$(warning RELATIVE_DIR $(RELATIVE_DIR))
72 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
73 #$(warning BACK2TOP_DIR $(BACK2TOP_DIR))
75 #$(warning SOURCES_DIR = $(SOURCES_DIR))
76 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
77 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
79 #vpath %.c $(SOURCES_DIR)
80 #vpath %.cc $(SOURCES_DIR)
81 #vpath %.cxx $(SOURCES_DIR)
83 VPATH = $(SOURCES_DIR)
84 srcdir = $(SOURCES_DIR)
86 # Defines for quiet compilation
88 ifeq ("$(origin V)", "command line")
95 ifeq ($(OMK_VERBOSE),1)
100 ifneq ($(findstring s,$(MAKEFLAGS)),)
101 QUIET_CMD_ECHO = true
104 QUIET_CMD_ECHO = echo
107 MAKEFILE_OMK=Makefile.omk
108 # All subdirectories (even linked ones) containing Makefile.omk
109 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
110 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
112 # ===================================================================
113 # We have set up all important variables, so we can check and include
114 # real OCERA style Makefile.omk now
116 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
121 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
122 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
123 echo "Your make program version is too old and does not support OMK system." ; \
124 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
127 distclean dist-clean:
128 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
129 @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME) $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
131 # Common OMK templates
132 # ====================
134 # Syntax: $(call mkdir,<dir name>)
136 [ -d $(1) ] || mkdir -p $(1) || exit 1
140 NO_PRINT_DIRECTORY := --no-print-directory
143 # Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>])
144 define omk_pass_template
145 .PHNOY: $(1) $(1)-local
147 +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \
148 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \
149 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(2)/$(dir) \
150 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) true
152 @echo "make[omk]: $$@ in $(RELATIVE_DIR)"; \
153 $(call mkdir_def,$(2)); \
154 $(MAKE) $(NO_PRINT_DIRECTORY) -C $(2) \
155 -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local)
159 # =======================
160 # DEFAULT CONFIG PASS
163 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
164 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
165 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
166 @echo >> "$(CONFIG_FILE)-default"
167 @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
168 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
169 -f $(MAKERULES_DIR)/Makefile default-config-pass
171 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
173 default-config-pass-local:
174 # @echo Default config for $(RELATIVE_DIR)
175 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
176 @$(foreach x, $(default_CONFIG), echo '$(x)' | \
177 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )