summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: da9a0ae63c9fcc7f939e1e4fd24ad3b8e27f980a (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
.POSIX:

CONFIGFILE = config.mk

CALLTYPE = multicall-hardlinks
# multicall-hardlinks = multiple hardlinks of the same multicall binary is installed
# multicall-symlinks  = multiple links to a multicall binary named $(PREFIX)/bin/basic-games are installed
# singlecall          = separate binaries are install for each command


BIN =\
	rock-paper-scissors\
	tic-tac-toe

HDR =\
	common.h

COMMON =

OBJ = $(BIN:=.o) $(COMMON)
BOBJ = $(OBJ:.o=.bo)
MAN1 = $(BIN:=.1)


include $(CONFIGFILE)
include $(CALLTYPE).mk


$(OBJ): $(@:.o=.c) $(HDR)
$(BOBJ): $(@:.bo=.c) $(HDR)

.c.o:
	$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS)

.c.bo:
	$(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -Dmain="$$(printf '%s\n' main__$* | tr - _)" -DMULTICALL_BINARY

basic-games: basic-games.o $(BOBJ)
	$(CC) -o $@ $@.o $(BOBJ) $(LDFLAGS)

basic-games.c: basic-games.c.in Makefile
	printf '#define LIST_COMMANDS' > $@
	printf '\\\n\tX(%s)' $(BIN) | tr - _ >> $@
	printf '\n\n' >> $@
	cat basic-games.c.in >> $@

tic-tac-toe: tic-tac-toe.o
	$(CC) -o $@ $@.o $(LDFLAGS)

install-common:
	mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1"
	cp -- $(MAN1) "$(DESTDIR)$(MANPREFIX)/man1"

uninstall:
	-cd -- "$(DESTDIR)$(PREFIX)/bin" && rm -f -- $(BIN_)
	-cd -- "$(DESTDIR)$(MANPREFIX)/man1" && rm -f -- $(MAN1)
	-rm -f -- "$(DESTDIR)$(PREFIX)/lib/basic-games"

clean:
	-rm -rf -- *.o *.a *.lo *.so *.bo *.su $(BIN) basic-games basic-games.c

.SUFFIXES:
.SUFFIXES: .o .c .bo

.PHONY: all install install-common uninstall clean