Makefile.static 13.7 KB
Newer Older
1 2

##############################################################################
3 4 5 6 7
#                                                                            #
#                                  Makefile                                  #
#                                  ========                                  #
#                                                                            #
##############################################################################
8 9 10 11 12


# No quotes for these four:
# NAME = [technical] name
# NAME_C = Capitalized name (human name)
Oskar Skog's avatar
Oskar Skog committed
13
# DESCRIPTION =
14 15 16 17
# VERSION = x.y.z
NAME := anonymine
NAME_C := Anonymine
DESCRIPTION = Minesweeper without guessing
18
VERSION := pre-0.5.11
19

20 21
# Four more variables are required: sysconfdir, vargamesdir, EXECUTABLES and
# MODULES
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# They will be prepended to the actual Makefile by the "configure" script.

# srcdir, builddir and DESTDIR may also be prepended by the "configure"
# script.

# freedesktop == "" if not freedesktop.org DE.
# macosx == "" if not on Mac OS X.

# See "INSTALL".

# Define these to prevent bugs on certain platforms.
PRE_INSTALL = true
NORMAL_INSTALL = true
POST_INSTALL = true
PRE_UNINSTALL = true
NORMAL_UNINSTALL = true
POST_UNINSTALL = true

40 41 42 43 44

##############################################################################
#                                                                            #
#                          all (build) & clean                               #
#                                                                            #
45 46
##############################################################################

47

Oskar Skog's avatar
Oskar Skog committed
48
verbose ?= true
49
info := test "$(verbose)" != true || >&2 echo '//'
Oskar Skog's avatar
Oskar Skog committed
50

51

52 53 54 55
# Desktop specific prefixes:
# FD_	freedesktop.org
# OSX_	Mac OS X

Oskar Skog's avatar
Oskar Skog committed
56 57 58
MAIN_SRC := $(srcdir)$(NAME).py
MAIN_STAGE := $(builddir)$(NAME)
MAIN_DEST := $(DESTDIR)$(EXECUTABLES)/$(NAME)
59 60 61 62 63 64

CFG_DIR := $(DESTDIR)$(sysconfdir)/$(NAME)

MAIN_STAGE_SED1 := s/MAKEFILE_GAME_VERSION/$(VERSION)/
SED_CFGDIR := `echo $(CFG_DIR) | sed -e 's/\\//\\\\\\//g'`
MAIN_STAGE_SED2 := s/MAKEFILE_CFGDIR/$(SED_CFGDIR)/
Oskar Skog's avatar
Oskar Skog committed
65

Oskar Skog's avatar
Oskar Skog committed
66
HISCORE_FILE := $(DESTDIR)$(vargamesdir)/anonymine
Oskar Skog's avatar
Oskar Skog committed
67
ENGINECFG_STAGE := $(builddir)enginecfg.out
68 69

# freedesktop.org, see desktop/README
Oskar Skog's avatar
Oskar Skog committed
70 71 72
FD_MK_DESKTOP := $(srcdir)desktop/desktop.sh
FD_DESKTOP_STAGE := $(builddir)$(NAME).desktop
FD_DESKTOP_DEST := $(DESTDIR)$(prefix)/share/applications/$(NAME).desktop
73 74

# Mac OS X, see desktop/README
75 76
OSX_WRAPPER1 := $(builddir)macosx1
OSX_WRAPPER2 := $(srcdir)desktop/macosx2
Oskar Skog's avatar
Oskar Skog committed
77 78 79 80
OSX_INFO_PLIST := $(builddir)Info.plist
OSX_MK_INFO_PLIST := $(srcdir)desktop/Info.plist.py
OSX_ICON := $(builddir)icon.icns
OSX_MK_ICON := $(srcdir)desktop/icon.icns.py
81 82
# See desktop/README
BUNDLE := /Applications/$(NAME_C).app
83 84 85


