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