# Copyright (C) 2000 Free Software Foundation, Inc.
# This makefile.mpw is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

VERSION 	= @version@

C		= @cc@
COptions	= @coptions@
Link		= @link@
LinkOptions	= @linkoptions@
ToolOptions     = @tooloptions@
Asm		= @asm@
AOptions	= @aoptions@

Lib	= "libgmp.{VERSION}"

# These are only needed for creating test programs as MPW tools


SysLibs		= @syslibs@

# Where to put object code. The reason we don't put them into
# the same directory is that some objectfiles have the same
# name.

MpfObjDir	= :MpfObj:
MpnObjDir	= :MpnObj:
MpqObjDir	= :MpqObj:
MpzObjDir	= :MpzObj:
CmnObjDir	= :CmnObj:
AsmObjDir	= :AsmObj:
AsmSrcDir	= :Asm:
MpfBinDir	= :MpfBin:
MpqBinDir	= :MpqBin:
MpzBinDir	= :MpzBin:

ObjDirs		= {MpfObjDir} {MpnObjDir} {MpqObjDir} {MpzObjDir} @c@
		  {CmnObjDir} {AsmObjDir} {AsmSrcDir} @c@
                  {MpfBinDir} {MpqBinDir} {MpzBinDir}

###########################################################################

MpfObjs = @c@
	{MpfObjDir}init.o {MpfObjDir}init2.o {MpfObjDir}set.o @c@
	{MpfObjDir}set_ui.o {MpfObjDir}set_si.o {MpfObjDir}set_str.o @c@
	{MpfObjDir}set_d.o {MpfObjDir}set_z.o {MpfObjDir}set_q.o @c@
	{MpfObjDir}iset.o {MpfObjDir}iset_ui.o {MpfObjDir}iset_si.o @c@
	{MpfObjDir}iset_str.o {MpfObjDir}iset_d.o {MpfObjDir}clear.o @c@
	{MpfObjDir}get_str.o {MpfObjDir}dump.o {MpfObjDir}size.o @c@
	{MpfObjDir}eq.o {MpfObjDir}reldiff.o {MpfObjDir}sqrt.o @c@
	{MpfObjDir}random2.o {MpfObjDir}inp_str.o {MpfObjDir}out_str.o @c@
	{MpfObjDir}add.o {MpfObjDir}add_ui.o {MpfObjDir}sub.o @c@
	{MpfObjDir}sub_ui.o {MpfObjDir}ui_sub.o {MpfObjDir}mul.o @c@
	{MpfObjDir}mul_ui.o {MpfObjDir}div.o {MpfObjDir}div_ui.o @c@
	{MpfObjDir}cmp.o {MpfObjDir}cmp_ui.o {MpfObjDir}cmp_si.o @c@
	{MpfObjDir}mul_2exp.o {MpfObjDir}div_2exp.o {MpfObjDir}abs.o @c@
	{MpfObjDir}neg.o {MpfObjDir}get_d.o {MpfObjDir}set_dfl_prec.o @c@
	{MpfObjDir}set_prc.o {MpfObjDir}set_prc_raw.o {MpfObjDir}get_prc.o @c@
	{MpfObjDir}ui_div.o {MpfObjDir}sqrt_ui.o {MpfObjDir}pow_ui.o @c@
	{MpfObjDir}urandom.o

MpnObjs = @c@
	@mpn_objects@

MpqObjs = @c@
	{MpqObjDir}add.o {MpqObjDir}canonicalize.o {MpqObjDir}clear.o @c@
	{MpqObjDir}cmp.o {MpqObjDir}cmp_ui.o {MpqObjDir}div.o @c@
	{MpqObjDir}get_d.o {MpqObjDir}get_den.o {MpqObjDir}get_num.o @c@
	{MpqObjDir}init.o {MpqObjDir}inv.o {MpqObjDir}mul.o @c@
	{MpqObjDir}neg.o {MpqObjDir}set.o {MpqObjDir}set_den.o @c@
	{MpqObjDir}set_num.o {MpqObjDir}set_si.o {MpqObjDir}set_ui.o @c@
	{MpqObjDir}sub.o {MpqObjDir}equal.o {MpqObjDir}set_z.o

MpzObjs = @c@
	{MpzObjDir}abs.o {MpzObjDir}add.o {MpzObjDir}add_ui.o @c@
	{MpzObjDir}addmul_ui.o {MpzObjDir}and.o {MpzObjDir}array_init.o @c@
	{MpzObjDir}bin_ui.o {MpzObjDir}bin_uiui.o {MpzObjDir}cdiv_q.o @c@
	{MpzObjDir}cdiv_q_ui.o {MpzObjDir}cdiv_qr.o {MpzObjDir}cdiv_qr_ui.o @c@
	{MpzObjDir}cdiv_r.o {MpzObjDir}cdiv_r_ui.o {MpzObjDir}cdiv_ui.o @c@
	{MpzObjDir}clear.o {MpzObjDir}clrbit.o {MpzObjDir}cmp.o @c@
	{MpzObjDir}cmp_si.o {MpzObjDir}cmp_ui.o {MpzObjDir}cmp_abs.o @c@
	{MpzObjDir}cmp_abs_ui.o {MpzObjDir}com.o {MpzObjDir}divexact.o @c@
	{MpzObjDir}dump.o {MpzObjDir}fac_ui.o {MpzObjDir}fdiv_q.o @c@
	{MpzObjDir}fdiv_q_2exp.o {MpzObjDir}fdiv_q_ui.o {MpzObjDir}fdiv_qr.o @c@
	{MpzObjDir}fdiv_qr_ui.o {MpzObjDir}fdiv_r.o {MpzObjDir}fdiv_r_2exp.o @c@
	{MpzObjDir}fdiv_r_ui.o {MpzObjDir}fdiv_ui.o {MpzObjDir}fib_ui.o @c@
	{MpzObjDir}gcd.o {MpzObjDir}gcd_ui.o {MpzObjDir}gcdext.o @c@
	{MpzObjDir}get_d.o {MpzObjDir}get_si.o {MpzObjDir}get_str.o @c@
	{MpzObjDir}get_ui.o {MpzObjDir}getlimbn.o {MpzObjDir}hamdist.o @c@
	{MpzObjDir}init.o {MpzObjDir}inp_raw.o {MpzObjDir}inp_str.o @c@
	{MpzObjDir}invert.o {MpzObjDir}ior.o {MpzObjDir}iset.o @c@
	{MpzObjDir}iset_d.o {MpzObjDir}iset_si.o {MpzObjDir}iset_str.o @c@
	{MpzObjDir}iset_ui.o {MpzObjDir}jacobi.o {MpzObjDir}lcm.o @c@
	{MpzObjDir}legendre.o {MpzObjDir}mod.o {MpzObjDir}mul.o @c@
	{MpzObjDir}mul_2exp.o {MpzObjDir}mul_ui.o {MpzObjDir}neg.o @c@
	{MpzObjDir}out_raw.o {MpzObjDir}out_str.o {MpzObjDir}perfpow.o @c@
	{MpzObjDir}perfsqr.o {MpzObjDir}popcount.o {MpzObjDir}pow_ui.o @c@
	{MpzObjDir}powm.o {MpzObjDir}powm_ui.o {MpzObjDir}pprime_p.o @c@
	{MpzObjDir}random.o {MpzObjDir}random2.o {MpzObjDir}realloc.o @c@
	{MpzObjDir}remove.o {MpzObjDir}root.o {MpzObjDir}scan0.o @c@
	{MpzObjDir}scan1.o {MpzObjDir}set.o {MpzObjDir}set_d.o @c@
	{MpzObjDir}set_f.o {MpzObjDir}set_q.o {MpzObjDir}set_si.o @c@
	{MpzObjDir}set_str.o {MpzObjDir}set_ui.o {MpzObjDir}setbit.o @c@
	{MpzObjDir}size.o {MpzObjDir}sizeinbase.o {MpzObjDir}sqrt.o @c@
	{MpzObjDir}sqrtrem.o {MpzObjDir}sub.o {MpzObjDir}sub_ui.o @c@
	{MpzObjDir}swap.o {MpzObjDir}tdiv_ui.o {MpzObjDir}tdiv_q.o @c@
	{MpzObjDir}tdiv_q_2exp.o {MpzObjDir}tdiv_q_ui.o {MpzObjDir}tdiv_qr.o @c@
	{MpzObjDir}tdiv_qr_ui.o {MpzObjDir}tdiv_r.o {MpzObjDir}tdiv_r_2exp.o @c@
	{MpzObjDir}tdiv_r_ui.o {MpzObjDir}tstbit.o {MpzObjDir}ui_pow_ui.o @c@
	{MpzObjDir}urandom.o {MpzObjDir}xor.o

CmnObjs = @c@
	{CmnObjDir}assert.o {CmnObjDir}memory.o {CmnObjDir}mp_set_fns.o @c@
	{CmnObjDir}mp_clz_tab.o {CmnObjDir}rand.o {CmnObjDir}randui.o @c@
	{CmnObjDir}randclr.o {CmnObjDir}randlc.o {CmnObjDir}randlcui.o @c@
	{CmnObjDir}version.o {CmnObjDir}stack-alloc.o {CmnObjDir}mp_bpl.o @c@
	{CmnObjDir}extract-dbl.o {CmnObjDir}insert-dbl.o

AsmObjs = @asm_objects@

AsmSrc = @asm_sources@


Objs = {AsmObjs} {MpfObjs} {MpnObjs} {MpqObjs} {MpzObjs} {CmnObjs}


###########################################################################

all	@dep@ {Lib}

{Lib} @dep@ {Objs} Makefile
	{Link} {LinkOptions} -o {Lib} {Objs}


###########################################################################
# Default rules/ directory rules

{MpfObjDir} @dep@ ::mpf:

{MpnObjDir} @dep@ ::mpn: ::mpn:generic:

{MpqObjDir} @dep@ ::mpq:

{MpzObjDir} @dep@ ::mpz:

{CmnObjDir} @dep@ ::

{AsmObjDir} @dep@ :Asm:

{MpzBinDir} @dep@ ::mpz:tests:
{MpqBinDir} @dep@ ::mpq:tests:
{MpfBinDir} @dep@ ::mpf:tests:

.o	@dep@ .c Makefile
	{C} {DepDir}{default}.c -o {TargDir}{default}.o {COptions}

.o	@dep@ .s Makefile
	{Asm} {DepDir}{default}.s -o {TargDir}{default}.o {AOptions}


clean @dep@
	Delete -c -i {Lib}
	Delete    -y {ObjDirs}
	Delete -c -i config.h
	Delete -c -i configure.mac
	Delete -c -i Makefile
	Delete -c -i RunTests
	Delete -c -i ::mpz:tests:@wildcard@.o
	Delete -c -i ::mpq:tests:@wildcard@.o
	Delete -c -i ::mpf:tests:@wildcard@.o
	Delete -c -i @wildcard@~

###########################################################################
# Test application FIXME: Not ready

TestApp = test
TestObj = test.o

{TestApp} @dep@ {TestObj}
	{Link} -o {TestApp} {TestObj} {Lib} {SysLibs}


###########################################################################
# FIXME: This does't work very well.....
# FIXME: Find dependency somehow. With the Unix mkdep like
#   mkdep -I. -Imacos -Impn -Impn/powerpc32 -Impz \
#     `find . -name "*.c" | grep -v Apple | grep -v tests | grep -v macos`
# or some MPW tool.

.exe @dep@ .o
	{Link} {ToolOptions} -o {TargDir}{default}.exe {DepDir}{default}.o {Lib} {SysLibs}


check @dep@ check-mpz check-mpq check-mpf

check-mpz @dep@ z-mul z-tdiv z-tdiv_ui z-fdiv z-fdiv_ui @c@
		z-gcd z-dive z-sqrtrem z-convert z-logic z-bit @c@
		z-powm z-powm_ui z-pow_ui z-2exp z-reuse z-root

# FIXME: Left out z-io, can't compile it.

z-mul @dep@ {MpzBinDir}t-mul.exe
	{MpzBinDir}t-mul.exe

z-tdiv @dep@ {MpzBinDir}t-tdiv.exe
	{MpzBinDir}t-tdiv.exe

z-tdiv_ui @dep@ {MpzBinDir}t-tdiv_ui.exe
	{MpzBinDir}t-tdiv_ui.exe

z-fdiv @dep@ {MpzBinDir}t-fdiv.exe
	{MpzBinDir}t-fdiv.exe

z-fdiv_ui @dep@ {MpzBinDir}t-fdiv_ui.exe
	{MpzBinDir}t-fdiv_ui.exe

z-gcd @dep@ {MpzBinDir}t-gcd.exe
	{MpzBinDir}t-gcd.exe

z-dive @dep@ {MpzBinDir}dive.exe
	{MpzBinDir}dive.exe

z-sqrtrem @dep@ {MpzBinDir}t-sqrtrem.exe
	{MpzBinDir}t-sqrtrem.exe

z-convert @dep@ {MpzBinDir}convert.exe
	{MpzBinDir}convert.exe

z-io @dep@ {MpzBinDir}io.exe
	{MpzBinDir}io.exe

z-logic @dep@ {MpzBinDir}logic.exe
	{MpzBinDir}logic.exe

z-bit @dep@ {MpzBinDir}bit.exe
	{MpzBinDir}bit.exe

z-powm @dep@ {MpzBinDir}t-powm.exe
	{MpzBinDir}t-powm.exe

z-powm_ui @dep@ {MpzBinDir}t-powm_ui.exe
	{MpzBinDir}t-powm_ui.exe

z-pow_ui @dep@ {MpzBinDir}t-pow_ui.exe
	{MpzBinDir}t-pow_ui.exe

z-2exp @dep@ {MpzBinDir}t-2exp.exe
	{MpzBinDir}t-2exp.exe

z-reuse @dep@ {MpzBinDir}reuse.exe
	{MpzBinDir}reuse.exe

z-root @dep@ {MpzBinDir}t-root.exe
	{MpzBinDir}t-root.exe


check-mpq @dep@ q-cmp q-cmp_ui q-get_d

q-cmp @dep@ {MpqBinDir}t-cmp.exe
	{MpqBinDir}t-cmp.exe

q-cmp_ui @dep@ {MpqBinDir}t-cmp_ui.exe
	{MpqBinDir}t-cmp_ui.exe

q-get_d @dep@ {MpqBinDir}t-get_d.exe
	{MpqBinDir}t-get_d.exe


check-mpf @dep@ f-add f-sub f-conv f-sqrt f-muldiv f-dm2exp f-reuse f-get_d

{MpfBinDir}t-add.exe @dep@ ::mpf:tests:t-add.o ::mpf:tests:ref.o
	{Link} {ToolOptions} -o {Targ} {Deps} {Lib} {SysLibs}

{MpfBinDir}t-sub.exe @dep@ ::mpf:tests:t-sub.o ::mpf:tests:ref.o
	{Link} {ToolOptions} -o {Targ} {Deps} {Lib} {SysLibs}

f-add @dep@ {MpfBinDir}t-add.exe
	{MpfBinDir}t-add.exe

f-sub @dep@ {MpfBinDir}t-sub.exe
	{MpfBinDir}t-sub.exe

f-conv @dep@ {MpfBinDir}t-conv.exe
	{MpfBinDir}t-conv.exe

f-sqrt @dep@ {MpfBinDir}t-sqrt.exe
	{MpfBinDir}t-sqrt.exe

f-muldiv @dep@ {MpfBinDir}t-muldiv.exe
	{MpfBinDir}t-muldiv.exe

f-dm2exp @dep@ {MpfBinDir}t-dm2exp.exe
	{MpfBinDir}t-dm2exp.exe

f-reuse @dep@ {MpfBinDir}reuse.exe
	{MpfBinDir}reuse.exe

f-get_d @dep@ {MpfBinDir}t-get_d.exe
	{MpfBinDir}t-get_d.exe
