]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/base
Build directory in default-config-pass fixed.
[omk.git] / snippets / base
1 #  Makefile.rules - OCERA make framework common project rules -*- makefile -*-
2 #
3 #  (C) Copyright 2003 by Pavel Pisa - OCERA team member
4 #  (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
5 #
6 #
7 # input variables
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 ...
11
12 # We need to ensure definition of sources directory first
13 ifndef SOURCES_DIR
14 SOURCES_DIR := $(shell ( pwd -L ) )
15 endif
16
17 .PHONY: all default check-make-ver
18
19 all: check-make-ver default
20
21 #=========================
22 # Include the config file
23
24 ifneq ($(CONFIG_FILE_OK),y)
25 ifndef CONFIG_FILE
26 CONFIG_FILE      := $(MAKERULES_DIR)/config.omk
27 endif
28 ifneq ($(wildcard $(CONFIG_FILE)-default),)
29 -include $(CONFIG_FILE)-default
30 else
31 $(warning Please, run "make default-config" first)
32 endif
33
34 ifneq ($(wildcard $(CONFIG_FILE)),)
35 include $(CONFIG_FILE)
36 CONFIG_FILE_OK = y
37 endif
38 endif #$(CONFIG_FILE_OK)
39
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.
44
45 ifndef RELATIVE_DIR
46 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
47 endif
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))
53
54 #$(warning SOURCES_DIR = $(SOURCES_DIR))
55 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
56 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
57
58 #vpath %.c $(SOURCES_DIR)
59 #vpath %.cc $(SOURCES_DIR)
60 #vpath %.cxx $(SOURCES_DIR)
61
62 VPATH = $(SOURCES_DIR)
63 srcdir = $(SOURCES_DIR)
64
65 # Defines for quiet compilation
66 ifdef V
67   ifeq ("$(origin V)", "command line")
68     OMK_VERBOSE = $(V)
69   endif
70 endif
71 ifndef OMK_VERBOSE
72   OMK_VERBOSE = 0
73 endif
74 ifeq ($(OMK_VERBOSE),1)
75   Q =
76 else
77   Q = @
78 endif
79 ifneq ($(findstring s,$(MAKEFLAGS)),)
80   QUIET_CMD_ECHO = true
81   OMK_SILENT = 1
82 else
83   QUIET_CMD_ECHO = echo
84 endif
85
86 # ===================================================================
87 # We have set up all important variables, so we can check and include
88 # real OCERA style Makefile.omk now
89 ifndef OMK_INCLUDED
90 include $(SOURCES_DIR)/Makefile.omk
91 OMK_INCLUDED := 1
92 endif
93
94
95 check-make-ver:
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 ; \
100         fi
101
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)
105
106 # Common OMK templates
107 # ====================
108
109 # Syntax: $(call mkdir,<dir name>)
110 define mkdir_def
111         [ -d $(1) ] || mkdir -p $(1) || exit 1
112 endef
113
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
117 $(1):
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 ;)
122         $(5)
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); \
128         fi
129
130 endef
131
132 # =======================
133 # DEFAULT CONFIG PASS
134
135 default-config:
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
143
144 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR)))
145
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" ; )