Makefile 12 KB
Newer Older
1 2 3 4 5

include config.mak

HEADERS = calc_sums.h hash_print.h common_func.h hash_update.h file.h file_mask.h file_set.h find_file.h hash_check.h output.h parse_cmdline.h rhash_main.h win_utils.h platform.h version.h
SOURCES = calc_sums.c hash_print.c common_func.c hash_update.c file.c file_mask.c file_set.c find_file.c hash_check.c output.c parse_cmdline.c rhash_main.c win_utils.c
6
OBJECTS = $(SOURCES:.c=.o)
7
WIN_DIST_FILES = dist/MD5.bat dist/magnet.bat dist/rhashrc.sample
8 9 10 11
OTHER_FILES = configure Makefile ChangeLog INSTALL.md COPYING README.md \
  build/vc-2010/rhash.vcxproj dist/rhash.spec.in dist/rhash.1 dist/rhash.1.win.sed \
  docs/CONTRIBUTING.md docs/LIBRHASH.md librhash/Doxyfile po/rhash.pot \
  tests/test_rhash.sh tests/test1K.data
12
LIBRHASH_FILES  = librhash/algorithms.c librhash/algorithms.h \
13 14 15
  librhash/byte_order.c librhash/byte_order.h librhash/plug_openssl.c librhash/plug_openssl.h \
  librhash/rhash.c librhash/rhash.h librhash/rhash_torrent.c librhash/rhash_torrent.h \
  librhash/rhash_timing.c librhash/rhash_timing.h \
16 17
  librhash/aich.c librhash/aich.h librhash/crc32.c librhash/crc32.h \
  librhash/ed2k.c librhash/ed2k.h librhash/edonr.c librhash/edonr.h \
18 19 20
  librhash/gost12.c librhash/gost12.h librhash/gost94.c librhash/gost94.h \
  librhash/has160.c librhash/has160.h librhash/hex.c librhash/hex.h librhash/md4.c \
  librhash/md4.h librhash/md5.c librhash/md5.h librhash/ripemd-160.c librhash/ripemd-160.h \
21
  librhash/sha1.c librhash/sha1.h librhash/sha3.c librhash/sha3.h \
22 23 24
  librhash/sha256.c librhash/sha256.h librhash/sha512.c librhash/sha512.h \
  librhash/snefru.c librhash/snefru.h librhash/tiger.c librhash/tiger.h \
  librhash/tiger_sbox.c librhash/tth.c librhash/tth.h librhash/whirlpool.c \
25
  librhash/whirlpool.h librhash/whirlpool_sbox.c librhash/test_hashes.c \
26
  librhash/test_hashes.h librhash/torrent.h librhash/torrent.c librhash/ustd.h \
27 28 29 30 31 32 33 34
  librhash/util.h librhash/Makefile
I18N_FILES  = po/ca.po po/de.po po/en_AU.po po/es.po po/fr.po po/gl.po po/it.po po/ro.po po/ru.po
ALL_FILES   = $(SOURCES) $(HEADERS) $(LIBRHASH_FILES) $(OTHER_FILES) $(WIN_DIST_FILES) $(I18N_FILES)
SPECFILE    = dist/rhash.spec
LIBRHASH_PC = dist/librhash.pc
RHASH_NAME     = rhash
RHASH_BINARY   = rhash$(EXEC_EXT)
CONFDIR_MACRO  = -DSYSCONFDIR=\"$(SYSCONFDIR)\"
35
TEST_OPTIONS   =
36 37
RPMTOP  = rpms
RPMDIRS = SOURCES SPECS BUILD SRPMS RPMS
38 39
INSTALL_PROGRAM = $(INSTALL) -m 755
INSTALL_DATA    = $(INSTALL) -m 644
40

41 42 43 44 45 46
all: $(BUILD_TARGETS)
install: build-install-binary install-data install-symlinks $(EXTRA_INSTALL)
build-static: $(RHASH_STATIC)
build-shared: $(RHASH_SHARED)
lib-shared: $(LIBRHASH_SHARED)
lib-static: $(LIBRHASH_STATIC)
47
install-data: install-man install-conf
48 49 50 51
uninstall: uninstall-binary uninstall-data uninstall-symlinks uninstall-lib uninstall-gmo uninstall-pkg-config

config.mak:
	echo "Run the ./configure script first" && false
52 53

# creating archives
54
WIN_SUFFIX     = win32
55 56 57 58 59 60 61
PACKAGE_NAME   = $(RHASH_NAME)-$(VERSION)
ARCHIVE_BZIP   = $(PACKAGE_NAME)-src.tar.bz2
ARCHIVE_GZIP   = $(PACKAGE_NAME)-src.tar.gz
ARCHIVE_FULL   = $(PACKAGE_NAME)-full-src.tar.gz
ARCHIVE_DEB_GZ = $(RHASH_NAME)_$(VERSION).orig.tar.gz
ARCHIVE_7Z     = $(PACKAGE_NAME)-src.tar.7z
ARCHIVE_ZIP    = $(PACKAGE_NAME)-$(WIN_SUFFIX).zip
62 63 64 65
WIN_ZIP_DIR    = RHash-$(VERSION)-$(WIN_SUFFIX)
dist: gzip gzip-bindings
dist-full: gzip-full
win-dist: zip
66 67
zip: $(ARCHIVE_ZIP)
dgz: check $(ARCHIVE_DEB_GZ)
68

69
build-install-binary: $(BUILD_TARGETS)
70 71
	+$(MAKE) install-binary

72
mkdir-bin:
73
	$(INSTALL) -d $(BINDIR)
74

75
# install binary without (re-)compilation
76
install-binary: mkdir-bin
77
	$(INSTALL_PROGRAM) $(RHASH_BINARY) $(BINDIR)/$(RHASH_BINARY)
78

79
install-man:
80 81
	$(INSTALL) -d $(MANDIR)/man1
	$(INSTALL_DATA) dist/rhash.1 $(MANDIR)/man1/rhash.1
82

83
install-conf:
84 85
	$(INSTALL) -d $(SYSCONFDIR)
	tr -d \\r < dist/rhashrc.sample > rc.tmp && $(INSTALL_DATA) rc.tmp $(SYSCONFDIR)/rhashrc
86 87 88
	rm -f rc.tmp

# dependencies should be properly set, otherwise 'make -j<n>' can fail
89
install-symlinks: mkdir-bin install-man install-binary
90 91
	cd $(BINDIR) && for f in $(SYMLINKS); do $(LN_S) $(RHASH_BINARY) $$f$(EXEC_EXT); done
	cd $(MANDIR)/man1 && for f in $(SYMLINKS); do $(LN_S) rhash.1 $$f.1; done
92 93 94 95

install-pkg-config:
	$(INSTALL) -d $(PKGCONFIGDIR)
	$(INSTALL_DATA) $(LIBRHASH_PC) $(PKGCONFIGDIR)/
96

97
uninstall-binary:
98
	rm -f $(BINDIR)/$(RHASH_BINARY)
99 100

uninstall-data:
101
	rm -f $(MANDIR)/man1/rhash.1
102 103

uninstall-symlinks:
104 105 106 107
	for f in $(SYMLINKS); do rm -f $(BINDIR)/$$f$(EXEC_EXT) $(MANDIR)/man1/$$f.1; done

uninstall-pkg-config:
	rm -f $(PKGCONFIGDIR)/librhash.pc
108 109

uninstall-lib:
110
	+cd librhash && $(MAKE) uninstall-lib
111

112
install-lib-static: $(LIBRHASH_STATIC) install-lib-headers
113
	+cd librhash && $(MAKE) install-lib-static
114

115 116
install-lib-shared: $(LIBRHASH_SHARED)
	+cd librhash && $(MAKE) install-lib-shared
117

118 119 120
install-lib-headers:
	+cd librhash && $(MAKE) install-lib-headers

121 122
install-lib-so-link:
	+cd librhash && $(MAKE) install-so-link
123

