1
2include config.mak
3
4HEADERS = 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
5SOURCES = 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
6OBJECTS = $(SOURCES:.c=.o)
7WIN_DIST_FILES = dist/MD5.bat dist/magnet.bat dist/rhashrc.sample
8OTHER_FILES = configure Makefile ChangeLog INSTALL.md COPYING README.md \
9  build/vc-2010/rhash.vcxproj dist/rhash.spec.in dist/rhash.1 dist/rhash.1.win.sed \
10  docs/CONTRIBUTING.md docs/LIBRHASH.md librhash/Doxyfile po/rhash.pot \
11  tests/test_rhash.sh tests/test1K.data
12LIBRHASH_FILES  = librhash/algorithms.c librhash/algorithms.h \
13  librhash/byte_order.c librhash/byte_order.h librhash/plug_openssl.c librhash/plug_openssl.h \
14  librhash/rhash.c librhash/rhash.h librhash/rhash_torrent.c librhash/rhash_torrent.h \
15  librhash/rhash_timing.c librhash/rhash_timing.h \
16  librhash/aich.c librhash/aich.h librhash/crc32.c librhash/crc32.h \
17  librhash/ed2k.c librhash/ed2k.h librhash/edonr.c librhash/edonr.h \
18  librhash/gost12.c librhash/gost12.h librhash/gost94.c librhash/gost94.h \
19  librhash/has160.c librhash/has160.h librhash/hex.c librhash/hex.h librhash/md4.c \
20  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  librhash/sha256.c librhash/sha256.h librhash/sha512.c librhash/sha512.h \
23  librhash/snefru.c librhash/snefru.h librhash/tiger.c librhash/tiger.h librhash/tiger_sbox.c \
24  librhash/torrent.h librhash/torrent.c librhash/tth.c librhash/tth.h \
25  librhash/whirlpool.c librhash/whirlpool.h librhash/whirlpool_sbox.c \
26  librhash/test_hashes.c librhash/test_hashes.h librhash/ustd.h \
27  librhash/util.c librhash/util.h librhash/Makefile
28I18N_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 po/uk.po
29ALL_FILES   = $(SOURCES) $(HEADERS) $(LIBRHASH_FILES) $(OTHER_FILES) $(WIN_DIST_FILES) $(I18N_FILES)
30SPECFILE    = dist/rhash.spec
31LIBRHASH_PC = dist/librhash.pc
32RHASH_NAME     = rhash
33RHASH_BINARY   = rhash$(EXEC_EXT)
34TEST_OPTIONS   =
35RPMTOP  = rpms
36RPMDIRS = SOURCES SPECS BUILD SRPMS RPMS
37INSTALL_PROGRAM = $(INSTALL) -m 755
38INSTALL_DATA    = $(INSTALL) -m 644
39
40all: $(BUILD_TARGETS)
41install: build-install-binary install-data install-symlinks $(EXTRA_INSTALL)
42build-static: $(RHASH_STATIC)
43build-shared: $(RHASH_SHARED)
44lib-shared: $(LIBRHASH_SHARED)
45lib-static: $(LIBRHASH_STATIC)
46install-data: install-man install-conf
47uninstall: uninstall-binary uninstall-data uninstall-symlinks uninstall-lib uninstall-gmo uninstall-pkg-config
48
49config.mak:
50	echo "Run the ./configure script first" && false
51
52# creating archives
53WIN_SUFFIX     = win32
54PACKAGE_NAME   = $(RHASH_NAME)-$(VERSION)
55ARCHIVE_TARGZ  = $(PACKAGE_NAME)-src.tar.gz
56ARCHIVE_TARGZ_CORE     = $(RHASH_NAME)-core-$(VERSION)-src.tar.gz
57ARCHIVE_TARGZ_BINDINGS = $(RHASH_NAME)-bindings-$(VERSION)-src.tar.gz
58ARCHIVE_TARGZ_DEB      = $(RHASH_NAME)_$(VERSION).orig.tar.gz
59ARCHIVE_XZ     = $(PACKAGE_NAME)-src.tar.xz
60ARCHIVE_ZIP    = $(PACKAGE_NAME)-$(WIN_SUFFIX).zip
61WIN_ZIP_DIR    = RHash-$(VERSION)-$(WIN_SUFFIX)
62dist: tgz
63win-dist: zip
64zip: $(ARCHIVE_ZIP)
65dgz: check $(ARCHIVE_TARGZ_DEB)
66
67build-install-binary: $(BUILD_TARGETS)
68	+$(MAKE) install-binary
69
70mkdir-bin:
71	$(INSTALL) -d $(BINDIR)
72
73# install binary without (re-)compilation
74install-binary: mkdir-bin
75	$(INSTALL_PROGRAM) $(RHASH_BINARY) $(BINDIR)/$(RHASH_BINARY)
76
77install-man:
78	$(INSTALL) -d $(MANDIR)/man1
79	$(INSTALL_DATA) dist/rhash.1 $(MANDIR)/man1/rhash.1
80
81install-conf:
82	$(INSTALL) -d $(SYSCONFDIR)
83	tr -d \\r < dist/rhashrc.sample > rc.tmp && $(INSTALL_DATA) rc.tmp $(SYSCONFDIR)/rhashrc.sample
84	rm -f rc.tmp
85
86# dependencies should be properly set, otherwise 'make -j<n>' can fail
87install-symlinks: mkdir-bin install-man install-binary
88	cd $(BINDIR) && for f in $(SYMLINKS); do $(LN_S) $(RHASH_BINARY) $$f$(EXEC_EXT); done
89	cd $(MANDIR)/man1 && for f in $(SYMLINKS); do $(LN_S) rhash.1 $$f.1; done
90
91install-pkg-config:
92	$(INSTALL) -d $(PKGCONFIGDIR)
93	$(INSTALL_DATA) $(LIBRHASH_PC) $(PKGCONFIGDIR)/
94
95uninstall-binary:
96	rm -f $(BINDIR)/$(RHASH_BINARY)
97
98uninstall-data:
99	rm -f $(MANDIR)/man1/rhash.1
100
101uninstall-symlinks:
102	for f in $(SYMLINKS); do rm -f $(BINDIR)/$$f$(EXEC_EXT) $(MANDIR)/man1/$$f.1; done
103
104uninstall-pkg-config:
105	rm -f $(PKGCONFIGDIR)/librhash.pc
106
107uninstall-lib:
108	+cd librhash && $(MAKE) uninstall-lib
109
110install-lib-static: $(LIBRHASH_STATIC) install-lib-headers
111	+cd librhash && $(MAKE) install-lib-static
112
113install-lib-shared: $(LIBRHASH_SHARED)
114	+cd librhash && $(MAKE) install-lib-shared
115
116install-lib-headers:
117	+cd librhash && $(MAKE) install-lib-headers
118
119install-lib-so-link:
120	+cd librhash && $(MAKE) install-so-link
121
122$(LIBRHASH_SHARED): $(LIBRHASH_FILES)
123	+cd librhash && $(MAKE) lib-shared
124
125$(LIBRHASH_STATIC): $(LIBRHASH_FILES)
126	+cd librhash && $(MAKE) lib-static
127
128test-lib: test-lib-$(BUILD_TYPE)
129test-lib-static: $(LIBRHASH_STATIC)
130	+cd librhash && $(MAKE) test-static
131
132test-lib-shared: $(LIBRHASH_SHARED)
133	+cd librhash && $(MAKE) test-shared
134
135test-libs: $(LIBRHASH_STATIC) $(LIBRHASH_SHARED)
136	+cd librhash && $(MAKE) test-static test-shared
137
138test-full:
139	+$(MAKE) TEST_OPTIONS=--full test
140
141test: test-$(BUILD_TYPE)
142test-static: $(RHASH_STATIC)
143	/bin/sh tests/test_rhash.sh $(TEST_OPTIONS) ./$(RHASH_STATIC)
144
145test-shared: $(RHASH_SHARED)
146	/bin/sh tests/test_rhash.sh --shared $(TEST_OPTIONS) ./$(RHASH_SHARED)
147
148print-info: lib-$(BUILD_TYPE)
149	+cd librhash && $(MAKE) print-info
150
151# check that source tree is consistent
152check:
153	grep -q '\* === Version $(VERSION) ===' ChangeLog
154	grep -q '^#define VERSION "$(VERSION)"' version.h
155	test ! -f bindings/version.properties || grep -q '^version=$(VERSION)$$' bindings/version.properties
156
157$(RHASH_STATIC): $(OBJECTS) $(LIBRHASH_STATIC)
158	$(CC) $(OBJECTS) $(LIBRHASH_STATIC) $(BIN_STATIC_LDFLAGS) -o $@
159
160$(RHASH_SHARED): $(OBJECTS) $(LIBRHASH_SHARED)
161	$(CC) $(OBJECTS) $(LIBRHASH_SHARED) $(LDFLAGS) -o $@
162
163# NOTE: dependences were generated by 'gcc -Ilibrhash -MM *.c'
164# we are using plain old makefile style to support BSD make
165calc_sums.o: calc_sums.c platform.h calc_sums.h common_func.h file.h \
166 hash_check.h hash_print.h output.h parse_cmdline.h rhash_main.h \
167 win_utils.h librhash/rhash.h librhash/rhash_torrent.h
168	$(CC) -c $(CFLAGS) $< -o $@
169
170common_func.o: common_func.c common_func.h parse_cmdline.h version.h \
171 win_utils.h
172	$(CC) -c $(CFLAGS) $< -o $@
173
174file.o: file.c file.h common_func.h platform.h win_utils.h
175	$(CC) -c $(CFLAGS) $< -o $@
176
177file_mask.o: file_mask.c file_mask.h common_func.h
178	$(CC) -c $(CFLAGS) $< -o $@
179
180file_set.o: file_set.c file_set.h calc_sums.h common_func.h file.h \
181 hash_check.h hash_print.h output.h parse_cmdline.h rhash_main.h \
182 librhash/rhash.h
183	$(CC) -c $(CFLAGS) $< -o $@
184
185find_file.o: find_file.c platform.h find_file.h common_func.h file.h \
186 output.h win_utils.h
187	$(CC) -c $(CFLAGS) $< -o $@
188
189hash_check.o: hash_check.c hash_check.h hash_print.h common_func.h \
190 output.h parse_cmdline.h librhash/rhash.h
191	$(CC) -c $(CFLAGS) $< -o $@
192
193hash_print.o: hash_print.c hash_print.h calc_sums.h common_func.h file.h \
194 hash_check.h output.h parse_cmdline.h win_utils.h librhash/rhash.h
195	$(CC) -c $(CFLAGS) $< -o $@
196
197hash_update.o: hash_update.c calc_sums.h common_func.h file.h \
198 hash_check.h file_set.h file_mask.h hash_print.h hash_update.h output.h \
199 parse_cmdline.h rhash_main.h win_utils.h
200	$(CC) -c $(CFLAGS) $< -o $@
201
202output.o: output.c platform.h calc_sums.h common_func.h file.h \
203 hash_check.h output.h parse_cmdline.h rhash_main.h win_utils.h \
204 librhash/rhash.h
205	$(CC) -c $(CFLAGS) $< -o $@
206
207parse_cmdline.o: parse_cmdline.c parse_cmdline.h common_func.h file.h \
208 file_mask.h find_file.h hash_print.h output.h rhash_main.h win_utils.h \
209 librhash/rhash.h
210	$(CC) -c $(CFLAGS) $(CONFCFLAGS) $< -o $@
211
212rhash_main.o: rhash_main.c rhash_main.h calc_sums.h common_func.h file.h \
213 hash_check.h file_mask.h find_file.h hash_print.h hash_update.h \
214 parse_cmdline.h output.h win_utils.h librhash/rhash.h
215	$(CC) -c $(CFLAGS) $(LOCALECFLAGS) $< -o $@
216
217win_utils.o: win_utils.c win_utils.h common_func.h file.h parse_cmdline.h \
218 rhash_main.h
219	$(CC) -c $(CFLAGS) $< -o $@
220
221dist/rhash.1.win.html: dist/rhash.1 dist/rhash.1.win.sed
222	sed -f dist/rhash.1.win.sed dist/rhash.1 | rman -fHTML -roff | \
223	sed -e '/<BODY/s/\(bgcolor=\)"[^"]*"/\1"white"/i' > dist/rhash.1.win.html
224#	verify the result
225	grep -q "utf8" dist/rhash.1.win.html
226	grep -q "APPDATA" dist/rhash.1.win.html
227
228dist/rhash.1.html: dist/rhash.1
229	-which rman 2>/dev/null && (rman -fHTML -roff dist/rhash.1 | sed -e '/<BODY/s/\(bgcolor=\)"[^"]*"/\1"white"/i' > $@)
230
231dist/rhash.1.txt: dist/rhash.1
232	-which groff &>/dev/null && (groff -t -e -mandoc -Tascii dist/rhash.1 | sed -e 's/.\[[0-9]*m//g' > $@)
233
234permissions:
235	find . build dist docs librhash po tests -maxdepth 1 -type f -exec chmod -x '{}' \;
236	chmod +x configure tests/test_rhash.sh
237
238copy-dist: $(ALL_FILES) permissions
239	rm -rf $(PACKAGE_NAME)
240	mkdir $(PACKAGE_NAME)
241	cp -rl --parents $(ALL_FILES) $(PACKAGE_NAME)/
242
243tgz-core: check
244	+$(MAKE) copy-dist PACKAGE_NAME=$(PACKAGE_NAME)-core
245	tar czf $(ARCHIVE_TARGZ_CORE) --owner=root --group=root $(PACKAGE_NAME)-core/
246	rm -rf $(PACKAGE_NAME)-core
247
248tgz-bindings:
249	+cd bindings && $(MAKE) gzip ARCHIVE_GZIP=../$(ARCHIVE_TARGZ_BINDINGS)
250
251tgz: check clean-bindings
252	+$(MAKE) copy-dist
253	+cd bindings && $(MAKE) copy-dist COPYDIR=../$(PACKAGE_NAME)/bindings
254	tar czf $(ARCHIVE_TARGZ) --owner=root:0 --group=root:0 $(PACKAGE_NAME)/
255	rm -rf $(PACKAGE_NAME)
256
257xz: check clean-bindings
258	+$(MAKE) copy-dist
259	+cd bindings && $(MAKE) copy-dist COPYDIR=../$(PACKAGE_NAME)/bindings
260	tar cJf $(ARCHIVE_XZ) --owner=root:0 --group=root:0 $(PACKAGE_NAME)/
261	rm -rf $(PACKAGE_NAME)
262
263$(ARCHIVE_ZIP): $(WIN_DIST_FILES) dist/rhash.1.win.html
264	test -s dist/rhash.1.win.html && test -x $(RHASH_BINARY)
265	-rm -rf $(WIN_ZIP_DIR)
266	mkdir $(WIN_ZIP_DIR)
267	cp $(RHASH_BINARY) ChangeLog $(WIN_DIST_FILES) $(WIN_ZIP_DIR)/
268	cp dist/rhash.1.win.html $(WIN_ZIP_DIR)/rhash-doc.html
269	zip -9r $(ARCHIVE_ZIP) $(WIN_ZIP_DIR)
270	rm -rf $(WIN_ZIP_DIR)
271
272$(ARCHIVE_TARGZ_DEB) : $(ALL_FILES)
273	+$(MAKE) tgz
274	mv -f $(ARCHIVE_TARGZ) $(ARCHIVE_TARGZ_DEB)
275
276# rpm packaging
277$(SPECFILE): $(SPECFILE).in config.mak
278	sed -e 's/@VERSION@/$(VERSION)/' $(SPECFILE).in > $(SPECFILE)
279
280rpm: tgz
281	-for i in $(RPMDIRS); do mkdir -p $(RPMTOP)/$$i; done
282	cp -f $(ARCHIVE_TARGZ) $(RPMTOP)/SOURCES
283	rpmbuild -ba --clean --define "_topdir `pwd`/$(RPMTOP)" $(SPECFILE)
284	mv -f `find $(RPMTOP) -name "*rhash*-$(VERSION)*.rpm"` .
285	rm -rf $(RPMTOP)
286
287clean-bindings:
288	+cd bindings && $(MAKE) clean
289
290clean-local:
291	rm -f *.o $(RHASH_SHARED) $(RHASH_STATIC)
292	rm -f po/*.gmo po/*.po~
293
294distclean: clean-local
295	rm -f config.log config.mak $(SPECFILE) $(LIBRHASH_PC)
296	+cd librhash && $(MAKE) distclean
297
298clean: clean-local
299	+cd librhash && $(MAKE) clean
300
301update-po:
302	xgettext *.c -k_ -cTRANSLATORS -o po/rhash.pot \
303		--msgid-bugs-address='Aleksey <rhash.admin@gmail.com>' --package-name='RHash'
304	for f in $(I18N_FILES); do \
305		msgmerge -U $$f po/rhash.pot; \
306	done
307
308compile-gmo:
309	for f in $(I18N_FILES); do \
310		g=`basename $$f .po`; \
311		msgfmt -o po/$$g.gmo $$f; \
312	done
313
314install-gmo: compile-gmo
315	for f in $(I18N_FILES); do \
316		l=`basename $$f .po`; \
317		$(INSTALL) -d $(LOCALEDIR)/$$l/LC_MESSAGES; \
318		$(INSTALL_DATA) po/$$l.gmo $(LOCALEDIR)/$$l/LC_MESSAGES/rhash.mo; \
319	done
320
321uninstall-gmo:
322	for f in $(I18N_FILES); do \
323		rm -f $(LOCALEDIR)/`basename $$f .po`/LC_MESSAGES/rhash.mo; \
324	done
325
326.PHONY: all build-shared build-static lib-shared lib-static clean clean-bindings distclean clean-local \
327	test test-shared test-static test-full test-lib test-libs test-lib-shared test-lib-static \
328	install build-install-binary install-binary install-lib-shared install-lib-static \
329	install-lib-headers install-lib-so-link install-conf install-data install-gmo install-man \
330	install-symlinks install-pkg-config uninstall-gmo uninstall-pkg-config \
331	uninstall uninstall-binary uninstall-data uninstall-lib uninstall-symlinks \
332	print-info check copy-dist update-po compile-gmo mkdir-bin permissions \
333	dgz dist tgz tgz-bindings tgz-core rpm win-dist xz zip
334