aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 3ca76e2b3b58caef47de4aac6a120cd955a62994 (plain) (blame)
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
PREFIX = /usr
BINDIR = $(PREFIX)/bin
DATADIR = $(PREFIX)/share
MANDIR = $(DATADIR)/man
MAN1DIR = $(MANDIR)/man1
MAN7DIR = $(MANDIR)/man7
LICENSEDIR = $(DATADIR)/licenses


PKGNAME = cg-tools


BIN = bin/cg-brilliance \
      bin/cg-darkroom \
      bin/cg-gamma \
      bin/cg-icc \
      bin/cg-limits \
      bin/cg-linear \
      bin/cg-negative \
      bin/cg-query \
      bin/cg-rainbow \
      bin/cg-remove \
      bin/cg-sleepmode

MAN1 = man/cg-brilliance.1 \
       man/cg-darkroom.1 \
       man/cg-gamma.1 \
       man/cg-icc.1 \
       man/cg-limits.1 \
       man/cg-linear.1 \
       man/cg-negative.1 \
       man/cg-query.1 \
       man/cg-rainbow.1 \
       man/cg-remove.1 \
       man/cg-sleepmode.1

MAN7 = man/cg-tools.7


OPTIMISE = -O2

WARN = -Wall -Wextra

DEF = -D'PKGNAME="$(PKGNAME)"' -D_DEFAULT_SOURCE -D_BSD_SOURCE


all: $(BIN)

bin/%: obj/%.o obj/cg-base.o
	@mkdir -p -- "$$(dirname -- "$@")"
	$(CC) -std=c99 $(OPTIMISE) $(WARN) $(DEF) -o $@ $^ $(LDFLAGS) -lm -lcoopgamma

bin/cg-query: obj/cg-query.o
	@mkdir -p -- "$$(dirname -- "$@")"
	$(CC) -std=c99 $(OPTIMISE) $(WARN) $(DEF) -o $@ $^ $(LDFLAGS) -lm -lcoopgamma

bin/cg-remove: obj/cg-remove.o
	@mkdir -p -- "$$(dirname -- "$@")"
	$(CC) -std=c99 $(OPTIMISE) $(WARN) $(DEF) -o $@ $^ $(LDFLAGS) -lm -lcoopgamma

obj/%.o: src/%.c src/*.h
	@mkdir -p -- "$$(dirname -- "$@")"
	$(CC) -std=c99 $(OPTIMISE) $(WARN) $(DEF) -c -o $@ $< $(CFLAGS) $(CPPFLAGS)


install: install-base install-doc

install-base: install-cmd install-copyright

install-copyright: install-license install-copying

install-doc: install-man

install-man: install-man1 install-man7

install-cmd: $(BIN)
	mkdir -p -- "$(DESTDIR)$(BINDIR)"
	install -m755 -- $(BIN) "$(DESTDIR)$(BINDIR)"

install-license:
	mkdir -p -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
	install -m644 -- LICENSE "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/LICENSE"

install-copying:
	mkdir -p -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
	install -m644 -- COPYING "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/COPYING"

install-man1:
	mkdir -p -- "$(DESTDIR)$(MAN1DIR)"
	install -m644 -- $(MAN1) "$(DESTDIR)$(MAN1DIR)"

install-man7:
	mkdir -p -- "$(DESTDIR)$(MAN7DIR)"
	install -m644 -- $(MAN7) "$(DESTDIR)$(MAN7DIR)"


uninstall:
	-cd "$(DESTDIR)$(BINDIR)" && rm -- $$(printf -- '%s\n' $(BIN) | cut -d / -f 2-)
	-rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/LICENSE"
	-rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/COPYING"
	-rmdir -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
	-cd "$(DESTDIR)$(MAN1DIR)" && rm -- $$(printf -- '%s\n' $(MAN1) | cut -d / -f 2-)
	-cd "$(DESTDIR)$(MAN7DIR)" && rm -- $$(printf -- '%s\n' $(MAN7) | cut -d / -f 2-)


clean:
	-rm -r -- bin obj

.PHONY: all clean install install-base install-doc install-cmd install-copyright \
	install-license install-copying install-man install-man1 install-man7 uninstall