]> rtime.felk.cvut.cz Git - omk/sssa.git/blob - snippets/base
config.target is included already in base.
[omk/sssa.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 #  Homepage: http://rtime.felk.cvut.cz/omk/
7 #
8 # The OMK build system is distributed under the GNU General Public
9 # License.  See file COPYING for details.
10 #
11 # input variables
12 # V                .. if set to 1, full command text is shown else short form is used
13 # W                .. whole tree - if set to 1, make is always called from the top-level directory
14 # SUBDIRS          .. list of subdirectories intended for make from actual directory
15 # default_CONFIG   .. list of default config assignments CONFIG_XXX=y/n ...
16
17 # We need to ensure definition of sources directory first
18 ifndef SOURCES_DIR
19 # Only shell built-in pwd understands -L
20 SOURCES_DIR := $(shell ( pwd -L ) )
21 endif
22
23 .PHONY: all default check-make-ver omkize
24
25 ifdef W
26   ifeq ("$(origin W)", "command line")
27     OMK_WHOLE_TREE:=$(W)
28   endif
29 endif
30 ifndef OMK_WHOLE_TREE
31   OMK_WHOLE_TREE:=0
32 endif
33
34 ifneq ($(OMK_WHOLE_TREE),1)
35 all: check-make-ver default
36         @echo "Compilation finished"
37 else
38 # Run make in the top-level directory
39 all:
40         @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
41 endif
42
43 ifdef OMK_TESTSROOT
44 # Usage: $(call canttest,<error message>)
45 define canttest
46         ( echo "$(1)" > $(MAKERULES_DIR)/_canttest; echo "$(1)"; exit 1 )
47 endef
48 else
49 define canttest
50         echo "$(1)"
51 endef
52 endif
53
54 #=========================
55 # Include the config file
56
57 ifneq ($(CONFIG_FILE_OK),y)
58 ifndef CONFIG_FILE
59 CONFIG_FILE      := $(MAKERULES_DIR)/config.omk
60 endif
61 ifneq ($(wildcard $(CONFIG_FILE)-default),)
62 -include $(CONFIG_FILE)-default
63 else
64 ifneq ($(MAKECMDGOALS),default-config)
65 $(warning Please, run "make default-config" first)
66 endif
67 endif
68
69 -include $(MAKERULES_DIR)/config.target
70
71 ifneq ($(wildcard $(CONFIG_FILE)),)
72 include $(CONFIG_FILE)
73 CONFIG_FILE_OK = y
74 endif
75 endif #$(CONFIG_FILE_OK)
76
77 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
78 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
79 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
80 # must to be serialized only in the toplevel make.
81
82 ifndef RELATIVE_DIR
83 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
84 endif
85 #$(warning  === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
86 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
87 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
88 #$(warning  RELATIVE_DIR = "$(RELATIVE_DIR)")
89 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
90 #$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
91
92 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
93 #$(warning MAKERULES_DIR = "$(MAKERULES_DIR)")
94 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
95
96 # We have to use RELATIVE_PREFIX because of mingw
97 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
98 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
99
100 #vpath %.c $(SOURCES_DIR)
101 #vpath %.cc $(SOURCES_DIR)
102 #vpath %.cxx $(SOURCES_DIR)
103
104 # Defines for quiet compilation
105 ifdef V
106   ifeq ("$(origin V)", "command line")
107     OMK_VERBOSE = $(V)
108   endif
109 endif
110 ifndef OMK_VERBOSE
111   OMK_VERBOSE = 0
112 endif
113 ifneq ($(OMK_VERBOSE),0)
114   Q =
115 else
116   Q = @
117 endif
118 ifneq ($(findstring s,$(MAKEFLAGS)),)
119   QUIET_CMD_ECHO = true
120   OMK_SILENT = 1
121 else
122   QUIET_CMD_ECHO = echo
123 endif
124
125 MAKEFILE_OMK=Makefile.omk
126 # All subdirectories (even linked ones) containing Makefile.omk
127 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
128 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
129
130 # ===================================================================
131 # We have set up all important variables, so we can check and include
132 # real OCERA style Makefile.omk now
133 ifndef OMK_INCLUDED
134 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
135 OMK_INCLUDED := 1
136 endif
137
138 check-make-ver:
139         @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
140         if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
141                 echo "Your make program version is too old and does not support OMK system." ; \
142                 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
143         fi
144
145 distclean dist-clean:
146         @$(QUIET_CMD_ECHO) "  RM      $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
147         @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)  $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
148
149 # Common OMK templates
150 # ====================
151
152 # Syntax: $(call mkdir,<dir name>)
153 define mkdir_def
154         [ -d $(1) ] || mkdir -p $(1) || exit 1
155 endef
156
157 ifneq ($(V),2)
158 NO_PRINT_DIRECTORY := --no-print-directory
159 endif
160
161 ifeq ($(USE_LEAF_MAKEFILES),n)
162 export USE_LEAF_MAKEFILES
163 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
164 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
165 else
166 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(dir)/Makefile
167 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
168 endif
169
170 ifdef OMK_TESTSROOT
171 check-target = $$(@:%=%-check)
172 endif
173
174 # Syntax: $(call omk_pass_template,<pass name(s)>,<build dir>,[<local make flags>],[<local condition>])
175 define omk_pass_template
176 .PHNOY: $(1) $(addsuffix -local,$(1)) $(addsuffix -check,$(1))
177 $(1):
178         +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \
179                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \
180                 RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(2)/$(dir) \
181                 -f $(SUBDIR_MAKEFILE) $$@ || exit 1 ;) true
182 ifneq ($(4),)
183         @echo "make[omk]: $$@ in $(RELATIVE_DIR)"; \
184         $(call mkdir_def,$(2)); \
185         $(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
186                 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $$(@:%=%-local)
187 endif
188 endef
189
190 # =======================
191 # DEFAULT CONFIG PASS
192
193 default-config:
194         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
195         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
196         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
197         @echo >> "$(CONFIG_FILE)-default"
198         @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
199                 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
200                 -f $(MAKERULES_DIR)/Makefile default-config-pass
201
202 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
203
204 default-config-pass-local:
205 #       @echo Default config for $(RELATIVE_DIR)
206         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
207         @$(foreach x, $(default_CONFIG), echo '$(x)' | \
208                 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
209
210
211 omkize:
212         $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
213            echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
214         fi
215         $(Q)for i in `find -L . -name Makefile.omk` ; do \
216            i=`dirname $${i}`; \
217            if [ x"$$i" != x"." ]; then \
218               rm -f $${i}/Makefile; \
219               cp Makefile $${i}/Makefile; \
220            fi \
221         done