# make clean
86
ALL_STAGE := "$(MAIN_STAGE)" "$(OSX_WRAPPER1)" "$(OSX_INFO_PLIST)" \
Oskar Skog's avatar
Oskar Skog committed
87
	"$(OSX_ICON)" "$(builddir)check.py" "$(FD_DESKTOP_STAGE)" \
88 89
	"$(ENGINECFG_STAGE)" "$(builddir)mkenginecfg.py" \
	"$(builddir)module-symlinks"
Oskar Skog's avatar
Oskar Skog committed
90

91
all : $(builddir)Makefile FORCE
92
	@cd "$(builddir)" && $(MAKE) _all >/dev/null
93
_all : $(MAIN_STAGE) $(ENGINECFG_STAGE) $(builddir)module-symlinks
94
	@if "$(freedesktop)"; then \
95
		cd "$(builddir)" && $(MAKE) build-freedesktop >/dev/null; \
96
	fi
97
	@if "$(macosx)"; then \
98
		cd "$(builddir)" && $(MAKE) build-macosx >/dev/null; \
99 100
	fi

101

102 103 104 105 106 107 108 109 110 111
$(builddir)Makefile : $(builddir)Makefile.vars $(srcdir)Makefile.static
	@$(info) 'Recreating Makefile'
	@cat "$(builddir)Makefile.vars" "$(srcdir)Makefile.static" \
		>"$(builddir)Makefile"

$(builddir)Makefile.vars : $(srcdir)configure $(srcdir)configure.py
	@$(info) 'Reconfiguring...'
	@cd "$(builddir)" && ./reconfigure


112
$(MAIN_STAGE) : $(MAIN_SRC) $(builddir)Makefile
Oskar Skog's avatar
Oskar Skog committed
113
	@$(info) 'Creating the appropriate shebang line'
114
	@echo "#!$(python)" > "$(MAIN_STAGE)"
115 116
	@sed -e "$(MAIN_STAGE_SED1)" "$(MAIN_SRC)" \
		| sed -e "$(MAIN_STAGE_SED2)" >> "$(MAIN_STAGE)"
Oskar Skog's avatar
Oskar Skog committed
117

118

119
$(ENGINECFG_STAGE) : $(srcdir)mkenginecfg $(builddir)Makefile.vars
Oskar Skog's avatar
Oskar Skog committed
120
	@$(info) 'Making enginecfg: mostly counting processors'
121
	@"$(srcdir)mkenginecfg" "$(python)" "$(srcdir)" "$(builddir)" "$(HISCORE_FILE)"
Oskar Skog's avatar
Oskar Skog committed
122

123

124
$(builddir)module-symlinks : $(builddir)Makefile.vars $(srcdir)mk-symlinks
125
	@$(python) "$(srcdir)mk-symlinks" "$(srcdir)" "$(prefix)" "$(libdir)" \
126 127 128
		"$(MODULES)" "$(DESTDIR)" "$(builddir)"


129
build-freedesktop : $(FD_DESKTOP_STAGE)
Oskar Skog's avatar
Oskar Skog committed
130
	@: # Refer to desktop/README for information about the following.
131 132
	@$(info) 'freedesktop.org stuff created'
$(FD_DESKTOP_STAGE) : $(FD_MK_DESKTOP) $(builddir)Makefile
Oskar Skog's avatar
Oskar Skog committed
133 134 135
	@"$(FD_MK_DESKTOP)" "$(FD_DESKTOP_STAGE)" $(NAME) "$(NAME_C)" \
		"$(DESCRIPTION) -- version $(VERSION)"

136
build-macosx : $(OSX_WRAPPER1) $(OSX_INFO_PLIST) $(OSX_ICON)
Oskar Skog's avatar
Oskar Skog committed
137
	@: # Refer to desktop/README for information about the following.
138
	@$(info) 'Mac OS X stuff created'
139 140 141
$(OSX_WRAPPER1) : $(builddir)Makefile
	@echo '#!/bin/sh' > "$(OSX_WRAPPER1)"
	@echo 'open -b com.apple.terminal' "$(BUNDLE)/Contents/MacOS/macosx2" >> "$(OSX_WRAPPER1)"
