Makefile 4.03 KB
Newer Older
Mark Fasheh's avatar
Mark Fasheh committed
1
VER=0.11.1
2
RELEASE=v$(VER)
3

4 5
CC ?= gcc
CFLAGS ?= -Wall -ggdb -O2
6

7
MANPAGES=duperemove.8 btrfs-extent-same.8 hashstats.8 show-shared-extents.8
Mark Fasheh's avatar
Mark Fasheh committed
8

9
HEADERS=csum.h hash-tree.h results-tree.h kernel.h list.h rbtree.h dedupe.h \
10
	btrfs-ioctl.h filerec.h btrfs-util.h debug.h util.h \
11
	memstats.h file_scan.h find_dupes.h run_dedupe.h xxhash.h \
Mark Fasheh's avatar
Mark Fasheh committed
12 13
	bswap.h dbfile.h interval_tree.h interval_tree_generic.h \
	rbtree_augmented.h list_sort.h stats.h
Mark Fasheh's avatar
Mark Fasheh committed
14
CFILES=duperemove.c hash-tree.c results-tree.c rbtree.c dedupe.c filerec.c \
15 16
	btrfs-util.c util.c memstats.c file_scan.c find_dupes.c run_dedupe.c \
	csum.c dbfile.c interval_tree.c list_sort.c stats.c debug.c
Mark Fasheh's avatar
Mark Fasheh committed
17
hash_CFILES=csum-xxhash.c xxhash.c csum-murmur3.c
18

19 20
CFILES += $(hash_CFILES)

Mark Fasheh's avatar
Mark Fasheh committed
21 22 23
hashstats_CFILES=hashstats.c
btrfs_extent_same_CFILES=btrfs-extent-same.c
csum_test_CFILES=csum-test.c
24

25
DIST_CFILES:=$(CFILES) $(hashstats_CFILES) $(btrfs_extent_same_CFILES) \
26
	$(csum_test_CFILES)
27
DIST_SOURCES:=$(DIST_CFILES) $(HEADERS) LICENSE LICENSE.xxhash Makefile \
Mark Fasheh's avatar
Mark Fasheh committed
28
	rbtree.txt README.md $(MANPAGES) SubmittingPatches docs/duperemove.html
29 30
DIST=duperemove-$(VER)
DIST_TARBALL=$(RELEASE).tar.gz
31 32
TEMP_INSTALL_DIR:=$(shell mktemp -du -p .)

Mark Fasheh's avatar
Mark Fasheh committed
33 34
objects = $(CFILES:.c=.o)

35
hash_obj=$(hash_CFILES:.c=.o)
36
hashstats_obj = $(hash_obj) rbtree.o hash-tree.o filerec.o util.o \
37
	results-tree.o csum.o dbfile.o interval_tree.o list_sort.o debug.o
38 39
show_shared_obj = rbtree.o util.o debug.o
csum_test_obj = $(hash_obj) util.o csum.o debug.o
Mark Fasheh's avatar
Mark Fasheh committed
40

41 42
install_progs = duperemove hashstats btrfs-extent-same show-shared-extents
progs = $(install_progs) csum-test
43

44 45
glib_CFLAGS=$(shell pkg-config --cflags glib-2.0)
glib_LIBS=$(shell pkg-config --libs glib-2.0)
46 47
sqlite_CFLAGS=$(shell pkg-config --cflags sqlite3)
sqlite_LIBS=$(shell pkg-config --libs sqlite3)
48

49 50 51 52
ifdef DEBUG
	DEBUG_FLAGS = -ggdb3 -fsanitize=address -fno-omit-frame-pointer	\
			-DDEBUG_BUILD
endif
Mark Fasheh's avatar
Mark Fasheh committed
53
override CFLAGS += -D_FILE_OFFSET_BITS=64 -DVERSTRING=\"$(RELEASE)\" \
54
	$(hash_CFLAGS) $(glib_CFLAGS) $(sqlite_CFLAGS) -rdynamic $(DEBUG_FLAGS)
