Compatibility with tolua++ 1.0.93
[fawkes.git] / etc / buildsys / rules.mk
1 #*****************************************************************************
2 #                      Makefile Build System for Fawkes
3 #                            -------------------
4 #   Created on Sun Sep 03 14:14:14 2006
5 #   Copyright (C) 2006-2009 by Tim Niemueller, AllemaniACs RoboCup Team
6 #
7 #*****************************************************************************
8 #
9 #   This program is free software; you can redistribute it and/or modify
10 #   it under the terms of the GNU General Public License as published by
11 #   the Free Software Foundation; either version 2 of the License, or
12 #   (at your option) any later version.
13 #
14 #*****************************************************************************
15
16 # see http://make.paulandlesley.org/autodep.html
17 # see http://make.paulandlesley.org/rules.html
18
19 ifndef __buildsys_rules_mk_
20 __buildsys_rules_mk := 1
21
22 include $(abspath $(BUILDSYSDIR)/ext/gmsl)
23
24 MAKE_MIN_VERSION_MAJOR=3
25 MAKE_MIN_VERSION_MINOR=81
26
27 MAKE_VERSION_SPLITTED=$(call split,.,$(MAKE_VERSION))
28 MAKE_VERSION_MAJOR=$(word 1,$(MAKE_VERSION_SPLITTED))
29 MAKE_VERSION_MINOR=$(word 2,$(MAKE_VERSION_SPLITTED))
30
31 ifneq ($(call gte,$(MAKE_VERSION_MAJOR),$(MAKE_MIN_VERSION_MAJOR)),$(true))
32   MAKE_INSUFFICIENT=1
33 else
34   ifeq ($(MAKE_VERSION_MAJOR),$(MAKE_MIN_VERSION_MAJOR))
35     ifneq ($(call gte,$(MAKE_VERSION_MINOR),$(MAKE_MIN_VERSION_MINOR)),$(true))
36       MAKE_INSUFFICIENT=1
37     endif
38   endif
39 endif
40
41 ifeq ($(MAKE_INSUFFICIENT),1)
42   $(error You need at least GNU Make version $(MAKE_MIN_VERSION_MAJOR).$(MAKE_MIN_VERSION_MINOR), but you have only $(MAKE_VERSION))
43 endif
44
45 # indentation definitions, dash (-) is replaced with space
46 INDENT_STRING = ---
47 INDENT_PRINT := $(subst -, ,$(INDENT))
48 ifeq ($(MAKECMDGOALS),clean)
49   DISABLE_OBJS_all_WARNING = 1
50   ifeq ($(shell test -d qa; if [ "$$?" = "0" ]; then echo "yes"; fi),yes)
51     ifneq ($(findstring qa,$(SUBDIRS)),qa)
52       SUBDIRS += qa
53     endif
54   endif
55 endif
56
57 # If SOVER for lib was not set (SOVER_libname empty), set it to DEFAULT_SOVER
58 $(foreach L,$(LIBS_all:$(LIBDIR)/%.so=%) $(LIBS_gui:$(LIBDIR)/%.so=%),$(if $(SOVER_$(subst /,_,$L)),,$(eval SOVER_$(subst /,_,$L) = $(DEFAULT_SOVER))))
59
60 ifdef __buildsys_lua_mk_
61 # Lua libraries do not set an SOVER, it's not checked anyway
62 $(foreach L,$(LIBS_all:$(LIBDIR)/lua/%.so=%),$(if $L,$(eval NOSOVER_lua_$(subst /,_,$L)=1)))
63 endif
64
65 # Dependencies
66 -include $(DEPDIR)/*.d
67
68 # One to build 'em all
69 .PHONY: all gui
70 ifeq ($(MAKELEVEL),1)
71   EXTRA_ALL = $(LIBS_gui) $(PLUGINS_gui) $(BINS_gui) $(TARGETS_gui)
72 endif
73 all: presubdirs $(LIBS_all) $(PLUGINS_all) $(BINS_all) $(TARGETS_all) $(EXTRA_ALL) subdirs
74 gui: presubdirs $(LIBS_gui) $(PLUGINS_gui) $(BINS_gui) $(TARGETS_gui) subdirs
75 uncolored-all: all
76 uncolored-gui: gui
77
78 ifdef OBJS_all
79 ifneq ($(OBJS_all),)
80 # Do not delete .o files to allow for incremental builds
81 .SECONDARY: $(OBJS_all)
82 # Whenever the Makefile is modified rebuild everything
83 $(OBJS_all): $(SRCDIR)/Makefile
84 endif
85 else
86   ifneq ($(LIBS_all)$(PLUGINS_all)$(BINS_all)$(LIBS_gui)$(PLUGINS_gui)$(BINS_gui),)
87     ifneq ($(DISABLE_OBJS_all_WARNING),1)
88       $(warning OBJS_all is not set. This is probably a bug. If you intended this set DISABLE_OBJS_all_WARNING to 1 to get rid of this warning.)
89     endif
90   endif
91 endif
92
93
94 .PHONY: clean
95 clean: presubdirs subdirs
96         $(SILENTSYMB) echo -e "$(INDENT_PRINT)--> Cleaning up directory $(TBOLDGRAY)$(CURDIR)$(TNORMAL)"
97         $(SILENT) if [ "$(SRCDIR)/$(OBJDIR)" != "/" ]; then rm -rf "$(SRCDIR)/$(OBJDIR)" ; fi
98         $(SILENT) if [ -n "$(DEPDIR)" ]; then rm -rf "$(DEPDIR)" ; fi
99         $(SILENT)$(foreach B,$(BINS_all),rm -f $(B);)
100         $(SILENT)$(foreach L,$(LIBS_all),rm -f $(addsuffix *,$(L));)
101         $(SILENT)$(foreach P,$(PLUGINS_all),rm -f $(P);)
102         $(SILENT)$(foreach T,$(TARGETS_all),rm -rf $(T);)
103         $(SILENT)$(foreach B,$(BINS_gui),rm -f $(B);)
104         $(SILENT)$(foreach L,$(LIBS_gui),rm -f $(L);)
105         $(SILENT)$(foreach P,$(PLUGINS_gui),rm -f $(P);)
106         $(SILENT)$(foreach T,$(TARGETS_gui),rm -rf $(T);)
107         $(SILENT)$(foreach E,$(CLEAN_FILES),rm -rf $(E);)
108
109 ifeq (,$(findstring qa,$(SUBDIRS)))
110 .PHONY: qa
111 qa: presubdirs subdirs
112         $(SILENT) if [ -d "$(subst /.objs,,$(realpath $(CURDIR)))/qa" ]; then \
113                 echo -e "$(INDENT_PRINT)--> Building QA in $(subst $(realpath $(CURDIR)/$(BASEDIR))/,,$(subst /.objs,,$(realpath $(CURDIR)))/qa)"; \
114                 $(MAKE) --no-print-directory --no-keep-going -C "$(subst /.objs,,$(CURDIR))/qa" \
115                         SRCDIR="$(subst /.objs,,$(CURDIR))/qa" $(MFLAGS) INDENT="$(INDENT)$(INDENT_STRING)" \
116                         OBJSSUBMAKE=0 || exit $$?; \
117         fi
118 endif
119
120 .PHONY: presubdirs $(PRESUBDIRS) subdirs $(SUBDIRS)
121 presubdirs: $(PRESUBDIRS)
122 subdirs: $(SUBDIRS)
123
124 ifneq ($(PRESUBDIRS)$(SUBDIRS),)
125 $(PRESUBDIRS) $(SUBDIRS):
126         $(SILENTSYMB) if [ ! -d "$(realpath $(SRCDIR)/$(@))" ]; then \
127                 echo -e "$(INDENT_PRINT)---$(TRED)Directory $(TNORMAL)$(TBOLDRED)$@$(TNORMAL)$(TRED) does not exist, check [PRE]SUBDIRS variable$(TNORMAL) ---"; \
128                 exit 1; \
129         else \
130                 echo -e "$(INDENT_PRINT)--> Entering sub-directory $(TBOLDBLUE)$@$(TNORMAL) ---"; \
131                 $(MAKE) --no-print-directory --no-keep-going -C "$(realpath $(SRCDIR)/$@)" \
132                 $(MFLAGS) $(MAKECMDGOALS) INDENT="$(INDENT)$(INDENT_STRING)" \
133                 SRCDIR="$(realpath $(SRCDIR)/$@)" OBJSSUBMAKE=0 || exit $$?; \
134                 if [ "$(MAKECMDGOALS)" != "clean" ]; then \
135                         echo -e "$(INDENT_PRINT)$(subst -, ,$(INDENT_STRING))<-- Leaving $@"; \
136                 fi \
137         fi
138 endif
139
140 # Cancel built-in implicit rules, they suck
141 %: %.cpp
142 %: %.c
143
144 # NOTE: .. are replaced by __. This is needed to have objects that are in upper relative
145 # directories are build in .objs, another change is needed below in bin, lib and plugin targets,
146 # mocs etc.
147 %.o: %.cpp
148         $(SILENT) mkdir -p $(DEPDIR)
149         $(SILENT) mkdir -p $(@D)
150         $(SILENTSYMB) echo "$(INDENT_PRINT)--- Compiling $(subst $(SRCDIR)/,,$<) (C++)"
151         $(SILENT) mkdir -p $(dir $(subst ..,__,$@))
152         $(SILENT) $(CC) -MD -MF $(DEPFILE).td $(CFLAGS_BASE) $(CFLAGS) $(CFLAGS_$*) \
153         $(addprefix -I,$(INCS_$*)) $(addprefix -I,$(INCDIRS)) -c -o $(subst ..,__,$@) $<
154         $(SILENT)sed -e '/^[^:]*\//! s/^\([^:]\+\): \(.*\)$$/$(subst /,\/,$(@D))\/\1: \2/' < $(DEPFILE).td > $(DEPFILE).d; \
155         sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e 's/^ *//' \
156             -e '/^$$/ d' -e 's/$$/ :/' < $(DEPFILE).td >> $(DEPFILE).d; \
157         rm -f $(DEPFILE).td
158
159 %.o: %.c
160         $(SILENT) mkdir -p $(DEPDIR)
161         $(SILENT) mkdir -p $(@D)
162         $(SILENTSYMB) echo "$(INDENT_PRINT)--- Compiling $(subst $(SRCDIR)/,,$<) (C)"
163         $(SILENT) mkdir -p $(dir $(subst ..,__,$@))
164         $(SILENT) $(CC) -MD -MF $(DEPFILE).td $(CFLAGS_BASE) $(CFLAGS) $(CFLAGS_$*) \
165         $(addprefix -I,$(INCS_$*)) $(addprefix -I,$(INCDIRS)) -c -o $(subst ..,__,$@) $<
166         $(SILENT)sed -e '/^[^:]*\//! s/^\([^:]\+\): \(.*\)$$/$(subst /,\/,$(@D))\/\1: \2/' < $(DEPFILE).td > $(DEPFILE).d; \
167         sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e 's/^ *//' \
168             -e '/^$$/ d' -e 's/$$/ :/' < $(DEPFILE).td >> $(DEPFILE).d; \
169         rm -f $(DEPFILE).td
170
171 moc_%.cpp: %.h
172         $(SILENTSYMB) echo "$(INDENT_PRINT)--- Running Qt moc on $(subst $(SRCDIR)/,,$<), creating $(subst ..,__,$@)"
173         $(SILENT) $(MOC) $(MOC_FLAGS) -p "../$(subst ..,__,$(@D))" $< -o $(subst ..,__,$@)
174
175 .SECONDEXPANSION:
176 $(BINDIR)/%: $$(OBJS_$$*)
177         $(SILENT) mkdir -p $(@D)
178         $(SILENTSYMB) echo -e "$(INDENT_PRINT)=== Linking $(TBOLDGREEN)$*$(TNORMAL) ---"
179         $(SILENT) $(CC) -o $@ $(subst ..,__,$^) \
180         $(LDFLAGS_BASE) \
181         $(if $(call seq,$(origin LDFLAGS_$(subst /,_,$*)),undefined),$(LDFLAGS),$(LDFLAGS_$(subst /,_,$*))) \
182         $(addprefix -l,$(LIBS_$*)) $(addprefix -l,$(LIBS)) \
183         $(addprefix -L,$(LIBDIRS_$*)) $(addprefix -L,$(LIBDIRS))
184
185 $(LIBDIR)/%.so: $$(OBJS_$$(subst /,_,$$*))
186         $(SILENT) mkdir -p $(@D)
187         $(SILENTSYMB) echo -e "$(INDENT_PRINT)=== Linking lib $(TBOLDGREEN)$*$(TNORMAL) ---"
188         $(SILENT) $(CC) -o $@$(if $(NOSOVER_$(subst /,_,$*)),,.$(SOVER_$(subst /,_,$*))) $(subst ..,__,$^) \
189         $(if $(NOSOVER_$(subst /,_,$*)),,-Wl,-soname=$(@F).$(SOVER_$(subst /,_,$*))) \
190         $(LDFLAGS_BASE) $(LDFLAGS_SHARED) \
191         $(if $(call seq,$(origin LDFLAGS_$(subst /,_,$*)),undefined),$(LDFLAGS),$(LDFLAGS_$(subst /,_,$*))) \
192         $(addprefix -l,$(LIBS_$(subst /,_,$*))) $(addprefix -l,$(LIBS)) \
193         $(addprefix -L,$(LIBDIRS_$(subst /,_,$*))) $(addprefix -L,$(LIBDIRS))
194         $(if $(NOSOVER_$(subst /,_,$*)),, \
195         $(SILENT) ln -fs $(@F).$(SOVER_$(subst /,_,$*)) $@; \
196         ln -fs $(@F).$(SOVER_$(subst /,_,$*)) $@.$(firstword $(call split,.,$(SOVER_$(subst /,_,$*)))); \
197         )
198
199 ### Check if there are special additions
200 ifneq ($(realpath $(BUILDSYSDIR)/btypes/rules_$(BUILD_TYPE).mk),)
201 include $(BUILDSYSDIR)/btypes/rules_$(BUILD_TYPE).mk
202 endif
203
204 endif # __buildsys_rules_mk_
205