142
$(OSX_INFO_PLIST) : $(OSX_MK_INFO_PLIST) $(builddir)Makefile
143
	@$(python) "$(OSX_MK_INFO_PLIST)" "$(OSX_INFO_PLIST)" "$(NAME_C)" \
Oskar Skog's avatar
Oskar Skog committed
144
		"$(NAME_C) - $(DESCRIPTION)" $(VERSION) $(NAME)
145
$(OSX_ICON) : $(srcdir)/desktop/$(NAME)*.png $(OSX_MK_ICON) $(builddir)Makefile
146
	@$(python) "$(OSX_MK_ICON)" "$(OSX_ICON)" "$(srcdir)desktop/$(NAME)"
Oskar Skog's avatar
Oskar Skog committed
147

148

149

150
clean : $(builddir)Makefile FORCE
151
	@cd "$(builddir)" && $(MAKE) _clean >/dev/null
152
_clean : FORCE
153 154
	@rm $(ALL_STAGE) 2> /dev/null || true
	@: # Remove the bytecode files.
Oskar Skog's avatar
Oskar Skog committed
155 156
	@rm -- "$(srcdir)"*.pyc 2> /dev/null || true
	@rm -r -- "$(srcdir)"__pycache__/ 2> /dev/null || true
157

158

159
distclean : $(builddir)Makefile FORCE
160
	@cd "$(builddir)" && $(MAKE) _distclean >/dev/null
161
_distclean : _clean
162 163 164
	@rm "$(builddir)Makefile"
	@rm "$(builddir)Makefile.vars"
	@rm "$(builddir)reconfigure"
Oskar Skog's avatar
0.3.4  
Oskar Skog committed
165

166

167 168 169 170 171 172 173
##############################################################################
#                                                                            #
#                install, unininstall & print-destinations                   #
#                                                                            #
##############################################################################


174
# configure.py will choose /usr/ucb/install on Solares.
175
INSTALL ?= install
176

177
INSTALL_CFG := $(python) "$(srcdir)install-cfg" "$(INSTALL)"
Oskar Skog's avatar
Oskar Skog committed
178

179
# Modules: FOO_SRC, FOO_DEST
Oskar Skog's avatar
Oskar Skog committed
180 181 182 183 184 185
ENGINE_SRC := $(srcdir)$(NAME)_engine.py
ENGINE_DEST := $(DESTDIR)$(MODULES)/$(NAME)_engine.py
SOLVER_SRC := $(srcdir)$(NAME)_solver.py
SOLVER_DEST := $(DESTDIR)$(MODULES)/$(NAME)_solver.py
FIELDS_SRC := $(srcdir)$(NAME)_fields.py
FIELDS_DEST := $(DESTDIR)$(MODULES)/$(NAME)_fields.py
186 187

# See desktop/README
188 189 190 191 192 193 194 195 196 197 198 199 200 201
# $$size would work in gmake while $$$$size would work in BSD make.
# Neither works in both.
FD_ICON_SRC16 := $(srcdir)desktop/$(NAME)-16x16.png
FD_ICON_DESTDIR16 := $(DESTDIR)$(prefix)/share/icons/hicolor/16x16/apps
FD_ICON_DEST16 := $(FD_ICON_DESTDIR16)/$(NAME).png
FD_ICON_SRC32 := $(srcdir)desktop/$(NAME)-32x32.png
FD_ICON_DESTDIR32 := $(DESTDIR)$(prefix)/share/icons/hicolor/32x32/apps
FD_ICON_DEST32 := $(FD_ICON_DESTDIR32)/$(NAME).png
FD_ICON_SRC64 := $(srcdir)desktop/$(NAME)-64x64.png
FD_ICON_DESTDIR64 := $(DESTDIR)$(prefix)/share/icons/hicolor/64x64/apps
FD_ICON_DEST64 := $(FD_ICON_DESTDIR64)/$(NAME).png
FD_ICON_SRC256 := $(srcdir)desktop/$(NAME)-256x256.png
FD_ICON_DESTDIR256 := $(DESTDIR)$(prefix)/share/icons/hicolor/256x256/apps
FD_ICON_DEST256 := $(FD_ICON_DESTDIR256)/$(NAME).png
202

