Initial commit
[amiga/OpenBoopsi.git] / common / general.mk
1 #
2 # $Id:$
3 #
4 # Copyright (C) 1999 by Matteo Cavalleri
5 #
6
7 # This makefile is flexible enough to be used for every
8 # class of the OpenBoopsi project. You should not need to
9 # modify anything
10 #
11 # all: create the demo program and the class library
12 #       with no debugging information and code
13 #
14 # lib: create just the library of the public class
15 #       with no debugging information and code
16 #
17 # private: create the demo program linked with optimized version of the class
18 #
19 # debug: create the demo program linked with debug version of the class
20 #
21 # obj: create just the class object ready to be linked
22 #       to a program, with no debugging information and code
23 #
24 # install: copy the demos and classes to the appropriate
25 #       directories
26 #
27
28 ###########################################################
29 # some variables...
30 #
31 BOOPSI_DEPS     := $(INCDIR)/BoopsiStubs.h $(INCDIR)/CompilerSpecific.h $(INCDIR)/DebugMacros.h
32 CLASSOBJ_SHARED := $(subst .c,_shared.o,$(CLASSSRC))
33 CLASSOBJ_STATIC := $(subst .c,_static.o,$(CLASSSRC))
34 CLASSOBJ_DEBUG  := $(subst .c,_dbg.o,$(CLASSSRC))
35 CLASSINC        := $(subst .c,.h,$(CLASSRC))
36 DEMOOBJ_STATIC  := $(subst .c,_static.o,$(DEMOSRC))
37 DEMOOBJ_SHARED  := $(subst .c,_shared.o,$(DEMOSRC))
38 DEMOOBJ_DEBUG   := $(subst .c,_dbg.o,$(DEMOSRC))
39
40 # Provide a default name for the demo program
41 ifeq ($(strip $(DEMOPROG)),)
42         ifneq ($(strip $(DEMOSRC)),)
43                 DEMOPROG := $(subst .c,,$(DEMOSRC))
44         endif
45 endif
46
47 # Generate the name of the debug demo
48 ifneq ($(strip $(DEMOPROG)),)
49         DEMOPROG_DEBUG := $(DEMOPROG)_debug
50 endif
51
52 ###########################################################
53 # additional compiler flags
54 #
55 ifeq ($(strip $(COMPILER)),gcc)
56         LIB_CFLAGS := -DDATE="\"$(CLASSDATE)"\" -DNAME="\"$(CLASSLIB)"\" \
57                         -DVERSION="\"$(CLASSVER).$(CLASSREV)"\"
58 else
59         LIB_CFLAGS := $(DEF) DATE=$(CLASSDATE) $(DEF) NAME="$(CLASSLIB)" \
60                         $(DEF) VERSION="$(CLASSVER).$(CLASSREV)"
61 endif
62
63 O_CFLAGS += $(LIB_CFLAGS)
64 D_CFLAGS += $(LIB_CFLAGS)
65
66
67 ###########################################################
68 # additional assembler flags
69 # do not modify the spaces in the lines below!
70 #
71 O_SFLAGS += SET "LIBVERSION=$(CLASSVER),LIBREVISION=$(CLASSREV) "
72 D_SFLAGS += SET "LIBVERSION=$(CLASSVER),LIBREVISION=$(CLASSREV) "
73
74
75 ###########################################################
76 # Main targets
77 ###########################################################
78 #
79
80 all: $(DEMOPROG) $(CLASSLIB)
81 ifneq ($(strip $(SUBDIRS)),)
82         for i in $(SUBDIRS); do $(MAKE) -C $$i TOP=$(TOP) ; done
83 endif
84
85 help-all:
86         @echo "This target will build all the classes and demo programs."; echo
87
88
89 lib: $(CLASSLIB)
90 ifneq ($(strip $(SUBDIRS)),)
91         for i in $(SUBDIRS); do $(MAKE) -C $$i TOP=$(TOP) lib ; done
92 endif
93
94 help-lib:
95         @echo "This target will build all the classes (but not the demo programs)."; echo
96
97
98 obj: $(CLASSOBJ_STATIC)
99 ifneq ($(strip $(SUBDIRS)),)
100         for i in $(SUBDIRS); do $(MAKE) -C $$i TOP=$(TOP) obj ; done
101 endif
102
103 help-obj:
104         @echo "This target create the classes object ready to be linked as a static"
105         @echo "library, with no debugging code."; echo
106
107
108 private: $(DEMOPROG)
109 ifneq ($(strip $(SUBDIRS)),)
110         for i in $(SUBDIRS); do $(MAKE) -C $$i TOP=$(TOP) private ; done
111 endif
112
113 help-private:
114         @echo "This target will build all the demo programs with the classes linked"
115         @echo "as static libraries. No debug code and symbols are added."
116         @echo
117         @echo "This may be useful to let other users test new versions of the classes"
118         @echo "without the need to install them or without overwriting old versions"
119         @echo "that may have been installed."; echo
120
121
122 debug: $(DEMOPROG_DEBUG)
123 ifneq ($(strip $(SUBDIRS)),)
124         for i in $(SUBDIRS); do $(MAKE) -C $$i TOP=$(TOP) debug ; done
125 endif
126
127 help-debug:
128         @echo "This target will build all the demo programs with the classes linked"
129         @echo "as static libraries. Debug code and symbols are added."; echo
130
131
132 install:
133 ifneq ($(strip $(SUBDIRS)),)
134         for i in $(SUBDIRS); do $(MAKE) -C $$i TOP=$(TOP) install ; done
135 endif
136 ifneq ($(strip $(DEMOPROG)),)
137         $(CP) $(DEMOPROG) $(PREFIX)/demos/
138 endif
139 ifneq ($(strip $(CLASSLIB)),)
140         $(CP) $(CLASSLIB) $(PREFIX)/classes/$(INSTALLDIR)/
141 endif
142
143 help-install:
144         @echo "This target copy all the classes and the demos in the dist/ directory,"
145         @echo "placing the classes in the correct subdirectories."; echo
146
147
148 clean:
149 ifneq ($(strip $(SUBDIRS)),)
150         for i in $(SUBDIRS); do $(MAKE) -C $$i TOP=$(TOP) clean ; done
151 endif
152         $(RM) $(DEMOPROG) $(CLASSLIB) $(CLASSOBJ_STATIC)
153
154 help-clean:
155         @echo "This target delete all the demoprograms, all the classes and all"
156         @echo "the objects in the sources subdirectories."; echo
157
158
159 help:
160         @echo "Type 'make help-(targetname) (e.g. 'make help-all') to get"
161         @echo "a detailed help for each target"; echo
162         @echo "Current package configuration:"
163         @echo "------------------------------"
164         @echo "Defined targets: all; lib; debug; private; obj; install; clean; setup;"
165         @echo "Defined subdirs: $(patsubst %,%;,$(SUBDIRS))"; echo
166         @echo "Your OpenBoopsi root directory: $(TOP)."; echo
167         @echo "Configured compiler: $(COMPILER)."
168         @echo "Configured cpu: $(CPU)."
169 ifeq ($(strip $(NOSTDLIB)),0)
170         @echo "Configured demo linking method: standard startup code."
171 else
172         @echo "Configured demo linking method: custom startup code."
173 endif
174         @echo; echo "Happy compiling!"; echo
175
176
177 ###########################################################
178 # build the class library
179 ###########################################################
180 #
181 $(CLASSLIB): ClassLib.o $(CLASSOBJ_SHARED) $(CLASSOBJ)
182         @$(ECHO) "Building class library..."
183         $(LDNOLIB) ClassLib.o $(CLASSOBJ_SHARED) $(CLASSOBJ) $(TO) $@ $(O_LFLAGS) $(ARG_LIB)
184         $(FLUSHLIBS)
185
186
187 ###########################################################
188 # compile class source
189 ###########################################################
190 #
191
192 # All objects depend on their headers
193 $(CLASSOBJ_SHARED) $(CLASSOBJ_STATIC) $(CLASSOBJ_DEBUG): $(CLASSINC) $(BOOPSI_DEPS)
194
195 $(CLASSOBJ_SHARED): %_shared.o : %.c
196         $(CC) $< $(TO) $@ $(O_CFLAGS) -DCLASS_FLAVOUR=3
197
198 $(CLASSOBJ_STATIC): %_static.o : %.c
199         $(CC) $< $(TO) $@ $(O_CFLAGS) -DCLASS_FLAVOUR=0
200
201 $(CLASSOBJ_DEBUG): %_dbg.o : %.c
202         $(CC) $< $(TO) $@ $(D_CFLAGS) -DCLASS_FLAVOUR=0
203
204 ###########################################################
205 # assemble the class library init code
206 ###########################################################
207 #
208 # All this mess is required since PhxAss can't handle
209 # UNIX paths. It would also be possible to link this
210 # object without converting it, but it seems that
211 # this leads to a bigger executable...
212 #
213 ClassLib.o: $(TOP)/common/ClassLib.s Makefile
214 ifeq ($(strip $(COMPILER)),gcc)
215         $(CP) $< /t
216         $(ASM) T:ClassLib.s TO T:temp.o $(O_SFLAGS)
217         $(HUNK2AOUT) /t/temp.o >NIL:
218         $(REN) obj.* $@
219         $(RM) /t/ClassLib.s /t/temp.o
220 else
221         $(ASM) $< $(TO) $@ $(O_SFLAGS)
222 endif
223
224
225 ###########################################################
226 # build the demo program
227 ###########################################################
228 #
229 ifneq ($(strip $(DEMOPROG)),)
230
231 $(DEMOPROG): $(DEMOOBJ_STATIC) $(DEMOOBJ) $(CLASSOBJ_STATIC) $(CLASSOBJ)
232         @$(ECHO) "Linking demo..."
233 ifeq ($(strip $(NOSTDLIB)),0)
234         $(LD) $(TO) $@ $(DEMOOBJ_STATIC) $(DEMOOBJ) $(CLASSOBJ_STATIC) $(CLASSOBJ) $(O_LIBS) $(O_LFLAGS)
235 else
236         $(LDNOLIB) $(TO) $@ $(APP_STARTUP) $(DEMOOBJ_STATIC) $(DEMOOBJ) $(CLASSOBJ_STATIC) $(CLASSOBJ) $(O_LIBS) $(O_LFLAGS)
237 endif
238
239 $(DEMOPROG_DEBUG): $(DEMOOBJ_DEBUG) $(DEMOOBJ) $(CLASSOBJ_DEBUG) $(CLASSOBJ)
240 ifeq ($(strip $(NOSTDLIB)),0)
241         $(CC) $(TO) $@ $(DEMOOBJ_DEBUG) $(DEMOOBJ) $(CLASSOBJ_DEBUG) $(CLASSOBJ) $(D_LIBS) $(D_LFLAGS)
242 else
243         $(LDNOLIB) $(TO) $@ $(APP_STARTUP) $(DEMOOBJ_DEBUG) $(DEMOOBJ) $(CLASSOBJ_DEBUG) $(CLASSOBJ) $(D_LIBS) $(D_LFLAGS)
244 endif
245
246 endif
247
248
249 ###########################################################
250 # compile demo source
251 ###########################################################
252 #
253
254 # All objects depend on their headers
255 $(DEMOOBJ_SHARED) $(DEMOOBJ_DEBUG) $(DEMOOBJ_STATIC): $(CLASSINC)
256
257 $(DEMOOBJ_SHARED): %_shared.o : %.c
258         $(CC) $< $(TO) $@ $(O_CFLAGS) -DCLASS_FLAVOUR=3
259
260 $(DEMOOBJ_STATIC): %_static.o : %.c
261         $(CC) $< $(TO) $@ $(O_CFLAGS) -DCLASS_FLAVOUR=0
262
263 $(DEMOOBJ_DEBUG): %_dbg.o : %.c
264         $(CC) $< $(TO) $@ $(D_CFLAGS) -DCLASS_FLAVOUR=0
265
266
267 ###########################################################
268 # GNU make quirks
269 ###########################################################
270
271 # disable all implicit rules for suffixes known to GNU make such as .c and .o
272 .SUFFIXES:
273
274 # Explicitly declare standard targets as phony
275 .PHONY: all lib debug private obj install clean help \
276         help-all help-lib help-debug help-private help-obj \
277         help-install help-clean