]> rtime.felk.cvut.cz Git - sysless.git/blob - Makefile.rules
The first step in OMK unification across projects.
[sysless.git] / Makefile.rules
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 # local_EVALUATE   .. commands to be evaluated at the end of the Makefile
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 ifndef GROUP_DIR_NAME
44 GROUP_DIR_NAME = nogroup
45 endif
46
47
48 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
49 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
50
51 ifndef RELATIVE_DIR
52 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
53 endif
54 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
55 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
56 #$(warning  RELATIVE_DIR $(RELATIVE_DIR))
57 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
58 #$(warning  BACK2TOP_DIR $(BACK2TOP_DIR))
59
60 #$(warning SOURCES_DIR = $(SOURCES_DIR))
61 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
62 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
63
64 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
65 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
66
67 #vpath %.c $(SOURCES_DIR)
68 #vpath %.cc $(SOURCES_DIR)
69 #vpath %.cxx $(SOURCES_DIR)
70
71 VPATH = $(SOURCES_DIR)
72 srcdir = $(SOURCES_DIR)
73
74 # Defines for quiet compilation
75 ifdef V
76   ifeq ("$(origin V)", "command line")
77     OMK_VERBOSE = $(V)
78   endif
79 endif
80 ifndef OMK_VERBOSE
81   OMK_VERBOSE = 0
82 endif
83 ifeq ($(OMK_VERBOSE),1)
84   Q =
85 else
86   Q = @
87 endif
88 ifneq ($(findstring s,$(MAKEFLAGS)),)
89   QUIET_CMD_ECHO = true
90   OMK_SILENT = 1
91 else
92   QUIET_CMD_ECHO = echo
93   CP_FLAGS += -v
94 endif
95
96 # ===================================================================
97 # We have set up all important variables, so we can check and include
98 # real OCERA style Makefile.omk now
99 ifndef OMK_INCLUDED
100 include $(SOURCES_DIR)/Makefile.omk
101 OMK_INCLUDED := 1
102 endif
103
104
105 check-make-ver:
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 ; \
110         fi
111
112 distclean dist-clean:
113         @$(QUIET_CMD_ECHO) "  RM      $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
114         @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)  $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
115
116 default-config:
117         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
118         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
119         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
120         @echo >> "$(CONFIG_FILE)-default"
121         @$(MAKE) --no-print-directory -C $(MAKERULES_DIR) \
122                 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
123                 -f $(MAKERULES_DIR)/Makefile default-config-pass
124
125 # Common OMK templates
126 # ====================
127
128 # Syntax: $(call mkdir,<pass name(s)>,<local make flags>)
129 define mkdir_def
130         [ -d $(1) ] || mkdir -p $(1) || exit 1
131 endef
132
133 # Syntax: $(call omk_pass_template,<pass name>,<local make flags>)
134 define omk_pass_template
135 .PHNOY: $(1) $(1)-local
136 $(1):
137         +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(LOCAL_BUILD_DIR)/$(dir)) ; \
138                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
139                 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(LOCAL_BUILD_DIR)/$(dir) \
140                 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;)
141         +@$(call mkdir_def,$(LOCAL_BUILD_DIR))
142         @$(MAKE) --no-print-directory -C $(LOCAL_BUILD_DIR) \
143                 -f $(SOURCES_DIR)/Makefile $(2) $$(@:%=%-local)
144 endef
145
146 # =======================
147 # DEFAULT CONFIG PASS
148
149 $(eval $(call omk_pass_template,default-config-pass))
150 default-config-pass-local:
151         @echo Default config for $(RELATIVE_DIR)
152         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
153         @$(foreach x, $(default_CONFIG), echo $(x) | \
154                 sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
155
156
157 # =======================
158
159
160 # TODO: Put rules specific to C language to a separate file
161 #include $(MAKERULES_DIR)/Makefile.rules.c-lang
162
163 include $(MAKERULES_DIR)/Makefile.rules.systemless
164
165 ifneq ($(local_EVALUATE),)
166 #$(warning $(local_EVALUATE))
167 $(eval $(local_EVALUATE))
168 endif
169