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
8 # V .. if set to 1, full command text is shown else short form is used
9 # SUBDIRS .. list of subdirectories intended for make from actual directory
10 # default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ...
12 # We need to ensure definition of sources directory first
14 SOURCES_DIR := $(shell ( pwd -L ) )
17 .PHONY: all default check-make-ver
19 all: check-make-ver default
21 #=========================
22 # Include the config file
24 ifneq ($(CONFIG_FILE_OK),y)
26 CONFIG_FILE := $(MAKERULES_DIR)/config.omk
28 ifneq ($(wildcard $(CONFIG_FILE)-default),)
29 -include $(CONFIG_FILE)-default
31 $(warning Please, run "make default-config" first)
34 ifneq ($(wildcard $(CONFIG_FILE)),)
35 include $(CONFIG_FILE)
38 endif #$(CONFIG_FILE_OK)
40 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
41 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
42 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
43 # must to be serialized only in the toplevel make.
46 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
48 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
49 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
50 #$(warning RELATIVE_DIR $(RELATIVE_DIR))
51 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
52 #$(warning BACK2TOP_DIR $(BACK2TOP_DIR))
54 #$(warning SOURCES_DIR = $(SOURCES_DIR))
55 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
56 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
58 #vpath %.c $(SOURCES_DIR)
59 #vpath %.cc $(SOURCES_DIR)
60 #vpath %.cxx $(SOURCES_DIR)
62 VPATH = $(SOURCES_DIR)
63 srcdir = $(SOURCES_DIR)
65 # Defines for quiet compilation
67 ifeq ("$(origin V)", "command line")
74 ifeq ($(OMK_VERBOSE),1)
79 ifneq ($(findstring s,$(MAKEFLAGS)),)
86 # ===================================================================
87 # We have set up all important variables, so we can check and include
88 # real OCERA style Makefile.omk now
90 include $(SOURCES_DIR)/Makefile.omk
96 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
97 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
98 echo "Your make program version is too old and does not support OMK system." ; \
99 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
102 distclean dist-clean:
103 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
104 @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME) $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
106 # Common OMK templates
107 # ====================
109 # Syntax: $(call mkdir,<dir name>)
111 [ -d $(1) ] || mkdir -p $(1) || exit 1
114 # Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>],[<subpass>])
115 define omk_pass_template
116 .PHNOY: $(1) $(1)-local
118 +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)) ; \
119 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) --no-print-directory \
120 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(2)/$(dir) \
121 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;)
123 +@if [ $(4) ] || [ -z "$(subst ",\",$(4))" ]; then \
124 echo " MAKE $$@ in $(RELATIVE_DIR)"; \
125 $(call mkdir_def,$(2)); \
126 $(MAKE) --no-print-directory -C $(2) \
127 -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local); \
132 # =======================
133 # DEFAULT CONFIG PASS
136 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
137 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
138 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
139 @echo >> "$(CONFIG_FILE)-default"
140 @$(MAKE) --no-print-directory -C $(MAKERULES_DIR) \
141 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
142 -f $(MAKERULES_DIR)/Makefile default-config-pass
144 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR)))
146 default-config-pass-local:
147 # @echo Default config for $(RELATIVE_DIR)
148 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
149 @$(foreach x, $(default_CONFIG), echo $(x) | \
150 sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )