#-----------------------------------------------------------------------------
#                               EXAMPLES  Makefile
#-----------------------------------------------------------------------------

# the C compiler
CC = gcc

# the Ada Compiler
ADAC = $(CC)

# the C++ compiler
CPLUSPLUS = c++

# Gnat1 compilation flags
GF = -O2

# Gnatbind binder flags
BF =

# Extension for ".o" files
o = o

# Extension for executable files
e =

LIST_EXEC = \
  hello$e \
  text_io_example$e \
  use_of_import$e   \
  tgef$e            \
  tef$e             \
  demo1$e           \
  demo2$e           \
  test_cl$e         \
  diners$e          \
  ex6_main          \
  cpp_main


#-----------------------------------------------------------------------------
# Main rule

all : clean $(LIST_EXEC) 

clean : force
	@/bin/rm -f *.$o *.ali b_*.c *.s *~ $(LIST_EXEC)

force :

# hello
########
hello$e:
	gnatmake hello$e -cargs $(GF)
	./hello$e

# text_io_example
#################
text_io_example$e:
	gnatmake text_io_example$e -cargs $(GF)
	./text_io_example$e


# use_of_import
###############
use_of_import$e: imported_function.o
	gnatmake use_of_import$e -cargs $(GF) -largs imported_function.o
	./use_of_import$e

# tgef
######
tgef$e:
	gnatmake tgef$e -cargs $(GF)
	./tgef$e
# tef
######
tef$e:
	gnatmake tef$e -cargs $(GF)
	./tef$e

# demo1
#######
demo1$e:
	gnatmake demo1$e -cargs $(GF)
	./demo1$e

# demo2
#######
demo2$e:
	gnatmake demo2$e -cargs $(GF)
	./demo2$e < demo2.rsp

# test_cl
#########
test_cl$e: imported_function.$o
	gnatmake test_cl
	./test_cl arg1 arg2 arg3
	@echo ""
	./test_cl a bb cccccc   d eeeeeee ff

# diners
########
diners$e:
	gnatmake diners$e -cargs $(GF)
	./diners$e

# ex6_main
##########
ex6.o :
	@echo -n "if c++ is not installed, the next command will fail"
	$(CPLUSPLUS) -c ex6.C


ex6_main$e: ex6.o
	gnatmake ex6_main -cargs $(GF) -bargs -C -largs -C ex6.$o -lstdc++ --GCC=$(CPLUSPLUS)
	./ex6_main$e

# cpp_main
##########
ex7.o :
	$(CPLUSPLUS) -c ex7.C

cpp_main.o :
	$(CPLUSPLUS) -c cpp_main.C

cpp_main$e: ex7.o cpp_main.o
	gnatmake -c simple_cpp_interface
	gnatbind -n simple_cpp_interface
	gnatlink simple_cpp_interface -o cpp_main --LINK=$(CPLUSPLUS) -lstdc++ ex7.o cpp_main.o

.PHONY: clean force


