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

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

# If you have a suggestion for a name, tell me about it:
# <[email protected]>

# 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 := 0.1.18
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

# Three more variables are required: EXECUTABLES and MODULES
# and MODULES_OTHERVER (= "non-existent").
# 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.
# windows == "" if not on Windows.
# 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 45
# Desktop specific prefixes:
# FD_	freedesktop.org
# OSX_	Mac OS X
# CYG_	Cygwin
# W_	Cygwin, "temporary" variables

46 47 48 49 50
MAIN_SRC := '$(srcdir)$(NAME).py'
MAIN_STAGE := '$(builddir)$(NAME)'
MAIN_DEST := '$(DESTDIR)$(EXECUTABLES)/$(NAME)'

# freedesktop.org, see desktop/README
51 52 53
FD_MK_DESKTOP := '$(srcdir)desktop/desktop.sh'
FD_DESKTOP_STAGE := '$(builddir)$(NAME).desktop'
FD_DESKTOP_DEST := '$(DESTDIR)$(prefix)/share/applications/$(NAME).desktop'
54 55 56

# Mac OS X, see desktop/README
OSX_WRAPPER := "$(builddir)$(NAME)-wrapper"
57 58
OSX_INFO_PLIST := "$(builddir)Info.plist"
OSX_MK_INFO_PLIST := "$(srcdir)desktop/Info.plist.py"
59
OSX_ICON := "$(builddir)icon.icns"
60
OSX_MK_ICON := "$(srcdir)desktop/icon.icns.py"
61 62

# Windows/Cygwin, see desktop/README
63 64 65
CYG_ICO_SRC := "$(srcdir)desktop/$(NAME).ico"
CYG_ICO_DIR := "$(DESTDIR)$(prefix)/share/pixmaps"
CYG_ICO_DEST := $(CYG_ICO_DIR)/$(NAME).ico
66 67

# make clean
68 69
ALL_STAGE := $(MAIN_STAGE) $(OSX_WRAPPER) $(OSX_INFO_PLIST) $(OSX_ICON) \
	"$(builddir)check.py" $(FD_DESKTOP_STAGE)
70 71 72 73 74 75 76

all : FORCE
	@: # Create the appropriate shebang line
	@echo "#!`which python`" > $(MAIN_STAGE)
	@cat $(MAIN_SRC) >> $(MAIN_STAGE)
	@: # Refer to desktop/README for information about the following.
	@if [ -n "$(freedesktop)" ]; then \
77
		$(FD_MK_DESKTOP) $(FD_DESKTOP_STAGE) $(NAME) "$(NAME_C)" \
78 79 80 81 82 83
			"$(DESCRIPTION) -- version $(VERSION)"; \
	fi
	@if [ -n "$(macosx)" ]; then \
		echo '#!/bin/sh' > $(OSX_WRAPPER); \
		echo 'open -b com.apple.terminal' $(MAIN_DEST) \
			>> $(OSX_WRAPPER); \
84
		python $(OSX_MK_INFO_PLIST) $(OSX_INFO_PLIST) "$(NAME_C)" \
85
			"$(NAME_C) - $(DESCRIPTION)" $(VERSION) $(NAME); \
86
		python $(OSX_MK_ICON) $(OSX_ICON) "$(srcdir)desktop/$(NAME)"; \
87 88 89 90 91 92 93 94 95
	fi

clean : FORCE
	@rm $(ALL_STAGE) 2> /dev/null || true
	@: # Remove the bytecode files.
	@rm -- $(srcdir)*.pyc 2> /dev/null || true
	@rm -r -- $(srcdir)__pycache__/ 2> /dev/null || true

# configure.py will choose /usr/ucb/install on Solares.
96
INSTALL ?= install
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

CFG_DIR := "$(DESTDIR)/etc/$(NAME)"
# Modules: FOO_SRC, FOO_DEST, FOO_DEST_OTHERVER
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"

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

# See desktop/README
114 115 116 117
FD_ICON_SRC := "$(srcdir)desktop/$(NAME)-$$size.png"
FD_ICON_DESTDIR := "$(DESTDIR)$(prefix)/share/icons/hicolor/$$size/apps"
FD_ICON_SIZES := 16x16 32x32 64x64 256x256
FD_ICON_DEST := $(FD_ICON_DESTDIR)/$(NAME).png
118 119 120 121 122 123 124

