1 INCLUDE := -I Include -I aweblibs/include
2 NETINCLUDE := -I /gg/netinclude
3 SSLINCLUDE := -I /gg/amissl-sdk/include
8 CFLAGS := -O2 -fomit-frame-pointer -m68020-60 -Werror-implicit-function-declaration \
11 CPPFLAGS := -Dstpbrk=strpbrk $(INCLUDE)
16 MKDIRS = for d in $(1); do if [ ! -d $$d ]; then mkdir -p $$d; fi; done
19 DISTDIR := distribution/
24 build/module/executable/common/language := C
26 ##################################
27 define build/module/executable/common/language/C
28 $(1)/OBJS += $($(1)/CFILES:%=$(BUILDDIR)$(1)/%.o)
29 $(1)/OBJS/CDEPS := $($(1)/CFILES:%=$(BUILDDIR)$(1)/%.d)
31 $(BUILDDIR)$(1)/%.o : $$($(1)/SRCDIR)%.c
32 $(CC) -c $(CFLAGS) $$($(1)/CFILES/CFLAGS) $$($(1)/CFILES/$$*/CFLAGS) \
33 $$($(1)/CFILES/$$*/CPPFLAGS) $$($(1)/CFILES/CPPFLAGS) $(CPPFLAGS) \
34 -I $$($(1)/SRCDIR)include $$< -o $$@
36 $(BUILDDIR)$(1)/%.d : $$($(1)/SRCDIR)%.c
37 $(CC) -M $$($(1)/CFILES/$$*/CPPFLAGS) $$($(1)/CFILES/CPPFLAGS) $(CPPFLAGS) \
38 -I $$($(1)/SRCDIR)include $$< | sed 's;^.*\.o:;$$(dir $$@)&;' > $$@
40 ifeq (,$(filter clean distclean $(1)-clean $(1)-distclean $(notdir $(1))-clean $(notdir $(1))-distclean, $(MAKECMDGOALS)))
42 ifneq (,$(filter $(1) $(notdir $(1)) $(BUILDDIR)$(1)/%.o $(DISTDIR)$(1),$(if $(ALL_DEPS),$(ALL_DEPS),$(1))))
44 -include $$($(1)/OBJS/CDEPS)
51 ##################################
53 ##################################
54 define build/module/executable/common
57 $$(foreach lang,$(build/module/executable/common/language),$$(eval $$(call build/module/executable/common/language/$$(lang),$(1))))
59 ##################################
61 ##################################
62 define build/module/executable/application
63 $(eval $(call build/module/executable/common,$(1)))
64 $(DISTDIR)$(1): $$($(1)/DEPS) $$($(1)/OBJS)
65 $(CC) -o $$@ $$($(1)/OBJS) $(LDFLAGS) $$($(1)/LDFLAGS)
67 ##################################
69 ##################################
70 define build/module/executable/library/amigashared
71 $(1)/LDFLAGS += -lgcc -nostdlib -lamiga -lamigastubs -nostartfiles -noixemul
72 $(eval $(call build/module/executable/application,$(1)))
74 ##################################
76 #default module type is executable/application
77 build/module/ = $(build/module/executable/application)
79 ##################################
81 #FIXME: this is not really good, because these targets might conflict with the $(BUILDDIR)/%
84 $(1)-clean: $(DISTDIR)$(1)-clean
85 $(1)-distclean: $(DISTDIR)$(1)-distclean
87 $(notdir $(1)): $(DISTDIR)$(1)
88 $(notdir $(1))-clean: $(DISTDIR)$(1)-clean
89 $(notdir $(1))-distclean: $(DISTDIR)$(1)-distclean
92 $(call RM, $(BUILDDIR)$(1)); \
93 $$(if "$$(wildcard $(dir $(BUILDDIR)$(1))*)",,$(call RM, $(dir $(BUILDDIR)$(1))))
95 $(DISTDIR)$(1)-distclean: $(DISTDIR)$(1)-clean
96 $(call RM, $(DISTDIR)$(1)); \
97 $$(if "$$(wildcard $(dir $(DISTDIR)$(1))*)",,$(call RM, $(dir $(DISTDIR)$(1))))
99 .PHONY: $(1) $(1)-clean $(1)-distclean $(notdir $(1)) $(notdir $(1))-clean $(notdir $(1))-distclean
101 ifeq (,$(filter clean distclean $(1)-clean $(1)-distclean $(notdir (1))-clean $(notdir (1))-distclean, $(MAKECMDGOALS)))
103 ifneq (,$(filter $(1) $(notdir $(1)) $(BUILDDIR)$(1)/%.o $(DISTDIR)$(1),$(if $(ALL_DEPS),$(ALL_DEPS),$(1))))
106 $$(call MKDIRS, $(BUILDDIR)$(1) $(DISTDIR)$(dir $(1)))
112 $(eval $(call build/module/$($(1)/TYPE),$(1)))
115 ##################################
117 ##################################
118 # 1) include a given makefile
119 # 2) add the modules it defines to the global modules list
120 # 3) set the SRCDIR variable for each module if it's not defined already
124 ALL_MODULES += $$(MODULES)
125 $$(foreach m,$$(MODULES),$$(eval $$(if $$($$(m)/SRCDIR), , $$(m)/SRCDIR := $$(dir $(1)))))
127 ########################################################################################
129 #The real makefile begins --here--
131 #This is the first target in the makefile. It just redirects to all_modules which
132 #does the real job. It's here so that even if the included makefiles define some
133 #other targets, all_modules always gets executed first (unless otherwise specified
134 #in the command line)
137 #find all makefiles in the tree and invoke add_modules on them.
138 #This phase is currently handled by the 'find' utility, however
139 #for better portability and performances it would be good
140 #to use a custom tool which also mantained a sort of cache
142 ALL_MAKEFILES := $(shell find . -name Tubsfile)
143 $(foreach mak,$(ALL_MAKEFILES),$(eval $(call add_modules,$(mak))))
145 #The two functions below work together to calculate the complete list
146 #of all dependencies of the modules to build, given on the command line.
147 #In case no modules are given by the user then the list will be empty,
148 #however the real list should be filled with ALL dependencies of ALL
149 #available modules, but we optimize this out so that the build is faster
151 $(foreach m,$(1),$(if $(filter $(m),$(__ALLDEPS__)),,$(eval __ALLDEPS__ += $(m)) \
152 $(call getdeplist_1,$($(m)/DEPS))))
154 getdeplist = $(eval __ALLDEPS__ :=) $(call getdeplist_1,$(1)) $(__ALLDEPS__)
156 ALL_DEPS := $(call getdeplist,$(MAKECMDGOALS))
158 all_modules: $(ALL_MODULES:%=$(DISTDIR)%)
160 #invoke build/module on every module
161 #build module recursively invokes some other functions which take care
162 #of everything on the basis of the module's type.
163 $(foreach m,$(ALL_MODULES),$(eval $(call build/module,$(m))))
165 #little trick to make the __setup__ target be invoked before anything else.
167 #It works because there's no "__setup__" file in the directory, thus make
168 #tries to generate it, and looks for a "__setup__" target, which is exactly
169 #what we provide below. The file is not really generated, so the include directive
170 #never succeeds, but this doesn't cause problems because we use "-include",
171 #rather than "include".
173 #We *MUST* make sure that this is the last include directive in the makefile, because
174 #make includes files starting from the last directive. Perhaps this is non-portable
175 #but I have no intention to switch to another make implementation anytime soon, so it's
180 #dummy target in case, for some reasons, no such targets are defined by the modules
182 __setup__: __setup_modules__
185 @$(call RM,$(BUILDDIR))
188 @$(call RM,$(DISTDIR))
190 .PHONY: __setup__ all all_modules clean