124 125
$(LIBRHASH_SHARED): $(LIBRHASH_FILES)
	+cd librhash && $(MAKE) lib-shared
126

127 128
$(LIBRHASH_STATIC): $(LIBRHASH_FILES)
	+cd librhash && $(MAKE) lib-static
129

130 131 132
test-lib: test-lib-$(BUILD_TYPE)
test-lib-static: $(LIBRHASH_STATIC)
	+cd librhash && $(MAKE) test-static
133

134 135
test-lib-shared: $(LIBRHASH_SHARED)
	+cd librhash && $(MAKE) test-shared
136

137 138 139
test-libs: $(LIBRHASH_STATIC) $(LIBRHASH_SHARED)
	+cd librhash && $(MAKE) test-static test-shared

140 141 142
test-full:
	+$(MAKE) TEST_OPTIONS=--full test

143 144
test: test-$(BUILD_TYPE)
test-static: $(RHASH_STATIC)
145
	chmod +x tests/test_rhash.sh
146
	tests/test_rhash.sh $(TEST_OPTIONS) ./$(RHASH_STATIC)
147

148
test-shared: $(RHASH_SHARED)
149
	chmod +x tests/test_rhash.sh
150
	tests/test_rhash.sh --shared $(TEST_OPTIONS) ./$(RHASH_SHARED)
151

152 153
print-info: lib-$(BUILD_TYPE)
	+cd librhash && $(MAKE) print-info
154

155 156
# check that source tree is consistent
check:
157 158
	grep -q '\* === Version $(VERSION) ===' ChangeLog
	grep -q '^#define VERSION "$(VERSION)"' version.h
159
	test ! -f bindings/version.properties || grep -q '^version=$(VERSION)$$' bindings/version.properties
160

161 162
$(RHASH_STATIC): $(OBJECTS) $(LIBRHASH_STATIC)
	$(CC) $(OBJECTS) $(LIBRHASH_STATIC) $(BIN_STATIC_LDFLAGS) -o $@
163

164 165
$(RHASH_SHARED): $(OBJECTS) $(LIBRHASH_SHARED)
	$(CC) $(OBJECTS) $(LIBRHASH_SHARED) $(LDFLAGS) -o $@
166 167 168

# NOTE: dependences were generated by 'gcc -Ilibrhash -MM *.c'
# we are using plain old makefile style to support BSD make
169 170 171 172 173 174
calc_sums.o: calc_sums.c platform.h calc_sums.h common_func.h \
 hash_check.h file.h hash_print.h output.h parse_cmdline.h rhash_main.h \
 win_utils.h librhash/rhash.h librhash/rhash_torrent.h
	$(CC) -c $(CFLAGS) $< -o $@

common_func.o: common_func.c common_func.h parse_cmdline.h version.h \
175
 win_utils.h
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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
	$(CC) -c $(CFLAGS) $< -o $@

file.o: file.c file.h common_func.h win_utils.h
	$(CC) -c $(CFLAGS) $< -o $@

file_mask.o: file_mask.c file_mask.h common_func.h
	$(CC) -c $(CFLAGS) $< -o $@

file_set.o: file_set.c file_set.h calc_sums.h common_func.h hash_check.h \
 hash_print.h output.h parse_cmdline.h rhash_main.h librhash/rhash.h
	$(CC) -c $(CFLAGS) $< -o $@

find_file.o: find_file.c platform.h find_file.h common_func.h file.h \
 output.h win_utils.h
	$(CC) -c $(CFLAGS) $< -o $@

hash_check.o: hash_check.c hash_check.h hash_print.h common_func.h \
 output.h parse_cmdline.h librhash/rhash.h
	$(CC) -c $(CFLAGS) $< -o $@

hash_print.o: hash_print.c hash_print.h calc_sums.h common_func.h \
 hash_check.h file.h parse_cmdline.h win_utils.h librhash/rhash.h
	$(CC) -c $(CFLAGS) $< -o $@

hash_update.o: hash_update.c common_func.h calc_sums.h hash_check.h \
 file.h file_set.h file_mask.h hash_print.h hash_update.h output.h \
 parse_cmdline.h rhash_main.h win_utils.h
	$(CC) -c $(CFLAGS) $< -o $@

output.o: output.c platform.h output.h calc_sums.h common_func.h \
 hash_check.h parse_cmdline.h rhash_main.h win_utils.h librhash/rhash.h
	$(CC) -c $(CFLAGS) $< -o $@

parse_cmdline.o: parse_cmdline.c parse_cmdline.h common_func.h \
 file_mask.h find_file.h file.h hash_print.h output.h rhash_main.h \
 win_utils.h librhash/rhash.h
	$(CC) -c $(CFLAGS) $< -o $@

rhash_main.o: rhash_main.c rhash_main.h calc_sums.h common_func.h \
 hash_check.h file_mask.h find_file.h file.h hash_print.h hash_update.h \
 parse_cmdline.h output.h win_utils.h librhash/rhash.h
	$(CC) -c $(CFLAGS) $< -o $@

win_utils.o: win_utils.c win_utils.h common_func.h file.h parse_cmdline.h \
 rhash_main.h
	$(CC) -c $(CFLAGS) $< -o $@
222

223 224 225 226 227 228
dist/rhash.1.win.html: dist/rhash.1 dist/rhash.1.win.sed
	sed -f dist/rhash.1.win.sed dist/rhash.1 | rman -fHTML -roff | \
	sed -e '/<BODY/s/\(bgcolor=\)"[^"]*"/\1"white"/i' > dist/rhash.1.win.html
#	verify the result
	grep -q "utf8" dist/rhash.1.win.html
	grep -q "APPDATA" dist/rhash.1.win.html
229

230
dist/rhash.1.html: dist/rhash.1
231
	-which rman 2>/dev/null && (rman -fHTML -roff dist/rhash.1 | sed -e '/<BODY/s/\(bgcolor=\)"[^"]*"/\1"white"/i' > $@)
232

233 234
dist/rhash.1.txt: dist/rhash.1
	-which groff &>/dev/null && (groff -t -e -mandoc -Tascii dist/rhash.1 | sed -e 's/.\[[0-9]*m//g' > $@)
235

236
permissions:
237
	find . build dist docs librhash po tests -maxdepth 1 -type f -exec chmod -x '{}' \;
238
	chmod +x configure tests/test_rhash.sh
239

240 241 242 243
copy-dist: $(ALL_FILES) permissions
	rm -rf $(PACKAGE_NAME)
	mkdir $(PACKAGE_NAME)
	cp -rl --parents $(ALL_FILES) $(PACKAGE_NAME)/
244

245
gzip: check
246
	+$(MAKE) copy-dist
247 248
	tar czf $(ARCHIVE_GZIP) --owner=root --group=root $(PACKAGE_NAME)/
	rm -rf $(PACKAGE_NAME)
249

250
gzip-bindings:
251
	+cd bindings && $(MAKE) gzip ARCHIVE_GZIP=../rhash-bindings-$(VERSION)-src.tar.gz
252

253
gzip-full: check clean-bindings
254
	+$(MAKE) copy-dist
255 256 257
	+cd bindings && $(MAKE) copy-dist COPYDIR=../$(PACKAGE_NAME)/bindings
	tar czf $(ARCHIVE_FULL) --owner=root:0 --group=root:0 $(PACKAGE_NAME)/
	rm -rf $(PACKAGE_NAME)
258

259
bzip: check
260
	+$(MAKE) copy-dist
261 262
	tar cjf $(ARCHIVE_BZIP) --owner=root:0 --group=root:0 $(PACKAGE_NAME)/
	rm -rf $(PACKAGE_NAME)
263

264
7z: check
265
	+$(MAKE) copy-dist
266 267
	tar cf - --owner=root:0 --group=root:0 $(PACKAGE_NAME)/ | 7zr a -si $(ARCHIVE_7Z)
	rm -rf $(PACKAGE_NAME)
268

269
$(ARCHIVE_ZIP): $(WIN_DIST_FILES) dist/rhash.1.win.html
270
	test -s dist/rhash.1.win.html && test -x $(RHASH_BINARY)
271 272
	-rm -rf $(WIN_ZIP_DIR)
	mkdir $(WIN_ZIP_DIR)
273
	cp $(RHASH_BINARY) ChangeLog $(WIN_DIST_FILES) $(WIN_ZIP_DIR)/
274
	cp dist/rhash.1.win.html $(WIN_ZIP_DIR)/rhash-doc.html
275 276
	zip -9r $(ARCHIVE_ZIP) $(WIN_ZIP_DIR)
	rm -rf $(WIN_ZIP_DIR)
277

278
$(ARCHIVE_DEB_GZ) : $(ALL_FILES)
279
	+$(MAKE) $(ARCHIVE_GZIP)
280 281
	mv -f $(ARCHIVE_GZIP) $(ARCHIVE_DEB_GZ)

282
# rpm packaging
283
$(SPECFILE): $(SPECFILE).in config.mak
284 285 286 287 288 289
	sed -e 's/@VERSION@/$(VERSION)/' $(SPECFILE).in > $(SPECFILE)

rpm: gzip
	-for i in $(RPMDIRS); do mkdir -p $(RPMTOP)/$$i; done
	cp -f $(ARCHIVE_GZIP) $(RPMTOP)/SOURCES
	rpmbuild -ba --clean --define "_topdir `pwd`/$(RPMTOP)" $(SPECFILE)
290
	mv -f `find $(RPMTOP) -name "*rhash*-$(VERSION)*.rpm"` .
291 292
	rm -rf $(RPMTOP)

293 294
clean-bindings:
	+cd bindings && $(MAKE) clean
295

296 297
clean-local:
	rm -f *.o $(RHASH_SHARED) $(RHASH_STATIC)
298
	rm -f po/*.gmo po/*.po~
299

300 301 302 303 304 305 306
distclean: clean-local
	rm -f config.log config.mak $(SPECFILE) $(LIBRHASH_PC)
	+cd librhash && $(MAKE) distclean

clean: clean-local
	+cd librhash && $(MAKE) clean

307 308
update-po:
	xgettext *.c -k_ -cTRANSLATORS -o po/rhash.pot \
309
		--msgid-bugs-address='Aleksey <rhash.admin@gmail.com>' --package-name='RHash'
310
	for f in $(I18N_FILES); do \
311 312 313 314
		msgmerge -U $$f po/rhash.pot; \
	done

compile-gmo:
315
	for f in $(I18N_FILES); do \
316
		g=`basename $$f .po`; \
317
		msgfmt -o po/$$g.gmo $$f; \
318 319 320
	done

install-gmo: compile-gmo
321 322 323 324 325 326 327 328 329
	for f in $(I18N_FILES); do \
		l=`basename $$f .po`; \
		$(INSTALL) -d $(LOCALEDIR)/$$l/LC_MESSAGES; \
		$(INSTALL_DATA) po/$$l.gmo $(LOCALEDIR)/$$l/LC_MESSAGES/rhash.mo; \
	done

uninstall-gmo:
	for f in $(I18N_FILES); do \
		rm -f $(LOCALEDIR)/`basename $$f .po`/LC_MESSAGES/rhash.mo; \
330 331
	done

332
.PHONY: all build-shared build-static lib-shared lib-static clean clean-bindings distclean clean-local \
333
	test test-shared test-static test-full test-lib test-libs test-lib-shared test-lib-static \
334
	install build-install-binary install-binary install-lib-shared install-lib-static \
335
	install-lib-headers install-lib-so-link install-conf install-data install-gmo install-man \
336
	install-symlinks install-pkg-config uninstall-gmo uninstall-pkg-config \
337
	uninstall uninstall-binary uninstall-data uninstall-lib uninstall-symlinks \
338
	print-info check copy-dist update-po compile-gmo mkdir-bin permissions \
339
	bzip dgz dist dist-full gzip gzip-bindings gzip-full rpm win-dist zip