hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 6d7aaf8af08871d17d05f2ccffd49e2d8b311203 (plain)
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
BIN := mktypst
PKG := hachem
VERSION := 0.1.0

CC := clang
STD := c17

DEBUG ?= 1
SANITIZE ?= 1

CFLAGS := -std=$(STD)          \
          -Wall                \
          -Wextra              \
          -Wshadow             \
          -Wpedantic           \
          -Wconversion         \
          -Wstrict-prototypes  \
          -Wsign-conversion    \
          -Wmissing-prototypes

ifeq ($(DEBUG),1)
CFLAGS += -g -fno-omit-frame-pointer
else
CFLAGS += -O2
endif

ifeq ($(SANITIZE),1)
CFLAGS += -fsanitize=address,undefined
LDFLAGS += -fsanitize=address,undefined
endif

PREFIX ?= /usr/local
bindir := $(DESTDIR)$(PREFIX)/bin
mandir := $(DESTDIR)$(PREFIX)/share/man/man1

ifeq ($(shell uname),Darwin)
DATADIR := $(HOME)/Library/Application Support
else
DATADIR := $(if $(XDG_DATA_HOME),$(XDG_DATA_HOME),$(HOME)/.local/share)
endif
pkgdir := $(DATADIR)/typst/packages/local/$(PKG)/$(VERSION)

all: $(BIN)

$(BIN): mktypst.c
	$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)

install: install-bin install-pkg

install-bin:
	$(MAKE) DEBUG=0 SANITIZE=0 clean $(BIN)
	install -d $(bindir)
	install -m 755 $(BIN) $(bindir)/$(BIN)
	install -d $(mandir)
	install -m 644 $(BIN).1 $(mandir)/$(BIN).1

install-pkg:
	mkdir -p "$(pkgdir)"
	cp typst.toml lib.typ README.md LICENSE "$(pkgdir)"/
	cp -r templates "$(pkgdir)"/

uninstall:
	rm -f $(bindir)/$(BIN)
	rm -f $(mandir)/$(BIN).1
	rm -rf "$(DATADIR)/typst/packages/local/$(PKG)/$(VERSION)"

samples:
	@for f in samples/*.typ; do \
		printf '  %s\n' "$${f%.typ}.pdf"; \
		typst compile --root . "$$f" "$${f%.typ}.pdf" || exit 1; \
	done

clean:
	rm -rf $(BIN) $(BIN).dSYM samples/*.pdf

.PHONY: all install install-bin install-pkg uninstall samples clean