File: Makefile

package info (click to toggle)
duperemove 0.11.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 844 kB
  • sloc: ansic: 11,586; makefile: 110
file content (132 lines) | stat: -rw-r--r-- 4,460 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
VER=0.11.2
RELEASE=v$(VER)

CC ?= gcc
CFLAGS ?= -Wall -ggdb

MANPAGES=duperemove.8 btrfs-extent-same.8 hashstats.8 show-shared-extents.8

HEADERS=csum.h hash-tree.h results-tree.h kernel.h list.h rbtree.h dedupe.h \
	ioctl.h filerec.h btrfs-util.h debug.h util.h \
	memstats.h file_scan.h find_dupes.h run_dedupe.h xxhash.h  xxh3.h \
	bswap.h dbfile.h interval_tree.h interval_tree_generic.h \
	rbtree_augmented.h list_sort.h stats.h
CFILES=duperemove.c hash-tree.c results-tree.c rbtree.c dedupe.c filerec.c \
	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
hash_CFILES=csum-xxhash.c csum-murmur3.c

CFILES += $(hash_CFILES)

hashstats_CFILES=hashstats.c
btrfs_extent_same_CFILES=btrfs-extent-same.c
csum_test_CFILES=csum-test.c

DIST_CFILES:=$(CFILES) $(hashstats_CFILES) $(btrfs_extent_same_CFILES) \
	$(csum_test_CFILES)
DIST_SOURCES:=$(DIST_CFILES) $(HEADERS) LICENSE LICENSE.xxhash Makefile \
	rbtree.txt README.md $(MANPAGES) SubmittingPatches docs/duperemove.html
DIST=duperemove-$(VER)
DIST_TARBALL=$(RELEASE).tar.gz
TEMP_INSTALL_DIR:=$(shell mktemp -du -p .)

objects = $(CFILES:.c=.o)

hash_obj=$(hash_CFILES:.c=.o)
hashstats_obj = $(hash_obj) rbtree.o hash-tree.o filerec.o util.o \
	results-tree.o csum.o dbfile.o interval_tree.o list_sort.o debug.o
show_shared_obj = rbtree.o util.o debug.o
csum_test_obj = $(hash_obj) util.o csum.o debug.o

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

glib_CFLAGS=$(shell pkg-config --cflags glib-2.0)
glib_LIBS=$(shell pkg-config --libs glib-2.0)
sqlite_CFLAGS=$(shell pkg-config --cflags sqlite3)
sqlite_LIBS=$(shell pkg-config --libs sqlite3)

ifdef DEBUG
	DEBUG_FLAGS = -ggdb3 -fsanitize=address -fno-omit-frame-pointer	-O0 \
			-DDEBUG_BUILD -DSQLITE_DEBUG -DSQLITE_MEMDEBUG \
			-DSQLITE_ENABLE_EXPLAIN_COMMENTS -fsanitize-address-use-after-scope
else
	CFLAGS += -O2
endif

override CFLAGS += -D_FILE_OFFSET_BITS=64 -DVERSTRING=\"$(RELEASE)\" \
	$(hash_CFLAGS) $(glib_CFLAGS) $(sqlite_CFLAGS) -rdynamic $(DEBUG_FLAGS)
LIBRARY_FLAGS += -Wl,--as-needed -latomic -lm
LIBRARY_FLAGS += $(hash_LIBS) $(glib_LIBS) $(sqlite_LIBS)

# make C=1 to enable sparse
ifdef C
	check = sparse -D__CHECKER__ -D__CHECK_ENDIAN__ -Wbitwise \
		-Wuninitialized -Wshadow -Wundef
else
	check = @true
endif

DESTDIR ?= /
PREFIX ?= /usr/local
SHAREDIR = $(PREFIX)/share
SBINDIR = $(PREFIX)/bin
MANDIR = $(SHAREDIR)/man

%.c.i: FORCE
	$(check) $(CPPFLAGS) $(CFLAGS) -c $(subst .i,,$@) -o $@ $(LIBRARY_FLAGS)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -E $(subst .i,,$@) -o $@ $(LIBRARY_FLAGS)

%.c.o: FORCE
	$(check) $(CPPFLAGS) $(CFLAGS) -c $(subst .o,,$@) -o $@ $(LIBRARY_FLAGS)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -c  $(subst .o,,$@) -o $@ $(LIBRARY_FLAGS)

all: $(progs)
debug:
	@echo "Deprecated, use \"make DEBUG=1\" instead please."

#TODO: Replace this with an auto-dependency
$(objects): $(HEADERS)
duperemove: $(objects)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(objects) -o duperemove $(LIBRARY_FLAGS)

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
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o btrfs-extent-same btrfs-extent-same.c

install: $(install_progs) $(MANPAGES)
	mkdir -p -m 0755 $(DESTDIR)$(SBINDIR)
	for prog in $(install_progs); do \
		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

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

csum-test: $(csum_test_obj) csum-test.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(csum_test_obj) -o csum-test csum-test.c  $(LIBRARY_FLAGS)

show-shared-extents: $(show_shared_obj) filerec.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -DFILEREC_TEST filerec.c $(show_shared_obj) -o show-shared-extents $(LIBRARY_FLAGS)

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

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

FORCE: