libtommath/makefile

181 lines
6.9 KiB
Makefile
Raw Normal View History

2003-07-16 00:26:58 +00:00
#Makefile for GCC
#
#Tom St Denis
2004-12-23 02:40:37 +00:00
ifeq ($V,1)
silent=
else
silent=@
endif
2003-02-28 16:08:34 +00:00
#default files to install
2005-08-01 16:37:28 +00:00
ifndef LIBNAME
LIBNAME=libtommath.a
endif
2006-12-24 16:12:36 +00:00
coverage: LIBNAME:=-Wl,--whole-archive $(LIBNAME) -Wl,--no-whole-archive
include makefile_include.mk
2015-12-12 19:19:15 +00:00
2019-09-05 14:58:39 +00:00
%.o: %.c $(HEADERS)
2017-03-31 22:34:19 +00:00
ifneq ($V,1)
@echo " * ${CC} $@"
endif
${silent} ${CC} -c ${LTM_CFLAGS} $< -o $@
2017-03-31 22:34:19 +00:00
2015-12-12 19:19:15 +00:00
LCOV_ARGS=--directory .
2006-12-24 16:12:36 +00:00
2014-10-13 13:49:23 +00:00
#START_INS
OBJECTS=mp_2expt.o mp_abs.o mp_add.o mp_add_d.o mp_addmod.o mp_and.o mp_clamp.o mp_clear.o mp_clear_multi.o \
mp_cmp.o mp_cmp_d.o mp_cmp_mag.o mp_cnt_lsb.o mp_complement.o mp_copy.o mp_count_bits.o mp_cutoffs.o \
mp_decr.o mp_div.o mp_div_2.o mp_div_2d.o mp_div_3.o mp_div_d.o mp_dr_is_modulus.o mp_dr_reduce.o \
mp_dr_setup.o mp_error_to_string.o mp_exch.o mp_expt_u32.o mp_exptmod.o mp_exteuclid.o mp_fread.o \
mp_from_sbin.o mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o mp_get_i64.o mp_get_l.o \
mp_get_ll.o mp_get_mag_u32.o mp_get_mag_u64.o mp_get_mag_ul.o mp_get_mag_ull.o mp_grow.o mp_incr.o \
mp_init.o mp_init_copy.o mp_init_i32.o mp_init_i64.o mp_init_l.o mp_init_ll.o mp_init_multi.o mp_init_set.o \
mp_init_size.o mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_init_ull.o mp_invmod.o mp_is_square.o \
mp_iseven.o mp_isodd.o mp_kronecker.o mp_lcm.o mp_log_u32.o mp_lshd.o mp_mod.o mp_mod_2d.o mp_mod_d.o \
mp_montgomery_calc_normalization.o mp_montgomery_reduce.o mp_montgomery_setup.o mp_mul.o mp_mul_2.o \
mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_fermat.o \
mp_prime_frobenius_underwood.o mp_prime_is_prime.o mp_prime_miller_rabin.o mp_prime_next_prime.o \
mp_prime_rabin_miller_trials.o mp_prime_rand.o mp_prime_strong_lucas_selfridge.o mp_prime_tab.o \
mp_radix_size.o mp_radix_smap.o mp_rand.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o mp_reduce_2k_l.o \
mp_reduce_2k_setup.o mp_reduce_2k_setup_l.o mp_reduce_is_2k.o mp_reduce_is_2k_l.o mp_reduce_setup.o \
mp_root_u32.o mp_rshd.o mp_sbin_size.o mp_set.o mp_set_double.o mp_set_i32.o mp_set_i64.o mp_set_l.o \
mp_set_ll.o mp_set_u32.o mp_set_u64.o mp_set_ul.o mp_set_ull.o mp_shrink.o mp_signed_rsh.o mp_sqr.o \
mp_sqrmod.o mp_sqrt.o mp_sqrtmod_prime.o mp_sub.o mp_sub_d.o mp_submod.o mp_to_radix.o mp_to_sbin.o \
mp_to_ubin.o mp_ubin_size.o mp_unpack.o mp_xor.o mp_zero.o s_mp_add.o s_mp_balance_mul.o \
s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_bit.o \
s_mp_invmod_fast.o s_mp_invmod_slow.o s_mp_karatsuba_mul.o s_mp_karatsuba_sqr.o s_mp_log.o s_mp_log_d.o \
s_mp_log_pow2.o s_mp_montgomery_reduce_fast.o s_mp_mul_digs.o s_mp_mul_digs_fast.o s_mp_mul_high_digs.o \
s_mp_mul_high_digs_fast.o s_mp_prime_is_divisible.o s_mp_rand_jenkins.o s_mp_rand_platform.o \
s_mp_reverse.o s_mp_sqr.o s_mp_sqr_fast.o s_mp_sub.o s_mp_toom_mul.o s_mp_toom_sqr.o
2003-02-28 16:02:06 +00:00
2014-10-13 13:49:23 +00:00
#END_INS
2005-08-01 16:37:28 +00:00
$(LIBNAME): $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS)
$(RANLIB) $@
2003-02-28 16:08:34 +00:00
2004-08-09 22:15:59 +00:00
#make a profiled library (takes a while!!!)
#
# This will build the library with profile generation
# then run the test demo and rebuild the library.
2014-09-02 00:14:38 +00:00
#
2004-08-09 22:15:59 +00:00
# So far I've seen improvements in the MP math
profiled:
make CFLAGS="$(CFLAGS) -fprofile-arcs -DTESTING" timing
2018-02-02 09:09:08 +00:00
./timing
rm -f *.a *.o timing
2004-08-09 22:15:59 +00:00
make CFLAGS="$(CFLAGS) -fbranch-probabilities"
2014-09-02 00:14:38 +00:00
#make a single object profiled library
2004-08-09 22:15:59 +00:00
profiled_single:
perl gen.pl
$(CC) $(LTM_CFLAGS) -fprofile-arcs -DTESTING -c mpi.c -o mpi.o
$(CC) $(LTM_CFLAGS) -DTESTING -DTIMER demo/timing.c mpi.o -lgcov -o timing
2018-02-02 09:09:08 +00:00
./timing
rm -f *.o timing
$(CC) $(LTM_CFLAGS) -fbranch-probabilities -DTESTING -c mpi.c -o mpi.o
2005-08-01 16:37:28 +00:00
$(AR) $(ARFLAGS) $(LIBNAME) mpi.o
2014-09-02 00:14:38 +00:00
ranlib $(LIBNAME)
2004-08-09 22:15:59 +00:00
2005-08-01 16:37:28 +00:00
install: $(LIBNAME)
install -d $(DESTDIR)$(LIBPATH)
install -d $(DESTDIR)$(INCPATH)
install -m 644 $(LIBNAME) $(DESTDIR)$(LIBPATH)
install -m 644 $(HEADERS_PUB) $(DESTDIR)$(INCPATH)
2003-02-28 16:08:34 +00:00
2017-08-28 13:56:30 +00:00
uninstall:
rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
rm $(HEADERS_PUB:%=$(DESTDIR)$(INCPATH)/%)
2019-10-15 08:42:48 +00:00
DEMOS=test mtest_opponent
define DEMO_template
$(1): demo/$(1).o demo/shared.o $$(LIBNAME)
$$(CC) $$(LTM_CFLAGS) $$(LTM_LFLAGS) $$^ -o $$@
endef
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))
2014-10-18 18:20:30 +00:00
2014-10-14 12:36:01 +00:00
.PHONY: mtest
mtest:
cd mtest ; $(CC) $(LTM_CFLAGS) -O0 mtest.c $(LTM_LFLAGS) -o mtest
2014-09-02 00:14:38 +00:00
2018-02-02 09:09:08 +00:00
timing: $(LIBNAME) demo/timing.c
$(CC) $(LTM_CFLAGS) -DTIMER demo/timing.c $(LIBNAME) $(LTM_LFLAGS) -o timing
2003-02-28 16:06:22 +00:00
tune: $(LIBNAME)
$(MAKE) -C etc tune CFLAGS="$(LTM_CFLAGS)"
$(MAKE)
2017-08-25 11:01:23 +00:00
# You have to create a file .coveralls.yml with the content "repo_token: <the token>"
# in the base folder to be able to submit to coveralls
coveralls: lcov
coveralls-lcov
2019-10-20 16:27:56 +00:00
docs manual:
2017-05-09 12:01:11 +00:00
$(MAKE) -C doc/ $@ V=$(V)
2004-08-09 22:15:59 +00:00
2015-11-07 15:23:27 +00:00
.PHONY: pre_gen
pre_gen:
2018-04-11 21:20:46 +00:00
mkdir -p pre_gen
2015-11-07 15:23:27 +00:00
perl gen.pl
sed -e 's/[[:blank:]]*$$//' mpi.c > pre_gen/mpi.c
rm mpi.c
zipup: clean astyle new_file docs
2017-08-28 14:58:26 +00:00
@# Update the index, so diff-index won't fail in case the pdf has been created.
@# As the pdf creation modifies the tex files, git sometimes detects the
@# modified files, but misses that it's put back to its original version.
@git update-index --refresh
@git diff-index --quiet HEAD -- || ( echo "FAILURE: uncommited changes or not a git" && exit 1 )
rm -rf libtommath-$(VERSION) ltm-$(VERSION).*
@# files/dirs excluded from "git archive" are defined in .gitattributes
git archive --format=tar --prefix=libtommath-$(VERSION)/ HEAD | tar x
2018-02-02 11:08:58 +00:00
@echo 'fixme check'
-@(find libtommath-$(VERSION)/ -type f | xargs grep 'FIXM[E]') && echo '############## BEWARE: the "fixme" marker was found !!! ##############' || true
2017-08-28 14:58:26 +00:00
mkdir -p libtommath-$(VERSION)/doc
cp doc/bn.pdf libtommath-$(VERSION)/doc/
2018-04-11 21:20:46 +00:00
$(MAKE) -C libtommath-$(VERSION)/ pre_gen
2017-08-28 14:58:26 +00:00
tar -c libtommath-$(VERSION)/ | xz -6e -c - > ltm-$(VERSION).tar.xz
zip -9rq ltm-$(VERSION).zip libtommath-$(VERSION)
2018-12-31 11:13:59 +00:00
cp doc/bn.pdf bn-$(VERSION).pdf
2017-08-28 14:58:26 +00:00
rm -rf libtommath-$(VERSION)
gpg -b -a ltm-$(VERSION).tar.xz
gpg -b -a ltm-$(VERSION).zip
2014-10-14 12:36:01 +00:00
new_file:
perl helper.pl --update-files
perlcritic:
2017-12-08 05:49:00 +00:00
perlcritic *.pl doc/*.pl
2017-09-15 10:47:06 +00:00
c89:
@echo "Applying substitutions for c89 compatibility..."
@sed -i \
-e 's/#include <stdbool.h>//g' \
-e 's/#include <stdint.h>/#include "tommath_c89.h"/g' \
-e 's/bool/mp_bool/g' \
-e 's/true/MP_YES/g' \
-e 's/false/MP_NO/g' \
-e 's/uint\([0-9][0-9]*\)_t/mp_u\1/g' \
-e 's/int\([0-9][0-9]*\)_t/mp_i\1/g' \
*.c *.h demo/*.c demo/*.h etc/*.c
@echo "/* please adapt this header to your needs */" > tommath_c89.h
@echo "typedef enum { MP_NO, MP_YES } mp_bool;" >> tommath_c89.h
@echo "typedef __INT8_TYPE__ mp_i8;" >> tommath_c89.h
@echo "typedef __INT16_TYPE__ mp_i16;" >> tommath_c89.h
@echo "typedef __INT32_TYPE__ mp_i32;" >> tommath_c89.h
@echo "typedef __INT64_TYPE__ mp_i64;" >> tommath_c89.h
@echo "typedef __UINT8_TYPE__ mp_u8;" >> tommath_c89.h
@echo "typedef __UINT16_TYPE__ mp_u16;" >> tommath_c89.h
@echo "typedef __UINT32_TYPE__ mp_u32;" >> tommath_c89.h
@echo "typedef __UINT64_TYPE__ mp_u64;" >> tommath_c89.h
2017-09-15 10:47:06 +00:00
astyle:
2019-04-06 15:45:05 +00:00
@echo " * run astyle on all sources"
@astyle --options=astylerc --formatted $(OBJECTS:.o=.c) tommath*.h demo/*.c etc/*.c mtest/mtest.c