| 1 |
# File: Makefile.osx |
| 2 |
|
| 3 |
# This is a Makefile for the Mac OS X Cocoa port of Angband. |
| 4 |
|
| 5 |
# default target |
| 6 |
all: install |
| 7 |
|
| 8 |
# settings |
| 9 |
CC = clang |
| 10 |
LD = ld |
| 11 |
OPT ?= -O2 |
| 12 |
|
| 13 |
# for consistency with older versions, use a lower case bundle ID |
| 14 |
BUNDLE_IDENTIFIER = org.rephial.angband |
| 15 |
|
| 16 |
ARCHS = x86_64 arm64 |
| 17 |
ARCHFLAGS = $(addprefix -arch ,$(ARCHS)) |
| 18 |
OSXVERSFLAGS = -mmacosx-version-min=10.9 |
| 19 |
WARNINGS = -W -Wall -Wextra -Wno-unused-parameter \ |
| 20 |
-Wno-missing-field-initializers -Wwrite-strings -Wmissing-prototypes \ |
| 21 |
-Wnested-externs -Wshadow -Wunused-macros |
| 22 |
JUST_C = -std=c99 |
| 23 |
OBJ_CFLAGS = -std=c99 -x objective-c -fobjc-arc |
| 24 |
CFLAGS = -g -I. $(WARNINGS) $(OPT) -DMACH_O_CARBON -DSOUND -DALLOW_BORG -DHAVE_MKSTEMP \ |
| 25 |
-fno-stack-protector $(OSXVERSFLAGS) $(ARCHFLAGS) |
| 26 |
LIBS = -framework Cocoa |
| 27 |
# Fix for bug #1663: Set the deployment target via environment variable |
| 28 |
# for the final link command. See http://grauonline.de/wordpress/?p=71 |
| 29 |
# or http://stackoverflow.com/questions/5509885/creating-app-for-old-mac-from-new-mac-machine |
| 30 |
DEPLOYMENT_TARGET = MACOSX_DEPLOYMENT_TARGET=10.9 |
| 31 |
|
| 32 |
# Import user prefs |
| 33 |
# If you don't want to edit this file, put your module redefinitions |
| 34 |
# and build flags in "./config" |
| 35 |
-include config |
| 36 |
|
| 37 |
# Check for autoconf.h; do not warn on nonexistence |
| 38 |
autoconf= $(wildcard autoconf.h) |
| 39 |
ifneq ($(autoconf),) |
| 40 |
CFLAGS += -DHAVE_CONFIG_H |
| 41 |
endif |
| 42 |
|
| 43 |
# Note that Makefile.inc sets VERSION, and so we must run version.sh after including Makefile.inc |
| 44 |
include Makefile.inc |
| 45 |
|
| 46 |
APPNAME = $(NAME).app |
| 47 |
EXE = $(PROGNAME) |
| 48 |
|
| 49 |
# For CFBundleShortVersionString and CFBundleVersion in Info.plist, Apple wants |
| 50 |
# up to three integers separated by periods. Versions given by version.sh |
| 51 |
# can have extra stuff beyond that so use VERSION as set by Makefile.inc |
| 52 |
# for the bundle identifiers. Use the result of version.sh for the build ID |
| 53 |
# compiled into the rest of the code and in the package file name. |
| 54 |
BUNDLE_VERSION := ${VERSION} |
| 55 |
VERSION := $(shell ../scripts/version.sh) |
| 56 |
ifeq (${VERSION},) |
| 57 |
VERSION := unknown |
| 58 |
else |
| 59 |
CFLAGS += -DBUILD_ID=${VERSION} |
| 60 |
endif |
| 61 |
|
| 62 |
# Include snd-cocoa.o in $(EXE).o rather than OSX_OBJS to avoid linking errors |
| 63 |
# with the unit test cases. |
| 64 |
OBJS = $(BASEOBJS) cocoa/snd-cocoa.o |
| 65 |
OSX_OBJS = main-cocoa.o |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
# |
| 70 |
# Build the "Angband" program |
| 71 |
# |
| 72 |
|
| 73 |
|
| 74 |
$(EXE).o: $(OBJS) |
| 75 |
@for A in $(ARCHS); do \ |
| 76 |
printf "%10s %-20s\n" LD $@.$$A; \ |
| 77 |
$(LD) -r -arch $$A -o $@.$$A $(OBJS); \ |
| 78 |
LIPO_ARGS="$$LIPO_ARGS -arch $$A $@.$$A"; \ |
| 79 |
done; \ |
| 80 |
lipo $$LIPO_ARGS -create -output $@ |
| 81 |
|
| 82 |
$(EXE): $(EXE).o $(OSX_OBJS) |
| 83 |
$(DEPLOYMENT_TARGET) $(CC) $(CFLAGS) $(LDFLAGS) -o $(EXE) $(EXE).o $(OSX_OBJS) $(LIBS) |
| 84 |
|
| 85 |
# |
| 86 |
# Clean up old junk |
| 87 |
# |
| 88 |
|
| 89 |
clean: |
| 90 |
-rm -f $(OBJS) $(EXE) $(addprefix $(EXE).o.,$(ARCHS)) $(EXE).o $(OSX_OBJS) |
| 91 |
|
| 92 |
|
| 93 |
# |
| 94 |
# Basic build rules and dependencies |
| 95 |
# |
| 96 |
|
| 97 |
%.o : %.m |
| 98 |
@printf "%10s %-20s (objective-c)\n" CC $< |
| 99 |
@$(CC) $(CFLAGS) $(OBJ_CFLAGS) -c -o $@ $< |
| 100 |
%.o : %.c |
| 101 |
@printf "%10s %-20s\n" CC $< |
| 102 |
@$(CC) $(JUST_C) $(CFLAGS) -c -o $@ $< |
| 103 |
|
| 104 |
|
| 105 |
# |
| 106 |
# Installation. |
| 107 |
# Application bundle -- a directory looking like an ordinary application |
| 108 |
# |
| 109 |
|
| 110 |
# Bundle of the game (it must be a directory whose name ends in ".app") |
| 111 |
APPBNDL = ../$(APPNAME) |
| 112 |
|
| 113 |
# A bundle must have these subdirectories |
| 114 |
APPCONT = $(APPBNDL)/Contents |
| 115 |
APPBIN = $(APPCONT)/MacOS |
| 116 |
APPRES = $(APPCONT)/Resources |
| 117 |
|
| 118 |
# Auxiliary files. |
| 119 |
# |
| 120 |
# For graphics tiles, it isn't generally safe just to convert GIF or BMP files |
| 121 |
# to PNG, because the Mac OS takes dpi values stored in various images quite |
| 122 |
# seriously. Almost all tilesets for *band requires adjustment, with the sole |
| 123 |
# exception of 8x8.png for Vanilla. Make sure setting dpi to 72, *not* |
| 124 |
# preserving the actual size of image. When you have them ready, put them in |
| 125 |
# the subdirectories of lib/tiles and rebuild. |
| 126 |
PLIST = cocoa/$(NAME)-Cocoa.xml |
| 127 |
|
| 128 |
ICONFILES = cocoa/$(NAME)_Icons.icns cocoa/Save.icns cocoa/Edit.icns cocoa/Data.icns |
| 129 |
|
| 130 |
LIBFILES = \ |
| 131 |
../lib/gamedata/*.txt \ |
| 132 |
../lib/screens/*.txt \ |
| 133 |
../lib/help/*.txt \ |
| 134 |
../lib/customize/*.prf \ |
| 135 |
|
| 136 |
install: $(EXE) $(ICONFILES) $(PLIST) $(LIBFILES) |
| 137 |
@echo making directories... |
| 138 |
@mkdir -p $(APPBNDL) |
| 139 |
@mkdir -p $(APPCONT) |
| 140 |
@mkdir -p $(APPBIN) |
| 141 |
@mkdir -p $(APPRES) |
| 142 |
@mkdir -p $(APPRES)/en.lproj |
| 143 |
@mkdir -p $(APPRES)/lib/gamedata |
| 144 |
@mkdir -p $(APPRES)/lib/screens |
| 145 |
@mkdir -p $(APPRES)/lib/help |
| 146 |
@mkdir -p $(APPRES)/lib/customize |
| 147 |
@mkdir -p $(APPRES)/lib/script |
| 148 |
@mkdir -p $(APPRES)/lib/tiles |
| 149 |
@mkdir -p $(APPRES)/lib/sounds |
| 150 |
|
| 151 |
@echo copying files... |
| 152 |
@cp ../lib/gamedata/*.txt $(APPRES)/lib/gamedata |
| 153 |
@cp ../lib/screens/*.txt $(APPRES)/lib/screens |
| 154 |
@cp ../lib/help/*.txt $(APPRES)/lib/help |
| 155 |
@cp ../lib/customize/*.prf $(APPRES)/lib/customize |
| 156 |
|
| 157 |
# 'optionally' install sound and graphics tiles, if present |
| 158 |
-cp -R ../lib/tiles/ $(APPRES)/lib/tiles |
| 159 |
-rm $(APPRES)/lib/tiles/Makefile $(APPRES)/lib/tiles/*/Makefile |
| 160 |
-cp ../lib/sounds/*.mp3 $(APPRES)/lib/sounds |
| 161 |
|
| 162 |
install -m 755 $(EXE) $(APPBIN) |
| 163 |
install -m 644 $(ICONFILES) $(APPRES) |
| 164 |
# Handle case of installing over an old version where MainMenu.nib |
| 165 |
# was a directory. |
| 166 |
-test -d $(APPRES)/en.lproj/MainMenu.nib && rm -r $(APPRES)/en.lproj/MainMenu.nib |
| 167 |
cp cocoa/en.lproj/MainMenu.nib $(APPRES)/en.lproj/MainMenu.nib |
| 168 |
cp cocoa/CommandMenu.plist $(APPRES)/CommandMenu.plist |
| 169 |
sed -e 's/\$$VERSION\$$/$(BUNDLE_VERSION)/' \ |
| 170 |
-e 's/\$$COPYRIGHT\$$/$(COPYRIGHT)/' \ |
| 171 |
-e 's/\$$NAME\$$/$(NAME)/' \ |
| 172 |
-e 's/\$$EXECUTABLE\$$/$(EXE)/' \ |
| 173 |
-e 's/\$$BUNDLE_VERSION\$$/$(BUNDLE_VERSION)/' \ |
| 174 |
-e 's/\$$BUNDLE_IDENTIFIER\$$/$(BUNDLE_IDENTIFIER)/' \ |
| 175 |
$(PLIST) > $(APPCONT)/Info.plist |
| 176 |
|
| 177 |
SetFile -a B $(APPBNDL) |
| 178 |
|
| 179 |
|
| 180 |
vars: |
| 181 |
@echo LDFLAGS = $(LDFLAGS) |
| 182 |
@echo CFLAGS = $(CFLAGS) |
| 183 |
@echo BASEOBJS = $(BASEOBJS) |
| 184 |
|
| 185 |
# build a version that has separate prefs (different bundle ID) and directories (setting SAFE_DIRECTORY preprocessor flag) |
| 186 |
safe-install: |
| 187 |
$(MAKE) -f Makefile.osx install CFLAGS="-DSAFE_DIRECTORY $(CFLAGS)" |
| 188 |
sed -e 's/\$$VERSION\$$/$(BUNDLE_VERSION)/' \ |
| 189 |
-e 's/\$$COPYRIGHT\$$/$(COPYRIGHT)/' \ |
| 190 |
-e 's/\$$NAME\$$/$(NAME)/' \ |
| 191 |
-e 's/\$$EXECUTABLE\$$/$(EXE)/' \ |
| 192 |
-e 's/\$$BUNDLE_VERSION\$$/$(BUNDLE_VERSION)/' \ |
| 193 |
-e 's/\$$BUNDLE_IDENTIFIER\$$/$(BUNDLE_IDENTIFIER).$(BUNDLE_VERSION)/' \ |
| 194 |
$(PLIST) > $(APPCONT)/Info.plist |
| 195 |
|
| 196 |
|
| 197 |
PACKAGE_NAME = $(NAME)-$(VERSION) |
| 198 |
|
| 199 |
# In the unlikely event that tar+zip isn't enough... |
| 200 |
|
| 201 |
dist: install |
| 202 |
@rm -rf disttemp* |
| 203 |
mkdir -p disttemp/Docs |
| 204 |
(cd ../docs/_build/html && tar -cf - .) | (cd disttemp/Docs && tar -xf -) |
| 205 |
cp -R -p "$(APPBNDL)" disttemp |
| 206 |
SetFile -a B disttemp/$(APPNAME) |
| 207 |
|
| 208 |
@-rm ../"$(PACKAGE_NAME)-osx.dmg" |
| 209 |
|
| 210 |
hdiutil create -quiet -fs HFS+ -volname $(PACKAGE_NAME) -srcfolder disttemp disttemp.dmg |
| 211 |
hdiutil convert disttemp.dmg -quiet -format UDZO -imagekey zlib-level=6 -o ../"$(PACKAGE_NAME)-osx.dmg" |
| 212 |
|
| 213 |
rm -rf disttemp* |
| 214 |
|
| 215 |
tests: $(EXE).o |
| 216 |
$(MAKE) -C tests all CFLAGS='-I.. -DDEFAULT_CONFIG_PATH=\"../../lib\" -DDEFAULT_LIB_PATH=\"../../lib\" -DDEFAULT_DATA_PATH=\"../../lib\" $(CFLAGS) -Wno-write-strings' LDFLAGS="$(LIBS)" |
| 217 |
|
| 218 |
test-depgen: |
| 219 |
$(MAKE) -C tests depgen |
| 220 |
|
| 221 |
test-clean: |
| 222 |
$(MAKE) -C tests clean |
| 223 |
|
| 224 |
.PHONY : tests test-clean |