Oskar Skog's avatar
Oskar Skog committed
203

204 205 206
check-install-cfg : $(builddir)Makefile FORCE
	@cd "$(builddir)" && $(MAKE) _check-install-cfg >/dev/null
_check-install-cfg : FORCE
207 208
	@$(PRE_INSTALL)
	@: # Cause installation to fail if the configuration is incompatible.
Oskar Skog's avatar
Oskar Skog committed
209
	@$(info) 'Installing or checking configuration'
210 211 212
	@: # Install the directory for the configuration files as install-dirs
	@: # might not have been run yet.
	@mkdir -p "$(CFG_DIR)"
213 214
	@$(INSTALL_CFG) "$(srcdir)cursescfg" "$(CFG_DIR)/cursescfg" $(verbose)
	@$(INSTALL_CFG) "$(ENGINECFG_STAGE)" "$(CFG_DIR)/enginecfg" $(verbose)
215

216
overwrite-cfg : $(builddir)Makefile FORCE
217
	@cd "$(builddir)" && $(MAKE) _overwrite-cfg >/dev/null
218
_overwrite-cfg: FORCE
Oskar Skog's avatar
Oskar Skog committed
219 220
	@$(INSTALL) -m 644 "$(srcdir)cursescfg" "$(CFG_DIR)/cursescfg"
	@$(INSTALL) -m 644 "$(ENGINECFG_STAGE)" "$(CFG_DIR)/enginecfg"
221 222
	@$(info) "Configuration has been overwritten"
	@$(info) "All (if any) system-wide modifications are lost"
223

224

225
install-dirs : $(builddir)Makefile FORCE
226
	@cd "$(builddir)" && $(MAKE) _install-dirs >/dev/null
227
_install-dirs : FORCE
Oskar Skog's avatar
Oskar Skog committed
228
	@$(info) 'Installing directories'
Oskar Skog's avatar
Oskar Skog committed
229 230
	@mkdir -p "$(CFG_DIR)" || true
	@mkdir -p "$(DESTDIR)$(vargamesdir)" || true
Oskar Skog's avatar
Oskar Skog committed
231 232
	@mkdir -p "$(DESTDIR)$(EXECUTABLES)" || true
	@mkdir -p "$(DESTDIR)$(MODULES)" || true
233
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
234 235 236
		mkdir -p "$(DESTDIR)$(prefix)/share/applications" || true; \
		mkdir -p "$(DESTDIR)$(prefix)/share/pixmaps" || true; \
	fi
237
	@if "$(macosx)"; then \
238 239 240
		$(INSTALL) -d "$(DESTDIR)$(BUNDLE)/Contents"; \
		$(INSTALL) -d "$(DESTDIR)$(BUNDLE)/Contents/MacOS"; \
		$(INSTALL) -d "$(DESTDIR)$(BUNDLE)/Contents/Resources"; \
241 242
	fi

243
install : $(builddir)Makefile FORCE
244
	@cd "$(builddir)" && $(MAKE) _install >/dev/null
245
_install : _all _check-install-cfg _install-dirs
246 247 248
	@$(NORMAL_INSTALL)
	@: # When the configuration has been installed, install the main
	@: # program, and then the modules for both versions of Python.
Oskar Skog's avatar
Oskar Skog committed
249 250 251 252 253
	@$(info) 'Installing executable and modules'
	@$(INSTALL) -m 755 "$(MAIN_STAGE)" "$(MAIN_DEST)"
	@$(INSTALL) -m 644 "$(ENGINE_SRC)" "$(ENGINE_DEST)"
	@$(INSTALL) -m 644 "$(SOLVER_SRC)" "$(SOLVER_DEST)"
	@$(INSTALL) -m 644 "$(FIELDS_SRC)" "$(FIELDS_DEST)"
Oskar Skog's avatar
Oskar Skog committed
254 255 256
	@: # Create highscore file unless it already exists.
	@touch "$(HISCORE_FILE)"
	@chmod 666 "$(HISCORE_FILE)"
257
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
258 259
		$(info) 'Installing icons and .desktop (NORMAL_INSTALL)'; \
		$(INSTALL) -m 644 "$(FD_DESKTOP_STAGE)" "$(FD_DESKTOP_DEST)"; \
260 261 262 263 264 265 266 267
		$(INSTALL) -d "$(FD_ICON_DESTDIR16)"; \
		$(INSTALL) -m 644 "$(FD_ICON_SRC16)" "$(FD_ICON_DEST16)"; \
		$(INSTALL) -d "$(FD_ICON_DESTDIR32)"; \
		$(INSTALL) -m 644 "$(FD_ICON_SRC32)" "$(FD_ICON_DEST32)"; \
		$(INSTALL) -d "$(FD_ICON_DESTDIR64)"; \
		$(INSTALL) -m 644 "$(FD_ICON_SRC64)" "$(FD_ICON_DEST64)"; \
		$(INSTALL) -d "$(FD_ICON_DESTDIR256)"; \
		$(INSTALL) -m 644 "$(FD_ICON_SRC256)" "$(FD_ICON_DEST256)"; \
268
	fi
269
	@if "$(macosx)"; then \
Oskar Skog's avatar
Oskar Skog committed
270 271
		$(info) 'Installing app/bundle'; \
		$(INSTALL) -m 644 "$(OSX_INFO_PLIST)" \
272 273 274 275 276
			"$(DESTDIR)$(BUNDLE)/Contents/Info.plist"; \
		$(INSTALL) -m 755 "$(OSX_WRAPPER1)" \
			"$(DESTDIR)$(BUNDLE)/Contents/MacOS/macosx1"; \
		$(INSTALL) -m 755 "$(OSX_WRAPPER2)" \
			"$(DESTDIR)$(BUNDLE)/Contents/MacOS/macosx2"; \
Oskar Skog's avatar
Oskar Skog committed
277
		$(INSTALL) -m 644 "$(OSX_ICON)" \
278
			"$(DESTDIR)$(BUNDLE)/Contents/Resources/icon.icns"; \
279 280
	fi
	@$(POST_INSTALL)
281
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
282
		$(info) 'Installing icons and .desktop (POST_INSTALL)'; \
283
		xdg-desktop-menu install --novendor --mode system \
Oskar Skog's avatar
Oskar Skog committed
284
			"$(FD_DESKTOP_DEST)" || true; \
285 286
	fi

Oskar Skog's avatar
...  
Oskar Skog committed
287
uninstall : FORCE
288
	@cd "$(builddir)" && $(MAKE) _uninstall >/dev/null
289
_uninstall : FORCE
290
	@$(PRE_UNINSTALL)
291
	@if "$(freedesktop)"; then \
292
		xdg-desktop-menu uninstall --novendor --mode system \
Oskar Skog's avatar
Oskar Skog committed
293
			"$(FD_DESKTOP_DEST)" || true; \
294
	fi
Oskar Skog's avatar
Oskar Skog committed
295 296 297 298 299 300
	@pypy symlinks uninstall 2>/dev/null || true
	@pypy3 symlinks uninstall 2>/dev/null || true
	@pypy2 symlinks uninstall 2>/dev/null || true
	@python symlinks uninstall 2>/dev/null || true
	@python3 symlinks uninstall 2>/dev/null || true
	@python2 symlinks uninstall 2>/dev/null || true
301
	@$(NORMAL_UNINSTALL)
