1CC ?= gcc
2CFLAGS += -std=c99 -Wall -Wextra -pedantic -MMD -ggdb
3
4TARGETS = f3write f3read
5EXTRA_TARGETS = f3probe f3brew f3fix
6
7PREFIX = /usr/local
8INSTALL = install
9LN = ln
10
11ifndef OS
12	OS = $(shell uname -s)
13endif
14ifneq ($(OS), Linux)
15	ARGP = /usr/local
16	CFLAGS += -I$(ARGP)/include
17	LDFLAGS += -L$(ARGP)/lib -largp
18endif
19
20all: $(TARGETS)
21extra: $(EXTRA_TARGETS)
22
23install: all
24	$(INSTALL) -d $(DESTDIR)$(PREFIX)/bin
25	$(INSTALL) -m755 $(TARGETS) $(DESTDIR)$(PREFIX)/bin
26	$(INSTALL) -d $(DESTDIR)$(PREFIX)/share/man/man1
27	$(INSTALL) -m644 f3read.1 $(DESTDIR)$(PREFIX)/share/man/man1
28	$(LN) -sf f3read.1 $(DESTDIR)$(PREFIX)/share/man/man1/f3write.1
29
30install-extra: extra
31	$(INSTALL) -d $(DESTDIR)$(PREFIX)/bin
32	$(INSTALL) -m755 $(EXTRA_TARGETS) $(DESTDIR)$(PREFIX)/bin
33
34f3write: utils.o libflow.o f3write.o
35	$(CC) -o $@ $^ $(LDFLAGS) -lm
36
37f3read: utils.o libflow.o f3read.o
38	$(CC) -o $@ $^ $(LDFLAGS) -lm
39
40f3probe: libutils.o libdevs.o libprobe.o f3probe.o
41	$(CC) -o $@ $^ $(LDFLAGS) -lm -ludev
42
43f3brew: libutils.o libdevs.o f3brew.o
44	$(CC) -o $@ $^ $(LDFLAGS) -lm -ludev
45
46f3fix: libutils.o f3fix.o
47	$(CC) -o $@ $^ $(LDFLAGS) -lparted
48
49-include *.d
50
51PHONY: cscope clean
52
53cscope:
54	cscope -b *.c *.h
55
56clean:
57	rm -f *.o *.d cscope.out $(TARGETS) $(EXTRA_TARGETS)
58