forked from endless-sky/endless-sky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.winmake
134 lines (114 loc) · 4.98 KB
/
.winmake
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# This makefile was originally generated by 'cbp2make' tool rev.147
# Edited by tehhowch
# Copyright: Public Domain
# Available targets:
# 'all' - cleans & compiles both standard targets
# 'release' - a 64-bit optimized (-O2 -march=native) version of Endless Sky
# 'debug' - a 64-bit version of Endless Sky with debugging symbols (-g)
# 'clean' - removes all compiled object files and .exe files
# 'dist' - a 64-bit general-release version of Endless Sky (non-specific architecture)
# Intended Usage
# CAPS VARIABLE -> override on command line or alter name in script
# lowercase variable -> should not need modification
#
# avoid paths with spaces. (escape with \ if necessary)
#
# Preliminary configuration
# https://github.com/endless-sky/endless-sky/wiki/BuildInstructions
# 1. Obtain the 'dev64' zip archive from the Endless Sky wiki, unzip it, and
# set DIR_ESLIB to its location
# 2. Set DIR_MINGW64 to the MinGW directory with a `bin` and `lib` subfolders
# that has `libmingw32.a` and `libopengl32.a` in the lib subfolder
# 3. Set OUTPUT_DIR to where you want the exe to be placed (it will ship in a
# config-dependent subfolder, e.g. OUTPUT_DIR\Debug\EndlessSky.exe)
# 4. Set SRC_ROOT to where the games source files are located
# 5. Set OBJECT_DIR to where you would like the intermediate .o files to reside
#
DIR_ESLIB ?= C:\dev64
DIR_MINGW64 ?= C:\Program\ Files\mingw64\x86_64-w64-mingw32
OUTPUT_DIR ?= bin
SRC_ROOT ?= source
OBJECT_DIR ?= obj
#######
# You should not need to modify the lines below.
ifdef build_dir
# The build directory is defined, so proceed to build the invoked target
target_dir ::= $(OUTPUT_DIR)/$(build_dir)/
exe := $(target_dir)EndlessSky.exe
# Get the source directory and its immediate subdirectories.
source_dirs ::= $(sort $(dir $(wildcard $(SRC_ROOT)/*/)))
# Get all .cpp files in all source directories.
sources ::= $(foreach dir,$(source_dirs),$(wildcard $(dir)*.cpp))
# Compute needed objects by swapping the .cpp extension for .o, and swapping
# the basepath component (i.e. $(SRC_ROOT)) for the build (sub)directory.
obj_dir ::= $(OBJECT_DIR)/$(build_dir)/
obj_build_dirs ::= $(patsubst $(SRC_ROOT)/%,$(obj_dir)%,$(source_dirs))
objects ::= $(sort $(foreach obj,$(sources:.cpp=.o),$(patsubst $(SRC_ROOT)/%,$(obj_dir)%,$(obj))))
# Include the target made from WinApp.rc
objects += $(obj_dir)/WinApp.o
depends ::= $(objects:.o=.d)
# Define non-default compilers and linkers
WINDRES = windres.exe
LD = g++.exe
# Compiler and linker flags
include_dir = -I$(DIR_ESLIB)/include
CXXFLAGS += -std=c++11 -Wall -MMD $(cxx_extra) $(include_dir)
# Require the linker uses WinMainCRTStartup as the entry point.
LDFLAGS += -mwindows -L$(DIR_ESLIB)/lib $(ldd_extra)
# Include the Windows Multimedia API.
LDLIBS += -lwinmm
archives ::= $(wildcard $(DIR_ESLIB)/lib/*.a) \
$(DIR_MINGW64)/lib/libmingw32.a \
$(DIR_MINGW64)/lib/libopengl32.a
# Default target (linker step)
$(exe): $(objects) | $(target_dir)
$(LD) -o $@ $^ $(LDFLAGS) $(LDLIBS) -Wl,-\( $(archives) -Wl,-\)
# Include .o dependencies to ensure changing any of the .cpp's included headers
# triggers the .o recompilation (this must be defined after the desired exe definition).
-include $(depends)
# Pattern rule for compiling .cpps in SRC_ROOT and its child directories.
# Search for *.cpp in each source directory, using lexical sort order.
vpath %.cpp $(source_dirs)
define make-goal
$(1)%.o: %.cpp | $(obj_build_dirs)
$(CXX) -c $(CXXFLAGS) $$< -o $$@
endef
# Generate implicit rules for all source directories from the pattern rule.
$(foreach bdir,$(obj_build_dirs),$(eval $(call make-goal,$(bdir))))
# Pattern rule for compiling .rc
$(obj_dir)/WinApp.o: $(SRC_ROOT)/WinApp.rc | $(obj_dir)
$(WINDRES) --input-format rc --output-format coff $(include_dir) $< $@
# Pattern rule for main.cpp
$(obj_dir)/main.o: $(SRC_ROOT)/main.cpp | $(obj_dir)
$(CXX) -c $(CXXFLAGS) $< -o $@
# Rules for making the output and build directories
$(OBJECT_DIR) \
$(obj_build_dirs) \
$(OUTPUT_DIR) \
$(target_dir):
-@cmd /c 'if not exist $(subst /,\,$@) md $(subst /,\,$@)'
else # build_dir not yet defined
# Define variables to be consumed by invoked make subprocess (which will have a target)
# Define targets as phony, i.e. invoke the subprocess no matter what. It will decide
# if there is anything to be done
.PHONY: default all release debug dist clean
# The default target invokes dist (e.g. portable)
default: dist
# make all invokes debug, release, and dist
all: debug release dist
# Define target-specific build directory for use by subprocess
debug: export build_dir := Debug
release: export build_dir := Win64
dist: export build_dir := pkgd
# Define compiler and linker flags for use by subprocess
debug: export cxx_extra := -g -DDEBUG
release: export cxx_extra := -O2 -march=native
dist: export cxx_extra := -O2
release dist: export ldd_extra := -Wl,-O2 -s
# Invoke the subprocess (-f flag is not sent in MAKEFLAGS)
debug release dist:
$(MAKE) -$(MAKEFLAGS) -f .winmake
clean:
cmd /c rd /S /Q $(OUTPUT_DIR)
cmd /c rd /S /Q $(OBJECT_DIR)
endif # build_dir