# See desktop/README
BUNDLE := "$(DESTDIR)/Applications/$(NAME_C).app"

check-install-cfg : FORCE
	@$(PRE_INSTALL)
	@: # Cause installation to fail if the configuration is incompatible.
125 126
	@"$(INSTALL)" -d "$(CFG_DIR)"
	@python install-cfg "$(INSTALL)" \
127
		"$(srcdir)enginecfg" "$(CFG_DIR)/enginecfg"
128
	@python install-cfg "$(INSTALL)" \
129 130 131
		"$(srcdir)cursescfg" "$(CFG_DIR)/cursescfg"

overwrite-cfg: FORCE
132 133
	@"$(INSTALL)" -m 644 "$(srcdir)enginecfg" $(CFG_DIR)/enginecfg
	@"$(INSTALL)" -m 644 "$(srcdir)cursescfg" $(CFG_DIR)/cursescfg
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	@echo "Configuration has been overwritten"
	@echo "All (if any) system-wide modifications are lost"

install-dirs : FORCE
	@mkdir -p $(DESTDIR)$(EXECUTABLES) || true
	@mkdir -p $(DESTDIR)$(MODULES) || true
	@if [ "$(MODULES_OTHERVER)" != "non-existent" ]; then \
		mkdir -p $(DESTDIR)$(MODULES_OTHERVER) || true; \
	fi
	@if [ -n "$(freedesktop)" ]; then \
		mkdir -p $(DESTDIR)$(prefix)/share/applications || true; \
		mkdir -p $(DESTDIR)$(prefix)/share/pixmaps || true; \
	fi

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.
152 153 154 155
	@"$(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)
156
	@if [ -n "$(freedesktop)" ]; then \
157 158 159 160
		$(INSTALL) -m 644 $(FD_DESKTOP_STAGE) $(FD_DESKTOP_DEST); \
		for size in $(FD_ICON_SIZES); do \
			$(INSTALL) -d $(FD_ICON_DESTDIR); \
			$(INSTALL) -m 644 $(FD_ICON_SRC) $(FD_ICON_DEST); \
161 162 163
		done; \
	fi
	@if [ -n "$(macosx)" ]; then \
164 165
		"$(INSTALL)" -d $(BUNDLE)/Contents; \
		"$(INSTALL)" -m 644 $(OSX_INFO_PLIST) \
166
			$(BUNDLE)/Contents/Info.plist; \
167 168
		"$(INSTALL)" -d $(BUNDLE)/Contents/MacOS; \
		"$(INSTALL)" -m 755 $(OSX_WRAPPER) \
169
			$(BUNDLE)/Contents/MacOS/$(NAME)-wrapper; \
170 171
		"$(INSTALL)" -d $(BUNDLE)/Contents/Resources; \
		"$(INSTALL)" -m 644 $(OSX_ICON) \
172 173 174 175 176 177 178 179
			$(BUNDLE)/Contents/Resources/icon.icns; \
	fi
	@$(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)
	@$(POST_INSTALL)
	@if [ -n "$(freedesktop)" ]; then \
		xdg-desktop-menu install --novendor --mode system \
180
			$(FD_DESKTOP_DEST) || true; \
181 182
	fi
	@if [ -n "$(windows)" ]; then \
183
		"$(INSTALL)" $(CYG_ICO_SRC) $(CYG_ICO_DEST); \
184
		mkshortcut -A -P -a '-lc $(NAME)' -n "$(NAME_C)" \
185
			-i $(CYG_ICO_DEST) /bin/bash.exe || \
186
			mkshortcut -P -a '-lc $(NAME)' -n "$(NAME_C)" \
187
			-i $(CYG_ICO_DEST) /bin/bash.exe; \
188
		mkshortcut -A -D -a '-lc $(NAME)' -n "$(NAME_C)" \
189
			-i $(CYG_ICO_DEST) /bin/bash.exe || \
190
			mkshortcut -D -a '-lc $(NAME)' -n "$(NAME_C)" \
191
			-i $(CYG_ICO_DEST) /bin/bash.exe; \
