Generate precomputed tables as sources in `precomps/'.
[u/mdw/catacomb] / math / Makefile.am
index 5bb546c..dfc5b58 100644 (file)
@@ -200,17 +200,20 @@ pkginclude_HEADERS        += limlee.h
 libmath_la_SOURCES     += limlee.c
 
 ## A table of small prime numbers.
-nodist_pkginclude_HEADERS += primetab.h
-nodist_libmath_la_SOURCES += primetab.c
-CLEANFILES             += primetab.h primetab.c
-BUILT_SOURCES          += primetab.h primetab.c
-noinst_PROGRAMS                += genprimes
+pkginclude_HEADERS     += $(precomp)/primetab.h
+libmath_la_SOURCES     += $(precomp)/primetab.c
+PRECOMPS               += $(precomp)/primetab.h $(precomp)/primetab.c
+PRECOMP_PROGS          += genprimes
 genprimes_LDADD                 = $(mLib_LIBS)
-primetab.h: primetab.c
-primetab.c: genprimes$e
-       $(AM_V_GEN)./genprimes -hprimetab.h -cprimetab.c \
-               -sCATACOMB_PRIMETAB_H \
+if !CROSS_COMPILING
+$(precomp)/primetab.h: $(precomp)/primetab.c
+$(precomp)/primetab.c:
+       $(AM_V_at)$(MKDIR_P) $(precomp)
+       $(AM_V_at)$(MAKE) genprimes$e
+       $(AM_V_GEN)./genprimes -sCATACOMB_PRIMETAB_H \
+               -h$(precomp)/primetab.h -c$(precomp)/primetab.c \
                -n256 -t"unsigned short" -iprimetab
+endif
 
 ## Filtering candidate prime numbers by checking for small factors
 ## efficiently.
@@ -235,7 +238,7 @@ libmath_la_SOURCES  += prim.c
 pkginclude_HEADERS     += primeiter.h
 libmath_la_SOURCES     += primeiter.c
 TESTS                  += primeiter.$t
-primeiter.lo: wheel.h
+primeiter.lo: $(precomp)/wheel.h
 
 ## The Miller--Rabin primality test.
 pkginclude_HEADERS     += rabin.h
@@ -247,16 +250,20 @@ pkginclude_HEADERS        += strongprime.h
 libmath_la_SOURCES     += strongprime.c
 
 ## A `wheel', used by the prime iteration machinery.
-nodist_pkginclude_HEADERS += wheel.h
-nodist_libmath_la_SOURCES += wheel.c
-CLEANFILES             += wheel.h wheel.c
-noinst_PROGRAMS                += genwheel
+pkginclude_HEADERS     += $(precomp)/wheel.h
+libmath_la_SOURCES     += $(precomp)/wheel.c
+PRECOMPS               += $(precomp)/wheel.h $(precomp)/wheel.c
+PRECOMP_PROGS          += genwheel
 genwheel_LDADD          = $(mLib_LIBS)
-wheel.h: wheel.c
-wheel.c: genwheel$e
-       $(AM_V_GEN)./genwheel -hwheel.h -cwheel.c \
-               -sCATACOMB_WHEEL_H \
+if !CROSS_COMPILING
+$(precomp)/wheel.h: $(precomp)/wheel.c
+$(precomp)/wheel.c:
+       $(AM_V_at)$(MKDIR_P) $(precomp)
+       $(AM_V_at)$(MAKE) genwheel$e
+       $(AM_V_GEN)./genwheel -sCATACOMB_WHEEL_H \
+               -h$(precomp)/wheel.h -c$(precomp)/wheel.c \
                -n5 -t"unsigned char" -iwheel
+endif
 
 ###--------------------------------------------------------------------------
 ### Binary polynomial arithmetic.
@@ -276,14 +283,17 @@ libmath_la_SOURCES        += gfx.c
 TESTS                  += gfx.$t
 libmath_la_SOURCES     += gfx-kmul.c
 TESTS                  += gfx-kmul.$t
-libmath_la_SOURCES     += gfx-sqr.c
-gfx-sqr.lo: gfx-sqr-tab.h
+libmath_la_SOURCES     += gfx-sqr.c $(precomp)/gfx-sqrtab.c
+PRECOMPS               += $(precomp)/gfx-sqrtab.c
+PRECOMP_PROGS          += gfx-sqr-mktab
+if !CROSS_COMPILING
+$(precomp)/gfx-sqrtab.c:
+       $(AM_V_at)$(MKDIR_P) $(precomp)
+       $(AM_V_at)$(MAKE) gfx-sqr-mktab$e
+       $(AM_V_GEN)./gfx-sqr-mktab >$(precomp)/gfx-sqrtab.c.new && \
+               mv $(precomp)/gfx-sqrtab.c.new $(precomp)/gfx-sqrtab.c
+endif
 TESTS                  += gfx-sqr.$t
-CLEANFILES             += gfx-sqr-tab.h
-noinst_PROGRAMS                += gfx-sqr-mktab
-gfx-sqr-tab.h: gfx-sqr-mktab$e
-       $(AM_V_GEN)./gfx-sqr-mktab >gfx-sqr-tab.h.in && \
-               mv gfx-sqr-tab.h.in gfx-sqr-tab.h
 EXTRA_DIST             += t/gfx
 
 ## Conversions between normal and polynomial basis representations for binary