Oskar Skog's avatar
Oskar Skog committed
302
	@-rm "$(ENGINE_DEST)" "$(SOLVER_DEST)" "$(FIELDS_DEST)" "$(MAIN_DEST)"
303

304
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
305
		rm "$(FD_DESKTOP_DEST)" || true; \
306
		for size in $(FD_ICON_SIZES); do \
Oskar Skog's avatar
Oskar Skog committed
307
			rm "$(FD_ICON_DEST)" || true; \
308 309
		done; \
	fi
310
	@if "$(macosx)"; then \
Oskar Skog's avatar
Oskar Skog committed
311
		rm -r "$(BUNDLE)" || true; \
312
	fi
313

314 315 316 317 318 319
nuke : uninstall FORCE
	@cd "$(builddir)" && $(MAKE) _nuke >/dev/null
_nuke : FORCE
	@-rm "$(HISCORE_FILE)"
	@-rm -r "$(CFG_DIR)"

320
print-destinations : $(builddir)Makefile FORCE
321
	@cd "$(builddir)" && $(MAKE) _print-destinations >/dev/null
322
_print-destinations : FORCE
323 324 325 326 327 328
	@echo >&2 "Main program:          $(MAIN_DEST)"
	@echo >&2 "Engine module:         $(ENGINE_DEST)"
	@echo >&2 "Solver module:         $(SOLVER_DEST)"
	@echo >&2 "Fields module:         $(FIELDS_DEST)"
	@echo >&2 "Configuration files:   $(CFG_DIR) (directory)"
	@echo >&2 "Highscores file:       $(HISCORE_FILE)"
329
	@if "$(freedesktop)"; then \
330 331 332 333 334
		echo >&2 "[freedesktop.org] .desktop: $(FD_DESKTOP_DEST)"; \
		echo >&2 "[freedesktop.org] Icon:     $(FD_ICON_DEST16)"; \
		echo >&2 "[freedesktop.org] Icon:     $(FD_ICON_DEST32)"; \
		echo >&2 "[freedesktop.org] Icon:     $(FD_ICON_DEST64)"; \
		echo >&2 "[freedesktop.org] Icon:     $(FD_ICON_DEST256)"; \
335
	fi
336
	@if "$(macosx)"; then \
337
		echo >&2 "[Mac OS X] Bundle (App): $(BUNDLE) (directory)"; \
338
	fi
339

340

341 342 343 344 345 346 347 348
##############################################################################
#                                                                            #
#                          check, dist & release                             #
#                                                                            #
##############################################################################


PKG := $(NAME)-$(VERSION)
Oskar Skog's avatar
Oskar Skog committed
349

350

351
test : $(builddir)Makefile FORCE
352
	@cd "$(builddir)" && $(MAKE) _check >/dev/null
353
check : $(builddir)Makefile FORCE
354
	@cd "$(builddir)" && $(MAKE) _check >/dev/null
355
_check : FORCE
Oskar Skog's avatar
Oskar Skog committed
356
	@$(info) "Checking that it works on both snakes... May take a while!"
357 358
	@$(srcdir)check.sh "$(srcdir)" "$(builddir)"

359
dist : $(builddir)Makefile FORCE
360
	@cd "$(builddir)" && $(MAKE) _dist >/dev/null
361
_dist : FORCE
Oskar Skog's avatar
Oskar Skog committed
362
	@$(info) "Building tarballs..."
363
	@$(srcdir)mkdist "$(srcdir)" "$(builddir)" "$(PKG)"
364

365
release : $(builddir)Makefile FORCE
366
	@cd "$(builddir)" && $(MAKE) _release >/dev/null
367
_release : dist check
Oskar Skog's avatar
Oskar Skog committed
368
	@cp -t ~www-data/archive/"$(NAME)/" "$(PKG).tar.gz" \
369
		|| echo You are not me.
370 371
	@cp -t ~www-data/archive/"$(NAME)/" "$(PKG).tar.xz" \
		|| echo You are not me.
372

373

374 375
##############################################################################
##############################################################################
376 377

FORCE:
378