#
# A "simple" Makefile to compile a C driver for the Conway Life Example
#
#

# this Makefiles uses GNU make extensions
include babel.make		# get files generated by Babel
STUBOBJS=$(STUBSRCS:.c=.lo)	# libtool objects
ALLOBJS=$(STUBSRCS:.c=.lo)	# all libtool objects
ALLSOBJS=$(STUBSRCS:.c=.o)	# all raw objects
ALLSTATICS=$(STUBSRCS:.c=.lo)	# .lo is used for statically linked objects
ALLSRCS=$(STUBSRCS)
#ifeq ($(BABEL_WITH_F90),1)
#SIDLFILES=../life.sidl ../libC/clife.sidl ../libCxx/cxxlife.sidl \
#	../libF90/f90life.sidl
#ALLLIBS= ../libC/libcconway.la ../libCxx/libcxxconway.la ../libF90/libf90conway.la
#else
SIDLFILES=../life.sidl ../libC/clife.sidl ../libCxx/cxxlife.sidl ../libF90/f90life.sidl
ALLLIBS= ../libC/libcconway.la ../libCxx/libcxxconway.la ../libF90/libf90conway.la 
#endif


all : my_driver	rmi_driver		#statically linked executable

babel-stamp: $(SIDLFILES)
	@rm -f babel-temp
	@touch babel-temp
	babel --client=C $(SIDLFILES)
	@mv -f babel-temp $@

$(ALLSRCS) : babel-stamp
	if test -f $@; then \
	  touch $@; \
	else \
	  rm -f babel-stamp; \
	  $(MAKE) $(MAKEFLAGS) babel-stamp; \
	fi

# Note: we use GNU libtool in a peculiar way, actually installing it
# with the rest of Babel as ... babel-libtool

my_driver : babel-stamp $(ALLOBJS) my_driver.lo 
	babel-cxx -g -o my_driver --with-f90 -static $(ALLSOBJS) my_driver.o ../libC/libcconway.la ../libCxx/libcxxconway.la  ../libF90/libf90conway.la 

rmi_driver : babel-stamp $(ALLOBJS) rmi_driver.lo 
	babel-cc -o rmi_driver -lsidlx $(ALLOBJS) rmi_driver.lo 

clean: new
	$(RM) *.o *.lo

# source files are generated, so its okay to remove most
# but not IMPLs!

new:
	$(RM) my_driver rmi_driver babel-stamp $(STUBHDRS) $(STUBSRCS) \
	$(IORHDRS) $(IORSRCS) $(SKELHDRS) $(SKELSRCS)

.SUFFIXES:
.SUFFIXES: .c .cxx .lo .o

.c.lo:
	babel-cc -g -c --with-f90 ${CFLAGS} $< 

.cxx.lo:
	babel-cxx -g -c ${CXXFLAGS} $<
