# developer -*-Makefile-*-

HOST = i486-linux
CPU = i386
GCC = gcc
GCCFLAGS = -O2 -fomit-frame-pointer -DHAVE_LONG_LONG_INT -DREENTRANT
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-m68k-netbsd.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-armel.s vacall-powerpc-aix.old.s vacall-powerpc-aix.new.s vacall-powerpc-sysv4.s vacall-powerpc-macos.s vacall-powerpc64.s vacall-m88k.s vacall-convex.s vacall-ia64.s vacall-x86_64.s \
      vacall_r.h.msvc config.h.msvc vacall_r.h.mingw32 config.h.mingw32

vacall-i386-macro.S : vacall-i386.c vacall_r.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_r.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_r.h"' ; echo '#endif' ; cat vacall-i386-macro.S) > vacall-i386-mingw32.c

vacall-m68k.mit.S : vacall-m68k.c vacall_r.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_r.h.in
	$(GCC) -V 2.95.2 -b m68k-linux $(GCCFLAGS) -D__m68k__ -S vacall-m68k.c -o vacall-m68k.mot.s

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

vacall-mips.S : vacall-mips.c vacall_r.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_r.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_r.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_r.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_r.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_r.h.in
	$(GCC) -V 2.7.2 -b alpha-dec-osf $(GCCFLAGS) -D__alpha__ -S vacall-alpha.c -o vacall-alpha-temp.s
	$(SED) -e '/ldgp/d' < vacall-alpha-temp.s > vacall-alpha.s
	$(RM) vacall-alpha-temp.s

vacall-hppa.s : vacall-hppa.c vacall_r.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_r.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-armel.s : vacall-armel.c vacall_r.h.in
	$(GCC) $(GCCFLAGS) -D__arm__ -D__ARMEL__ -DHAVE_LONG_LONG -fomit-frame-pointer -S vacall-armel.c -o vacall-armel.s

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

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

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

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

vacall-powerpc64.s : vacall-powerpc64.c vacall_r.h.in
	/cross/powerpc64-linux-tools/bin/powerpc64-linux-gcc $(GCCFLAGS) -D__powerpc64__ -S vacall-powerpc64.c -o vacall-powerpc64.s

vacall-m88k.s : vacall-m88k.c vacall_r.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_r.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_r.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_r.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_r.man : vacall_r.3
	$(ROFF_MAN) vacall_r.3 > vacall_r.man

VERSION = $(shell cat ../../VERSION)

vacall_r.h.msvc : vacall_r.h.in ../../VERSION
	sed -e 's,^#undef __i386__$$,#define __i386__ 1,' \
	    -e 's,@LIBFFCALL_VERSION@,$(VERSION),' \
	    -e 's,^#undef __SMALL_STRUCT_RETURN__$$,#define __SMALL_STRUCT_RETURN__ 1,' < vacall_r.h.in > vacall_r.h.msvc

vacall_r.h.mingw32 : vacall_r.h.in ../../VERSION
	sed -e 's,^#undef __i386__$$,#define __i386__ 1,' \
	    -e 's,@LIBFFCALL_VERSION@,$(VERSION),' \
	    -e 's,^#undef __SMALL_STRUCT_RETURN__$$,#define __SMALL_STRUCT_RETURN__ 1,' < vacall_r.h.in > vacall_r.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
