view Makefile @ 71:a87eb778f225

Improvements to the MinGW crossbuild. Should now build with default tools from Debian mingw packages, though you need Win32 version of libSDL with the necessary headers and so on in addition. 64-bit builds not tested and probably won't work. Tested on Debian 7.0, earlier won't work. binutils-mingw-w64-i686 gcc-mingw-w64-i686 mingw-w64-i686-dev
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 14 Aug 2012 03:08:10 +0300
parents 1bd4e39c600b
children 1096f6ffd15c
line wrap: on
line source

### Global settings
CFLAGS += -W -Wall -O3
LDFLAGS +=
RANLIB=ranlib

MINGW32_PREFIX=i686-w64-mingw32-
MINGW32_PATH=/usr/i686-w64-mingw32
MINGW64_PREFIX=x86_64-w64-mingw32-

### Subdirectories to build
SUBDIRS=pwplib peluce nykyaeka oldchsool pwpzax

### 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 re-build: 'make all'"; \
	echo "To reconfigure: 'make clean' and 'make <target>'"; \
	fi

endianchk: endianchk.c
	$(CC) -o $@ $<

config.mak:
	@echo "" > $@
	@echo "# Build target: $(XTARGET)" >> $@
	@echo "XTARGET=$(XTARGET)" >> $@
	@echo "CC=$(PREFIX)$(CC)" >> $@
	@echo "AR=$(PREFIX)$(AR)" >> $@
	@echo "LD=$(PREFIX)$(LD)" >> $@
	@echo "RANLIB=$(PREFIX)$(RANLIB)" >> $@
	@echo "CFLAGS=$(CFLAGS) $(XCFLAGS)" >> $@
	@echo "LDFLAGS=$(LDFLAGS) $(XLDFLAGS)" >> $@
	@echo "BINEXT=$(BINEXT)" >> $@
	@echo "" >> $@

### Build sub targets	
all:
	@for subdir in $(SUBDIRS); do if ! $(MAKE) -C "$$subdir"; then echo "Make returned $?"; exit 1; fi; done

pwplib.a:
	$(MAKE) -C pwplib

clean:
	@for subdir in $(SUBDIRS); do $(MAKE) -C "$$subdir" clean; done
	$(RM) config.mak endianchk

### Major targets
unix: endianchk
	$(RM) config.mak && endianflags=`./endianchk` && \
	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX $$endianflags" XLDFLAGS="-lm" && \
	$(MAKE) all

hpux:
	$(RM) config.mak && \
	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX -DBIG_ENDIAN -DDRIVE_HPUX" XLDFLAGS="-lm" && \
	$(MAKE) all

linux: endianchk
	$(RM) config.mak && endianflags=`./endianchk` && \
	$(MAKE) config.mak XTARGET="$@" XCFLAGS="-DUNIX -DDRIVE_LINUXCON -DDRIVE_OSS $$endianflags" XLDFLAGS="-lm" && \
	$(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

sdl-win32:
	$(RM) config.mak && \
	$(MAKE) config.mak PREFIX="$(MINGW32_PREFIX)" BINEXT=".exe" CC="gcc" \
	XTARGET="$@" XCFLAGS="-DDRIVE_SDL `$(MINGW32_PATH)/bin/sdl-config --cflags`" \
	XLDFLAGS="-s -L$(MINGW32_PATH)/lib/ `$(MINGW32_PATH)/bin/sdl-config --libs` -lwinmm" && \
	$(MAKE) all

sdl-win64:
	$(RM) config.mak && \
	$(MAKE) config.mak PREFIX="$(MINGW64_PREFIX)" BINEXT=".exe" CC="gcc" \
	XTARGET="$@" XCFLAGS="-DDRIVE_SDL `$(MINGW64_PATH)/bin/sdl-config --cflags`" \
	XLDFLAGS="-s -L$(MINGW64_PATH)/lib/ `$(MINGW64_PATH)/bin/sdl-config --libs` -lwinmm" && \
	$(MAKE) all

PACKAGE=pwpunix-1.96-sdl
ZIPFILE=$(PACKAGE)-win32-bin.zip

README.txt: README
	unix2dos -n $< $@

sdl-win32-zip: clean sdl-win32 README.txt SDL.dll
	$(RM) $(ZIPFILE)
	for subdir in $(SUBDIRS); do tmp=`ls $$subdir/*.exe`; if test -f "$$tmp"; then cp "$$tmp" .; fi; done; \
	zip -9vv $(ZIPFILE) *.exe README.txt SDL.dll

hg-tar:
	hg archive -t tgz $(PACKAGE).tar.gz

.dummy: