Makefile.static 10.7 KB
Newer Older
1 2 3 4 5 6 7 8 9

##############################################################################

# If you have a suggestion for a name, tell me about it:
# <oskar.skog.finland@gmail.com>

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

Oskar Skog's avatar
Oskar Skog committed
17 18
# Five more variables are required: sysconfdir, vargamesdir, EXECUTABLES and
# MODULES, and MODULES_OTHERVER which may be set to "non-existent".
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
# 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

##############################################################################

39

Oskar Skog's avatar
Oskar Skog committed
40 41 42
verbose ?= true
info := test "$(verbose)" != true || echo '//'

43

44 45 46 47
# Desktop specific prefixes:
# FD_	freedesktop.org
# OSX_	Mac OS X

Oskar Skog's avatar
Oskar Skog committed
48 49 50
MAIN_SRC := $(srcdir)$(NAME).py
MAIN_STAGE := $(builddir)$(NAME)
MAIN_DEST := $(DESTDIR)$(EXECUTABLES)/$(NAME)
51 52 53 54 55 56

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
57

Oskar Skog's avatar
Oskar Skog committed
58
HISCORE_FILE := $(DESTDIR)$(vargamesdir)/anonymine
Oskar Skog's avatar
Oskar Skog committed
59
ENGINECFG_STAGE := $(builddir)enginecfg.out
60 61

# freedesktop.org, see desktop/README
Oskar Skog's avatar
Oskar Skog committed
62 63 64
FD_MK_DESKTOP := $(srcdir)desktop/desktop.sh
FD_DESKTOP_STAGE := $(builddir)$(NAME).desktop
FD_DESKTOP_DEST := $(DESTDIR)$(prefix)/share/applications/$(NAME).desktop
65 66

# Mac OS X, see desktop/README
Oskar Skog's avatar
Oskar Skog committed
67 68 69 70 71
OSX_WRAPPER := $(builddir)$(NAME)-wrapper
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
72 73 74


# make clean
Oskar Skog's avatar
Oskar Skog committed
75
ALL_STAGE := "$(MAIN_STAGE)" "$(OSX_WRAPPER)" "$(OSX_INFO_PLIST)" \
Oskar Skog's avatar
Oskar Skog committed
76 77 78
	"$(OSX_ICON)" "$(builddir)check.py" "$(FD_DESKTOP_STAGE)" \
	"$(ENGINECFG_STAGE)" "$(builddir)mkenginecfg.py"

79

Oskar Skog's avatar
Oskar Skog committed
80 81
all : $(MAIN_STAGE) $(ENGINECFG_STAGE)
	@$(info) 'Maybe building .desktop and app/bundle'
82
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
83
		cd "$(builddir)" && make build-freedesktop > /dev/null; \
84
	fi
85
	@if "$(macosx)"; then \
Oskar Skog's avatar
Oskar Skog committed
86
		cd "$(builddir)" && make build-macosx > /dev/null; \
87 88
	fi

89

90
$(MAIN_STAGE) : $(MAIN_SRC) $(srcdir)Makefile.static
Oskar Skog's avatar
Oskar Skog committed
91 92
	@$(info) 'Creating the appropriate shebang line'
	@echo "#!`which python`" > "$(MAIN_STAGE)"
93 94
	@sed -e "$(MAIN_STAGE_SED1)" "$(MAIN_SRC)" \
		| sed -e "$(MAIN_STAGE_SED2)" >> "$(MAIN_STAGE)"
Oskar Skog's avatar
Oskar Skog committed
95

96

97
$(ENGINECFG_STAGE) : $(srcdir)mkenginecfg
Oskar Skog's avatar
Oskar Skog committed
98 99
	@$(info) 'Making enginecfg: mostly counting processors'
	@"$(srcdir)mkenginecfg" "$(srcdir)" "$(builddir)" "$(HISCORE_FILE)"
Oskar Skog's avatar
Oskar Skog committed
100

101

Oskar Skog's avatar
Oskar Skog committed
102 103 104 105 106
build-freedesktop : FORCE
	@: # Refer to desktop/README for information about the following.
	@"$(FD_MK_DESKTOP)" "$(FD_DESKTOP_STAGE)" $(NAME) "$(NAME_C)" \
		"$(DESCRIPTION) -- version $(VERSION)"

107

Oskar Skog's avatar
Oskar Skog committed
108 109 110 111 112 113 114 115
build-macosx : FORCE
	@: # Refer to desktop/README for information about the following.
	@echo '#!/bin/sh' > "$(OSX_WRAPPER)"
	@echo 'open -b com.apple.terminal' "$(MAIN_DEST)" >> "$(OSX_WRAPPER)"
	@python "$(OSX_MK_INFO_PLIST)" "$(OSX_INFO_PLIST)" "$(NAME_C)" \
		"$(NAME_C) - $(DESCRIPTION)" $(VERSION) $(NAME)
	@python "$(OSX_MK_ICON)" "$(OSX_ICON)" "$(srcdir)desktop/$(NAME)"

116

117 118 119
clean : FORCE
	@rm $(ALL_STAGE) 2> /dev/null || true
	@: # Remove the bytecode files.
Oskar Skog's avatar
Oskar Skog committed
120 121
	@rm -- "$(srcdir)"*.pyc 2> /dev/null || true
	@rm -r -- "$(srcdir)"__pycache__/ 2> /dev/null || true
122

123

Oskar Skog's avatar
0.3.4  
Oskar Skog committed
124 125 126
distclean : clean
	@rm $(builddir)Makefile

127

128
# configure.py will choose /usr/ucb/install on Solares.
129
INSTALL ?= install
130

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

133
# Modules: FOO_SRC, FOO_DEST, FOO_DEST_OTHERVER
Oskar Skog's avatar
Oskar Skog committed
134 135 136 137 138 139 140 141 142
ENGINE_SRC := $(srcdir)$(NAME)_engine.py
ENGINE_DEST := $(DESTDIR)$(MODULES)/$(NAME)_engine.py
ENGINE_DEST_OTHERVER := $(DESTDIR)$(MODULES_OTHERVER)/$(NAME)_engine.py
SOLVER_SRC := $(srcdir)$(NAME)_solver.py
SOLVER_DEST := $(DESTDIR)$(MODULES)/$(NAME)_solver.py
SOLVER_DEST_OTHERVER := $(DESTDIR)$(MODULES_OTHERVER)/$(NAME)_solver.py
FIELDS_SRC := $(srcdir)$(NAME)_fields.py
FIELDS_DEST := $(DESTDIR)$(MODULES)/$(NAME)_fields.py
FIELDS_DEST_OTHERVER := $(DESTDIR)$(MODULES_OTHERVER)/$(NAME)_fields.py
143 144 145 146 147

# Installation commands for modules:
NO_OTHERVER := test "$(MODULES_OTHERVER)" "=" non-existent

# See desktop/README
148 149 150 151 152 153 154 155 156 157 158 159 160 161
# $$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
162 163

# See desktop/README
Oskar Skog's avatar
Oskar Skog committed
164 165
BUNDLE := $(DESTDIR)/Applications/$(NAME_C).app

166 167 168 169

check-install-cfg : FORCE
	@$(PRE_INSTALL)
	@: # Cause installation to fail if the configuration is incompatible.
Oskar Skog's avatar
Oskar Skog committed
170
	@$(info) 'Installing or checking configuration'
171 172 173
	@: # Install the directory for the configuration files as install-dirs
	@: # might not have been run yet.
	@mkdir -p "$(CFG_DIR)"
174 175
	@$(INSTALL_CFG) "$(srcdir)cursescfg" "$(CFG_DIR)/cursescfg" $(verbose)
	@$(INSTALL_CFG) "$(ENGINECFG_STAGE)" "$(CFG_DIR)/enginecfg" $(verbose)
176

177

178
overwrite-cfg: FORCE
179 180
	@echo "overwrite-cfg has been disabled" >/dev/stderr && false
	@false
Oskar Skog's avatar
Oskar Skog committed
181 182
	@$(INSTALL) -m 644 "$(srcdir)cursescfg" "$(CFG_DIR)/cursescfg"
	@$(INSTALL) -m 644 "$(ENGINECFG_STAGE)" "$(CFG_DIR)/enginecfg"
183 184
	@$(info) "Configuration has been overwritten"
	@$(info) "All (if any) system-wide modifications are lost"
185

186

187
install-dirs : FORCE
Oskar Skog's avatar
Oskar Skog committed
188
	@$(info) 'Installing directories'
Oskar Skog's avatar
Oskar Skog committed
189 190
	@mkdir -p "$(CFG_DIR)" || true
	@mkdir -p "$(DESTDIR)$(vargamesdir)" || true
Oskar Skog's avatar
Oskar Skog committed
191 192
	@mkdir -p "$(DESTDIR)$(EXECUTABLES)" || true
	@mkdir -p "$(DESTDIR)$(MODULES)" || true
193
	@if [ "$(MODULES_OTHERVER)" != "non-existent" ]; then \
Oskar Skog's avatar
Oskar Skog committed
194
		mkdir -p "$(DESTDIR)$(MODULES_OTHERVER)" || true; \
195
	fi
196
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
197 198 199
		mkdir -p "$(DESTDIR)$(prefix)/share/applications" || true; \
		mkdir -p "$(DESTDIR)$(prefix)/share/pixmaps" || true; \
	fi
200
	@if "$(macosx)"; then \
Oskar Skog's avatar
Oskar Skog committed
201 202 203
		$(INSTALL) -d "$(BUNDLE)/Contents"; \
		$(INSTALL) -d "$(BUNDLE)/Contents/MacOS"; \
		$(INSTALL) -d "$(BUNDLE)/Contents/Resources"; \
204 205
	fi

206

