]> rtime.felk.cvut.cz Git - omk/sssa.git/blob - snippets/base
Makefile.rules can now tell the OMK tester that the test cannot be executed.
[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 ifneq ($(wildcard $(CONFIG_FILE)),)
70 include $(CONFIG_FILE)
71 CONFIG_FILE_OK = y
72 endif
73 endif #$(CONFIG_FILE_OK)
74
75 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
76 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
77 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
78 # must to be serialized only in the toplevel make.
79
80 ifndef RELATIVE_DIR
81 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
82 endif
83 #$(warning  === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
84 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
85 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
86 #$(warning  RELATIVE_DIR = "$(RELATIVE_DIR)")
87 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
88 #$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
89
90 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
91 #$(warning MAKERULES_DIR = "$(MAKERULES_DIR)")
92 #$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
93
94 # We have to use RELATIVE_PREFIX because of mingw
95 override RELATIVE_PREFIX := $(RELATIVE_DIR)/
96 override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
97
98 #vpath %.c $(SOURCES_DIR)
99 #vpath %.cc $(SOURCES_DIR)
100 #vpath %.cxx $(SOURCES_DIR)
101
102 # Defines for quiet compilation
103 ifdef V
104   ifeq ("$(origin V)", "command line")
105     OMK_VERBOSE = $(V)
106   endif
107 endif
108 ifndef OMK_VERBOSE
109   OMK_VERBOSE = 0
110 endif
111 ifneq ($(OMK_VERBOSE),0)
112   Q =
113 else
114   Q = @
115 endif
116 ifneq ($(findstring s,$(MAKEFLAGS)),)
117   QUIET_CMD_ECHO = true
118   OMK_SILENT = 1
119 else
120   QUIET_CMD_ECHO = echo
121 endif
122
123 MAKEFILE_OMK=Makefile.omk
124 # All subdirectories (even linked ones) containing Makefile.omk
125 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
126 ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
127
128 # ===================================================================
129 # We have set up all important variables, so we can check and include
130 # real OCERA style Makefile.omk now
131 ifndef OMK_INCLUDED
132 include $(SOURCES_DIR)/$(MAKEFILE_OMK)
133 OMK_INCLUDED := 1
134 endif
135
136 check-make-ver:
137         @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
138         if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
139                 echo "Your make program version is too old and does not support OMK system." ; \
140                 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
141         fi
142
143 distclean dist-clean:
144         @$(QUIET_CMD_ECHO) "  RM      $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
145         @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)  $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
146
147 # Common OMK templates
148 # ====================
149
150 # Syntax: $(call mkdir,<dir name>)
151 define mkdir_def
152         [ -d $(1) ] || mkdir -p $(1) || exit 1
153 endef
154
155 ifneq ($(V),2)
156 NO_PRINT_DIRECTORY := --no-print-directory
157 endif
158
159 ifeq ($(USE_LEAF_MAKEFILES),n)
160 export USE_LEAF_MAKEFILES
161 SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
162 SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
163 else
164 SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(dir)/Makefile
165 SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
166 endif
167
168 ifdef OMK_TESTSROOT
169 check-target = $$(@:%=%-check)
170 endif
171
172 # Syntax: $(call omk_pass_template,<pass name(s)>,<build dir>,[<local make flags>],[<local condition>])
173 define omk_pass_template
174 .PHNOY: $(1) $(addsuffix -local,$(1)) $(addsuffix -check,$(1))
175 $(1):
176         +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \
177                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \
178                 RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(2)/$(dir) \
179                 -f $(SUBDIR_MAKEFILE) $$@ || exit 1 ;) true
180 ifneq ($(4),)
181         @echo "make[omk]: $$@ in $(RELATIVE_DIR)"; \
182         $(call mkdir_def,$(2)); \
183         $(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
184                 -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $$(@:%=%-local)
185 endif
186 endef
187
188 # =======================
189 # DEFAULT CONFIG PASS
190
191 default-config:
192         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
193         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
194         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
195         @echo >> "$(CONFIG_FILE)-default"
196         @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
197                 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
198                 -f $(MAKERULES_DIR)/Makefile default-config-pass
199
200 $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
201
202 default-config-pass-local:
203 #       @echo Default config for $(RELATIVE_DIR)
204         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
205         @$(foreach x, $(default_CONFIG), echo '$(x)' | \
206                 sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
207
208
209 omkize:
210         $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
211            echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
212         fi
213         $(Q)for i in `find -L . -name Makefile.omk` ; do \
214            i=`dirname $${i}`; \
215            if [ x"$$i" != x"." ]; then \
216               rm -f $${i}/Makefile; \
217               cp Makefile $${i}/Makefile; \
218            fi \
219         done