# Choose one version of gcc to use throughout the build.
GCC = "C:\GNAT\2013\bin\gcc.exe"

all:
# Compile exported functions.
	gnatmake --GCC=$(GCC) -c ada_sample
	$(GCC) -c c_sample.c
	ghc --make haskell_sample.hs
	
# Prepare Ada for linking.
	gnatbind -n ada_sample
	gnatlink --GCC=$(GCC) -r -nostdlib ada_sample.ali -o ada.o

# Compile the C main program; link it to Ada, C, and Haskell
	ghc --make -no-hs-main -pgmc $(GCC) -pgml $(GCC) C_main.c haskell_sample c_sample.o ada.o -o C_main

# Compile the Haskell main program; link to Ada and C.
	ghc --make haskell_main -pgmc $(GCC) -pgml $(GCC) c_sample.o ada.o
	
# Compile the Ada main program.
	gnatmake --GCC=$(GCC) -c ada_main
# Generate code to intialize/finalize the Ada run time.
	gnatbind ada_main
# Compile Ada init/final code and link it together with the Ada main program.
	gnatlink --GCC=$(GCC) -nostdlib -r ada_main.ali -o ada_main_program.o

# Link the Ada main program to C and Haskell.
	ghc --make -no-hs-main -pgmc $(GCC) -pgml $(GCC) haskell_sample c_sample.o ada_main_program.o -o Ada_main
