aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 518f30c1995f9f48271c88f7efb5875fa88d4003 (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
CC?      = cc
MAIN     = dwmclock
SRC      = dwmclock.c
OBJ      = $(SRC:.c=.o)
CFLAGS  := -std=c99 -Wall -Wextra -pedantic -Os $(shell pkg-config --cflags x11) $(CFLAGS)
LDFLAGS := $(shell pkg-config --libs x11) $(LDFLAGS)

# install in /usr/local/bin
DESTDIR ?= /
PREFIX  ?= /usr/local

# install in ~/.local/bin
#DESTDIR ?= ~
#PREFIX  ?= /.local

include config.mk

all: $(SRC) $(MAIN)

$(MAIN): $(OBJ)
	$(CC) $(LDFLAGS) -o $@ $(OBJ)

$(MAIN)-print: CFLAGS+=-DPRINT
$(MAIN)-print: LDFLAGS=
$(MAIN)-print: $(OBJ:.o=-print.o)
	$(CC) $(LDFLAGS) -o $@ $(OBJ:.o=-print.o)

%-print.o:
	$(CC) -c $(CFLAGS) $(@:-print.o=.c) -o $@

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

clean:
	-rm -f $(MAIN) $(OBJ) $(MAIN)-print $(OBJ:.o=-print.o)

install: $(MAIN)
	install -d $(DESTDIR)$(PREFIX)/bin/
	install -m 755 $(MAIN) $(DESTDIR)$(PREFIX)/bin/
	[ -f $(MAIN)-print ] && install -m 755 $(MAIN)-print $(DESTDIR)$(PREFIX)/bin/

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/$(MAIN) $(DESTDIR)$(PREFIX)/bin/$(MAIN)-print

.PHONY: all clean install uninstall