diff --git a/Makefile b/Makefile index 4137950..c0c0861 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,9 @@ # SporeModLoader & SporeModManager Makefile # +THIRDPARTY_DIR := 3rdParty # relative to project directories -BINARY_DIR := ../bin +BINARY_DIR := ../bin CC := gcc CXX := g++ @@ -19,13 +20,21 @@ clean: $(MAKE) -C SporeModManager clean BINARY_DIR=$(BINARY_DIR)/SporeModLoader/SporeModManager $(MAKE) -C SporeModManager clean MINGW=1 BINARY_DIR=$(BINARY_DIR)/SporeModLoader/SporeModManager +# this is needed due to compiling SporeModLoader twice, +# which, when compiling with multiple threads, will cause +# zconf.h to be generated twice, causing a build failure +# due to a race condition (cp will fail due to the file +# already existing, even with -f) +$(THIRDPARTY_DIR)/zlib/zconf.h: $(THIRDPARTY_DIR)/zlib/zconf.h.in + $(MAKE) -C SporeModManager ../$@ + SporeModLoader: $(MAKE) -C $@ BINARY_DIR=$(BINARY_DIR)/SporebinEP1 -SporeModManager: +SporeModManager: $(THIRDPARTY_DIR)/zlib/zconf.h $(MAKE) -C $@ BINARY_DIR=$(BINARY_DIR)/SporeModLoader/SporeModManager -SporeModManager.exe: +SporeModManager.exe: $(THIRDPARTY_DIR)/zlib/zconf.h $(MAKE) -C $(basename $@) BINARY_DIR=$(BINARY_DIR)/SporeModLoader/SporeModManager MINGW=1 .PHONY: SporeModLoader SporeModManager SporeModManager.exe all clean diff --git a/SporeModLoader/Makefile b/SporeModLoader/Makefile index 999ec21..17f81ce 100644 --- a/SporeModLoader/Makefile +++ b/SporeModLoader/Makefile @@ -44,14 +44,12 @@ endif all: $(BINARY_DIR)/$(DLL_FILE) -$(BINARY_DIR): - $(QUIET)mkdir -p $@ - -$(BINARY_DIR)/$(DLL_FILE): $(BINARY_DIR) $(THIRDPARTY_OBJECT_FILES) $(OBJECT_FILES) +$(BINARY_DIR)/$(DLL_FILE): $(THIRDPARTY_OBJECT_FILES) $(OBJECT_FILES) @echo "MINGW_LD $@" + $(QUIET)mkdir -p $(BINARY_DIR) $(QUIET)$(MINGW_CXX) $(THIRDPARTY_OBJECT_FILES) $(OBJECT_FILES) -static -shared $(SOURCE_DIR)/dllmain.def -o $@ $(LDFLAGS) clean: rm -f $(BINARY_DIR)/$(DLL_FILE) $(OBJECT_FILES) $(THIRDPARTY_OBJECT_FILES) $(THIRDPARTY_HEADER_FILES) -.PHONY: all clean \ No newline at end of file +.PHONY: all clean diff --git a/SporeModManager/Makefile b/SporeModManager/Makefile index 519654e..9481eed 100644 --- a/SporeModManager/Makefile +++ b/SporeModManager/Makefile @@ -1,12 +1,12 @@ # # SporeModManager Makefile # -THIRDPARTY_DIR ?= ../3rdParty -BINARY_DIR ?= bin -SOURCE_DIR ?= . -EXE_FILE ?= SporeModManager -VERBOSE ?= 0 -MINGW ?= 0 +THIRDPARTY_DIR := ../3rdParty +BINARY_DIR := bin +SOURCE_DIR := . +EXE_FILE := SporeModManager +VERBOSE := 0 +MINGW := 0 CC ?= gcc CXX ?= g++ @@ -22,7 +22,7 @@ else # mingw doesn't like LTO # and we need to statically link LDFLAGS := -s -municode -static -OPTFLAGS := -Os +OPTFLAGS := -Os -flto OBJ := obj EXE_EXT := .exe endif @@ -90,19 +90,18 @@ endif all: $(BINARY_DIR)/$(EXE_FILE)$(EXE_EXT) -$(BINARY_DIR): - $(QUIET)mkdir -p $@ - -$(THIRDPARTY_DIR)/zlib/zconf.h: +$(THIRDPARTY_DIR)/zlib/zconf.h: $(THIRDPARTY_DIR)/zlib/zconf.h.in @echo "GEN $@" $(QUIET)cp -f $@.in $@ -$(BINARY_DIR)/$(EXE_FILE): $(BINARY_DIR) $(THIRDPARTY_OBJECT_FILES) $(OBJECT_FILES) +$(BINARY_DIR)/$(EXE_FILE): $(THIRDPARTY_OBJECT_FILES) $(OBJECT_FILES) @echo "LD $@" + $(QUIET)mkdir -p $(BINARY_DIR) $(QUIET)$(CXX) $(OBJECT_FILES) $(THIRDPARTY_OBJECT_FILES) -o $@ $(LDFLAGS) -$(BINARY_DIR)/$(EXE_FILE).exe: $(BINARY_DIR) $(THIRDPARTY_OBJECT_FILES) $(OBJECT_FILES) +$(BINARY_DIR)/$(EXE_FILE).exe: $(THIRDPARTY_OBJECT_FILES) $(OBJECT_FILES) @echo "MINGW_LD $@" + $(QUIET)mkdir -p $(BINARY_DIR) $(QUIET)$(MINGW_CXX) $(OBJECT_FILES) $(THIRDPARTY_OBJECT_FILES) -o $@ $(LDFLAGS) clean: