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 BUILD_DIR_NAME = _build
11 COMPILED_DIR_NAME = _compiled
13 GROUP_DIR_NAME = nogroup
16 # We need to ensure definition of sources directory first
18 SOURCES_DIR := $(shell ( pwd -L ) )
21 .PHONY: all default check-make-ver
23 all: check-make-ver default
25 #=========================
26 # Include the config file
28 # First, include for which target we are compiling
29 -include $(MAKERULES_DIR)/config.target
30 ifeq ($(wildcard $(MAKERULES_DIR)/config.target),)
31 $(warning You may want to create $(MAKERULES_DIR)/config.target)
36 CONFIG_FILE := $(MAKERULES_DIR)/config.omk
38 ifneq ($(wildcard $(CONFIG_FILE)-default),)
39 -include $(CONFIG_FILE)-default
41 $(warning Please, run "make default-config" first)
44 ifneq ($(wildcard $(CONFIG_FILE)),)
45 include $(CONFIG_FILE)
49 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
50 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
53 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
55 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
56 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
57 #$(warning RELATIVE_DIR $(RELATIVE_DIR))
58 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
59 #$(warning BACK2TOP_DIR $(BACK2TOP_DIR))
61 #$(warning SOURCES_DIR = $(SOURCES_DIR))
62 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
63 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
65 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
66 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
68 #vpath %.c $(SOURCES_DIR)
69 #vpath %.cc $(SOURCES_DIR)
70 #vpath %.cxx $(SOURCES_DIR)
72 VPATH = $(SOURCES_DIR)
73 srcdir = $(SOURCES_DIR)
75 # Defines for quiet compilation
77 ifeq ("$(origin V)", "command line")
84 ifeq ($(OMK_VERBOSE),1)
89 ifneq ($(findstring s,$(MAKEFLAGS)),)
97 # We have set up all important variables, so we can check and include
98 # real OCERA style Makefile.omk now
100 include $(SOURCES_DIR)/Makefile.omk
106 @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
107 if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
108 echo "Your make program version is too old and does not support OMK system." ; \
109 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
113 @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
114 @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
115 @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
116 @echo >> "$(CONFIG_FILE)-default"
117 @$(MAKE) --no-print-directory -C $(MAKERULES_DIR) \
118 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
119 -f $(MAKERULES_DIR)/Makefile default-config-pass
121 # Common OMK templates
122 # ====================
124 # Syntax: $(call mkdir,<pass name>,<local make flags>)
126 [ -d $(1) ] || mkdir -p $(1) || exit 1
129 # Syntax: $(call omk_pass_template,<pass name>,<local make flags>)
130 define omk_pass_template
131 .PHNOY: $(1) $(1)-local
133 +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(LOCAL_BUILD_DIR)/$(dir)) ; \
134 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
135 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(LOCAL_BUILD_DIR)/$(dir) \
136 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;)
137 +@$(call mkdir_def,$(LOCAL_BUILD_DIR))
138 @$(MAKE) --no-print-directory -C $(LOCAL_BUILD_DIR) \
139 -f $(SOURCES_DIR)/Makefile $(2) $$(@:%=%-local)
142 # =======================
143 # DEFAULT CONFIG PASS
145 $(eval $(call omk_pass_template,default-config-pass))
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" ; )
153 # =======================
156 # TODO: Put rules specific to C language to a separate file
157 #include $(MAKERULES_DIR)/Makefile.rules.c-lang
159 include $(MAKERULES_DIR)/Makefile.rules.h8300-boot