added game functionality to use time score for 1 or 10 seconds left
[rocksndiamonds.git] / src / Makefile
index 8f18fa7679f134fe705f121107479f52f2d745f6..0db8f54d511017105f573f6f2242f89ea5e5245b 100644 (file)
@@ -31,6 +31,7 @@ endif
 AR = ar
 RANLIB = ranlib
 ETAGS = etags
+STRIP = strip
 RM = rm -f
 
 CONVERT = convert
@@ -57,6 +58,14 @@ PROGNAME = ../$(PROGBASE).exe
 EXTRA_LDFLAGS = -lshfolder -lwsock32
 endif
 
+ifeq ($(PLATFORM),emscripten)          # compiling with Emscripten
+PROGNAME = ../$(PROGBASE).js
+CC = emcc
+AR = emar
+RANLIB = emranlib
+STRIP = true
+endif
+
 ifdef BUILD_DIST                       # distribution build
 ifeq ($(shell uname -s),Darwin)                # compiling on Mac OS X
 MAC_TARGET_VERSION_MIN = 10.7
@@ -84,9 +93,17 @@ endif
 # $(info Using SDL version $(SDL_VERSION) [TARGET == $(TARGET)])
 
 ifeq ($(TARGET),sdl2)                  # compiling for SDL2 target
-SYS_CFLAGS = -DTARGET_SDL2 $(shell sdl2-config --cflags)
+ifeq ($(PLATFORM),emscripten)
+SDL_LIBS = -s USE_SDL_IMAGE=2 -s USE_SDL_MIXER=2 -s USE_SDL_NET=2 -s USE_ZLIB=1
+SDL_FMTS = -s SDL2_IMAGE_FORMATS='["bmp","png","pcx","xpm"]'
+EXTRA_CFLAGS = $(SDL_LIBS)
+EXTRA_LDFLAGS = $(SDL_FMTS) -s INITIAL_MEMORY=65536000 -s ALLOW_MEMORY_GROWTH=1 --preload-file ../graphics/ --preload-file ../sounds/ --preload-file ../levels/ --preload-file ../music/ -s NO_EXIT_RUNTIME=0 -s ASYNCIFY -O2
+else
 SDL_LIBS = -lSDL2_image -lSDL2_mixer -lSDL2_net
-SYS_LDFLAGS = $(SDL_LIBS) $(shell sdl2-config --libs)
+endif
+
+SYS_CFLAGS := -DTARGET_SDL2 $(shell sdl2-config --cflags)
+SYS_LDFLAGS := $(SDL_LIBS) $(shell sdl2-config --libs) -lm -lz
 endif
 
 
@@ -109,22 +126,22 @@ DEBUG = -DDEBUG -g
 # PROFILING = $(PROFILING_FLAGS)
 
 # OPTIONS = $(DEBUG) -Wall                     # only for debugging purposes
-# OPTIONS = $(DEBUG) -O3 -Wall                 # only for debugging purposes
+# OPTIONS = $(DEBUG) -O2 -Wall                 # only for debugging purposes
 # OPTIONS = $(DEBUG) -Wall                     # only for debugging purposes
 OPTIONS = $(DEBUG) -Wall -Wstrict-prototypes -Wmissing-prototypes
 # OPTIONS = $(DEBUG) -Wall -ansi -pedantic     # only for debugging purposes
-# OPTIONS = -O3 -Wall -ansi -pedantic
-# OPTIONS = -O3 -Wall
-# OPTIONS = -O3
+# OPTIONS = -O2 -Wall -ansi -pedantic
+# OPTIONS = -O2 -Wall
+# OPTIONS = -O2
 
 ifdef BUILD_DIST                       # distribution build
 SYS_LDFLAGS := $(shell echo $(SYS_LDFLAGS) |   \
                       sed -e "s%-rpath,[^ ]*%-rpath,'\$$ORIGIN/lib'%")
-OPTIONS = -O3 -Wall
+OPTIONS = -O2 -Wall
 endif
 
 CFLAGS = $(OPTIONS) $(SYS_CFLAGS)  $(EXTRA_CFLAGS) $(CONFIG)
-LDFLAGS =           $(SYS_LDFLAGS) $(EXTRA_LDFLAGS) -lm -lz
+LDFLAGS =           $(SYS_LDFLAGS) $(EXTRA_LDFLAGS)
 
 
 SRCS = main.c          \
@@ -192,6 +209,12 @@ SOURCE_DATE_EPOCH ?= $(shell test -d ../.git && test `git ls-files -m | wc -l` -
 # get source date string from either GNU / Linux or BSD / Mac OS X style "date"
 SOURCE_DATE_STRING := $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+$(TIMESTAMP_FORMAT)"  2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+$(TIMESTAMP_FORMAT)" 2>/dev/null || date -u "+$(TIMESTAMP_FORMAT)")
 
+COMMIT_HASH_FILE = confhash.h
+COMMIT_HASH_NONE = "[changed files]"
+
+# get last Git commit hash, if no files were changed
+SOURCE_HASH_STRING ?= $(shell test -d ../.git && test `git ls-files -m | wc -l` -eq 0 && git show -s --format=%h || echo "$(COMMIT_HASH_NONE)")
+
 LIBGAME_DIR = libgame
 LIBGAME = $(LIBGAME_DIR)/libgame.a
 
@@ -224,10 +247,10 @@ GRAPHICS_DIR = ../graphics
 
 all: $(AUTOCONF) libgame_dir game_em_dir game_sp_dir game_mm_dir $(PROGNAME) graphics_dir
 
-$(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(OBJS) $(ICON)
+$(PROGNAME): $(RNDLIBS) $(TIMESTAMP_FILE) $(COMMIT_HASH_FILE) $(OBJS) $(ICON)
        $(CC) $(PROFILING) $(OBJS) $(ICON) $(RNDLIBS) $(LDFLAGS) -o $(PROGNAME)
 ifdef BUILD_DIST
-       strip $(PROGNAME)
+       $(STRIP) $(PROGNAME)
 endif
 
 libgame_dir:
@@ -275,9 +298,16 @@ conf-time:
        @echo '#define SOURCE_DATE_STRING "$(SOURCE_DATE_STRING)"' \
        > $(TIMESTAMP_FILE)
 
+conf-hash:
+       @echo '#define SOURCE_HASH_STRING "$(SOURCE_HASH_STRING)"' \
+       > $(COMMIT_HASH_FILE)
+
 $(TIMESTAMP_FILE): $(SRCS) $(RNDLIBS)
        @$(MAKE) conf-time
 
+$(COMMIT_HASH_FILE): $(SRCS) $(RNDLIBS)
+       @$(MAKE) conf-hash
+
 $(ICON):
 #      $(CONVERT) $(ICON32X32) $(CONVERT_ICON_ARGS) $(ICONBASE).ico
        $(CONVERT) $(ICON_PATH)/*.png $(CONVERT_ICON_ARGS) $(ICONBASE).ico
@@ -303,7 +333,10 @@ clean-ico:
 
 clean-bin:
        $(RM) $(PROGNAME)
-       $(RM) ../*.exe
+       $(RM) $(PROGNAME).exe
+       $(RM) $(PROGNAME).js
+       $(RM) $(PROGNAME).wasm
+       $(RM) $(PROGNAME).data
 
 clean: clean-obj clean-ico clean-bin