This repository has been archived by the owner on Sep 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
112 lines (91 loc) · 3.31 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
CXX := c++
CXXFLAGS := -O -g -std=c++11 -Wall -pedantic
LINKFLAGS := -O -g
INCLUDE_DIRS := -Isrc -isystem ext/include
LIB_DIRS := -Lext/lib
PUTKARTS_VERSION :=
CXX_VER = "-DPUTKARTS_VERSION=\"$(PUTKARTS_VERSION)\""
FILES_CPP := $(wildcard src/*.cpp) $(wildcard src/*/*.cpp) $(wildcard src/*/*/*.cpp) $(wildcard src/*/*/*/*.cpp)
FILES_HPP := $(wildcard src/*.hpp) $(wildcard src/*/*.hpp) $(wildcard src/*/*/*.hpp) $(wildcard src/*/*/*/*.hpp)
FILES_DEP := $(patsubst src/%,build/%.dep,$(FILES_CPP))
CLI_SRC := $(filter-out src/gui/%,$(FILES_CPP))
CLI_BIN := bin/PutkaRTS-cli
CLI_LIBS := -lboost_filesystem -lboost_system -llua
GUI_SRC := $(filter-out src/cli/%,$(FILES_CPP))
GUI_BIN := bin/PutkaRTS
GUI_LIBS := $(CLI_LIBS) -lsfml-system -lsfml-window -lsfml-graphics -lsfml-audio
# Hack for OS differences.
# On Windows, echo '1' produces literally '1' instead of 1.
ifeq "$(shell echo '1')" "'1'"
WIN32 := 1
mkdir = $(shell mkdir $(subst /,\,$(1)/dummy.mkdir) && rmdir $(subst /,\,$(1)/dummy.mkdir))
rm_rf = $(foreach F,$(subst /,\,$(1)),$(shell rmdir /Q /S $(F) 2>NUL >NUL || del /Q /S $(F) 2>NUL >NUL)) $(1)
# Get the version number from git; we must first check manually that git.exe exists
ifeq "$(findstring git,$(shell for %%i in (git.exe) do @echo.%%~$$PATH:i))" "git"
PUTKARTS_VERSION := $(strip $(shell git describe 2>NUL))
endif
else
mkdir = $(shell mkdir -p $(1))
rm_rf = $(shell rm -rf $(1)) $(1)
# Get the version number from git
PUTKARTS_VERSION := $(strip $(shell git describe 2>/dev/null))
# Something needs pthread.
CLI_LIBS += -lpthread
GUI_LIBS += -lpthread
# Mac OS X needs different libraries
ifeq "$(shell uname -s)" "Darwin"
CLI_LIBS := $(patsubst -l%,-framework %,$(CLI_LIBS))
GUI_LIBS := $(patsubst -l%,-framework %,$(GUI_LIBS))
endif
ifeq "$(findstring mingw,$(CXX))" "mingw"
WIN32 := 1
endif
endif
ifdef WIN32
CLI_BIN := $(CLI_BIN).exe
GUI_BIN := $(GUI_BIN).exe
CLI_LIBS := $(CLI_LIBS) -lws2_32
GUI_LIBS := $(GUI_LIBS) -lws2_32
CXXFLAGS2 := -D_WIN32_WINNT=0x0501
endif
# Abstract build rules.
.PHONY: all gui cli dirs
all: cli gui
gui: $(GUI_BIN)
cli: $(CLI_BIN)
clean:
@echo [RM] $(call rm_rf,build html bin/PutkaRTS*)
clean_deps:
@echo [RM] $(call rm_rf,$(FILES_DEP))
clean_html:
@echo [RM] $(call rm_rf,html)
# Directories
dirs: | bin/ html/ $(patsubst src/%,build/%,$(sort $(dir $(CLI_SRC) $(GUI_SRC))))
%/:
@echo [MKDIR] $@
@$(call mkdir,$@)
# Documentation build with Doxygen
html: Doxyfile $(FILES_CPP) $(FILES_HPP) | html/
@echo [DOXYGEN]
@doxygen > html/doxygen.log
# Build rules for binaries.
$(CLI_BIN): $(patsubst src/%,build/%.o,$(CLI_SRC))
$(GUI_BIN): $(patsubst src/%,build/%.o,$(GUI_SRC))
$(GUI_BIN): | dirs
@echo [LINK] $@
@$(CXX) $(LINKFLAGS) $(LIB_DIRS) -o $@ $(filter %.o,$^) $(GUI_LIBS)
$(CLI_BIN): | dirs
@echo [LINK] $@
@$(CXX) $(LINKFLAGS) $(LIB_DIRS) -o $@ $(filter %.o,$^) $(CLI_LIBS)
# Include dependencies; generation rules are below.
-include $(FILES_DEP)
# Dependency generation.
build/%.dep: src/% | dirs
@echo [DEPEND] $<
@$(CXX) $(CXXFLAGS) $(CXXFLAGS2) $(INCLUDE_DIRS) $(CXX_VER) -MM $< -MT $@ -MP > $@
# Compilation
build/%.o: src/% build/%.dep | dirs
@echo [CXX] $<
@$(CXX) $(CXXFLAGS) $(CXXFLAGS2) $(INCLUDE_DIRS) $(CXX_VER) $< -c -o $@
# Always regenerate program version string
build/ProgramInfo.cpp.o: $(FILES_CPP) $(FILES_HPP)