1#
2# Motor IDE functional Makefile template
3# 	for terminal program in C++
4#
5# Written by Konstantin Klyagin <konst@konst.org.ua>
6# Distributed under the GNU Public License
7
8# Project settings and files
9
10SOURCES = 3dobject-ase.cpp 3dobject.cpp bitmap.cpp bullet.cpp cmc.cpp construction.cpp enemy_ai.cpp glprintf.cpp main.cpp mainmenu.cpp maps.cpp menu.cpp myglutaux.cpp nether.cpp nethercycle.cpp netherdebug.cpp nethersave.cpp particles.cpp piece3dobject.cpp quaternion.cpp radar.cpp robot_ai.cpp robots.cpp shadow3dobject.cpp vector.cpp
11HEADERS = 3dobject.h bitmap.h cmc.h glprintf.h list.h myglutaux.h nether.h piece3dobject.h quaternion.h shadow3dobject.h vector.h
12DOCS =
13MISCF = netherearth.motor
14BUILDF = configure.in Makefile.am netherearth.spec
15ALL_FILES := $(strip $(SOURCES) $(HEADERS) $(MISCF) $(DOCS))
16ALL_DIRS := $(sort $(dir $(ALL_FILES)))
17PROJNAME = netherearth
18PROJVER = 0.51
19INCLDIRS = /usr/local/include
20PROG = netherearth
21DIST_TARGZ := $(PROJNAME)-$(PROJVER).tar.gz
22LDFLAGS =  -L/usr/local/lib
23CLNAMES =
24WANT_AM = WANT_AUTOCONF=2.1 WANT_AUTOMAKE=1.4
25WANT = $(WANT_AM) CFLAGS="-O0 -g" CXXFLAGS="-O0 -g"
26
27# Motor specific targets
28
29# Executed every time there is a need to compile the stuff
30
31build: ready
32	$(WANT) $(MAKE)
33
34# Executed to make sure the build environment is ready
35
36ready:
37	@if test ! -f Makefile.am; then $(MAKE) -f Makefile.func automake; fi
38	@if test ! -f Makefile.in; then $(WANT) automake; fi
39	@if test ! -f configure; then autoconf; fi
40	@if test ! -f Makefile; then \
41	    $(WANT) ./configure; \
42	fi
43
44# Invoked for cleaning up
45
46clean: ready
47	$(MAKE) distclean
48
49# This one starts the debugger
50
51debug:
52	@prg=`echo "$(PROG)" | sed 's/-/_/g'`; prg=`find . -name "$${prg}"`; \
53	exec gdb --fullname -silent -tty `cat .debugtty && rm -f .debugtty` $${prg}
54
55# Runs the program
56
57run:
58	@prg=`echo "$(PROG)" | sed 's/-/_/g'`; \
59	CMD="`find . -name "$${prg}" -type f`"; \
60	`echo $$CMD`
61
62# Executed on project creation
63
64start: automake makesure
65
66# Executed on project modification
67
68update: automake
69	rm -f config.cache && $(WANT) ./configure
70
71#
72# Add connected libs into the distribution package
73#
74
75distextra:
76	@sed 's|^EXTRA_DIST\(.*\)$$|EXTRA_DIST\1 $(addsuffix /*, $(CLNAMES))|g' Makefile.am >.makefile.am; \
77	mv .makefile.am Makefile.am
78
79#
80# Modify the Makefile.am thus connected libraries are to compile
81# don't forget to replace dirs in -L and -I
82#
83
84linklibs:
85
86distlib: linklibs
87	@echo; \
88	if test ! -z "$$rsed"; then \
89	    for file in `find . -name Makefile.am`; do \
90		sed "$$rsed" $$file >.makefile.am; \
91		mv .makefile.am $$file; \
92	    done; \
93	fi
94	@echo -e "dist-hook:\n\tcd \$$(top_distdir); subs=\`egrep \"^[:space:]*SUBDIRS\" Makefile.am | sed 's/SUBDIRS[ =]\+//g'\`; \\" >.makefile.am
95	@echo -e "\techo \"SUBDIRS = $(CLNAMES) \$$\$$subs\" >>.makefile.am; \\" >>.makefile.am
96	@echo -e "\tegrep -v \"^[:space:]*SUBDIRS\" Makefile.am >>.makefile.am; \\" >>.makefile.am
97	@echo -e "\tmv .makefile.am Makefile.am; $(WANT_AM) autoconf && automake" >>.makefile.am
98	@echo -e "\n# END OF MOTOR DIST TARGETS #" >>.makefile.am
99	@cat Makefile.am >>.makefile.am
100	@mv .makefile.am Makefile.am
101	@cat configure.in | egrep -v "^[[:space:]]*AC_OUTPUT|^[[:space:]]*AC_CONFIG_SUBDIRS" >.configure.in; \
102	libdirs="$(CLNAMES)"; \
103	if test -n "$$libdirs"; then \
104	    libdirs=`echo $$libdirs | sed 's/^\s+|\s+$$//g'`; \
105	    echo "AC_CONFIG_SUBDIRS($$libdirs)" >>.configure.in; \
106	fi; \
107	cat configure.in | egrep "^[[:space:]]*AC_OUTPUT" >>.configure.in; \
108	mv .configure.in configure.in; \
109
110dist: makesure automake distextra distlib
111	@-for i in . $(CLNAMES); do \
112	    if cd "/usr/home/oleg/projects/netherearth"/$$i; then \
113		if test "$$i" != "."; then for file in `find . -name Makefile.am`; do \
114		    sed 's/ [[:alnum:]]*\.spec//g' $$file >.makefile.am; \
115		    mv .makefile.am $$file; \
116		done; fi; \
117		$(WANT) autoconf; automake -a -c; \
118		if test $$i != "."; then \
119		    find . -name "*.spec" -exec rm -f {} \;; \
120		fi; \
121	    fi; \
122	done
123	@if test ! -z "$(CLNAMES)"; then find $(CLNAMES) -name "*.spec" -exec rm -f {} \;; fi
124	@if test ! -f Makefile; then ./configure --cache-file=/usr/home/oleg/projects/netherearth/config.cache; fi
125	$(MAKE) dist
126	$(MAKE) -f Makefile.func automake
127
128distcleanup:
129	@if test -f Makefile.am; then \
130	    cat Makefile.am | perl -e \
131		"while(<STDIN>) { \
132		    chomp; push (@toshow, \$$_); \
133		    @toshow = () if \$$_ eq '# END OF MOTOR DIST TARGETS #'; \
134		}; \
135		print map { \$$_, \"\n\" } @toshow;" \
136	    >.makefile.am; \
137	    mv .makefile.am Makefile.am; \
138	fi
139
140rpmspec:
141	@if test ! -f netherearth.spec; then \
142	    echo "netherearth.spec file not found!"; \
143	    exit 1; \
144	fi
145	@sed "s/^[[:space:]]*Version\: .*$$/Version: $(PROJVER)/g" <netherearth.spec >netherearth.spec.uver
146	@if test -z "`egrep '^[[:space:]]*BuildRoot: ' netherearth.spec`"; then \
147	    echo "BuildRoot: /var/tmp/%{name}-buildroot" >netherearth.spec; \
148	    cat netherearth.spec.uver >>netherearth.spec; \
149	else \
150	    mv netherearth.spec.uver netherearth.spec; \
151	fi
152	@rm -f mv netherearth.spec.uver
153
154rpm: rpmspec dist
155	@if test ! -f ~/.motor/rpmrc; then \
156	    echo "macrofiles:	/usr/lib/rpm/macros:/usr/lib/rpm/%{_target}/macros:/etc/rpm/macros.specspo:/etc/rpm/macros:/etc/rpm/%{_target}/macros:~/.rpmmacros:~/.motor/rpmmacros" >~/.motor/rpmrc; \
157	fi
158	@if test ! -f ~/.motor/rpmmacros; then \
159	    echo "%_topdir	$${HOME}/.motor/rpm"	>>~/.motor/rpmmacros; \
160	    echo "%_builddir	%{_topdir}/BUILD"	>>~/.motor/rpmmacros; \
161	    echo "%_rpmdir	%{_topdir}/RPMS"	>>~/.motor/rpmmacros; \
162	    echo "%_sourcedir	%{_topdir}/SOURCES"	>>~/.motor/rpmmacros; \
163	    echo "%_specdir	%{_topdir}/SPECS"	>>~/.motor/rpmmacros; \
164	    echo "%_srcrpmdir	%{_topdir}/SRPMS"	>>~/.motor/rpmmacros; \
165	    echo "%_tmppath	%{_var}/tmp"		>>~/.motor/rpmmacros; \
166	fi
167	@-for i in SPECS BUILD RPMS SRPMS; do mkdir -p "$${HOME}/.motor/rpm/$$i"; done
168	unset LINGUAS; rpmbuild -ta --rcfile ~/.motor/rpmrc --target i386-pc-linux-gnu /$(DIST_TARGZ)
169	find "${HOME}/.motor/rpm" -name "$(PROJNAME)-$(PROJVER)*rpm" -exec mv {} "" \;
170	rm -rf "${HOME}/.motor/rpm"
171
172#
173# mfdetect(currentfiles) returns
174#	1 - root dir	2 - prog dir
175#	3 - lib dir	4 - doc dir
176#	5 - misc dir
177#
178# finlist(currentfiles, setof) $result to the list of files matched
179#
180# variables
181#	rfnames - files in the current directory (with relative path names)
182#	fnames  - files in the current directory (filenames only)
183#	dnames  - current dir subdirectories
184#
185automake: distcleanup
186	@rootfound=0; \
187	cflgs=""; \
188	if test ! -z "$(INCLDIRS)"; then \
189	    idirs=`for i in $(addprefix -I, $(INCLDIRS)); do (echo -n "$$i " | \
190		grep -v "^-I/" | sed 's/^-I/-I\\\\044(top_srcdir)\//g'); done; \
191		for i in $(addprefix -I, $(INCLDIRS)); do (echo -n "$$i " | \
192		grep "^-I/"); done`; \
193	    idirs=`echo -e $$idirs | sed "s/\n//g"`; \
194	fi; \
195	amfnames=""; \
196	plibs=`for i in  "GL" "GLU" "glut" "SDL" "SDL_mixer" "pthread"; do printf " %s" $$i | sed 's/-/_/g'; done`; \
197	plibs=`for i in $$plibs; do printf " -l%s" $$i; done`; \
198	 \
199	\
200	finlist () { \
201	    result=""; \
202	    for i in $$1; do \
203		gmask=`echo $$i | sed 's/\//\\\\\//g' | sed 's/\./\\\\\./g'`; \
204		gmask="\<$$gmask\>"; \
205		if test ! -z "`echo $$2 | egrep $$gmask`"; then \
206		result="$$result $$i"; fi; \
207	    done; \
208	}; \
209	mfdetect () { \
210	    finlist "$$1" "$(SOURCES)"; \
211	    if test ! -z "$$result"; then \
212		if test "$$rootfound" = "0"; then \
213		rootfound=1; return 2; else \
214		return 3; fi; \
215	    fi; \
216	    finlist "$$1" "$(DOCS)"; \
217	    if test ! -z "$$result"; then return 4; fi; \
218	    return 5; \
219	}; \
220	getlastword () { \
221	    result=`echo $$1 | sed "s/^\(.*\)\/\([^/]\+\)\/$$/\2/g" | sed "s/\///g"`; \
222	}; \
223	filteram () { \
224	    if test -f $$1; then egrep -v "^[^#]+_PROGRAMS|^[^#]+_SOURCES|^[[:space:]]*EXTRA_DIST|^[[:space:]]*AUTOMAKE_OPTIONS|^[^#]+_LIBRARIES|^[[:space:]]*SUBDIRS|^[[:space:]]*INCLUDES|^[[:space:]]*CPPFLAGS|^[[:space:]]*CFLAGS|^[^#]+_LDADD|^[^#]+_LDFLAGS" $$1 >$${1}.motmp; \
225	    else touch $${1}.motmp; fi; \
226	    echo -n >$$1; \
227	}; \
228	extractsubdirs () { dextracted=""; \
229	    for ndir; do \
230		pathcomp=""; \
231		set `echo ":$$ndir" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`; \
232		if test "$$ndir" != "po/" -a "$$ndir" != "./po/" -a "$$ndir" != "intl/" -a "$$ndir" != "./intl/"; then \
233		for d; do pathcomp="$$pathcomp$$d"; \
234		    pathcomp="$$pathcomp/"; \
235		    dextracted="$$dextracted $$pathcomp"; \
236		    if test $$pathcomp = "./"; then pathcomp=""; fi; \
237		done; fi; \
238	    done; \
239	    dextracted=`for i in $$dextracted; do echo $$i; done | sort -u`; \
240	}; \
241	\
242	extractsubdirs ./ $(ALL_DIRS); \
243	echo "$$dextracted" >.dextracted; \
244	for dir in $$dextracted; do \
245	    if test "$$dir" = "./"; then dir=""; fi; \
246	    gmask="^$$dir[^/]+$$"; \
247	\
248	    if test ! -z "$(ALL_FILES)"; then \
249		rfnames=`for i in $(ALL_FILES); do echo $$i | egrep $$gmask; done`; \
250		rfnames=`echo $$rfnames | sed "s/\n//g"`; \
251	    fi; \
252	    if test ! -z "$$dir"; then \
253		gmask="s/`echo $$dir | sed 's/\//\\\\\//g'`//g"; \
254		fnames=`echo $$rfnames | sed $$gmask`; \
255		gmask="^$$dir[^/]+/$$" ;\
256	    else \
257		fnames="$$rfnames"; \
258		gmask="^[^.][^/]*/$$" ;\
259	    fi; \
260	    if test -f "$${dir}netherearth.spec"; then fnames="$$fnames netherearth.spec"; fi; \
261	\
262	    dnames=`for i in $$dextracted; do echo $$i | egrep $$gmask; done`; \
263	    dnames=`echo $$dnames | sed "s/\n//g"`; \
264	    if test ! -z "$$dir"; then \
265		gmask="s/`echo $$dir | sed 's/\//\\\\\//g'`//g"; \
266		dnames=`echo $$dnames | sed $$gmask`; \
267	    fi; \
268	    dnames=`echo $$dnames | sed "s/\///g"`; \
269	\
270	    mfdetect $$rfnames; tmf=$$?; \
271	    amfname="$${dir}Makefile.am"; filteram $$amfname; \
272	    amfnames="$$amfnames $$amfname"; \
273	    case "$$tmf" in \
274		2) pdir="$$dir"; \
275		   pfnames="$$fnames"; \
276		   pdnames="$$dnames"; \
277		   ;; \
278		3) getlastword $$dir; lib=$$result; \
279		   finlist "$$fnames" "$(SOURCES)"; \
280		   if test ! -z "$$result"; then \
281		       if test ! -z "$$idirs"; then echo "INCLUDES = $$idirs" >>$$amfname; fi; \
282		       if test ! -z "$$cflgs"; then \
283		           echo "CPPFLAGS = $$cflgs" >>$$amfname; \
284		       fi; \
285		       lib=`echo $$lib | sed 's/[-.,]/_/g'`; \
286		       echo "noinst_LIBRARIES = lib$${lib}.a" >>$$amfname; \
287		       echo "lib$${lib}_a_SOURCES =$${result}" >>$$amfname; \
288		       plibs="\$$(top_srcdir)/$${dir}lib$${lib}.a $${plibs}"; \
289		   fi; ;; \
290		4) ;; \
291	    esac; \
292	    if test ! -z "$$fnames"; then echo "EXTRA_DIST = $$fnames" >>$$amfname; fi; \
293	    if test ! -z "$$dnames"; then echo "SUBDIRS = $$dnames" >>$$amfname; fi; \
294	    if test -z "$$dir"; then echo "AUTOMAKE_OPTIONS = foreign" >>$$amfname; fi; \
295	    cat $${amfname}.motmp >>$$amfname; rm -f $${amfname}.motmp; \
296	done; \
297	amfname="$${pdir}Makefile.am"; filteram $$amfname; \
298	amfnames="$$amfnames $$amfname"; \
299	prog=$(notdir $(PROG)); \
300	prog=`echo $$prog | sed 's/[-.,]/_/g'`; \
301	if test ! -z "$$idirs"; then echo "INCLUDES = $$idirs" >>$$amfname; fi; \
302	if test ! -z "$$cflgs"; then \
303	    echo "CPPFLAGS = $$cflgs" >>$$amfname; \
304	fi; \
305	finlist "$$pfnames" "$(SOURCES)"; \
306	echo "bin_PROGRAMS = $$prog" >>$$amfname; \
307	echo "$${prog}_SOURCES =$${result}" >>$$amfname; \
308	pldflags="$(LDFLAGS)"; \
309	if test ! -z "$$pldflags"; then \
310	    echo "$${prog}_LDFLAGS = $$pldflags" >> $$amfname; \
311	fi; if test ! -z "$$plibs"; then \
312	    echo "$${prog}_LDADD = $${plibs}" >>$$amfname; \
313	fi; if test ! -z "$$pdnames"; then \
314	    echo "SUBDIRS = $$pdnames" >>$$amfname; \
315	fi; \
316	echo "EXTRA_DIST = $${pfnames}" >>$$amfname; \
317	echo "AUTOMAKE_OPTIONS = foreign" >>$$amfname; \
318	cat $${amfname}.motmp >>$$amfname; rm -f $${amfname}.motmp; \
319	echo "$${amfnames}" >.amfnames
320	@rm -f .amfnames
321	@cat configure.in | egrep -v "^[[:space:]]*AC_OUTPUT" >configure.in.acout
322	@for i in `cat .dextracted && rm -f .dextracted`; do \
323	    if test ! -z "$$acmfnames"; then acmfnames="$$acmfnames "; fi; \
324	    if test $$i = "./"; then i=""; fi; \
325	    acmfnames="$${acmfnames}$${i}Makefile"; \
326	done; \
327	echo "AC_OUTPUT($${acmfnames})" >>configure.in.acout
328	@sed "s/^[[:space:]]*AM_INIT_AUTOMAKE\(.*\)/AM_INIT_AUTOMAKE($(PROJNAME), $(PROJVER))/g" <configure.in.acout >configure.in
329	@$(RM) configure.in.acout
330	@if test ! -z "`egrep '^[[:space:]]*AM_CONFIG_HEADER' configure.in`"; then \
331	    if test ! -f config.h.in; then $(WANT) autoheader; fi; \
332	fi
333	$(WANT) aclocal
334	$(WANT) autoconf
335	-$(WANT) automake -a -c
336
337gettext:
338	@for i in `ls po/*.po`; do linguas="`basename $$i .po` $$linguas"; done; \
339	cat configure.in | egrep -v "^[[:space:]]*AM_GNU_GETTEXT|^[[:space:]]*ALL_LINGUAS" >configure.in.acout; \
340	if test ! -z "$$linguas"; then \
341	    cat configure.in | egrep -v "^[[:space:]]*AM_GNU_GETTEXT|^[[:space:]]*ALL_LINGUAS|^[[:space:]]*AC_OUTPUT" >configure.in.acout; \
342	    echo "ALL_LINGUAS=\"`echo $$linguas | sed 's/^[ ]*\(.*\)[ ]*$$/\1/g' `\"" \
343		>>configure.in.acout; \
344	    echo "AM_GNU_GETTEXT" >>configure.in.acout; \
345	    acoutadd=""; if test -d intl; then acoutadd=" intl/Makefile"; fi; \
346		acopt="s|^\s*AC_OUTPUT(\\(.*\\))|AC_OUTPUT(\\1 po/Makefile.in$$acoutadd)|g"; \
347	    cat configure.in | egrep "^[[:space:]]*AC_OUTPUT" | \
348		sed "$$acopt" >>configure.in.acout; \
349	    if test ! -z "`egrep '^\s*SUBDIRS' Makefile.am`"; then \
350		sed 's/^\s*SUBDIRS[ 	=]*\(.*\)$$/SUBDIRS = intl po \1/g' <Makefile.am >Makefile.am.motmp; \
351	    else \
352		echo "SUBDIRS = intl po" >Makefile.am.motmp; cat Makefile.am >>Makefile.am.motmp; \
353	    fi; \
354	    mv Makefile.am.motmp Makefile.am; \
355	    if test ! -f po/Makefile.in.in; then \
356		m4d=""; if test -d m4; then m4d=1; fi; \
357		yes | gettextize -c -f --no-changelog --intl; \
358		if test -f po/Makevars.template -a ! -f po/Makevars; \
359		    then mv po/Makevars.template po/Makevars; fi; \
360		if test -z "$$m4d"; then \
361		    rm -rf m4; \
362		    sed 's/^\s*SUBDIRS[ 	=]*m4[ 	=]*\(.*\)$$/SUBDIRS = \1/g' <Makefile.am >Makefile.am.motmp; \
363		    grep -v "ACLOCAL_AMFLAGS = -I m4" Makefile.am.motmp >Makefile.am; \
364		fi; \
365		if test ! -d intl; then \
366		    sed 's/^\s*SUBDIRS[ 	=]*intl[ 	=]*\(.*\)$$/SUBDIRS = \1/g' <Makefile.am >Makefile.am.motmp; \
367		    mv Makefile.am.motmp Makefile.am; \
368		fi; \
369	    fi; \
370	    echo -n >po/POTFILES.in; for i in $(SOURCES) $(HEADERS); do echo $$i >>po/POTFILES.in; done; \
371	    touch po/ChangeLog; \
372	fi; \
373	mv configure.in.acout configure.in
374
375makesure:
376	@for i in $(ALL_FILES) $(BUILDF); do \
377	    if test ! -f $$i; then touch $$i; fi; \
378	done
379
380tags:
381	@if test "$$MOTOR_TAGS" = "file"; then \
382	    TFILES="$$MOTOR_CURRENTFILE"; \
383	elif test "$$MOTOR_TAGS" = "project"; then \
384	    TFILES=" 3dobject-ase.cpp 3dobject.cpp bitmap.cpp bullet.cpp cmc.cpp construction.cpp enemy_ai.cpp glprintf.cpp main.cpp mainmenu.cpp maps.cpp menu.cpp myglutaux.cpp nether.cpp nethercycle.cpp netherdebug.cpp nethersave.cpp particles.cpp piece3dobject.cpp quaternion.cpp radar.cpp robot_ai.cpp robots.cpp shadow3dobject.cpp vector.cpp 3dobject.h bitmap.h cmc.h glprintf.h list.h myglutaux.h nether.h piece3dobject.h quaternion.h shadow3dobject.h vector.h"; \
385	elif test "$$MOTOR_TAGS" = "all"; then \
386	    TFILES=" 3dobject-ase.cpp 3dobject.cpp bitmap.cpp bullet.cpp cmc.cpp construction.cpp enemy_ai.cpp glprintf.cpp main.cpp mainmenu.cpp maps.cpp menu.cpp myglutaux.cpp nether.cpp nethercycle.cpp netherdebug.cpp nethersave.cpp particles.cpp piece3dobject.cpp quaternion.cpp radar.cpp robot_ai.cpp robots.cpp shadow3dobject.cpp vector.cpp 3dobject.h bitmap.h cmc.h glprintf.h list.h myglutaux.h nether.h piece3dobject.h quaternion.h shadow3dobject.h vector.h"; \
387	fi; \
388	if test ! -z "$$TFILES"; then ctags --c++-types=cdefgmnpstuvx --excmd=number -f - $$TFILES; fi
389
390target: ready
391	@$(WANT) $(MAKE) ${MOTOR_TARGET}
392
393gnudoc:
394	touch INSTALL NEWS README COPYING AUTHORS ChangeLog
395
396.PHONY: build update debug automake dist rpm start makesure distextra \
397    distlib gettext target linklibs gnudoc
398