1 # Makefile.rules - OCERA make framework common project rules -*- makefile -*-
3 # (C) Copyright 2003 by Pavel Pisa - OCERA team member
6 # V .. if set to 1, full command text is shown else short form is used
7 # SUBDIRS .. list of subdirectories intended for make from actual directory
8 # default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ...
10 # We need to ensure definition of sources directory first
12 SOURCES_DIR := $(shell ( pwd -L ) )
15 .PHONY: all default check-make-ver
17 all: check-make-ver default
19 #=========================
20 # Include the config file
22 ifneq ($(CONFIG_FILE_OK),y)
24 CONFIG_FILE := $(MAKERULES_DIR)/config.omk
26 ifneq ($(wildcard $(CONFIG_FILE)-default),)
27 -include $(CONFIG_FILE)-default
29 $(warning Please, run "make default-config" first)
32 ifneq ($(wildcard $(CONFIG_FILE)),)
33 include $(CONFIG_FILE)
36 endif #$(CONFIG_FILE_OK)
38 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
39 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
40 # FIXME: Is it correct to export OMK_SERIALIZE_INCLUDED to submakes???
43 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
45 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
46 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
47 #$(warning RELATIVE_DIR $(RELATIVE_DIR))
48 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
49 #$(warning BACK2TOP_DIR $(BACK2TOP_DIR))
51 #$(warning SOURCES_DIR = $(SOURCES_DIR))
52 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
53 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
55 #vpath %.c $(SOURCES_DIR)
56 #vpath %.cc $(SOURCES_DIR)
57 #vpath %.cxx $(SOURCES_DIR)
59 VPATH = $(SOURCES_DIR)
60 srcdir = $(SOURCES_DIR)
62 # Defines for quiet compilation
64 ifeq ("$(origin V)", "command line")
71 ifeq ($(OMK_VERBOSE),1)
76 ifneq ($(findstring s,$(MAKEFLAGS)),)
84 # ===================================================================
85 # We have set up all important variables, so we can check and include
86 # real OCERA style Makefile.omk now
88 include $(SOURCES_DIR)/Makefile.omk
94 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
95 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
96 echo "Your make program version is too old and does not support OMK system." ; \
97 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
100 distclean dist-clean:
101 @$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
102 @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME) $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
104 # Common OMK templates
105 # ====================
107 # Syntax: $(call mkdir,<dir name>)
109 [ -d $(1) ] || mkdir -p $(1) || exit 1
112 # Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>],[<subpass>])
113 define omk_pass_template
114 .PHNOY: $(1) $(1)-local
116 +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)) ; \
117 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) --no-print-directory \
118 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(2)/$(dir) \
119 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;)
121 @echo " MAKE $$@ in $(RELATIVE_DIR)"
122 +@if [ $(4) ] || [ -z "$(subst ",\",$(4))" ]; then \
123 $(call mkdir_def,$(2)); \
124 $(MAKE) --no-print-directory -C $(2) \
125 -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local); \
130 # =======================
131 # DEFAULT CONFIG PASS
134 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
135 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
136 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
137 @echo >> "$(CONFIG_FILE)-default"
138 @$(MAKE) --no-print-directory -C $(MAKERULES_DIR) \
139 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
140 -f $(MAKERULES_DIR)/Makefile default-config-pass
142 $(eval $(call omk_pass_template,default-config-pass))
144 default-config-pass-local:
145 @echo Default config for $(RELATIVE_DIR)
146 @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
147 @$(foreach x, $(default_CONFIG), echo $(x) | \
148 sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )