-LIBS = -lpthread -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer\r
-\r
-WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype\r
-\r
-FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2 -Wall -Wextra -Werror\r
-\r
-MFLAGS64 = 64\r
-\r
-all:\r
- @echo "Building for 32-bit target"\r
- @rm -f out/*.o\r
- @cd src; $(MAKE) $(MFLAGS)\r
- @echo " CXX main.cpp"\r
- @g++ $(FLAGS) -m32 -o main main.cpp out/*.o $(LIBS) -lSDL2main\r
-\r
-64:\r
- @echo "Building for 64-bit target"\r
- @rm -f out64/*.o\r
- @cd src; $(MAKE) $(MFLAGS64)\r
- @echo " CXX main.cpp"\r
- @g++ $(FLAGS) -m64 -o main main.cpp out64/*.o $(LIBS)\r
-\r
-win32:\r
- @g++ $(FLAGS) -o main main.cpp src/*.cpp $(WIN_LIBS)\r
-\r
-clean:\r
- @echo " RM main"\r
- @-rm -f main\r
- @echo " RM out/*.o"\r
- @-rm -f out/*.o\r
- @echo " RM out64/*.o"\r
- @-rm -f out64/*.o\r
+include setup.mk
+
+CC = gcc
+CXX = g++
+
+ifeq ($(TARGET_OS),linux)
+ LIBS = -lpthread -lGL -lGLEW -lfreetype \
+ -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2main
+endif
+ifeq ($(TARGET_OS),win32)
+ LIBS = -lopengl32 -lglew32 -lmingw32 \
+ -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
+endif
+
+CXXFLAGS = -m$(TARGET_BITS) -std=c++11
+CXXINC = -Iinclude -Iinclude/freetype2
+CXXWARN = -Wall -Wextra -Werror
+
+CXXSRCDIR = src
+CXXOUTDIR = out
+CXXSRC = $(wildcard $(CXXSRCDIR)/*.cpp)
+CXXOBJ = $(patsubst $(CXXSRCDIR)/%.cpp, $(CXXOUTDIR)/%.o, $(CXXSRC))
+
+EXEC = main
+
+all: $(EXEC)
+
+clean:
+ rm -f $(EXEC)
+ rm -f out/*.o
+
+$(EXEC): $(CXXOUTDIR)/$(CXXOBJ)
+ @echo " CXX/LD main"
+ @$(CXX) $(CXXFLAGS) $(CXXINC) $(CXXWARN) -o $(EXEC) main.cpp out/*.o $(LIBS)
+
+$(CXXOUTDIR)/%.o: $(CXXSRCDIR)/%.cpp
+ @echo " CXX " $<
+ @$(CXX) $(CXXFLAGS) $(CXXINC) $(CXXWARN) $(LIBS) -c $< -o $@
+++ /dev/null
-LIBS = -lpthread -lGL -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
-
-FLAGS = -std=c++11 -I../include -I../include/freetype2 -Wall -Wextra -Werror
-
-OUT = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out\//g'`
-OUT64 = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out64\//g'`
-
-../out/%.o:
- @echo " CXX " $(shell echo $@ | sed 's/..\/out\///g' | sed 's/\.o/\.cpp/')
- @g++ $(FLAGS) -m32 -o $@ -c $(shell echo $@ | sed 's/..\/out\///g' | sed 's/\.o/\.cpp/') $(LIBS) -lSDL2main
-
-../out64/%.o:
- @echo " CXX " $(shell echo $@ | sed 's/..\/out64\///g' | sed 's/\.o/\.cpp/')
- @g++ $(FLAGS) -m64 -o $@ -c $(shell echo $@ | sed 's/..\/out64\///g' | sed 's/\.o/\.cpp/') $(LIBS)
-
-all: $(shell echo $(OUT))
-
-64: $(shell echo $(OUT64))