55 56
LIBRARY_FLAGS += -Wl,--as-needed -latomic -lm
LIBRARY_FLAGS += $(hash_LIBS) $(glib_LIBS) $(sqlite_LIBS)
57

58 59 60 61 62
# make C=1 to enable sparse
ifdef C
	check = sparse -D__CHECKER__ -D__CHECK_ENDIAN__ -Wbitwise \
		-Wuninitialized -Wshadow -Wundef
else
63
	check = @true
64 65
endif

66 67
DESTDIR ?= /
PREFIX ?= /usr/local
Benedikt Morbach's avatar
Benedikt Morbach committed
68 69 70 71
SHAREDIR = $(PREFIX)/share
SBINDIR = $(PREFIX)/sbin
MANDIR = $(SHAREDIR)/man

Mark Fasheh's avatar
Mark Fasheh committed
72
.c.o:
73 74
	$(check) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ $(LIBRARY_FLAGS)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -c $< -o $@ $(LIBRARY_FLAGS)
75

Mark Fasheh's avatar
Mark Fasheh committed
76
all: $(progs)
77 78
debug:
	@echo "Deprecated, use \"make DEBUG=1\" instead please."
79

Mark Fasheh's avatar
Mark Fasheh committed
80 81 82
#TODO: Replace this with an auto-dependency
$(objects): $(HEADERS)
duperemove: $(objects)
83
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(objects) -o duperemove $(LIBRARY_FLAGS)
84 85 86 87 88 89 90 91

tarball: clean
	mkdir -p $(TEMP_INSTALL_DIR)/$(DIST)
	cp $(DIST_SOURCES) $(TEMP_INSTALL_DIR)/$(DIST)
	tar -C $(TEMP_INSTALL_DIR) -zcf $(DIST_TARBALL) $(DIST)
	rm -fr $(TEMP_INSTALL_DIR)

btrfs-extent-same: btrfs-extent-same.c
92
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o btrfs-extent-same btrfs-extent-same.c
93

94
install: $(install_progs) $(MANPAGES)
Benedikt Morbach's avatar
Benedikt Morbach committed
95
	mkdir -p -m 0755 $(DESTDIR)$(SBINDIR)
96
	for prog in $(install_progs); do \
Benedikt Morbach's avatar
Benedikt Morbach committed
97 98 99 100 101 102 103
		install -m 0755 $$prog $(DESTDIR)$(SBINDIR); \
	done
	mkdir -p -m 0755 $(DESTDIR)$(MANDIR)/man8
	for man in $(MANPAGES); do \
		install -m 0644 $$man $(DESTDIR)$(MANDIR)/man8; \
	done

104 105 106 107 108 109 110 111
uninstall:
	for prog in $(install_progs); do \
		rm -f $(DESTDIR)$(SBINDIR)/$$prog; \
	done
	for man in $(MANPAGES); do \
		rm -f $(DESTDIR)$(MANDIR)/man8/$$man; \
	done

Mark Fasheh's avatar
Mark Fasheh committed
112
csum-test: $(csum_test_obj) csum-test.c
113
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(csum_test_obj) -o csum-test csum-test.c  $(LIBRARY_FLAGS)
114

Mark Fasheh's avatar
Mark Fasheh committed
115
show-shared-extents: $(show_shared_obj) filerec.c
116
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -DFILEREC_TEST filerec.c $(show_shared_obj) -o show-shared-extents $(LIBRARY_FLAGS)
117

118
hashstats: $(hashstats_obj) hashstats.c
119
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(hashstats_obj) hashstats.c -o hashstats $(LIBRARY_FLAGS)
120

121
clean:
122
	rm -fr $(objects) $(progs) $(DIST_TARBALL) btrfs-extent-same filerec-test show-shared-extents hashstats csum-*.o *~