aboutsummaryrefslogtreecommitdiffstats
path: root/src/Makefile.in
blob: 8bdbca40b6498aa3e433a6068ae6fc08f0703278 (plain) (blame)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#################################################
# @PACKAGE_STRING@
# @configure_input@
#################################################

@SET_MAKE@

#################################################
# Standard definitions
#################################################

# project root-dir (directory of configure script)
top_srcdir  ?= @top_srcdir@
# project src-dir (directory of the current Makefile)
srcdir      ?= @srcdir@

# file-type suffix of executables (e.g. ".exe" in windows)
EXEEXT ?= @EXEEXT@

#################################################
# Tools
#################################################

# recursive dir creation tool (mkdir -p)
MKDIR     ?= @MKDIR_P@
RM        ?= rm -f
RM_REC    ?= $(RM) -r

#################################################
# USDX Paths
#################################################

USDX_SRC_DIR   := $(top_srcdir)/src
USDX_GAME_DIR  := $(top_srcdir)/game
USDX_TOOLS_DIR := $(top_srcdir)/tools
USDX_BUILD_DIR := $(top_srcdir)/build
USDX_LIB_DIR   := $(USDX_SRC_DIR)/lib

#################################################
# RC -> resource.inc
#################################################

# RC resource extraction config
RESEXTRACTOR_DIR := $(USDX_TOOLS_DIR)/ResourceExtractor
RESEXTRACTOR_BIN := $(RESEXTRACTOR_DIR)/ResourceExtractor$(EXEEXT)
RESOURCE_DIR  := $(USDX_GAME_DIR)/resources
RESOURCE_FILE := $(srcdir)/resource.inc
RC_FILE       := $(srcdir)/ultrastardx.rc

#################################################
# FPC config
#################################################

# Free Pascal compiler binary
PPC := @PPC@
# FPC target platform and processor
PPLATFORM  := @FPC_PLATFORM@
PPROCESSOR := @FPC_PROCESSOR@

# Directories added to the unit path
PUNIT_FLAGS := -Fu.

# Directory where compiled units (.ppu and .o files) are stored
PCUNIT_DIR   := $(USDX_BUILD_DIR)/fpc-$(PPROCESSOR)-$(PPLATFORM)
PCUNIT_FLAGS := -FU$(PCUNIT_DIR)

# Directories added to the includes path
PINC_FLAGS := -Fi$(USDX_LIB_DIR)/JEDI-SDL/SDL/Pas

PFLAGS_BASE    ?= -S2gi -vB
PFLAGS_EXTRA   ?= @PFLAGS_EXTRA@
PFLAGS_DEBUG   ?= @PFLAGS_DEBUG@
PFLAGS_RELEASE ?= @PFLAGS_RELEASE@
# user-flags (specified with configure) must be last in
# list to overwrite defaults (e.g. the "-"-option: -Xs-).
PFLAGS         ?= $(PFLAGS_BASE) @PFLAGS_MAKE@ $(PFLAGS_EXTRA)

LIBS       ?= @LIBS@
LDFLAGS    ?= @LDFLAGS@
linkflags  := $(strip $(LDFLAGS) $(LIBS))
ifneq ($(linkflags),)
PLINKFLAGS := -k"$(linkflags)"
endif

#################################################
# USDX project config
#################################################

# dpr project file used as input
USDX_PROJ := ultrastardx.dpr
# name of executable
USDX_BIN_NAME ?= ultrastardx$(EXEEXT)
USDX_BIN := $(USDX_GAME_DIR)/$(USDX_BIN_NAME)

#################################################
# ProjectM
#################################################

PROJECTM_CWRAPPER_DIR := $(USDX_LIB_DIR)/projectM/cwrapper
PROJECTM_CWRAPPER_LIB := $(PROJECTM_CWRAPPER_DIR)/libprojectM-cwrapper.a
USE_PROJECTM_CWRAPPER = @USE_PROJECTM_CWRAPPER@

#################################################
# Static libs
#################################################

STATIC_LIBS := 
ifeq ($(USE_PROJECTM_CWRAPPER), yes)
STATIC_LIBS += $(PROJECTM_CWRAPPER_LIB)
endif

#################################################
# general targets
#################################################

INC_FILES = $(shell find . -name "*.inc")
PAS_FILES = $(shell find . -name "*.pas" -o -name "*.pp")
BIN_DEPS = 

.PHONY: all
all: rebuild

# one shot debug build
.PHONY: debug
debug: PFLAGS := $(PFLAGS_BASE) $(PFLAGS_DEBUG) $(PFLAGS_EXTRA)
debug: rebuild

# one shot release build
.PHONY: release
release: PFLAGS := $(PFLAGS_BASE) $(PFLAGS_RELEASE) $(PFLAGS_EXTRA)
release: rebuild

# build, but always clean old data before compiling.
# FPC does not reliably recognize changes in .inc-files, static libs
# (and maybe even conditional .pas) dependencies. This might result
# in corrupted builds and renders debugging difficult.
# Clean if any (%) file changed.
.PHONY: rebuild
rebuild: CLEANON_PATTERN := %
rebuild: $(USDX_BIN)

# Use FPC to determine if the sources have to be rebuild.
# This does not work if an .inc or a static lib (e.g. .a) changed so we will
# manually clean in these cases. FPC might even miss some changes in 
# .pas files so we prefer the rebuild target.
# Clean if an inc-file (%.inc) or static lib (%.a) changed.
.PHONY: build
build: CLEANON_PATTERN := %.inc %.a
build: $(USDX_BIN)

#################################################
# build
#################################################

# After expansion of the expression, check_clean will
# contain the first changed prerequisite ($?) that matches
# CLEANON_PATTERN. It is used to check if any prerequisite of CLEANON_PATTERN
# type changed (we just return the first word to avoid spaces in 
# the result that might crash "test x$(check_clean)").
check_clean = $(firstword $(filter $(CLEANON_PATTERN), $?))

$(USDX_BIN): $(RESOURCE_FILE) $(USDX_PROJ) $(STATIC_LIBS) $(INC_FILES) $(PAS_FILES)
	@echo "==================================="
	@echo "Changed files:"
	@echo "$?"
	@echo "==================================="

# Checks if a rebuild is required.
# This is the case if any file matching $CLEANON_PATTERN changed.
	@if test x$(check_clean) != x; then \
	  echo "-----------------------------------"; \
	  echo "Clean objects..."; \
	  $(MAKE) clean_obj; \
	  echo "-----------------------------------"; \
	fi

	$(MKDIR) "$(PCUNIT_DIR)"
	$(PPC) $(strip $(PFLAGS) $(PDEFINES) $(PLINKFLAGS) $(PINC_FLAGS) $(PUNIT_FLAGS) $(PCUNIT_FLAGS)) -o$@ $(USDX_PROJ)

#################################################
# Resource-file
#################################################

$(RESOURCE_FILE): $(RC_FILE)
	$(RESEXTRACTOR_BIN) $(RC_FILE) $(RESOURCE_DIR) $(RESOURCE_FILE)


#################################################
# clean-up
#################################################

.PHONY: clean
clean: clean_obj clean_res

.PHONY: clean_res
clean_res:
	$(RM) "$(RESOURCE_FILE)"

.PHONY: clean_obj
clean_obj: clean_bin
	$(RM_REC) "$(PCUNIT_DIR)"
	-rmdir "$(USDX_BUILD_DIR)"

.PHONY: clean_bin
clean_bin:
	$(RM) "$(USDX_BIN)"