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