192 193 194 195 196 197 198 199 200 201
	fi

# http://superuser.com/questions/86078/where-do-start-menu-all-programs-shortcuts-reside
W_C := "$(DESTDIR)/cygdrive/c"
W_U := "$(DESTDIR)`cygpath --unix '$(USERPROFILE)'`"
W_F := "$(NAME_C).lnk"
W_M := "/Start Menu/Programs/"
# W_C is the C drive, W_U is the users real home directory,
# W_F is the filename and W_M is a part of the path to the start menu
# common for both NT 5 and 6.
202 203 204 205 206 207 208
CYG_STARTMENU_NT5X_ALL := $(W_C)"/Documents and Settings/All Users"$(W_M)$(W_F)
CYG_STARTMENU_NT5X_ME := $(W_U)$(W_M)$(W_F)
CYG_STARTMENU_NT6X_ALL := $(W_C)"/ProgramData/Microsoft/Windows"$(W_M)$(W_F)
CYG_STARTMENU_NT6X_ME := $(W_U)"/AppData/Roaming/Microsoft/Windows"$(W_M)$(W_F)
CYG_DESKTOP_NT5X_ALL := $(W_C)"/Documents and Settings/All Users/Desktop"$(W_F)
CYG_DESKTOP_NT6X_ALL := $(W_C)/Users/Public/Desktop/$(W_F)
CYG_DESKTOP_ME := $(W_U)/Desktop/$(W_F)
209 210 211 212 213

uninstall: FORCE
	@$(PRE_UNINSTALL)
	@if [ -n "$(freedesktop)" ]; then \
		xdg-desktop-menu uninstall --novendor --mode system \
214
			$(FD_DESKTOP_DEST) || true; \
215 216 217 218 219 220 221
	fi
	@$(NORMAL_UNINSTALL)
	@-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
	@if [ -n "$(freedesktop)" ]; then \
222 223 224
		rm $(FD_DESKTOP_DEST) || true; \
		for size in $(FD_ICON_SIZES); do \
			rm $(FD_ICON_DEST) || true; \
225 226 227 228 229 230
		done; \
	fi
	@if [ -n "$(macosx)" ]; then \
		rm -r $(BUNDLE) || true; \
	fi
	@if [ -n "$(windows)" ]; then \
231 232 233 234 235 236 237
		rm $(CYG_STARTMENU_NT5X_ALL) || true; \
		rm $(CYG_STARTMENU_NT5X_ME) || true; \
		rm $(CYG_STARTMENU_NT6X_ALL) || true; \
		rm $(CYG_STARTMENU_NT6X_ME) || true; \
		rm $(CYG_DESKTOP_NT5X_ALL) || true; \
		rm $(CYG_DESKTOP_NT6X_ALL) || true; \
		rm $(CYG_DESKTOP_ME) || true; \
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
	fi

print-destinations: FORCE
	@echo "> Main program:\t\t\t" $(MAIN_DEST)
	@echo "> Engine module:\t\t" $(ENGINE_DEST)
	@echo "> Solver module:\t\t" $(SOLVER_DEST)
	@echo "> Fields module:\t\t" $(FIELDS_DEST)
	@$(NO_OTHERVER) || \
		echo "> Engine module symlink:\t" $(ENGINE_DEST_OTHERVER)
	@$(NO_OTHERVER) || \
		echo "> Solver module symlink:\t" $(SOLVER_DEST_OTHERVER)
	@$(NO_OTHERVER) || \
		echo "> Fields module symlink:\t" $(FIELDS_DEST_OTHERVER)
	@echo "> Configuration files:\t\t" $(CFG_DIR)
	@if [ -n "$(freedesktop)" ]; then \
253 254 255
		echo "> [freedesktop.org] .desktop:\t" $(FD_DESKTOP_DEST); \
		for size in $(FD_ICON_SIZES); do \
			echo "> [freedesktop.org] Icon:\t" $(FD_ICON_DEST); \
256 257 258 259 260 261
		done; \
	fi
	@if [ -n "$(macosx)" ]; then \
		echo "> [Mac OS X] Bundle (App):\t" $(BUNDLE); \
	fi
	@if [ -n "$(windows)" ]; then \
