diff Makefile @ 23:c3622b53a23e

Clean up the build system.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 23 May 2010 22:59:25 +0300
parents acb5694e93d9
children 78235ee17b69
line wrap: on
line diff
--- a/Makefile	Sun May 23 20:22:57 2010 +0300
+++ b/Makefile	Sun May 23 22:59:25 2010 +0300
@@ -1,46 +1,78 @@
-all: pwplib.a
-	cd peluce; make
-	cd nykyaeka; make
-	cd oldchsool; make
+### Global settings
+CFLAGS=-g -W -Wall -O3
+LDFLAGS=
+
+### Subdirectories to build
+SUBDIRS=pwplib peluce nykyaeka oldchsool pwpzax
 
-./configure:
-	$(CC) configure.c -o configure
+### Show some help
+help:
+	@if test ! -f config.mak; then \
+	echo "PWPLib build system"; \
+	echo "Usage: make <target>"; \
+	echo ""; \
+	echo "sdl        - LibSDL video/audio for POSIX style systems"; \
+	echo "unix       - Terminal only POSIX style systems"; \
+	echo "linux      - Like unix, but with Linux console and OSS audio support"; \
+	echo "hpux       - HP-UX (untested now)"; \
+	echo "sdl-win32  - LibSDL for Win32, cross compilation via MinGW toolchain"; \
+	echo "sdl-win64  - Like above, but for Win64 via MinGW64"; \
+	echo ""; \
+	else \
+	echo "Configured as:"; \
+	cat config.mak; \
+	echo "To build: 'make all'"; \
+	echo "To reconfigure: 'make clean' or 'make <target>'"; \
+	fi
 
-pwplib/Makefile: ./configure
-	./configure
-	exit 123
+endianchk: endianchk.c
+	$(CC) -o $@ $<
 
-pwplib.a: pwplib/Makefile
-	cd pwplib; make
+config.mak:
+	@echo "" > $@
+	@echo "# Build target: $(XTARGET)" >> $@
+	@echo "CC=$(CC)" >> $@
+	@echo "CFLAGS=$(CFLAGS) $(XCFLAGS)" >> $@
+	@echo "LDFLAGS=$(LDFLAGS) $(XLDFLAGS)" >> $@
+	@echo "" >> $@
+
+### Build sub targets	
+all:
+	@for subdir in $(SUBDIRS); do $(MAKE) -C "$$subdir"; done
+
+pwplib.a:
+	$(MAKE) -C pwplib
 
 clean:
-	rm -f *~ ./configure ./configure.exe
-	cd pwplib; make clean; rm -f Makefile
-	cd peluce; make clean; rm -f Makefile
-	cd nykyaeka; make clean; rm -f Makefile
-	cd oldchsool; make clean; rm -f Makefile
+	@for subdir in $(SUBDIRS); do $(MAKE) -C "$$subdir" clean; done
+	$(RM) config.mak endianchk
 
-linux: ./configure
-	./configure linux
-	make all
+### Major targets
+unix: endianchk
+	$(RM) config.mak && endianflags=`./endianchk` && \
+	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX $$endianflags" XLDFLAGS="-lm" && \
+	$(MAKE) all
 
-sdl: ./configure
-	./configure sdl
-	make all
+hpux:
+	$(RM) config.mak && \
+	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX -DBIG_ENDIAN -DDRIVE_HPUX" XLDFLAGS="-lm" && \
+	$(MAKE) all
 
-unix: ./configure
-	./configure unix
-	make all
-
-hpux: ./configure
-	./configure hpux
-	make all
+linux: endianchk
+	$(RM) config.mak && endianflags=`./endianchk` && \
+	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX -DDRIVE_LINUXCON -DDRIVE_OSS $$endianflags" XLDFLAGS="-lm" && \
+	$(MAKE) all
 
-cygwin: ./configure
-	./configure cygwin
-	make all
+sdl: endianchk
+	$(RM) config.mak && endianflags=`./endianchk` && \
+	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX -DDRIVE_SDL $$endianflags `sdl-config --cflags`" XLDFLAGS="`sdl-config --libs` -lm" && \
+	$(MAKE) all
 
-win32: ./configure
-	./configure win32
-	make all
+sdl-win32: endianchk
+	$(RM) config.mak && \
+	$(MAKE) config.mak CC=i586-mingw32msvc-gcc AR=i586-mingw32msvc-ar \
+	XTARGET="$@" XCFLAGS="-DUNIX -DDRIVE_SDL `sdl-config --cflags`" XLDFLAGS="`sdl-config --libs`" && \
+	$(MAKE) all
 
+.dummy:
+