## @configure_input@
##
## @file    Makefile
## @brief   Builds the C# example programs
## @author  Akiya Jouraku
##
## $Id: Makefile.in 8704 2009-01-04 02:26:05Z mhucka $
## $HeadURL: http://sbml.svn.sourceforge.net/svnroot/sbml/trunk/libsbml/examples/csharp/Makefile.in $
##
## This file is part of libSBML.  Please visit http://sbml.org for more
## information about SBML, and the latest version of libSBML.
##

# -----------------------------------------------------------------------------
#  # Configuration variables
# -----------------------------------------------------------------------------
# Some of the following are substituted automatically by `configure'.  If
# you are looking at "Makefile", do not edit these values; instead, run the
# configure script at the top level of the src tree.  It will recreate
# "Makefile".
#
include @top_srcdir@/config/makefile-common-vars.mk

# `srcdir' points to the current directory, but should be set by configure.
# `subdir' must be set manually to the relative dir under srcdir.  Don't
# set `subdir' to an absolute path, or some make actions will fail.

srcdir    = @srcdir@
thisdir   = examples/csharp

#
# DLL of libSBML C# proxy classes
#
csproxy_lib = ../../src/bindings/csharp/libsbmlcsP.dll

# 
# command line options for Mono
#
ifeq (Mono,$(findstring Mono,$(shell $(CSHARP_COMPILER) --version 2>&1)))
  CSC_OPT_SHARED = -target:library
  CSC_OPT_EXE    = -target:exe
  CSC_OPT_OUTPUT = -out:
  CSC_OPT_REF    = -r:
endif

# 
# command line options for Portable.NET
#
#  (*NOTICE*) 
#    Currently (2008-07-25), runtime implementation of Portable.NET (ilrun) 
#    doesn't seem to work for libSBML C# binding. 
#    Although C# DLL can be built by cscc, a segmentation fault happens 
#    when an executable file is launched by ilrun. 
#
ifeq (cscc,$(findstring cscc,$(shell $(CSHARP_COMPILER) --version 2>&1)))
  CSC_OPT_SHARED = -shared
  CSC_OPT_EXE    =
  CSC_OPT_OUTPUT = -o 
  CSC_OPT_REF    = -l
endif

#
# Target C# source files (and the corresponding .exe files)
#
cs_files  = $(wildcard *.cs)
exe_files = $(cs_files:.cs=.exe) 

all: Makefile check_csproxy_lib $(exe_files)

check_csproxy_lib:
ifeq "@USE_CSHARP@" ""
	@echo "libSBML must be configured with --with-csharp to use the C# bindings."
	exit 1
else
	@if ! test -f "$(csproxy_lib)"; then \
	  echo ;\
	  echo "[ERROR] $(csproxy_lib) doesn't exist." ; \
	  echo "Please build $(csproxy_lib) in ../../src/bindings/csharp/ directory."; \
	  exit 1 ; \
	fi;
endif


# The following is the generic rule for making a .exe file from one of
# the .csfiles in this directory.  

$(exe_files) : %.exe: %.cs
	"$(CSHARP_COMPILER)" $(CSC_OPT_EXE) $(CSC_OPT_OUTPUT)$@ $(CSC_OPT_REF)$(csproxy_lib) $<

# The rest of the commands here are general-purpose things.

clean:
	-rm -f $(exe_files) *~

distclean: clean
	-rm Makefile

# The following are generic 'make' targets that are not used in
# this simple examples directory.

check dist docs install install-docs uninstall \
mostlyclean maintainer-clean installcheck dvi pdf ps info html \
distcheck:

#-----------------------------------------------------------------------------
# Miscellaneous
#-----------------------------------------------------------------------------

include @top_srcdir@/config/makefile-common-actions.mk

#-----------------------------------------------------------------------------
#End.
#-----------------------------------------------------------------------------
