-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
278 lines (220 loc) · 8.24 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
277
# Fluxfonts – a continual font generator for increased privacy
# Copyright 2012–2022, Daniel Aleksandersen
# All rights reserved.
#
# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
# License-Filename: COPYING
#
# This file is part of Fluxfonts.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# • Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# • Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
SHELL = /bin/sh
NAME = Fluxfonts
LNAME = fluxfonts
PROGRAM = fluxfontd
REVERSE_DOMAIN = no.priv.daniel.$(LNAME)
SHORTDESC = $(NAME), a continual font generator for increased privacy.
LONGDDESC = The $(PROGRAM) daemon for $(SHORTDESC)
VERSION = 2.2
AUTHOR = Daniel Aleksandersen
OBJS = lib/buffer.o\
lib/familyname.o\
lib/opentype.o\
lib/utils.o\
lib/tables/cff.o\
lib/tables/cmap.o\
lib/tables/head.o\
lib/tables/hhea.o\
lib/tables/hmtx.o\
lib/tables/maxp.o\
lib/tables/name.o\
lib/tables/os2.o\
lib/tables/post.o\
lib/tables/tables.o\
main.o
DOCS = AUTHORS COPYING README
# directories
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
DOCDIR = $(PREFIX)/share/doc/$(LNAME)
TEMPDIR = /var/tmp
LAUNCHDDIR = /Library/LaunchDaemons
LAUNCHDCONF = $(LAUNCHDDIR)/$(LNAME).plist
SYSTEMDDIR = $(PREFIX)/lib/systemd/system
SYSTEMDCONF = $(SYSTEMDDIR)/$(LNAME).service
DISTROOTDIR = $(TEMPDIR)/$(LNAME).dist
DISTPKGDIR = $(DISTROOTDIR)/dest_root
DISTSCRIPTSDIR = $(DISTROOTDIR)/scripts
OSXPKGPOSTINSTALL = $(DISTSCRIPTSDIR)/postinstall
LDFLAGS += -lm
# OS differences
ifeq ($(shell sh -c 'uname -s'),Linux)
LDFLAGS += -lsystemd
CFLAGS += -DSYSTEMD
endif
ifeq ($(shell sh -c 'uname -s'),FreeBSD)
INSTALLFLAGS = -S
LDFLAGS += -liconv -L/usr/local/lib
CFLAGS += -I/usr/local/include
endif
ifeq ($(shell sh -c 'uname -s'),Darwin)
INSTALLFLAGS = -S
LDFLAGS += -liconv
PACKAGE_OSX = $(NAME)-$(VERSION).pkg
TEMPDIR = /private/var/tmp
endif
# programs and compiler
INSTALL_PROGRAM = /usr/bin/install
LAUNCHDUTIL = /bin/launchctl
DEFAULTSUTIL = /usr/bin/defaults
SERVICEUTIL = /usr/sbin/service
INITDEFUTIL = /sbin/insserv
OSXPKGBUILD = /usr/bin/pkgbuild
CC ?= clang
CFLAGS += -Wall -std=c17
# launchd or systemd based on available directories
ifneq ($(wildcard $(SYSTEMDDIR)),)
CONFIG_SYSTEMD = install-systemd
DECONFIG_SYSTEMD = deconfigure-systemd
endif
ifneq ($(wildcard $(LAUNCHDDIR)),)
CONFIG_LAUNCHD = install-launchd
DECONFIG_LAUNCHD = deconfigure-launchd
endif
# sources for daemon configuration files
define newline
endef
define LAUNCHDCONF-SRC
$(DEFAULTSUTIL) write $(DISTPKGDIR)$(LAUNCHDCONF) RunAtLoad -boolean TRUE
$(DEFAULTSUTIL) write $(DISTPKGDIR)$(LAUNCHDCONF) Label -string $(REVERSE_DOMAIN)
$(DEFAULTSUTIL) write $(DISTPKGDIR)$(LAUNCHDCONF) ProgramArguments -array-add $(BINDIR)/$(PROGRAM)
endef
define SYSTEMDCONF-SRC
[Unit]
Description=$(SHORTDESC)
[Service]
Type=notify
ExecStart=$(BINDIR)/$(PROGRAM)
PIDFile=/run/$(LNAME).pid
Nice=15
PrivateDevices=true
ProtectKernelTunables=true
ProtectControlGroups=true
ProtectSystem=strict
ReadWritePaths=/run/ +/usr/local/share/fonts/ +/var/lib/fluxfonts/
[Install]
WantedBy=multi-user.target
endef
all: build
build: $(PROGRAM)
lib/buffer.o: lib/buffer.c
$(CC) $(CFLAGS) -o $@ -c lib/buffer.c
lib/familyname.o: lib/familyname.c lib/buffer.h lib/define.h lib/utils.h
$(CC) $(CFLAGS) -o $@ -c lib/familyname.c
lib/opentype.o: lib/opentype.c lib/buffer.h lib/define.h lib/familyname.h lib/tables/*.h
$(CC) $(CFLAGS) -o $@ -c lib/opentype.c
lib/utils.o: lib/utils.c lib/define.h
$(CC) $(CFLAGS) -o $@ -c lib/utils.c
lib/tables/cff.o: lib/tables/cff.c lib/buffer.h lib/familyname.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/cff.c
lib/tables/cmap.o: lib/tables/cmap.c lib/buffer.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/cmap.c
lib/tables/head.o: lib/tables/head.c lib/buffer.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/head.c
lib/tables/hhea.o: lib/tables/hhea.c lib/buffer.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/hhea.c
lib/tables/hmtx.o: lib/tables/hmtx.c lib/buffer.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/hmtx.c
lib/tables/maxp.o: lib/tables/maxp.c lib/buffer.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/maxp.c
lib/tables/name.o: lib/tables/name.c lib/buffer.h lib/familyname.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/name.c
lib/tables/os2.o: lib/tables/os2.c lib/buffer.h lib/familyname.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/os2.c
lib/tables/post.o: lib/tables/post.c lib/buffer.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/post.c
lib/tables/tables.o: lib/tables/tables.c lib/buffer.h
$(CC) $(CFLAGS) -o $@ -c lib/tables/tables.c
main.o: main.c lib/define.h lib/buffer.h lib/familyname.h lib/utils.h lib/opentype.h
$(CC) $(CFLAGS) -o $@ -c main.c
$(PROGRAM): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(PROGRAM) $(LDFLAGS)
install: build install-docs
$(INSTALL_PROGRAM) -d $(DESTDIR)$(BINDIR)
$(INSTALL_PROGRAM) $(INSTALLFLAGS) $(PROGRAM) $(DESTDIR)$(BINDIR)
install-docs:
$(INSTALL_PROGRAM) -d $(DESTDIR)$(DOCDIR)
$(INSTALL_PROGRAM) -m 644 $(INSTALLFLAGS) $(DOCS) $(DESTDIR)$(DOCDIR)
install-daemon: $(CONFIG_LAUNCHD) $(CONFIG_SYSTEMD)
install-dist-osx: $(NAME)-$(VERSION).pkg
/usr/sbin/installer --pkg $(NAME)-$(VERSION).pkg --PROGRAM /
uninstall: $(DECONFIG_LAUNCHD) $(DECONFIG_SYSTEMD)
rm $(BINDIR)/$(PROGRAM)
rm -rf $(DOCDIR)
configure-launchd:
-rm $(DISTPKGDIR)$(LAUNCHDCONF)
$(INSTALL_PROGRAM) -m 644 -d $(DISTPKGDIR)$(LAUNCHDDIR)
$(LAUNCHDCONF-SRC)
install-launchd: configure-launchd
$(INSTALL_PROGRAM) -d $(DESTDIR)$(LAUNCHDDIR)
$(INSTALL_PROGRAM) $(DISTPKGDIR)$(LAUNCHDCONF) $(DESTDIR)$(LAUNCHDDIR)
$(LAUNCHDUTIL) load $(DESTDIR)$(LAUNCHDCONF)
deconfigure-launchd:
-$(LAUNCHDUTIL) unload $(LAUNCHDCONF)
-rm $(LAUNCHDCONF)
configure-systemd:
-rm $(DISTPKGDIR)$(SYSTEMDCONF)
$(INSTALL_PROGRAM) -d $(DISTPKGDIR)$(SYSTEMDDIR)
printf '$(subst $(newline),\n,${SYSTEMDCONF-SRC})' > $(DISTPKGDIR)$(SYSTEMDCONF)
install-systemd: configure-systemd
$(INSTALL_PROGRAM) -d $(DESTDIR)$(SYSTEMDDIR)
$(INSTALL_PROGRAM) -m 644 $(DISTPKGDIR)$(SYSTEMDCONF) $(DESTDIR)$(SYSTEMDDIR)
deconfigure-systemd:
-rm $(SYSTEMDCONF)
dist: $(PACKAGE_OSX)
$(NAME)-$(VERSION).pkg: build configure-launchd
-rm $(NAME)-$(VERSION).pkg
$(INSTALL_PROGRAM) -d $(DISTPKGDIR)$(BINDIR)
$(INSTALL_PROGRAM) -d $(DISTPKGDIR)$(LAUNCHDDIR)
$(INSTALL_PROGRAM) -d $(DISTSCRIPTSDIR)
$(INSTALL_PROGRAM) -d $(DISTPKGDIR)$(DOCDIR)
$(INSTALL_PROGRAM) $(INSTALLFLAGS) $(PROGRAM) $(DISTPKGDIR)$(BINDIR)
$(INSTALL_PROGRAM) $(INSTALLFLAGS) $(DOCS) $(DISTPKGDIR)$(DOCDIR)
echo "#!$(SHELL)\n$(LAUNCHDUTIL) load $(LAUNCHDCONF)\nexit 0" > $(OSXPKGPOSTINSTALL)
chmod +x $(OSXPKGPOSTINSTALL)
$(OSXPKGBUILD) --identifier $(REVERSE_DOMAIN) --version $(VERSION) --root $(DISTPKGDIR) --ownership recommended --scripts $(DISTSCRIPTSDIR) $(NAME)-$(VERSION).pkg
$(LNAME)-$(VERSION).tar.gz: build maintainer-clean
mkdir $(TEMPDIR)/$(LNAME)-$(VERSION)
cp -r . $(TEMPDIR)/$(LNAME)-$(VERSION)
-rm -rf $(TEMPDIR)/$(LNAME)-$(VERSION)/.*
mv $(TEMPDIR)/$(LNAME)-$(VERSION) ./
tar -c -z -f $(LNAME)-$(VERSION).tar.gz $(LNAME)-$(VERSION)
clean:
-rm $(OBJS)
-rm -rf $(PROGRAM).dSYM
distclean:
-rm -rf $(DISTROOTDIR) $(TEMPDIR)/$(NAME)-$(VERSION) $(LNAME)-$(VERSION)/ $(NAME)-$(VERSION).pkg $(LNAME)-$(VERSION).tar.gz
maintainer-clean: clean distclean
-rm $(PROGRAM)