## @configure_input@
##
## @file    Makefile
## @brief   Builds the C# example programs
## @author  Akiya Jouraku
##
## <!--------------------------------------------------------------------------
## This file is part of libSBML.  Please visit http://sbml.org for more
## information about SBML, and the latest version of libSBML.
##
## Copyright (C) 2013-2018 jointly by the following organizations:
##     1. California Institute of Technology, Pasadena, CA, USA
##     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
##     3. University of Heidelberg, Heidelberg, Germany
##
## Copyright (C) 2009-2013 jointly by the following organizations: 
##     1. California Institute of Technology, Pasadena, CA, USA
##     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
##  
## Copyright (C) 2006-2008 by the California Institute of Technology,
##     Pasadena, CA, USA 
##  
## Copyright (C) 2002-2005 jointly by the following organizations: 
##     1. California Institute of Technology, Pasadena, CA, USA
##     2. Japan Science and Technology Agency, Japan
## 
## This library is free software; you can redistribute it and/or modify it
## under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation.  A copy of the license agreement is provided
## in the file named "LICENSE.txt" included with this software distribution
## and also available online as http://sbml.org/software/libsbml/license.html
## ------------------------------------------------------------------------ -->

# -----------------------------------------------------------------------------
#  # 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.
# ----------------------------------------------------------------------------

