-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
203 lines (147 loc) · 5.81 KB
/
Makefile
File metadata and controls
203 lines (147 loc) · 5.81 KB
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
# ------------------------------------------------------------
# MSYS2 UCRT64 (Windows 10)
# WSL2 Ubuntu 24.04 (Windows 10/11)
#
# Makefile for generating PasDoc + Graphviz documentation
# ------------------------------------------------------------
# =================================================================
# WSL ENVIRONMENTAL MONITORING
# =================================================================
OSRELEASE := $(shell cat /proc/sys/kernel/osrelease 2>/dev/null)
VERSION := $(shell cat /proc/version 2>/dev/null)
IS_WSL_OSRELEASE := $(findstring microsoft,$(OSRELEASE))
IS_WSL_VERSION := $(findstring microsoft,$(VERSION))
ifeq ($(strip $(IS_WSL_OSRELEASE)$(IS_WSL_VERSION)),)
PASDOC_P = pasdoc
DOT_P = dot
BUILD_ENV = Native/Linux
SEP = /
PATH_ROOT_SRC = /
PATH_ROOT_OPT = /
else
PASDOC_P = pasdoc.exe
DOT_P = dot.exe
BUILD_ENV = WSL/Windows
# Obtains the Linux CWD (e.g. /mnt/c/Users/...) and converts it to Windows format (e.g. C:\Users\...)
PATH_WIN_ROOT := $(shell wslpath -w "$$(pwd)")
SEP = \\
PATH_ROOT_SRC = $(PATH_WIN_ROOT)
PATH_ROOT_OPT = $(PATH_WIN_ROOT)
endif
$(info Environment detected: $(BUILD_ENV))
$(info PasDoc executable: $(PASDOC_P))
$(info Dot executable: $(DOT_P))
$(info Windows root path: $(PATH_WIN_ROOT))
# =================================================================
# PROJECT VERSION
# =================================================================
# Check if the project is a prerelease version
IS_PRERELEASE := $(shell grep "Attributes pvaPreRelease=\"True\"" project/StarTools.lpi)
PRERELEASE := $(if $(IS_PRERELEASE),-alpha,)
# Extract versions with fallback to 0 if the tag is missing
MAJOR := $(shell grep "MajorVersionNr Value" project/startools.lpi | sed 's/[^0-9]*//g' || echo 0)
MINOR := $(shell grep "MinorVersionNr Value" project/startools.lpi | sed 's/[^0-9]*//g' || echo 0)
REVIS := $(shell grep "RevisionNr Value" project/startools.lpi | sed 's/[^0-9]*//g' || echo 0)
# If the grep command fails or the result is empty, set 0 as default value
MAJOR := $(if $(MAJOR),$(MAJOR),0)
MINOR := $(if $(MINOR),$(MINOR),0)
REVIS := $(if $(REVIS),$(REVIS),0)
VERSION_STR := $(MAJOR).$(MINOR).$(REVIS)$(PRERELEASE)
# =================================================================
# ZIP FILES
# =================================================================
BIN_DIR = bin
DATA_SRC = project/data
SAVES_SRC = project/saves
DOC_FILES = README.md LICENSE CHANGELOG.md
ZIP_RELEASE = $(BIN_DIR)/StarTools_v$(VERSION_STR)-Release.zip
ZIP_DEBUG = $(BIN_DIR)/StarTools_v$(VERSION_STR)-Debug.zip
# =================================================================
# OPERATIONS
# =================================================================
OUTDIR = docs
OUTDIR_WIN = $(PATH_ROOT_SRC)$(SEP)$(OUTDIR)
DOT_CLASSES = $(OUTDIR)/GVClasses.dot
DOT_USES = $(OUTDIR)/GVUses.dot
PNG_CLASSES = $(OUTDIR)/GVClasses.png
PNG_USES = $(OUTDIR)/GVUses.png
DOT_CLASSES_WIN = $(PATH_ROOT_SRC)$(SEP)$(OUTDIR)/GVClasses.dot
DOT_USES_WIN = $(PATH_ROOT_SRC)$(SEP)$(OUTDIR)/GVUses.dot
PNG_CLASSES_WIN = $(PATH_ROOT_SRC)$(SEP)$(OUTDIR)/GVClasses.png
PNG_USES_WIN = $(PATH_ROOT_SRC)$(SEP)$(OUTDIR)/GVUses.png
FILES_REL := $(wildcard project/src/*.pas)
ifeq ($(strip $(IS_WSL_OSRELEASE)$(IS_WSL_VERSION)),)
# Native/Linux
SRC = $(FILES_REL)
else
SRC = $(foreach f,$(FILES_REL),"$(PATH_WIN_ROOT)\$(subst /,$(SEP),$(f))")
endif
CSS = style/pasdoc_custom.css
FOOTER = style/footer.html
AGPL_ICON = agplv3-with-text-100x42.png
AGPL_ICON_SOURCE = style/$(AGPL_ICON)
EXTERNAL_CH = external_class_hierarchy.txt
CSS_WIN = $(PATH_ROOT_OPT)$(SEP)$(CSS)
FOOTER_WIN = $(PATH_ROOT_OPT)$(SEP)$(FOOTER)
EXTERNAL_CH_WIN = $(PATH_ROOT_OPT)$(SEP)$(EXTERNAL_CH)
DEFINES = --define FPC --define MSWINDOWS
PASDOC_OPTS = \
--format html \
--output "$(OUTDIR_WIN)" \
--markdown \
--auto-abstract \
--marker=* \
--link-gv-uses png \
--link-gv-classes png \
--graphviz-uses \
--graphviz-classes \
--verbosity 2 \
--exclude-generator \
--title "StarTools Docs" \
--footer "$(FOOTER_WIN)" \
--css "$(CSS_WIN)" \
--external-class-hierarchy="$(EXTERNAL_CH_WIN)"
$(OUTDIR):
mkdir $(OUTDIR)
# PasDoc generates documentation + DOT files
doc: $(OUTDIR) $(FOOTER) $(CSS)
$(PASDOC_P) $(DEFINES) $(PASDOC_OPTS) $(SRC)
cp "$(AGPL_ICON_SOURCE)" "$(OUTDIR)/$(AGPL_ICON)"
$(DOT_CLASSES): doc
$(DOT_USES): doc
# Convert DOT -> PNG with Graphviz
$(PNG_CLASSES): $(DOT_CLASSES)
$(DOT_P) -Tpng "$(DOT_CLASSES_WIN)" -o "$(PNG_CLASSES_WIN)"
$(PNG_USES): $(DOT_USES)
$(DOT_P) -Tpng "$(DOT_USES_WIN)" -o "$(PNG_USES_WIN)"
graphs: $(PNG_CLASSES) $(PNG_USES)
full-doc: doc graphs
dist:
@if [ ! -f "project/startools-release.exe" ]; then echo "Error: Release executable not found! Build it in Lazarus first."; exit 1; fi
@if [ ! -f "project/startools-debug.exe" ]; then echo "Error: Debug executable not found! Build it in Lazarus first."; exit 1; fi
@echo "Cleaning up old packages..."
mkdir -p $(BIN_DIR)
@# Removes only the zip files of the current version to avoid conflicts or "ghost files"
rm -f $(ZIP_RELEASE) $(ZIP_DEBUG)
@echo "Packaging version $(VERSION_STR)..."
# Release package creation
@rm -rf temp_dist
mkdir -p temp_dist/data temp_dist/saves
cp -r $(DATA_SRC)/* temp_dist/data/
cp $(DOC_FILES) temp_dist/
cp project/startools-release.exe temp_dist/StarTools.exe
cd temp_dist && zip -r ../$(ZIP_RELEASE) .
# Debug package creation
@rm -rf temp_dist
mkdir -p temp_dist/data temp_dist/saves
cp -r $(DATA_SRC)/* temp_dist/data/
cp $(DOC_FILES) temp_dist/
cp project/startools-debug.exe temp_dist/StarTools.exe
cd temp_dist && zip -r ../$(ZIP_DEBUG) .
@rm -rf temp_dist
@echo "Packages created in $(BIN_DIR):"
@ls -lh $(BIN_DIR)
all: full-doc dist
.PHONY: all clean doc graphs dist
clean:
rm -rf $(OUTDIR)