207 208 209 210
install : check-install-cfg install-dirs
	@$(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
211 212 213 214 215
	@$(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
216 217 218
	@: # Create highscore file unless it already exists.
	@touch "$(HISCORE_FILE)"
	@chmod 666 "$(HISCORE_FILE)"
219
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
220 221
		$(info) 'Installing icons and .desktop (NORMAL_INSTALL)'; \
		$(INSTALL) -m 644 "$(FD_DESKTOP_STAGE)" "$(FD_DESKTOP_DEST)"; \
222 223 224 225 226 227 228 229
		$(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)"; \
230
	fi
231
	@if "$(macosx)"; then \
Oskar Skog's avatar
Oskar Skog committed
232 233 234 235 236 237 238
		$(info) 'Installing app/bundle'; \
		$(INSTALL) -m 644 "$(OSX_INFO_PLIST)" \
			"$(BUNDLE)/Contents/Info.plist"; \
		$(INSTALL) -m 755 "$(OSX_WRAPPER)" \
			"$(BUNDLE)/Contents/MacOS/$(NAME)-wrapper"; \
		$(INSTALL) -m 644 "$(OSX_ICON)" \
			"$(BUNDLE)/Contents/Resources/icon.icns"; \
239
	fi
Oskar Skog's avatar
Oskar Skog committed
240 241 242 243
	@$(info) 'Symlinking the modules to the other Python'
	@$(NO_OTHERVER) || ln -sf "$(ENGINE_DEST)" "$(ENGINE_DEST_OTHERVER)"
	@$(NO_OTHERVER) || ln -sf "$(SOLVER_DEST)" "$(SOLVER_DEST_OTHERVER)"
	@$(NO_OTHERVER) || ln -sf "$(FIELDS_DEST)" "$(FIELDS_DEST_OTHERVER)"
244
	@$(POST_INSTALL)
245
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
246
		$(info) 'Installing icons and .desktop (POST_INSTALL)'; \
247
		xdg-desktop-menu install --novendor --mode system \
Oskar Skog's avatar
Oskar Skog committed
248
			"$(FD_DESKTOP_DEST)" || true; \
249 250 251 252 253
	fi


uninstall: FORCE
	@$(PRE_UNINSTALL)
254
	@if "$(freedesktop)"; then \
255
		xdg-desktop-menu uninstall --novendor --mode system \
Oskar Skog's avatar
Oskar Skog committed
256
			"$(FD_DESKTOP_DEST)" || true; \
257 258
	fi
	@$(NORMAL_UNINSTALL)
Oskar Skog's avatar
Oskar Skog committed
259 260 261 262
	@-rm -r "$(CFG_DIR)"
	@-rm "$(ENGINE_DEST)" "$(SOLVER_DEST)" "$(FIELDS_DEST)" "$(MAIN_DEST)"
	@$(NO_OTHERVER) || rm "$(ENGINE_DEST_OTHERVER)" \
		"$(SOLVER_DEST_OTHERVER)" "$(FIELDS_DEST_OTHERVER)" || true
263
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
264
		rm "$(FD_DESKTOP_DEST)" || true; \
265
		for size in $(FD_ICON_SIZES); do \
Oskar Skog's avatar
Oskar Skog committed
266
			rm "$(FD_ICON_DEST)" || true; \
267 268
		done; \
	fi
269
	@if "$(macosx)"; then \
Oskar Skog's avatar
Oskar Skog committed
270
		rm -r "$(BUNDLE)" || true; \
271
	fi
272

273 274

print-destinations: FORCE
Oskar Skog's avatar
Oskar Skog committed
275 276 277 278
	@echo "Main program:          $(MAIN_DEST)"
	@echo "Engine module:         $(ENGINE_DEST)"
	@echo "Solver module:         $(SOLVER_DEST)"
	@echo "Fields module:         $(FIELDS_DEST)"
279
	@$(NO_OTHERVER) || \
280
		echo "Engine module symlink: $(ENGINE_DEST_OTHERVER)"
281
	@$(NO_OTHERVER) || \
282
		echo "Solver module symlink: $(SOLVER_DEST_OTHERVER)"
283
	@$(NO_OTHERVER) || \
284
		echo "Fields module symlink: $(FIELDS_DEST_OTHERVER)"
Oskar Skog's avatar
Oskar Skog committed
285 286
	@echo "Configuration files:   $(CFG_DIR) (directory)"
	@echo "Highscores file:       $(HISCORE_FILE)"
287
	@if "$(freedesktop)"; then \
Oskar Skog's avatar
Oskar Skog committed
288 289 290 291 292
		echo "[freedesktop.org] .desktop: $(FD_DESKTOP_DEST)"; \
		echo "[freedesktop.org] Icon:     $(FD_ICON_DEST16)"; \
		echo "[freedesktop.org] Icon:     $(FD_ICON_DEST32)"; \
		echo "[freedesktop.org] Icon:     $(FD_ICON_DEST64)"; \
		echo "[freedesktop.org] Icon:     $(FD_ICON_DEST256)"; \
293
	fi
294
	@if "$(macosx)"; then \
Oskar Skog's avatar
Oskar Skog committed
295
		echo "[Mac OS X] Bundle (App): $(BUNDLE) (directory)"; \
296
	fi
297

298

Oskar Skog's avatar
Oskar Skog committed
299 300 301
test : check
	@true

302

303
check: FORCE
Oskar Skog's avatar
Oskar Skog committed
304
	@$(info) "Checking that it works on both snakes... May take a while!"
305 306
	@$(srcdir)check.sh "$(srcdir)" "$(builddir)"

307

308
dist : FORCE
Oskar Skog's avatar
Oskar Skog committed
309
	@$(info) "Building tarballs..."
310
	@cd "$(builddir)" && make tarballs > /dev/null
311

312

313
release : dist check
Oskar Skog's avatar
Oskar Skog committed
314
	@cp -t ~www-data/archive/"$(NAME)/" "$(PKG).tar.gz" \
315
		|| echo You are not me.
316 317
	@cp -t ~www-data/archive/"$(NAME)/" "$(PKG).tar.xz" \
		|| echo You are not me.
318

319

320 321
PKG := $(NAME)-$(VERSION)

322
tarballs : FORCE
323
	@$(srcdir)mkdist "$(srcdir)" "$(builddir)" "$(PKG)" tar
324 325 326


FORCE: