Rework Makefile and add support for Windows

This commit is contained in:
Yamagi Burmeister 2012-06-27 14:50:48 +02:00
parent e341087a80
commit 4366acb6c0
2 changed files with 68 additions and 21 deletions

View file

@ -10,28 +10,32 @@
# Yamagi Quake II ist recommended. #
# #
# Platforms: #
# - Linux #
# - FreeBSD #
# - Linux #
# - Windows #
# ----------------------------------------------------- #
# Check the OS type
# Detect the OS
ifdef SystemRoot
OSTYPE := Windows
else
OSTYPE := $(shell uname -s)
endif
# Some plattforms call it "amd64" and some "x86_64"
# Detect the architecture
ifeq ($(OSTYPE), Windows)
# At this time only i386 is supported on Windows
ARCH := i386
else
# Some platforms call it "amd64" and some "x86_64"
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/amd64/x86_64/)
endif
# Refuse all other plattforms as a firewall against PEBKAC
# Refuse all other platforms as a firewall against PEBKAC
# (You'll need some #ifdef for your unsupported plattform!)
ifneq ($(ARCH),i386)
ifneq ($(ARCH),x86_64)
ifeq ($(findstring $(ARCH), i386 x86_64 sparc64),)
$(error arch $(ARCH) is currently not supported)
endif
endif
# ----------
# The compiler
CC := gcc
# ----------
@ -54,7 +58,7 @@ CC := gcc
#
# -MMD to generate header dependencies.
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-fPIC -Wall -pipe -g -MMD
-Wall -pipe -g -MMD
# ----------
@ -68,23 +72,59 @@ all: rogue
# ----------
# When make is invoked by "make VERBOSE=1" print
# the compiler and linker commands.
ifdef VERBOSE
Q :=
else
Q := @
endif
# ----------
# Phony targets
.PHONY : all clean rogue
# ----------
# Cleanup
ifeq ($(OSTYPE), Windows)
clean:
@echo "===> CLEAN"
@rm -Rf build release
@-rmdir /S /Q release build
else
clean:
@echo "===> CLEAN"
${Q}rm -Rf build release
endif
# ----------
# The rogue game
ifeq ($(OSTYPE), Windows)
rogue:
@echo '===> Building game.so'
@mkdir -p release/
@echo "===> Building game.dll"
${Q}tools/mkdir.exe -p release
$(MAKE) release/game.dll
build/%.o: %.c
@echo "===> CC $<"
${Q}tools/mkdir.exe -p $(@D)
${Q}$(CC) -c $(CFLAGS) -o $@ $<
else
rogue:
@echo "===> Building game.so"
${Q}mkdir -p release
$(MAKE) release/game.so
build/%.o: %.c
@echo '===> CC $<'
@mkdir -p $(@D)
@$(CC) -c $(CFLAGS) -o $@ $<
@echo "===> CC $<"
${Q}mkdir -p $(@D)
${Q}$(CC) -c $(CFLAGS) -o $@ $<
release/game.so : CFLAGS += -fPIC
endif
# ----------
@ -150,6 +190,7 @@ ROGUE_OBJS_ = \
src/player/weapon.o \
src/savegame/savegame.o \
src/shared/flash.o \
src/shared/rand.o \
src/shared/shared.o
# ----------
@ -169,8 +210,14 @@ ROGUE_DEPS= $(ROGUE_OBJS:.o=.d)
# ----------
ifeq ($(OSTYPE), Windows)
release/game.dll : $(ROGUE_OBJS)
@echo "===> LD $@"
${Q}$(CC) $(LDFLAGS) -o $@ $(ROGUE_OBJS)
else
release/game.so : $(ROGUE_OBJS)
@echo '===> LD $@'
@$(CC) $(LDFLAGS) -o $@ $(ROGUE_OBJS)
@echo "===> LD $@"
${Q}$(CC) $(LDFLAGS) -o $@ $(ROGUE_OBJS)
endif
# ----------

BIN
tools/mkdir.exe Normal file

Binary file not shown.