shithub: cstory

Download patch

ref: b8c70473dce4099c2b50be54784a9a95ffaa7cc7
parent: 0af9bcc89b64bd2a8dc46e1bce0a1c0a665068c4
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Dec 5 07:51:57 EST 2019

Make Makefile CXXFLAGS overriding safe

The new mingw-w64-make package on Arch Linux's AUR enables
cross-compiling by overriding the CC, CXXFLAGS, and LDFLAGS
variables, but previously CSE2's Makefile wasn't designed to allow
this, causing it to break. Now, it should work properly.

--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,18 @@
-WINDRES ?= windres
+WINDRES = windres
 
 BUILD_DIRECTORY = game
 ASSETS_DIRECTORY = assets
 
+ALL_CXXFLAGS = $(CXXFLAGS)
+ALL_LDFLAGS = $(LDFLAGS)
+ALL_LIBS = $(LIBS)
+
 ifeq ($(RELEASE), 1)
-	CXXFLAGS = -O3
-	LDFLAGS = -s
+	ALL_CXXFLAGS += -O3
+	ALL_LDFLAGS += -s
 	FILENAME_DEF = CSE2.exe
 else
-	CXXFLAGS = -Og -ggdb3
+	ALL_CXXFLAGS += -Og -ggdb3
 	FILENAME_DEF = CSE2_debug.exe
 endif
 
@@ -15,7 +19,7 @@
 ifeq ($(JAPANESE), 1)
 	DATA_DIRECTORY = $(ASSETS_DIRECTORY)/data_jp
 
-	CXXFLAGS += -DJAPANESE
+	ALL_CXXFLAGS += -DJAPANESE
 else
 	DATA_DIRECTORY = $(ASSETS_DIRECTORY)/data_en
 endif
@@ -23,24 +27,24 @@
 FILENAME ?= $(FILENAME_DEF)
 
 ifeq ($(FIX_BUGS), 1)
-	CXXFLAGS += -DFIX_BUGS
+	ALL_CXXFLAGS += -DFIX_BUGS
 endif
 
 ifeq ($(CONSOLE), 1)
-	CXXFLAGS += -mconsole
+	ALL_CXXFLAGS += -mconsole
 else
-	CXXFLAGS += -mwindows
+	ALL_CXXFLAGS += -mwindows
 endif
 
 ifeq ($(DEBUG_SAVE), 1)
-	CXXFLAGS += -DDEBUG_SAVE
+	ALL_CXXFLAGS += -DDEBUG_SAVE
 endif
 
-CXXFLAGS += -std=c++98 -Wall -Wextra -pedantic -MMD -MP -MF $@.d
-LIBS += -lkernel32 -lgdi32 -lddraw -ldinput -ldsound -lversion -lshlwapi -limm32 -lwinmm -ldxguid
+ALL_CXXFLAGS += -std=c++98 -Wall -Wextra -pedantic -MMD -MP -MF $@.d
+ALL_LIBS += -lkernel32 -lgdi32 -lddraw -ldinput -ldsound -lversion -lshlwapi -limm32 -lwinmm -ldxguid
 
 ifeq ($(STATIC), 1)
-	LDFLAGS += -static
+	ALL_LDFLAGS += -static
 endif
 
 SOURCES = \
@@ -197,12 +201,12 @@
 $(BUILD_DIRECTORY)/$(FILENAME): $(OBJECTS)
 	@mkdir -p $(@D)
 	@echo Linking $@
-	@$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
+	@$(CXX) $(ALL_CXXFLAGS) $(ALL_LDFLAGS) $^ -o $@ $(ALL_LIBS)
 
 obj/$(FILENAME)/%.o: %.cpp
 	@mkdir -p $(@D)
 	@echo Compiling $<
-	@$(CXX) $(CXXFLAGS) $< -o $@ -c
+	@$(CXX) $(ALL_CXXFLAGS) $< -o $@ -c
 
 include $(wildcard $(DEPENDENCIES))