This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Makefile
276 lines (206 loc) · 7.17 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# Versioning
MAJOR=2
MINOR=44
VERSION = $(MAJOR).$(MINOR)
# If we're working from git, we have access to proper variables. If
# not, make it clear that we're working from a release.
GIT_DIR ?= .git
ifneq ($(and $(wildcard $(GIT_DIR)),$(shell which git)),)
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
GIT_HASH = $(shell git rev-parse HEAD)
GIT_HASH_SHORT = $(shell git rev-parse --short HEAD)
GIT_TAG = $(shell git describe --abbrev=0 --tags)
else
GIT_BRANCH = none
GIT_HASH = none
GIT_HASH_SHORT = none
GIT_TAG = $(VERSION)
endif
BUILD_DATE_TIME = $(shell date +%Y%m%d.%k%M%S | sed s/\ //g)
export CFLAGS
# Enable compiler warnings. This is an absolute minimum.
CFLAGS += -Wall -std=c99 #-Wextra
# strdup, strndup
CFLAGS += -D_POSIX_C_SOURCE=200809L
# Define your optimization flags.
#
# These are good for regular use.
#CFLAGS += -O2 -fomit-frame-pointer -falign-functions=2 -falign-loops=2 -falign-jumps=2
# These are handy for debugging.
CFLAGS += -g
# Define where you want Frotz installed
PREFIX ?= /usr/local
MANDIR ?= $(PREFIX)/share/man
SYSCONFDIR ?= /etc
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
## INCLUDEDIR path for Apple MacOS Sierra 10.12 plus MacPorts
#INCLUDEDIR ?= /opt/local/include
## LIBDIR path for Apple MacOS Sierra 10.12 plus MacPorts
#LIBDIR ?= /opt/local/lib
CFLAGS += -I$(INCLUDEDIR)
LDFLAGS += -L$(LIBDIR)
RANLIB ?= $(shell which ranlib)
# Choose your sound support
# OPTIONS: ao, none
export SOUND ?= ao
# Default sample rate for sound effects.
# All modern sound interfaces can be expected to support 44100 Hz sample
# rates. Earlier ones, particularly ones in Sun 4c workstations support
# only up to 8000 Hz.
SAMPLERATE ?= 44100
# Audio buffer size in frames
BUFFSIZE ?= 4096
# Default sample rate converter type
DEFAULT_CONVERTER ?= SRC_SINC_MEDIUM_QUALITY
ifeq ($(SOUND), ao)
CURSES_LDFLAGS = -lao -ldl -lpthread -lm \
-lsndfile -lvorbisfile -lmodplug -lsamplerate
endif
##########################################################################
# The configuration options below are intended mainly for older flavors
# of Unix. For Linux, BSD, and Solaris released since 2003, you can
# ignore this section.
##########################################################################
# If your machine's version of curses doesn't support color...
#
COLOR ?= yes
# If this matters, you can choose -lcurses or -lncurses
CURSES ?= -lncurses
# Uncomment this if you're compiling Unix Frotz on a machine that lacks
# the strrchr() libc library call. If you don't know what this means,
# leave it alone.
#
#STRRCHR_DEF = -DNO_STRRCHR
# Uncomment this if you're compiling Unix Frotz on a machine that lacks
# the memmove(3) system call. If you don't know what this means, leave it
# alone.
#
#NO_MEMMOVE = yes
#########################################################################
# This section is where Frotz is actually built.
# Under normal circumstances, nothing in this section should be changed.
#########################################################################
# Source locations
SRCDIR = src
COMMON_DIR = $(SRCDIR)/common
COMMON_LIB = $(COMMON_DIR)/frotz_common.a
COMMON_DEFINES = $(COMMON_DIR)/version.c
HASH = $(COMMON_DIR)/git_hash.h
CURSES_DIR = $(SRCDIR)/curses
CURSES_LIB = $(CURSES_DIR)/frotz_curses.a
CURSES_DEFINES = $(CURSES_DIR)/defines.h
DUMB_DIR = $(SRCDIR)/dumb
DUMB_LIB = $(DUMB_DIR)/frotz_dumb.a
BLORB_DIR = $(SRCDIR)/blorb
BLORB_LIB = $(BLORB_DIR)/blorblib.a
SDL_DIR = $(SRCDIR)/sdl
SDL_LIB = $(SDL_DIR)/frotz_sdl.a
export SDL_PKGS = libpng libjpeg sdl2 SDL2_mixer freetype2 zlib
SDL_LDFLAGS = `pkg-config $(SDL_PKGS) --libs` -lm
SUBDIRS = $(COMMON_DIR) $(CURSES_DIR) $(SDL_DIR) $(DUMB_DIR) $(BLORB_DIR)
SUB_CLEAN = $(SUBDIRS:%=%-clean)
all: frotz dfrotz sfrotz
$(COMMON_LIB): $(COMMON_DEFINES) $(HASH) $(COMMON_DIR);
$(CURSES_LIB): $(CURSES_DEFINES) $(CURSES_DIR);
$(SDL_LIB): $(SDL_DIR);
$(DUMB_LIB): $(DUMB_DIR);
$(BLORB_LIB): $(BLORB_DIR);
$(SUBDIRS):
$(MAKE) -C $@
$(SUB_CLEAN):
-$(MAKE) -C $(@:%-clean=%) clean
# Main programs
frotz: $(COMMON_LIB) $(CURSES_LIB) $(BLORB_LIB) $(COMMON_LIB)
$(CC) $(CFLAGS) $+ -o $@$(EXTENSION) $(CURSES) $(LDFLAGS) \
$(CURSES_LDFLAGS)
dfrotz: $(COMMON_LIB) $(DUMB_LIB) $(BLORB_LIB) $(COMMON_LIB)
$(CC) $(CFLAGS) $+ -o $@$(EXTENSION)
sfrotz: $(COMMON_LIB) $(SDL_LIB) $(BLORB_LIB) $(COMMON_LIB)
$(CC) $(CFLAGS) $+ -o $@$(EXTENSION) $(LDFLAGS) $(SDL_LDFLAGS)
# Libs
%.a:
$(AR) rc $@ $^
$(RANLIB) $@
%.o: %.c
$(CC) $(CFLAGS) -fPIC -fpic -o $@ -c $<
common_lib: $(COMMON_LIB)
curses_lib: $(CURSES_LIB)
dumb_lib: $(DUMB_LIB)
blorb_lib: $(BLORB_LIB)
# Defines
common_defines: $(COMMON_DEFINES)
$(COMMON_DEFINES):
@echo "Generating $@"
@echo "#include \"frotz.h\"" > $@
@echo "const char frotz_version[] = \"$(VERSION)\";" >> $@
@echo "const char frotz_v_major[] = \"$(MAJOR)\";" >> $@
@echo "const char frotz_v_minor[] = \"$(MINOR)\";" >> $@
@echo "const char frotz_v_build[] = \"$(BUILD_DATE_TIME)\";" >> $@
curses_defines: $(CURSES_DEFINES)
$(CURSES_DEFINES):
@echo "Generating $@"
@echo "#define CONFIG_DIR \"$(SYSCONFDIR)\"" > $@
@echo "#define SOUND \"$(SOUND)\"" >> $@
@echo "#define SAMPLERATE $(SAMPLERATE)" >> $@
@echo "#define BUFFSIZE $(BUFFSIZE)" >> $@
@echo "#define DEFAULT_CONVERTER $(DEFAULT_CONVERTER)" >> $@
ifeq ($(SOUND), none)
@echo "#define NO_SOUND" >> $@
endif
ifndef SOUND
@echo "#define NO_SOUND" >> $@
endif
ifdef COLOR
@echo "#define COLOR_SUPPORT" >> $@
endif
ifdef NO_MEMMOVE
@echo "#define NO_MEMMOVE" >> $@
endif
hash: $(HASH)
$(HASH):
@echo "Creating $@"
@echo "#define GIT_BRANCH \"$(GIT_BRANCH)\"" > $@
@echo "#define GIT_HASH \"$(GIT_HASH)\"" >> $@
@echo "#define GIT_HASH_SHORT \"$(GIT_HASH_SHORT)\"" >> $@
@echo "#define GIT_TAG \"$(GIT_TAG)\"" >> $@
# Administrative stuff
install: frotz
install -d "$(DESTDIR)$(PREFIX)/bin" "$(DESTDIR)$(MANDIR)/man6"
install "frotz$(EXTENSION)" "$(DESTDIR)$(PREFIX)/bin/"
install -m 644 doc/frotz.6 "$(DESTDIR)$(MANDIR)/man6/"
uninstall:
rm -f "$(DESTDIR)$(PREFIX)/bin/frotz"
rm -f "$(DESTDIR)$(MANDIR)/man6/frotz.6"
install_dfrotz install_dumb: dfrotz
install -d "$(DESTDIR)$(PREFIX)/bin" "$(DESTDIR)$(MANDIR)/man6"
install "dfrotz$(EXTENSION)" "$(DESTDIR)$(PREFIX)/bin/"
install -m 644 doc/dfrotz.6 "$(DESTDIR)$(MANDIR)/man6/"
uninstall_dfrotz uninstall_dumb:
rm -f "$(DESTDIR)$(PREFIX)/bin/dfrotz"
rm -f "$(DESTDIR)$(MANDIR)/man6/dfrotz.6"
dist: frotz-$(GIT_TAG).tar.gz
frotz-$(GIT_TAG).tar.gz:
git archive --format=tar.gz -o "frotz-$(GIT_TAG).tar.gz" "$(GIT_TAG)"
clean: $(SUB_CLEAN)
rm -f $(SRCDIR)/*.h $(SRCDIR)/*.a $(COMMON_DEFINES) \
$(COMMON_DIR)/git_hash.h $(CURSES_DEFINES) \
$(OBJECTS) frotz*.tar.gz
help:
@echo "Targets:"
@echo " frotz: the standard edition"
@echo " dfrotz: for dumb terminals and wrapper scripts"
@echo " install"
@echo " uninstall"
@echo " install_dfrotz"
@echo " uninstall_dfrotz"
@echo " clean"
@echo " dist: create a source tarball of the latest tagged release"
.SUFFIXES:
.SUFFIXES: .c .o .h
.PHONY: all clean dist dumb hash help \
curses_defines \
blorb_lib common_lib curses_lib dumb_lib \
install install_dfrotz install_dumb \
uninstall uninstall_dfrotz uninstall_dumb $(SUBDIRS) $(SUB_CLEAN) \
$(COMMON_DIR)/version.c $(CURSES_DIR)/defines.h