diff --git a/Makefile b/Makefile index c81f8f4..c9c004c 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,14 @@ ifneq (,$(findstring MINGW,$(shell uname -s))) TARGET_ARCH=mingw -else -ARCH:=$(shell uname) -ifeq ($(ARCH), Darwin) - TARGET_ARCH=macosx else TARGET_ARCH=linux -endif # Darwin endif # windir - - - ifeq ($(TARGET_ARCH),mingw) include Makefile.win32 else ifeq ($(TARGET_ARCH),linux) include Makefile.linux -else -ifeq ($(TARGET_ARCH),macosx) - include Makefile.macosx -endif # macosx endif # linux endif # mingw diff --git a/Makefile.common b/Makefile.common index bc8814b..d6fdc31 100644 --- a/Makefile.common +++ b/Makefile.common @@ -4,7 +4,7 @@ # GameLib Declarations # ######################## CFLAGS += -IGameLib -HEADS= \ +GAMELIB_HEADS = \ GameLib/Time.h \ GameLib/Util.h \ GameLib/QuadArray2D.h \ @@ -14,7 +14,7 @@ HEADS= \ GameLib/Anim.h \ GameLib/Entity.h \ GameLib/GameLib.h -OBJS= \ +GAMELIBS_OBJS = \ $(BUILDDIR)/GameLib/Time.o \ $(BUILDDIR)/GameLib/Util.o \ $(BUILDDIR)/GameLib/QuadArray2D.o \ @@ -23,34 +23,34 @@ OBJS= \ $(BUILDDIR)/GameLib/Audio.o \ $(BUILDDIR)/GameLib/Anim.o \ $(BUILDDIR)/GameLib/Entity.o \ - $(BUILDDIR)/GameLib/GameLib.o \ - + $(BUILDDIR)/GameLib/GameLib.o +RES_GAMELIB_OUT = $(BUILDDIR)/$(RES_GAMELIB) ##################### # Game Declarations # ##################### -HEADS+= GameEnts.h GameMap.h - -OBJS+= \ +GAME_HEADS = $(GAMELIB_HEADS) GameEnts.h GameMap.h +GAME_OBJS = \ $(BUILDDIR)/GameEnts.o \ $(BUILDDIR)/GameMap.o \ $(BUILDDIR)/main.o +RES_GAME_OUT = $(BUILDDIR)/$(RES_GAME) ################# # General Rules # ################# -all: $(BUILDDIR) $(BUILDDIR)/$(RESULT) +all: $(BUILDDIR) $(RES_GAME_OUT) $(BUILDDIR): - mkdir $(BUILDDIR) - mkdir $(BUILDDIR)/GameLib + $(MKDIR) $(BUILDDIR) + $(MKDIR) $(BUILDDIR)/GameLib clean: - rm -f $(OBJS) $(BUILDDIR)/$(RESULT) + $(RM) $(GAMELIBS_OBJS) $(RES_GAMELIB_OUT) $(GAME_OBJS) $(RES_GAME_OUT) -run: $(BUILDDIR) $(BUILDDIR)/$(RESULT) - $(LAUNCHER) ./$(BUILDDIR)/$(RESULT) debug +run: $(BUILDDIR) $(RES_GAME_OUT) + $(LAUNCHER) ./$(RES_GAME_OUT) debug rebuild: clean all @@ -95,8 +95,11 @@ $(BUILDDIR)/main.o: main.c $(HEADS) # Result Rules # ################ -$(BUILDDIR)/$(RESULT): $(OBJS) - $(CC) -o $(BUILDDIR)/$(RESULT) $(OBJS) $(LIBS) $(CFLAGS) $(LDFLAGS) +$(RES_GAMELIB_OUT): $(GAMELIBS_OBJS) + $(AR) rcs $(RES_GAMELIB_OUT) $(GAMELIBS_OBJS) + +$(RES_GAME_OUT): $(RES_GAMELIB_OUT) $(GAME_OBJS) + $(CC) $(GAME_OBJS) $(RES_GAMELIB_OUT) -o $(RES_GAME_OUT) $(LIBS) $(CFLAGS) $(LDFLAGS) diff --git a/Makefile.emscripten b/Makefile.emscripten index 779f15f..fa45447 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -1,14 +1,16 @@ -CC= emcc -LAUNCHER= start -RM=rm -rf +CC = emcc +AR = emar +LAUNCHER = start +RM = rm -rf +MKDIR = mkdir LIBS= CFLAGS= -s FULL_ES2=1 -s ASM_JS=1 -O1 -Wno-implicit-function-declaration #LDFLAGS= --embed-file data LDFLAGS= --preload-file data - -RESULT=game.html +RES_GAMELIB=libgame.a +RES_GAME=game.html BUILDDIR=build-emscripten ifeq ($(target),release) diff --git a/Makefile.linux b/Makefile.linux index bee462e..9cc978b 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -1,12 +1,15 @@ -CC=gcc -LAUNCHER= -RM=rm -rf +CC = gcc +AR = ar +LAUNCHER = +RM = rm -rf +MKDIR = mkdir LIBS= -lSDL -lpthread -L/usr/X11R6/lib -L/usr/lib -lm -lGL -lX11 CFLAGS= -Wall -g -I/usr/include/ -I/usr/include/SDL/ -I/usr/X11R6/include/ LDFLAGS= -RESULT=game +RES_GAMELIB=libgame.a +RES_GAME=game BUILDDIR=build-linux include Makefile.common diff --git a/Makefile.mingw b/Makefile.mingw index 58e8e56..cb2bff4 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -1,12 +1,15 @@ -CC= i486-mingw32-gcc -LAUNCHER= -RM=rm -rf +CC = i486-mingw32-gcc +AR = i486-mingw32-ar +LAUNCHER = +RM = rm -rf +MKDIR = mkdir LIBS= -L/usr/i486-mingw/lib -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32 CFLAGS= -I/usr/i486-mingw/include -lmingw32 -lSDLmain -lSDL -mwindows LDFLAGS= -RESULT=game.exe +RES_GAMELIB=libgame.a +RES_GAME=game.exe BUILDDIR=build-mingw include Makefile.common diff --git a/Makefile.win32 b/Makefile.win32 index 1ae5bf6..769b170 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -1,12 +1,15 @@ -CC=gcc -LAUNCHER= -RM=rm -rf +CC = gcc +AR = ar +LAUNCHER = +RM = rm -rf +MKDIR = mkdir LIBS=-I/mingw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32 CFLAGS= -L/mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows -g LDFLAGS= -RESULT=game.exe +RES_GAMELIB=libgame.a +RES_GAME=game.exe BUILDDIR=build-mingw include Makefile.common diff --git a/gamelib-config b/gamelib-config new file mode 100644 index 0000000..7e79c93 --- /dev/null +++ b/gamelib-config @@ -0,0 +1,73 @@ +#!/bin/sh + +prefix=$( dirname "$0" ) +usage="\ +Uso: gamelib-config [--cflags] [--libs] [--static-libs] [--builddir] [--platform]" + + +# Preparar configuracion +uname=$( uname ) +unamem=$( uname -m ) +if test $1 = "emscripten"; then + uname="EMSCRIPTEN" + unamem="EMSCRIPTEN" + shift +fi +case "$uname" in + *MINGW*) + # Configuracion de Win32/Mingw + libs="-lopengl32" + cflags="-Dmain=SDL_main -lmingw32 -lSDLmain -lSDL -mwindows -g" + builddir="build-mingw" + platform="win32" + ;; + *EMSCRIPTEN*) + # Configuracion de Emscripten + libs="" + cflags="-s FULL_ES2=1 -s ASM_JS=1 -Wno-implicit-function-declaration" + builddir="build-emscripten" + platform="emscripten" + ;; + *) + # Configuracion de Linux + libs="-lSDL -lpthread -L/usr/X11R6/lib -L/usr/lib -lm -lGL -lX11" + cflags="-Wall -g -I/usr/include/ -I/usr/include/SDL/ -I/usr/X11R6/include/" + builddir="build-linux-$unamem" + platform="linux-$unamem" + ;; +esac + + + +if test $# -eq 0; then + echo "${usage}" 1>&2 + exit 1 +fi + + + +while test $# -gt 0; do + case $1 in + --cflags) + echo "$cflags -I$prefix/GameLib" + ;; + --libs) + echo "$libs" + ;; + --static-libs) + echo "$prefix/$builddir/libgame.a" + ;; + --builddir) + echo "$builddir" + ;; + --platform) + echo "$platform" + ;; + *) + echo "${usage}" 1>&2 + exit 1 + ;; + esac + shift +done +