262 263 264 265 266 267 268 269
		echo "> [Windows] Shortcut:\t\t" $(CYG_STARTMENU_NT5X_ALL); \
		echo "> [Windows] Shortcut:\t\t" $(CYG_STARTMENU_NT5X_ME); \
		echo "> [Windows] Shortcut:\t\t" $(CYG_STARTMENU_NT6X_ALL); \
		echo "> [Windows] Shortcut:\t\t" $(CYG_STARTMENU_NT6X_ME); \
		echo "> [Windows] Shortcut:\t\t" $(CYG_DESKTOP_NT5X_ALL); \
		echo "> [Windows] Shortcut:\t\t" $(CYG_DESKTOP_NT6X_ALL); \
		echo "> [Windows] Shortcut:\t\t" $(CYG_DESKTOP_ME); \
		echo "> [Windows] Icon:\t\t" $(CYG_ICO_DEST); \
270 271 272 273 274 275 276 277 278 279
	fi

PKG_INDIR := $(NAME)-$(VERSION)
PKG := "$(builddir)$(PKG_INDIR)"
# .txt in zips.
PKG_TEXTFILES := BUGS ChangeLog FAQ FILES INSTALL NEWS README desktop/FILES \
	desktop/README
# Already CRLF + old crap.
PKG_NOCONV := Windows.txt Windows-admin.bat Windows-user.bat \
	configure desktop/$(NAME).ico desktop/desktop.sh \
Oskar Skog's avatar
Oskar Skog committed
280
	desktop/$(NAME)-*.png desktop/$(NAME)*.xcf
281 282
PKG_FILES := $(NAME).py $(NAME)_engine.py $(NAME)_fields.py $(NAME)_solver.py \
	configure.py Makefile.static install-cfg check.sh enginecfg cursescfg \
283 284
	test.py desktop/Info.plist.py desktop/icon.icns.py \
	VM-README.md vmsetup update-anonymine calibrate-anonymine addplayer
Oskar Skog's avatar
Oskar Skog committed
285
PKG_SUBDIRS := desktop
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333

check: FORCE
	@$(srcdir)check.sh "$(srcdir)" "$(builddir)"

dist : tarballs zip
	@echo Depends on '"'tarballs'"' and '"'zip'"'
	@echo make check
	@make check >/dev/null
	@echo make release
	@make release >/dev/null

release : FORCE
	@cp -t ~www-data/archive/$(NAME)/ $(PKG).tar.gz \
		|| echo You are not me.
	@cp -t ~www-data/archive/$(NAME)/ $(PKG).zip \
		|| echo You are not me.

tarballs : FORCE
	@mkdir $(PKG)
	@for subdir in $(PKG_SUBDIRS); do mkdir $(PKG)/$$subdir; done;
	@: # Copy all files normally:
	@for f in $(PKG_TEXTFILES); do cp $(srcdir)$$f $(PKG)/$$f; done
	@for f in $(PKG_NOCONV); do cp $(srcdir)$$f $(PKG)/$$f; done
	@for f in $(PKG_FILES); do cp $(srcdir)$$f $(PKG)/$$f; done
	@: # Tar:
	@cd $(builddir) && tar -cf $(PKG_INDIR).tar $(PKG_INDIR)
	@: # Compress:
	@gzip -f9k -- $(PKG).tar
	@: # Clean-up:
	@rm -- $(PKG).tar
	@rm -r -- $(PKG)

zip : FORCE
	@mkdir $(PKG)
	@for subdir in $(PKG_SUBDIRS); do mkdir $(PKG)/$$subdir; done;
	@: # /(.*)$/ -> /\1.txt/
	@for f in $(PKG_TEXTFILES); do \
		unix2dos -q -n $(srcdir)$$f $(PKG)/$$f.txt; \
	done
	@: # Already with CRLF line ends + configure.
	@for f in $(PKG_NOCONV); do cp $(srcdir)$$f $(PKG)/$$f; done
	@: # Notepad is stupid.
	@for f in $(PKG_FILES); do unix2dos -q -n $(srcdir)$$f $(PKG)/$$f; done
	@cd $(builddir) && zip -rXq $(PKG_INDIR).zip $(PKG_INDIR)
	@rm -r -- $(PKG)


FORCE: