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

# the C compiler
CC = gcc

# the Ada Compiler
ADAC = $(CC)

# the C++ compiler
CPLUSPLUS = gcc

# Gnat1 compilation flags
GF = -O2

# Gnatbind binder flags
BF =
# Use this version to use SharedCLibrary instead of UnixLib
#BF = -mstubs -lgnat_cc

# Extension for ".o" files
o = o

# Extension for executable files
e =


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

main_rule : process
	obey

#-----------------------------------------------------------------------------
#                               EXAMPLES  Makefile
#-----------------------------------------------------------------------------
#
# Intructions to Add a new example
#
#   1. Update the variable LIST_EXEC with the new target (executable name).
#      Do not include any extensions; instead append $(e) to this name.
#
#   2. Add a new entry in the dependencies with the following format :
#       name_exec_DEP= {list of .o files needed to build the executable -
#         use $(o) as the extension instead of .o or .obj}
#       name_exec$(e) : name_exec.$(o) $(name_exec_DEP)
#-----------------------------------------------------------------------------

# Put here the final target of each test case.
# it can be a '.o' file if the test is just a compilation one
# otherwise it is the final executable
LIST_COMPILE_ONLY =
LIST_EXEC = textioexam$(e) useofimpor$(e) tgef$(e) tef$(e) \
 demo1$(e) demo2$(e) test_cl$(e) hello$(e)

#-----------------------------------------------------------------------------
# Dependencies

hello_DEP=
hello$(e) : hello.$(o) $(hello_DEP)
	gnatbl $@.ali $(hello_DEP) $(BF)
	$@

demo1_DEP=
demo1$(e) : demo1.$(o)  instr.$(o) $(demo1_DEP)
	gnatbl $@.ali $(demo1_DEP) $(BF)
	$@

demo2_DEP=
demo2$(e) : demo2.$(o) instr.$(o) instrchild.$(o) $(demo2_DEP)
	gnatbl $@.ali $(demo2_DEP) $(BF)
	$@

useofimpor_DEP = imported_function.$(o)
useofimpor$(e) : useofimpor.$(o) $(useofimpor_DEP)
	gnatbl useofimpor.ali $(useofimpor_DEP) $(BF)
	useofimpor

textioexam_DEP =
textioexam$(e) : textioexam.$(o) $(textioexam_DEP)
	gnatbl textioexam.ali $(textioexam_DEP) $(BF)
	textioexam

tgef_DEP =
tgef$(e) : tgef.$(o) $(tgef_DEP)
	gnatbl $@.ali $(tgef_DEP) $(BF)
	$@

tef_DEP =
tef$(e) : tef.$(o) $(tef_DEP)
	gnatbl $@.ali $(tef_DEP) $(BF)
	$@

ex6_main_DEP = ex6.$(o)
ex6_main.$(o) : ex6_main.adb ex6_if.ads
ex6_if.$(o) : ex6_if.ads ex6_if.adb

test_cl_DEP =
test_cl: test_cl.o
#test_cl.o: test_cl.adb

process : announce $(LIST_EXEC) clean
	obey

###############################################################################
# General rules
###############################################################################
.SUFFIXES: .adb .ads .ali .o
#.PHONY: clean process announce force

.adb.o:
	$(ADAC) -c $(GF)  $*.adb

.ads.o:
	$(ADAC) -c $(GF)  $*.ads

.c.o:
	$(CC) -c $(CFLAGS) $*.c

#% : %.o
#	gnatbl $@.ali $($@_DEP)
#	./$@

clean :
	/rm -f $(o) ali c.b_* i s __* $(LIST_EXEC)

announce :
	@echo
	@echo ANNOUNCES:
	@echo    * if you are interested by the C++ interface: try 'make ex6_main'
	@echo

force :

##############################################################################
# special stuff for the c++ interface
##############################################################################

ex6.o :
	@echo if g++ is not installed on your standard 'gcc', the next command will fail
	$(CPLUSPLUS) -c ex6.cc


ex6_main$(e) : ex6_main.$(o) ex6_if.$(o) $(ex6_main_DEP)
	gnatbl ex6_main.ali ex6.$(o) -lstdc++ $(BF)
	./ex6_main$(e)

##############################################################################
# special exec for test_cl
##############################################################################
test_cl$(e) : test_cl.$(o)
	gnatbl test_cl.ali $(BF)
	@echo example kindly sent by Timothy J. Halloran
	test_cl arg1 arg2 arg3
	test_cl a bb cccccc   d eeeeeee ff
