libzahl

big integer library
git clone git://git.suckless.org/libzahl
Log | Files | Refs | README | LICENSE

Makefile (5418B)


      1 .POSIX:
      2 
      3 CONFIG = config.mk
      4 include $(CONFIG)
      5 
      6 HDR_SEMIPUBLIC =\
      7 	zahl/inlines.h\
      8 	zahl/internals.h\
      9 	zahl/memory.h
     10 
     11 HDR_PRIVATE =\
     12 	src/internals.h
     13 
     14 FUN =\
     15 	zadd\
     16 	zand\
     17 	zbset\
     18 	zdivmod\
     19 	zerror\
     20 	zfree\
     21 	zgcd\
     22 	zload\
     23 	zlsh\
     24 	zmodmul\
     25 	zmodpow\
     26 	zmodpowu\
     27 	zmodsqr\
     28 	zmul\
     29 	znot\
     30 	zor\
     31 	zperror\
     32 	zpow\
     33 	zpowu\
     34 	zptest\
     35 	zrand\
     36 	zrsh\
     37 	zsets\
     38 	zsetup\
     39 	zsqr\
     40 	zstr\
     41 	zstr_length\
     42 	zsub\
     43 	ztrunc\
     44 	zunsetup\
     45 	zxor
     46 
     47 INLINE_FUN =\
     48 	zabs\
     49 	zbits\
     50 	zbtest\
     51 	zcmp\
     52 	zcmpi\
     53 	zcmpmag\
     54 	zcmpu\
     55 	zdiv\
     56 	zeven\
     57 	zeven_nonzero\
     58 	zinit\
     59 	zlsb\
     60 	zmod\
     61 	zneg\
     62 	zodd\
     63 	zodd_nonzero\
     64 	zsave\
     65 	zset\
     66 	zseti\
     67 	zsetu\
     68 	zsignum\
     69 	zsplit\
     70 	zswap\
     71 	zzero
     72 
     73 DOC =\
     74 	refsheet.pdf\
     75 	libzahl.pdf
     76 
     77 TEXSRC =\
     78 	doc/libzahl.tex\
     79 	doc/what-is-libzahl.tex\
     80 	doc/libzahls-design.tex\
     81 	doc/get-started.tex\
     82 	doc/miscellaneous.tex\
     83 	doc/arithmetic.tex\
     84 	doc/bit-operations.tex\
     85 	doc/number-theory.tex\
     86 	doc/random-numbers.tex\
     87 	doc/not-implemented.tex\
     88 	doc/exercises.tex
     89 
     90 HDR_PUBLIC = zahl.h $(HDR_SEMIPUBLIC)
     91 HDR        = $(HDR_PUBLIC) $(HDR_PRIVATE)
     92 OBJ        = $(FUN:=.o) allocator.o
     93 MAN3       = $(FUN:=.3) $(INLINE_FUN:=.3)
     94 MAN7       = libzahl.7
     95 
     96 VPATH = src
     97 
     98 BENCHMARK_LIB_            = libzahl.a
     99 BENCHMARK_LIB_zahl        = libzahl.a
    100 BENCHMARK_LIB_libzahl     = libzahl.a
    101 BENCHMARK_LIB_tommath     = -ltommath
    102 BENCHMARK_LIB_libtommath  = -ltommath
    103 BENCHMARK_LIB_gmp         = -lgmp
    104 BENCHMARK_LIB_libgmp      = -lgmp
    105 BENCHMARK_LIB_tfm         = libtfm.a
    106 BENCHMARK_LIB_libtfm      = libtfm.a
    107 BENCHMARK_LIB_hebimath    = libhebimath.a
    108 BENCHMARK_LIB_libhebimath = libhebimath.a
    109 
    110 BENCHMARK_DEP_            = libzahl.a
    111 BENCHMARK_DEP_zahl        = libzahl.a
    112 BENCHMARK_DEP_libzahl     = libzahl.a
    113 BENCHMARK_DEP_tommath     = bench/libtommath.h
    114 BENCHMARK_DEP_libtommath  = bench/libtommath.h
    115 BENCHMARK_DEP_gmp         = bench/libgmp.h
    116 BENCHMARK_DEP_libgmp      = bench/libgmp.h
    117 BENCHMARK_DEP_tfm         = bench/libtfm.h
    118 BENCHMARK_DEP_libtfm      = bench/libtfm.h
    119 BENCHMARK_DEP_hebimath    = bench/libhebimath.h
    120 BENCHMARK_DEP_libhebimath = bench/libhebimath.h
    121 
    122 BENCHMARK_CPP_tommath     = '-DBENCHMARK_LIB="libtommath.h"'
    123 BENCHMARK_CPP_libtommath  = '-DBENCHMARK_LIB="libtommath.h"'
    124 BENCHMARK_CPP_gmp         = '-DBENCHMARK_LIB="libgmp.h"'
    125 BENCHMARK_CPP_libgmp      = '-DBENCHMARK_LIB="libgmp.h"'
    126 BENCHMARK_CPP_tfm         = '-DBENCHMARK_LIB="libtfm.h"'
    127 BENCHMARK_CPP_libtfm      = '-DBENCHMARK_LIB="libtfm.h"'
    128 BENCHMARK_CPP_hebimath    = '-DBENCHMARK_LIB="libhebimath.h"'
    129 BENCHMARK_CPP_libhebimath = '-DBENCHMARK_LIB="libhebimath.h"'
    130 
    131 BENCHMARK_C_hebimath      = -static
    132 BENCHMARK_C_libhebimath   = -static
    133 
    134 CPPFLAGS += $(BENCHMARK_CPP_$(BENCHMARK_LIB))
    135 
    136 CFLAGS_WITHOUT_O = $$(printf '%s\n' $(CFLAGS) | sed '/^-O.*$$/d')
    137 
    138 
    139 all: libzahl.a $(DOC)
    140 
    141 .o: .c $(HDR) $(CONFIG)
    142 	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
    143 
    144 libzahl.a: $(OBJ)
    145 	$(AR) -rcs $@ $?
    146 
    147 test-random.c: test-generate.py
    148 	./test-generate.py > test-random.c
    149 
    150 test: test.c libzahl.a test-random.c
    151 	$(CC) $(LDFLAGS) $(CFLAGS_WITHOUT_O) -O0 $(CPPFLAGS) -o $@ test.c libzahl.a
    152 
    153 benchmark: bench/benchmark.c bench/util.c bench/util.h $(BENCHMARK_DEP_$(BENCHMARK_LIB))
    154 	$(CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS) -o $@ bench/benchmark.c bench/util.c \
    155 		$(BENCHMARK_LIB_$(BENCHMARK_LIB)) $(BENCHMARK_C_$(BENCHMARK_LIB))
    156 
    157 benchmark-func: bench/benchmark-func.c bench/util.c bench/util.h $(BENCHMARK_DEP_$(BENCHMARK_LIB))
    158 	$(CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS) -o $@ bench/benchmark-func.c bench/util.c \
    159 		$(BENCHMARK_LIB_$(BENCHMARK_LIB)) $(BENCHMARK_C_$(BENCHMARK_LIB))
    160 
    161 benchmark-zrand: bench/benchmark-zrand.c bench/util.c bench/util.h libzahl.a
    162 	$(CC) $(LDFLAGS) $(CFLAGS) $(CPPFLAGS) -o $@ bench/benchmark-zrand.c bench/util.c libzahl.a
    163 
    164 refsheet.pdf: doc/refsheet.tex
    165 	pdflatex doc/refsheet.tex </dev/null
    166 	pdflatex doc/refsheet.tex </dev/null
    167 	-@printf 'refsheet.%s\n' aux log | xargs rm -f --
    168 
    169 libzahl.pdf: $(TEXSRC)
    170 	pdflatex doc/libzahl.tex </dev/null
    171 	pdflatex doc/libzahl.tex </dev/null
    172 	-@printf 'libzahl.%s\n' aux idx log maf toc out | xargs rm -f -- libzahl.mtc*
    173 
    174 check: test
    175 	./test
    176 
    177 install: libzahl.a
    178 	mkdir -p -- "$(DESTDIR)$(EXECPREFIX)/lib"
    179 	mkdir -p -- "$(DESTDIR)$(PREFIX)/include/zahl"
    180 	mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man3"
    181 	mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7"
    182 	mkdir -p -- "$(DESTDIR)$(DOCPREFIX)/libzahl"
    183 	@if test -n "$(DESTDIR)"; then \
    184 		cd man && test -d "$(DESTDIR)$(MANPREFIX)/man7" || \
    185 		(printf '\n\n!!  DESTDIR must be an absolute path.  !!\n\n\n' ; exit 1) \
    186 	fi
    187 	cp -- libzahl.a "$(DESTDIR)$(EXECPREFIX)/lib"
    188 	cp -- zahl.h "$(DESTDIR)$(PREFIX)/include"
    189 	cp -- $(HDR_SEMIPUBLIC) "$(DESTDIR)$(PREFIX)/include/zahl"
    190 	cd man && cp -- $(MAN3) "$(DESTDIR)$(MANPREFIX)/man3"
    191 	cd man && cp -- $(MAN7) "$(DESTDIR)$(MANPREFIX)/man7"
    192 	cp -- $(DOC) "$(DESTDIR)$(DOCPREFIX)/libzahl"
    193 
    194 uninstall:
    195 	-rm -f -- "$(DESTDIR)$(EXECPREFIX)/lib/libzahl.a"
    196 	-cd -- "$(DESTDIR)$(PREFIX)/include" && rm -f $(HDR_PUBLIC)
    197 	-rmdir -- "$(DESTDIR)$(PREFIX)/include/zahl"
    198 	-cd -- "$(DESTDIR)$(MANPREFIX)/man3" && rm -f $(MAN3)
    199 	-cd -- "$(DESTDIR)$(MANPREFIX)/man7" && rm -f $(MAN7)
    200 	-cd -- "$(DESTDIR)$(DOCPREFIX)/libzahl" && rm -f $(DOC)
    201 	-rmdir -- "$(DESTDIR)$(DOCPREFIX)/libzahl"
    202 
    203 clean:
    204 	-rm -f -- *.o *.su *.a *.so test test-random.c
    205 	-rm -f -- benchmark benchmark-zrand benchmark-func
    206 	-rm -f -- *.aux *.log *.out *.idx *.maf *.mtc* *.toc
    207 	-rm -f -- refsheet.pdf refsheet.dvi refsheet.ps
    208 	-rm -f -- libzahl.pdf libzahl.dvi libzahl.ps
    209 
    210 .PHONY: all check install uninstall clean