-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
252 lines (209 loc) · 5.7 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# makefile release 0.4.0
PROJECT_VERSION = $(getVer)
#############
# Dirs #
#############
ROOT_SOURCE_DIR = src
BIN = bin
#############
# Sources #
#############
SRC = $(getSources)
#############
# Names #
#############
SDL_FILE = dub.sdl
ifneq ("$(wildcard $(SDL_FILE))","")
NAME = $(getNameSdl)
else
NAME = $(getNameJson)
SDL_FILE = dub.json
endif
BIN_NAME = $(BIN)/lib$(NAME).a
#############
# Packages #
#############
ZIP_BIN = $(BIN_NAME)
ZIP_SRC = $(ZIP_BIN) $(SRC) $(SDL_FILE) README.md CHANGELOG.md makefile
ZIP_SRC += tests/*.d
ZIP_PREFIX = $(NAME)-$(PROJECT_VERSION)
getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d")
getVer = $(shell ag -o --nofilename '\d+\.\d+\.\d+(-\w+\.\d)?' $(ROOT_SOURCE_DIR)/$(NAME)/semver.d)
#http://stackoverflow.com/questions/1546711/can-grep-show-only-words-that-match-search-pattern#1546735
getNameSdl = $(shell ag -m1 --silent -o 'name\s+\"\K\w+' dub.sdl)
getNameJson = $(shell ag -o -m1 '\"name\":\s+\"\K[[:alpha:]]+' dub.json)
#############
# Commands #
#############
DUB = dub
DSCAN = $(D_DIR)/Dscanner/bin/dscanner
MKDIR = mkdir -p
RM = -rm -f
UPX = upx --no-progress
#############
# Flags #
#############
# per impostatare la configurazione conf
# make c=conf
# per debug
# make b=debug
CONFIG += $(if $(c), -c$(c))
BUILD += $(if $(b), -b$(b))
# make run s=timer:countdown
SUB += $(if $(s), $(NAME):$(s))
DUBFLAGS = -q $(CONFIG) $(BUILD) $(SUB)
# si usa cosi:
# make test W=tests.common.testRunOnce
# oppure con piu' parametri
# make test W='tests.common.testRunOnce -d'
WHERE += $(if $(W), $(W))
SEP = $(if $(WHERE), -- )
.PHONY: all release force run run-rel test btest upx dx rx pkgall pkg pkgtar pkgsrc up tags style syn loc clean clobber pb pc pp ver var help
DEFAULT: all
all:
$(DUB) build $(DUBFLAGS)
build-ldc:
$(DUB) build $(DUBFLAGS) --compiler=ldc
release:
$(DUB) build -brelease $(DUBFLAGS)
rel-ldc:
$(DUB) build -brelease --compiler=ldc $(DUBFLAGS)
force:
$(DUB) build --force --combined $(DUBFLAGS)
run:
$(DUB) run $(DUBFLAGS)
run-rel:
$(DUB) run -brelease $(DUBFLAGS)
test:
$(DUB) test -q $(SEP) $(WHERE)
testd:
$(DUB) test -q -- -d $(WHERE)
testc:
$(DUB) test -q -- -c $(WHERE)
testl:
$(DUB) test -q -- -l
btest:
$(DUB) build -cunittest -q
dx: all upx
rx: release upx
upx: $(BIN)/$(NAME)
$(UPX) $^
pkgdir:
$(MKDIR) pkg
pkgall: pkg pkgtar pkgsrc
pkg: pkgdir | pkg/$(ZIP_PREFIX).zip
pkg/$(ZIP_PREFIX).zip: $(ZIP_BIN)
zip $@ $(ZIP_BIN)
pkgtar: pkgdir | pkg/$(ZIP_PREFIX).tar.bz2
pkg/$(ZIP_PREFIX).tar.bz2: $(ZIP_BIN)
tar -jcf $@ $^
pkgsrc: pkgdir | pkg/$(ZIP_PREFIX)-src.tar.bz2
pkg/$(ZIP_PREFIX)-src.tar.bz2: $(ZIP_SRC)
tar -jcf $@ $^
up:
$(DUB) upgrade
tags: $(SRC)
$(DSCAN) --ctags $^ > tags
style: $(SRC)
$(DSCAN) --styleCheck $^
syn: $(SRC)
$(DSCAN) --syntaxCheck $^
loc: $(SRC)
$(DSCAN) --sloc $^
imp: $(SRC)
$(DSCAN) -i $^
clean:
$(DUB) clean
clobber: clean
$(RM) $(BIN_NAME)
$(RM) $(BIN)/*.log
$(RM) $(BIN)/test-runner
pb:
@$(DUB) build --print-builds
pc:
$(DUB) build --print-configs
pp:
$(DUB) build --print-platform
changelog: CHANGELOG.txt
CHANGELOG.txt: CHANGELOG.md
pandoc -f markdown_github -t plain $^ > $@
ver:
@echo $(PROJECT_VERSION)
var:
@echo
@echo "General"
@echo "--------------------"
@echo "NAME :" $(NAME)
@echo "BIN_NAME :" $(BIN_NAME)
@echo "PRJ_VER :" $(PROJECT_VERSION)
@echo "DUBFLAGS :" $(DUBFLAGS)
@echo "DUB FILE :" $(SDL_FILE)
@echo
@echo "Directory"
@echo "--------------------"
@echo "D_DIR :" $(D_DIR)
@echo "BIN :" $(BIN)
@echo "ROOT_SOURCE_DIR :" $(ROOT_SOURCE_DIR)
@echo "TEST_SOURCE_DIR :" $(TEST_SOURCE_DIR)
@echo
@echo "Zip"
@echo "--------------------"
@echo "ZIP_BIN : " $(ZIP_BIN)
@echo "ZIP_PREFIX :" $(ZIP_PREFIX)
@echo
@echo "Zip source"
@echo "--------------------"
@echo $(ZIP_SRC)
@echo
@echo "Source"
@echo "--------------------"
@echo $(SRC)
@echo
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "Compile"
@echo "--------------------"
@echo " all : (the default if no target is provided)"
@echo " release : Compiles in release mode"
@echo " rel-ldc : Compiles in release mode with ldc compiler"
@echo " force : Forces a recompilation"
@echo " run : Builds and runs"
@echo " test : Build and executes the tests"
@echo " testd : Build and executes the tests in debug mode"
@echo " testc : Build and executes the tests with execution time"
@echo " btest : Build the tests"
@echo " upx : Compress using upx"
@echo " dx : Make debug and compress using upx"
@echo " rx : Make release and compress using upx"
@echo ""
@echo "Pack"
@echo "--------------------"
@echo " pkgall : Executes pkg, pkgtar, pkgsrc"
@echo " pkg : Zip binary"
@echo " pkgtar : Tar binary"
@echo " pkgsrc : Tar source"
@echo ""
@echo "Utility"
@echo "--------------------"
@echo " up : Forces an upgrade of all dub dependencies"
@echo " tags : Generates tag file"
@echo " style : Checks programming style"
@echo " syn : Syntax check"
@echo " loc : Counts lines of code"
@echo " clean : Removes intermediate build files"
@echo " clobber : Removes all"
@echo ""
@echo "Print"
@echo "--------------------"
@echo " pb : Prints the list of available build types"
@echo " pc : Prints the list of available configurations"
@echo " pp : Prints the identifiers for the current build platform as used for the build fields"
@echo " ver : Prints version"
@echo " var : Lists all variables"
@echo ""
@echo "Common options"
@echo "--------------------"
@echo " make c=conf : Uses 'conf' configuration"
@echo " make b=debug : Uses 'debug' build"
@echo " make s=y : Uses 'y' subpakages"