File: Makefile

package info (click to toggle)
dupd 1.7.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 12,688 kB
  • sloc: ansic: 8,381; sh: 879; makefile: 121; perl: 58
file content (200 lines) | stat: -rw-r--r-- 4,667 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#
#  Copyright 2012-2018 Jyri J. Virkki <jyri@virkki.com>
#
#  This file is part of dupd.
#
#  dupd is free software: you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  dupd is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with dupd.  If not, see <http://www.gnu.org/licenses/>.
#

TOP:=$(shell  pwd)
BUILD_OS:=$(shell uname)
BUILD_MACHINE:=$(shell uname -m)
VERSION:=$(shell cat version)
OPTGEN:=$(shell which optgen | head -c1)

# For -dev versions, record where in source history the binary came from.
ifeq (dev,$(findstring dev,$(VERSION)))
GITHASH:=$(shell git rev-parse HEAD)
else
GITHASH=$(VERSION)
endif

ifeq ($(LCOV_OUTPUT_DIR),)
LCOV_OUTPUT_DIR=./lcov.out
endif

# The install target uses these default locations to install bin/dupd
# and man1/dupd.1. Override in the environment if desired.  Note that
# install prefixes these with the value of DESTDIR which should
# normally be empty so it has no default. It is only used by build
# environments which install to a temporary staging area. This is used
# by the MacPorts build, for instance.
# https://www.gnu.org/prep/standards/html_node/DESTDIR.html

INSTALL_PREFIX ?= /usr/local

BUILD=$(TOP)/build
CCC=$(CC) -Wall -Wextra -std=gnu99 $(OPT)

SRCS:=$(wildcard src/*.c)
OBJS:=$(patsubst src/%.c,$(BUILD)/%.o,$(SRCS))


#
# Linux
#
ifeq ($(BUILD_OS),Linux)
CFLAGS+=-D_FILE_OFFSET_BITS=64 -DDIRENT_HAS_TYPE -DUSE_FIEMAP
endif

#
# OpenBSD
#
ifeq ($(BUILD_OS),OpenBSD)
CFLAGS+=-DDIRENT_HAS_TYPE
endif

#
# FreeBSD
#
# In FreeBSD libsqlite3 lives under /usr/local/ instead of /usr/lib
# so need to point at it. If you wanted to override the location so
# it is obtained from elsewhere, set INCLUDE_DIR and LIB_DIR accordingly.
#
ifeq ($(BUILD_OS),FreeBSD)

CFLAGS+=-DDIRENT_HAS_TYPE

ifeq ($(INCLUDE_DIR),)
INC+=-I/usr/local/include
else
INC+=-I$(INCLUDE_DIR)
endif

ifeq ($(LIB_DIR),)
LIB+=-L/usr/local/lib
else
LIB+=-L$(LIB_DIR)
endif
endif

#
# SunOS (Solaris and descendants)
#
ifeq ($(BUILD_OS),SunOS)
CCC=$(CC) $(OPT)
CFLAGS=-m64
endif

#
# Darwin (Mac OS X)
#
ifeq ($(BUILD_OS),Darwin)
CFLAGS+=-DDIRENT_HAS_TYPE
endif


ifeq ($(DEBUG),1)
OPT=-g $(DEBUGOPT)
else
OPT?=-O3
endif


dupd: src/optgen.c src/optgen.h $(OBJS)
	$(CCC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIB) \
	    -lsqlite3 -lcrypto -lpthread -lm -o dupd

$(BUILD)/%.o: src/%.c src/%.h
	mkdir -p $(BUILD)
	$(CCC) $(INC) $(CFLAGS) \
		-DDUPD_VERSION=\"$(VERSION)\" -DGITHASH=\"$(GITHASH)\" \
		 -c $< -o $@

clean:
	rm -f dupd
	rm -rf $(BUILD)
	rm -f dupd*.tar.gz

lint:
	lint -x -errfmt=simple $(LIB) $(INC) $(SRCS)

test:
	(cd tests && ./run)

valgrind:
	(cd tests && DUPD_VALGRIND=1 ./run)

gcov:
	$(MAKE) clean
	DEBUG=1 DEBUGOPT="-fprofile-arcs -ftest-coverage" $(MAKE) dupd
	$(MAKE) test
	(cd $(BUILD) && \
		cp ../src/*.c . && \
		ln -s ../src . && \
		gcov -bf *.c | tee gcov.output)
	@echo Remember to make clean to remove instrumented objects

lcov: gcov
	lcov --capture --directory build --output-file lcov.info
	lcov --remove lcov.info xxhash.c --output-file lcov.info
	genhtml lcov.info --no-branch-coverage \
		--output-directory $(LCOV_OUTPUT_DIR)
	rm -f lcov.info
	$(MAKE) clean

# dupd uses optgen to generate its option parsing code based on
# the config file src/options.conf
#
# optgen is a ruby gem, install it as follows:
#
# sudo gem install optgen
#
# If optgen is not present, skip option handling code generation.
# This allows compiling dupd without optgen present. The downside is
# that optgen.c is checked in although it really should not be.
src/optgen.c src/optgen.h: src/options.conf
ifeq (/,$(OPTGEN))
	(cd src; optgen options.conf)
else
	@echo optgen not found, unable to regenerate option code
endif

.PHONY: man
man:
	MANWIDTH=80 man -l man/dupd.1 > man/dupd
	xxd -i man/dupd > src/man.h

release:
	$(MAKE) clean
	DEBUG=0 $(MAKE)
	rm -rf tar/
	mkdir tar
	( cd tar && \
	mkdir bin man docs && \
	cp ../dupd bin/ && strip bin/dupd && \
	cp ../man/dupd.1 man/ && \
	cp ../docs/* docs/ && \
	tar -cvf dupd_$(VERSION)_$(BUILD_OS)_$(BUILD_MACHINE).tar \
		bin docs man && \
	gzip --best *.tar)
	cp tar/*.tar.gz .
	rm -rf tar/

install: dupd
	mkdir -p $(DESTDIR)$(INSTALL_PREFIX)/bin/
	cp dupd $(DESTDIR)$(INSTALL_PREFIX)/bin/

uninstall:
	rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/dupd