]> rtime.felk.cvut.cz Git - sysless.git/blob - Makefile.rules
Initial import.
[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
10 BUILD_DIR_NAME = _build
11 COMPILED_DIR_NAME = _compiled
12 ifndef GROUP_DIR_NAME
13 GROUP_DIR_NAME = nogroup
14 endif
15
16 # We need to ensure definition of sources directory first
17 ifndef SOURCES_DIR
18 SOURCES_DIR := $(shell ( pwd -L ) )
19 endif
20
21 .PHONY: all default check-make-ver
22
23 all: check-make-ver default
24
25 #=========================
26 # Include the config file
27
28 # First, include for which target we are compiling
29 -include $(MAKERULES_DIR)/config.target
30 ifeq ($(wildcard $(MAKERULES_DIR)/config.target),)
31 $(warning You may want to create $(MAKERULES_DIR)/config.target)
32 endif
33
34
35 ifndef CONFIG_FILE
36 CONFIG_FILE      := $(MAKERULES_DIR)/config.omk
37 endif
38 ifneq ($(wildcard $(CONFIG_FILE)-default),)
39 -include $(CONFIG_FILE)-default
40 else
41 $(warning Please, run "make default-config" first)
42 endif
43
44 ifneq ($(wildcard $(CONFIG_FILE)),)
45 include $(CONFIG_FILE)
46 CONFIG_FILE_OK = y
47 endif
48
49 export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR 
50 export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
51
52 ifndef RELATIVE_DIR
53 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
54 endif
55 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
56 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
57 #$(warning  RELATIVE_DIR $(RELATIVE_DIR))
58 override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
59 #$(warning  BACK2TOP_DIR $(BACK2TOP_DIR))
60
61 #$(warning SOURCES_DIR = $(SOURCES_DIR))
62 #$(warning MAKERULES_DIR = $(MAKERULES_DIR))
63 #$(warning RELATIVE_DIR = $(RELATIVE_DIR))
64
65 LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
66 #$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
67
68 #vpath %.c $(SOURCES_DIR)
69 #vpath %.cc $(SOURCES_DIR)
70 #vpath %.cxx $(SOURCES_DIR)
71
72 VPATH = $(SOURCES_DIR)
73 srcdir = $(SOURCES_DIR)
74
75 # Defines for quiet compilation
76 ifdef V
77   ifeq ("$(origin V)", "command line")
78     OMK_VERBOSE = $(V)
79   endif
80 endif
81 ifndef OMK_VERBOSE
82   OMK_VERBOSE = 0
83 endif
84 ifeq ($(OMK_VERBOSE),1)
85   Q =
86 else
87   Q = @
88 endif
89 ifneq ($(findstring s,$(MAKEFLAGS)),)
90   QUIET_CMD_ECHO = true
91   OMK_SILENT = 1
92 else
93   QUIET_CMD_ECHO = echo
94   CP_FLAGS += -v
95 endif
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 default-config:
113         @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
114         @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
115         @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
116         @echo >> "$(CONFIG_FILE)-default"
117         @$(MAKE) --no-print-directory -C $(MAKERULES_DIR) \
118                 RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
119                 -f $(MAKERULES_DIR)/Makefile default-config-pass
120
121 # Common OMK templates
122 # ====================
123
124 # Syntax: $(call mkdir,<pass name>,<local make flags>)
125 define mkdir_def
126         [ -d $(1) ] || mkdir -p $(1) || exit 1
127 endef
128
129 # Syntax: $(call omk_pass_template,<pass name>,<local make flags>)
130 define omk_pass_template
131 .PHNOY: $(1) $(1)-local
132 $(1):
133         +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(LOCAL_BUILD_DIR)/$(dir)) ; \
134                 $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
135                 RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(LOCAL_BUILD_DIR)/$(dir) \
136                 -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;)
137         +@$(call mkdir_def,$(LOCAL_BUILD_DIR))
138         @$(MAKE) --no-print-directory -C $(LOCAL_BUILD_DIR) \
139                 -f $(SOURCES_DIR)/Makefile $(2) $$(@:%=%-local)
140 endef
141
142 # =======================
143 # DEFAULT CONFIG PASS
144
145 $(eval $(call omk_pass_template,default-config-pass))
146 default-config-pass-local:
147         @echo Default config for $(RELATIVE_DIR)
148         @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
149         @$(foreach x, $(default_CONFIG), echo $(x) | \
150                 sed -e 's/^.*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
151
152
153 # =======================
154
155
156 # TODO: Put rules specific to C language to a separate file
157 #include $(MAKERULES_DIR)/Makefile.rules.c-lang
158
159 include $(MAKERULES_DIR)/Makefile.rules.h8300-boot
160