1CC	= gcc
2CFLAGS	= -Wall -O2 -g -W
3ALL_CFLAGS = $(CFLAGS) -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
4PROGS	= blkparse blktrace verify_blkparse blkrawverify blkiomon
5LIBS	= -lpthread
6SCRIPTS	= btrace
7
8ALL = $(PROGS) $(SCRIPTS) btt/btt btreplay/btrecord btreplay/btreplay \
9      btt/bno_plot.py
10
11all: $(ALL)
12
13btt/btt:
14	$(MAKE) -C btt
15
16btreplay/btrecord:
17	$(MAKE) -C btreplay
18
19btreplay/btreplay:
20	$(MAKE) -C btreplay
21
22%.o: %.c
23	$(CC) -o $*.o -c $(ALL_CFLAGS) $<
24
25blkparse: blkparse.o blkparse_fmt.o rbtree.o act_mask.o
26	$(CC) $(ALL_CFLAGS) -o $@ $(filter %.o,$^)
27
28blktrace: blktrace.o act_mask.o
29	$(CC) $(ALL_CFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
30
31verify_blkparse: verify_blkparse.o
32	$(CC) $(ALL_CFLAGS) -o $@ $(filter %.o,$^)
33
34blkrawverify: blkrawverify.o
35	$(CC) $(ALL_CFLAGS) -o $@ $(filter %.o,$^)
36
37blkiomon: blkiomon.o rbtree.o
38	$(CC) $(ALL_CFLAGS) -o $@ $(filter %.o,$^) $(LIBS) -lrt
39
40$(PROGS): | depend
41
42docs:
43	$(MAKE) -C doc all
44	$(MAKE) -C btt docs
45	$(MAKE) -C btreplay docs
46
47docsclean:
48	$(MAKE) -C doc clean
49	$(MAKE) -C btt clean
50	$(MAKE) -C btreplay clean
51
52depend:
53	@$(CC) -MM $(ALL_CFLAGS) *.c 1> .depend
54
55INSTALL = install
56prefix = /usr/local
57bindir = $(prefix)/bin
58mandir = $(prefix)/man
59RPMBUILD = rpmbuild
60TAR = tar
61
62export prefix INSTALL TAR
63
64dist: btrace.spec
65	git-tar-tree HEAD btrace-1.0 > btrace-1.0.tar
66	@mkdir -p btrace-1.0
67	@cp btrace.spec btrace-1.0
68	$(TAR) rf btrace-1.0.tar btrace-1.0/btrace.spec
69	@rm -rf btrace-1.0
70	@bzip2 btrace-1.0.tar
71
72rpm: dist
73	$(RPMBUILD) -ta btrace-1.0.tar.bz2
74
75clean: docsclean
76	-rm -f *.o $(PROGS) .depend btrace-1.0.tar.bz2
77	$(MAKE) -C btt clean
78	$(MAKE) -C btreplay clean
79
80install: all
81	$(INSTALL) -m 755 -d $(DESTDIR)$(bindir)
82	$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man1
83	$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man8
84	$(INSTALL) -m 755 $(ALL) $(DESTDIR)$(bindir)
85	$(INSTALL) -m 644 doc/*.1 $(DESTDIR)$(mandir)/man1
86	$(INSTALL) -m 644 doc/*.8 $(DESTDIR)$(mandir)/man8
87
88ifneq ($(wildcard .depend),)
89include .depend
90endif
91