]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/base
Fixed sysless rules and added first aproach to linux rules.
[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 #
5 # input variables
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 ...
9 # PREFIX_DIR       .. Prefix to  directories in _compiled and _build. Used in config.omk.
10
11 # We need to ensure definition of sources directory first
12 ifndef SOURCES_DIR
13 SOURCES_DIR := $(shell ( pwd -L ) )
14 endif
15
16 .PHONY: all default check-make-ver
17
18 all: check-make-ver default
19
20 #=========================
21 # Include the config file
22
23 ifndef CONFIG_FILE
24 CONFIG_FILE      := $(MAKERULES_DIR)/config.omk
25 endif
26 ifneq ($(wildcard $(CONFIG_FILE)-default),)
27 -include $(CONFIG_FILE)-default
28 else
29 $(warning Please, run "make default-config" first)
30 endif
31
32 ifneq ($(wildcard $(CONFIG_FILE)),)
33 include $(CONFIG_FILE)
34 CONFIG_FILE_OK = y
35 endif
36
37 ifeq ($(wildcard $(MAKERULES_DIR)/config.target),$(MAKERULES_DIR)/config.target)
38 $(error Please, rename $(MAKERULES_DIR)/config.target to config.omk!)
39 endif
40
41 BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR))
42 COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR))
43
44 # FIXME: Is GROUP_DIR_NAME useful for non-linux rules? If not, move it
45 # to linux snippet.
46 ifndef GROUP_DIR_NAME
47 GROUP_DIR_NAME = nogroup
48 endif
49
50
51 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
52 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
53 # FIXME: Is it correct to export OMK_SERIALIZE_INCLUDED to submakes???
54
55 ifndef RELATIVE_DIR
56 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
57 endif
58 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
59 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
60 #$(warning  RELATIVE_DIR $(RELATIVE_DIR))
61 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
62 #$(warning  BACK2TOP_DIR $(BACK2TOP_DIR))
63
64 #$(warning SOURCES_DIR = $(SOURCES_DIR))
65 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
66 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
67
68 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
69 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
70
71 #vpath %.c $(SOURCES_DIR)
72 #vpath %.cc $(SOURCES_DIR)
73 #vpath %.cxx $(SOURCES_DIR)
74
75 VPATH = $(SOURCES_DIR)
76 srcdir = $(SOURCES_DIR)
77
78 # Defines for quiet compilation
79 ifdef V
80   ifeq ("$(origin V)", "command line")
81     OMK_VERBOSE = $(V)
82   endif
83 endif
84 ifndef OMK_VERBOSE
85   OMK_VERBOSE = 0
86 endif
87 ifeq ($(OMK_VERBOSE),1)
88   Q =
89 else
90   Q = @
91 endif
92 ifneq ($(findstring s,$(MAKEFLAGS)),)
93   QUIET_CMD_ECHO = true
94   OMK_SILENT = 1
95 else
96   QUIET_CMD_ECHO = echo
97   CP_FLAGS += -v
98 endif
99
100 # ===================================================================
101 # We have set up all important variables, so we can check and include
102 # real OCERA style Makefile.omk now
103 ifndef OMK_INCLUDED
104 include $(SOURCES_DIR)/Makefile.omk
105 OMK_INCLUDED := 1
106 endif
107
108
109 check-make-ver:
110         @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
111         if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
112                 echo "Your make program version is too old and does not support OMK system." ; \
113                 echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
114         fi
115
116 distclean dist-clean:
117         @$(QUIET_CMD_ECHO) "  RM      $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
118         @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)  $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
119
120 default-config:
121         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
122         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
123         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
124         @echo >> "$(CONFIG_FILE)-default"
125         @$(MAKE) --no-print-directory -C $(MAKERULES_DIR) \
126                 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
127                 -f $(MAKERULES_DIR)/Makefile default-config-pass
128
129 # Common OMK templates
130 # ====================
131
132 # Syntax: $(call mkdir,<dir name>)
133 define mkdir_def
134         [ -d $(1) ] || mkdir -p $(1) || exit 1
135 endef
136
137 # Syntax: $(call omk_pass_template,<pass name>,[<local make flags>],[<local condition>],[<build dir>],[<subpass>])
138 define omk_pass_template
139 .PHNOY: $(1) $(1)-local
140
141 ifeq ($(3),)
142 $(1): cond := true
143 else
144 $(1): cond := $(3)
145 endif
146
147 ifeq ($(4),)
148 $(1): build_dir := $(LOCAL_BUILD_DIR)
149 else
150 $(1): build_dir := $(4)
151 endif
152
153 $(1):
154         +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$$(build_dir)/$(dir)) ; \
155                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
156                 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $$(build_dir)/$(dir) \
157                 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;)
158         $(5)
159         +@$(call mkdir_def,$$(build_dir))
160         +@if [ $$(cond) ]; then \
161             $(MAKE) --no-print-directory -C $$(build_dir) \
162                 -f $(SOURCES_DIR)/Makefile $(2) $$(@:%=%-local); \
163         fi
164
165 endef
166
167 # =======================
168 # DEFAULT CONFIG PASS
169
170 $(eval $(call omk_pass_template,default-config-pass))
171 default-config-pass-local:
172         @echo Default config for $(RELATIVE_DIR)
173         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
174         @$(foreach x, $(default_CONFIG), echo $(x) | \
175                 sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )