# -*-Makefile-*-

HOST = i486-linux
CPU = i386
GCC = gcc
GCCFLAGS = -O2 -fomit-frame-pointer -DHAVE_LONGLONG
LN = ln -s
RM = rm -f
SED = sed
ROFF_MAN = groff -Tascii -mandoc

all : vacall-i386-macro.S vacall-i386-msvc.c vacall-i386-mingw32.c vacall-m68k.mit.S vacall-m68k.mot.s vacall-mips.S vacall-mipsn32.S vacall-mips64.S vacall-sparc.S vacall-sparc64.S vacall-alpha.s vacall-hppa.s vacall-arm.S vacall-rs6000-aix.old.s vacall-rs6000-aix.new.s vacall-rs6000-sysv4.s vacall-rs6000-macos.s vacall-m88k.s vacall-convex.s vacall-ia64.s vacall-x86_64.s vacall.man \
      vacall.h.msvc config.h.msvc vacall.h.mingw32 config.h.mingw32

vacall-i386-macro.S : vacall-i386.c vacall.h.in asmi386.sh
	$(GCC) -V 2.7.2 -b i486-linuxaout $(GCCFLAGS) -D__i386__ -S vacall-i386.c -o vacall-i386.s
	(echo '#include "asmi386.h"' ; sed -e '/\.align.*,0x90$$/d' < vacall-i386.s | ./asmi386.sh) > vacall-i386-macro.S
	$(RM) vacall-i386.s

vacall-i386-msvc.c : vacall-i386-macro.S
	(echo '#ifdef _MSC_VER' ; echo '#include "vacall.h"' ; echo '#endif' ; cat vacall-i386-macro.S) > vacall-i386-msvc.c

vacall-i386-mingw32.c : vacall-i386-macro.S
	(echo '#ifdef __MINGW32__' ; echo '#include "vacall.h"' ; echo '#endif' ; cat vacall-i386-macro.S) > vacall-i386-mingw32.c

vacall-m68k.mit.S : vacall-m68k.c vacall.h.in asmm68k.sh
	$(GCC) -V 2.95.2 -b m68k-sun $(GCCFLAGS) -D__m68k__ -S vacall-m68k.c -o vacall-m68k.mit.s
	(echo '#include "asmm68k.h"' ; ./asmm68k.sh < vacall-m68k.mit.s) > vacall-m68k.mit.S
	$(RM) vacall-m68k.mit.s

vacall-m68k.mot.s : vacall-m68k.c vacall.h.in
	$(GCC) -V 2.95.2 -b m68k-linux $(GCCFLAGS) -D__m68k__ -S vacall-m68k.c -o vacall-m68k.mot.s

vacall-mips.S : vacall-mips.c vacall.h.in asmmips.sh
	$(GCC) -V 2.95.2 -b mips-sgi $(GCCFLAGS) -D__mips__ -fno-omit-frame-pointer -S vacall-mips.c -o vacall-mips.s
	(echo '#include "asmmips.h"' ; ./asmmips.sh < vacall-mips.s) > vacall-mips.S
	$(RM) vacall-mips.s

vacall-mipsn32.S : vacall-mipsn32.c vacall.h.in asmmips.sh
	$(GCC) -V 2.95.2 -b mips-sgi-irix6 $(GCCFLAGS) -D__mipsn32__ -S vacall-mipsn32.c -o vacall-mipsn32.s
	(echo '#include "asmmips.h"' ; $(SED) -e 's/\$$sp,\$$sp,192/$$sp,$$sp,256/' -e 's/\$$sp,192,/$$sp,256,/' < vacall-mipsn32.s | ./asmmips.sh) > vacall-mipsn32.S
	$(RM) vacall-mipsn32.s

vacall-mips64.S : vacall-mips64.c vacall.h.in asmmips.sh
	$(GCC) -V 2.95.2 -b mips-sgi -mips3 -mlong64 $(GCCFLAGS) -U__mips__ -D__mips64__ -S vacall-mips64.c -o vacall-mips64.s
	(echo '#include "asmmips.h"' ; ./asmmips.sh < vacall-mips64.s) > vacall-mips64.S
	$(RM) vacall-mips64.s

vacall-sparc.S : vacall-sparc.c vacall.h.in asmsparc.sh
	$(GCC) -V 2.95.2 -b sparc-sun $(GCCFLAGS) -D__sparc__ -S vacall-sparc.c -o vacall-sparc.s
	(echo '#include "asmsparc.h"' ; ./asmsparc.sh < vacall-sparc.s) > vacall-sparc.S
	$(RM) vacall-sparc.s

vacall-sparc64.S : vacall-sparc64.c vacall.h.in asmsparc.sh
	sparc64-linux-gcc -V 2.95.2 -b sparc64-linux $(GCCFLAGS) -D__sparc64__ -S vacall-sparc64.c -o vacall-sparc64.s
	(echo '#include "asmsparc.h"' ; ./asmsparc64.sh < vacall-sparc64.s) > vacall-sparc64.S
	$(RM) vacall-sparc64.s

vacall-alpha.s : vacall-alpha.c vacall.h.in
	$(GCC) -V 2.7.2 -b alpha-dec-osf $(GCCFLAGS) -D__alpha__ -S vacall-alpha.c -o vacall-alpha-temp.s
	cat < vacall-alpha-temp.s > vacall-alpha.s
	$(RM) vacall-alpha-temp.s

vacall-hppa.s : vacall-hppa.c vacall.h.in
	$(GCC) -V 2.6.3 -b hppa1.0-hpux $(GCCFLAGS) -D__hppa__ -S vacall-hppa.c -o vacall-hppa.s

vacall-arm.S : vacall-arm.c vacall.h.in asmarm.sh
	$(GCC) -V 2.6.3 -b arm-acorn-riscix $(GCCFLAGS) -D__arm__ -S vacall-arm.c -o vacall-arm.s
	(echo '#include "asmarm.h"' ; ./asmarm.sh < vacall-arm.s) > vacall-arm.S
	$(RM) vacall-arm.s

vacall-rs6000-aix.old.s : vacall-rs6000.c vacall.h.in
	$(GCC) -V 2.95.2 -b rs6000 -mno-power -mno-power2 -mno-powerpc -mold-mnemonics $(GCCFLAGS) -D__rs6000__ -S vacall-rs6000.c -o vacall-rs6000-aix.old.s

vacall-rs6000-aix.new.s : vacall-rs6000.c vacall.h.in
	$(GCC) -V 2.95.2 -b rs6000 -mno-power -mno-power2 -mno-powerpc -mnew-mnemonics $(GCCFLAGS) -D__rs6000__ -S vacall-rs6000.c -o vacall-rs6000-aix.new.s

vacall-rs6000-sysv4.s : vacall-rs6000.c vacall.h.in
	$(GCC) -V 2.95.2 -b ppc-linux -mno-power -mno-power2 -mno-powerpc $(GCCFLAGS) -D__rs6000__ -S vacall-rs6000.c -o vacall-rs6000-sysv4.s

vacall-rs6000-macos.s : vacall-rs6000.c vacall.h.in
	$(GCC) -V 3.3.2 -b powerpc-darwin $(GCCFLAGS) -D__rs6000__ -S vacall-rs6000.c -o vacall-rs6000-macos.s

vacall-m88k.s : vacall-m88k.c vacall.h.in
	$(GCC) -V 2.95.2 -b m88k-dgux $(GCCFLAGS) -D__m88k__ -S vacall-m88k.c -o vacall-m88k.s

vacall-convex.s : vacall-convex.c vacall.h.in
	$(GCC) -V 2.6.3 -b convex-c2 $(GCCFLAGS) -D__convex__ -S vacall-convex.c -o vacall-convex.s

vacall-ia64.s : vacall-ia64.c vacall.h.in
	$(GCC) -V 2.9-ia64-000216 -b ia64-hp-linux $(GCCFLAGS) -D__ia64__ -S vacall-ia64.c -o vacall-ia64.s

vacall-x86_64.s : vacall-x86_64.c vacall.h.in
	$(GCC) -V 3.2.2 -b x86_64-suse-linux $(GCCFLAGS) -D__x86_64__ -S vacall-x86_64.c -o vacall-x86_64.s

vacall.man : vacall.3
	$(ROFF_MAN) vacall.3 > vacall.man

vacall.h.msvc : vacall.h.in
	sed -e 's,^#undef __i386__$$,#define __i386__ 1,' -e 's,^#undef __SMALL_STRUCT_RETURN__$$,#define __SMALL_STRUCT_RETURN__ 1,' < vacall.h.in > vacall.h.msvc

vacall.h.mingw32 : vacall.h.in
	sed -e 's,^#undef __i386__$$,#define __i386__ 1,' -e 's,^#undef __SMALL_STRUCT_RETURN__$$,#define __SMALL_STRUCT_RETURN__ 1,' < vacall.h.in > vacall.h.mingw32

config.h.msvc : config.h.in
	cp config.h.in config.h.msvc

config.h.mingw32 : config.h.in
	cp config.h.in config.h.mingw32

tests : tests-i386.s tests-m68k.s tests-mips.s tests-sparc.s tests-alpha.s tests-hppa.s tests-arm.s tests-rs6000.s tests-m88k.s tests-convex.s tests-ia64.s tests-x86_64.s
	true

tests-i386.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.7.2 -b i486-linuxaout $(GCCFLAGS) -I/usr/include -D__i386__ -S tests.c -o tests-i386.s
	$(RM) vacall.h

tests-m68k.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.95.2 -b m68k-sun $(GCCFLAGS) -I/usr/include -D__m68k__ -S tests.c -o tests-m68k.s
	$(RM) vacall.h

tests-mips.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.95.2 -b mips-sgi $(GCCFLAGS) -I/usr/include -D__mips__ -S tests.c -o tests-mips.s
	$(RM) vacall.h

tests-sparc.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.95.2 -b sparc-sun $(GCCFLAGS) -I/usr/include -D__sparc__ -S tests.c -o tests-sparc.s
	$(RM) vacall.h

tests-alpha.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.7.2 -b alpha-dec-osf $(GCCFLAGS) -I/usr/include -D__alpha__ -S tests.c -o tests-alpha.s
	$(RM) vacall.h

tests-hppa.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.6.3 -b hppa1.0-hpux $(GCCFLAGS) -I/usr/include -D__hppa__ -S tests.c -o tests-hppa.s
	$(RM) vacall.h

tests-arm.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.6.3 -b arm-acorn-riscix $(GCCFLAGS) -I/usr/include -D__arm__ -S tests.c -o tests-arm.s
	$(RM) vacall.h

tests-rs6000.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.95.2 -b rs6000 $(GCCFLAGS) -I/usr/include -D__rs6000__ -S tests.c -o tests-rs6000.s
	$(RM) vacall.h

tests-m88k.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.95.2 -b m88k-dgux $(GCCFLAGS) -I/usr/include -D__m88k__ -S tests.c -o tests-m88k.s
	$(RM) vacall.h

tests-convex.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.6.3 -b convex-c2 $(GCCFLAGS) -I/usr/include -D__convex__ -S tests.c -o tests-convex.s
	$(RM) vacall.h

tests-ia64.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 2.9-ia64-000216 -b ia64-hp-linux $(GCCFLAGS) -I/usr/include -D__ia64__ -S tests.c -o tests-ia64.s
	$(RM) vacall.h

tests-x86_64.s : tests.c vacall.h.in
	$(LN) vacall.h.in vacall.h
	$(GCC) -V 3.2.2 -b x86_64-suse-linux $(GCCFLAGS) -I/usr/include -D__x86_64__ -S tests.c -o tests-x86_64.s
	$(RM) vacall.h

