## @configure_input@
##
## @file    Makefile.in
## @brief   Makefile template for libSBML CSharp bindings
##          This file is based on Makefile.in for SWIG Java bindings 
##          written by Michael Hucka and Ben Kovitz 
## @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           = src/bindings/csharp

# -----------------------------------------------------------------------------
# To avoid Windows specific encoding problem in SWIG/C#, additional directives 
# are used in SWIG interface file (local.i) only for Windows.
# Thus, generated wrapper files (libsbml_wrap*.cpp and *.cs files) are different 
# between Windows and non-Windows platforms as follows:
#
# (Windows)
#   1) libsbml_wrap-win.cpp
#   2) csharp-files-win/*.cs
#   -----------------------------------------------------------------------
#    These files can be built by using one of Visual Studio solution files 
#    (CSharp_binding_win32-*.sln) in this directory.
#   -----------------------------------------------------------------------
#
# (Other platforms)
#   1) libsbml_wrap.cpp
#   2) csharp-files/*.cs
#   ------------------------------------------------------------------------
#    These files can be built by running make with this Makefile.
#    Currently, Mono is required to build C# DLL (by gmcs or mcs) and run an 
#    executable file (by mono).
#
#    (*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. 
#  --------------------------------------------------------------------------
#
# -----------------------------------------------------------------------------
sources           = \
                     libsbml_wrap.cpp \
                     libsbml_wrap.h 

extra_sources     = \
                     libsbml.i \
                     local.cpp \
                     local.i \
					 local-downcast-extension-layout.i \
					 local-downcast-extension.i.in \
					 local-downcast-astplugins.i.in \
					 local-downcast-converters.i.in \
					 local-downcast-converters-layout.i \
					 local-downcast-namespaces-layout.i \
					 local-downcast-namespaces.i.in \
					 local-packages-layout.i \
					 local-packages.i.in \
					 local-downcast-extension-l3v2extendedmath.i \
					 local-downcast-astplugins-l3v2extendedmath.i \
					 local-downcast-namespaces-l3v2extendedmath.i \
					 local-packages-l3v2extendedmath.i \

test_dir          = test
test_source_path  = $(test_dir)

check_runner_source_cvt = TestRunner.cs Compiler.cs
check_runner_source_man = TestRW.cs

assembly_info_source    = Properties/AssemblyInfo.cs 
assembly_info_source_tr = Properties/AssemblyInfoTR.cs 

# Test*.cs are not implemented yet
test_sources        = $(wildcard $(test_source_path)/**/Test*.cs)
check_sources       = $(test_sources) $(check_runner_source_cvt) $(check_runner_source_man) 

assembly_name     = libsbmlcsP
csproxy_lib       = ${assembly_name}.dll
dllimport_name    = libsbmlcs
dllimport_lib     = $(dllimport_name).$(CSHARP_EXT)

sn_keyfile = libsbmlcs.snk

# There are two libraries to build: the shared native library file used for
# Platform Invocation Service, and the CSharp proxy class DLL file.

libraries         = $(csproxy_lib) $(dllimport_lib)


#############################################################################
#
# Generates $(dllimport_name).$(CSHARP_EXT) (C++ library for DllImport) with 
# an object file in this directory (libsbml_wrap.o) and other object files 
# in sub directories in 'src' directory (src/sbml, src/common, ... ) instead
# of linking a shared library of libSBML (libsbml.$(SHAREDLIBEXT)).
#

#
# All directories that contain *.{c,cpp} (implementation) files of libSBML need 
# to be listed in the following 'otherdirs' variable.
#
otherdirs = ../../sbml/common ../../sbml/util ../../sbml/xml \
	    ../../sbml/math ../../sbml/validator ../../sbml/validator/constraints \
	    ../../sbml/units ../../sbml/annotation ../../sbml/compress \
            ../../sbml/ ../../sbml/extension


ifdef USE_COMP
  otherdirs += ../../sbml/packages/comp/common \
               ../../sbml/packages/comp/extension \
               ../../sbml/packages/comp/sbml \
               ../../sbml/packages/comp/util \
               ../../sbml/packages/comp/validator \
               ../../sbml/packages/comp/validator/constraints 
endif
ifdef USE_FBC
  otherdirs += ../../sbml/packages/fbc/common \
               ../../sbml/packages/fbc/extension \
               ../../sbml/packages/fbc/sbml \
               ../../sbml/packages/fbc/util \
               ../../sbml/packages/fbc/validator \
               ../../sbml/packages/fbc/validator/constraints 
endif
ifdef USE_GROUPS
  otherdirs += ../../sbml/packages/groups/common \
               ../../sbml/packages/groups/extension \
               ../../sbml/packages/groups/sbml \
               ../../sbml/packages/groups/validator \
               ../../sbml/packages/groups/validator/constraints 
endif
ifdef USE_LAYOUT
  otherdirs += ../../sbml/packages/layout/common \
               ../../sbml/packages/layout/extension \
               ../../sbml/packages/layout/sbml \
               ../../sbml/packages/layout/util \
               ../../sbml/packages/layout/validator \
               ../../sbml/packages/layout/validator/constraints 
endif
ifdef USE_QUAL
  otherdirs += ../../sbml/packages/qual/common \
               ../../sbml/packages/qual/extension \
               ../../sbml/packages/qual/sbml \
               ../../sbml/packages/qual/validator \
               ../../sbml/packages/qual/validator/constraints 
endif
ifdef USE_MULTI
  otherdirs += ../../sbml/packages/multi/common \
               ../../sbml/packages/multi/extension \
               ../../sbml/packages/multi/sbml \
               ../../sbml/packages/multi/validator \
               ../../sbml/packages/multi/validator/constraints 
endif
ifdef USE_RENDER
  otherdirs += ../../sbml/packages/render/common \
               ../../sbml/packages/render/extension \
               ../../sbml/packages/render/sbml \
               ../../sbml/packages/render/validator \
               ../../sbml/packages/render/validator/constraints 
endif
ifdef USE_L3V2EXTENDEDMATH
  otherdirs += ../../sbml/packages/l3v2extendedmath/common \
               ../../sbml/packages/l3v2extendedmath/extension \
               ../../sbml/packages/l3v2extendedmath/validator \
               ../../sbml/packages/l3v2extendedmath/validator/constraints 
endif

objfiles  = libsbml_wrap.lo $(wildcard $(addsuffix /*.lo,$(otherdirs)))


#############################################################################


# Variables `subdirs', `headers', `sources', `libraries', `extra_CPPFLAGS',
# `extra_CXXFLAGS', `extra_LDFLAGS' and `distfiles' are used by the default
# rules in `makefile-common-actions.mk' included at the end.

extra_CPPFLAGS    = $(CSHARP_CPPFLAGS) -I../swig
SWIGFLAGS        += $(CSHARP_SWIGFLAGS) -I../swig 
SWIGFLAGS_WIN     = -DSWIGWIN -DSWIG_CSHARP_NO_WSTRING_HELPER

extra_LDFLAGS     = $(CSHARP_LDFLAGS)

extra_LIBS        = ../../libsbml.la

ifdef USE_EXPAT
  extra_CPPFLAGS += @EXPAT_CPPFLAGS@
  extra_LDFLAGS  += @EXPAT_LDFLAGS@
  extra_LIBS     += @EXPAT_LIBS@
endif

ifdef USE_XERCES
  extra_CPPFLAGS += @XERCES_CPPFLAGS@
  extra_LDFLAGS  += @XERCES_LDFLAGS@
  extra_LIBS     += @XERCES_LIBS@
endif

ifdef USE_LIBXML
  extra_CPPFLAGS += @LIBXML_CPPFLAGS@
  extra_LDFLAGS  += @LIBXML_LDFLAGS@
  extra_LIBS     += @LIBXML_LIBS@
endif

# SBML package plug-ins
ifdef USE_COMP
  SWIGFLAGS      += -DUSE_COMP
  SWIGDOCDEFINES += --define USE_COMP
endif # USE_COMP  

ifdef USE_FBC
  SWIGFLAGS      += -DUSE_FBC
  SWIGDOCDEFINES += --define USE_FBC
endif # USE_FBC  

ifdef USE_GROUPS
  SWIGFLAGS      += -DUSE_GROUPS
  SWIGDOCDEFINES += --define USE_GROUPS
endif # USE_GROUPS  

ifdef USE_LAYOUT
  SWIGFLAGS      += -DUSE_LAYOUT
  SWIGDOCDEFINES += --define USE_LAYOUT
endif # USE_LAYOUT  

ifdef USE_QUAL
  SWIGFLAGS      += -DUSE_QUAL
  SWIGDOCDEFINES += --define USE_QUAL
endif # USE_QUAL  

ifdef USE_MULTI
  SWIGFLAGS      += -DUSE_MULTI
  SWIGDOCDEFINES += --define USE_MULTI
endif # USE_MULTI

ifdef USE_RENDER
  SWIGFLAGS      += -DUSE_RENDER
  SWIGDOCDEFINES += --define USE_RENDER
endif # USE_RENDER

ifdef USE_L3V2EXTENDEDMATH
  SWIGFLAGS      += -DUSE_L3V2EXTENDEDMATH
  SWIGDOCDEFINES += --define USE_L3V2EXTENDEDMATH
endif # USE_L3V2EXTENDEDMATH  


# -fno-strict-aliasing option is added to CXXFLAGS when using GCC.
# As written in the SWIG Manual (section 20.2.4), SWIG generated code could cause
# crash problems when compiled by GCC with -fstrict-aliasing option (automatically 
# enabled when using -O2 or higher optimization in GCC 3 or later) and the option 
# should be disabled by adding -fno-strict-aliasing option.
#
# Currently, we know that Java binding library causes crash when it is compiled by
# GCC 4 with -O2 or higher optimization, and the problem can be avoided by adding
# -fno-strict-aliasing option.

ifeq (GCC,$(findstring GCC,$(shell $(CXX) -dumpversion | sed -e 's/^[34]\./GCC/' )))
      CXXFLAGS += -fno-strict-aliasing
endif

# For Linux/Unix LD_LIBRARY_PATH *may* need to contain one or more library
# paths to libsbml.so, libxerces-c.so and/or libexpat.so and/or the
# libsbml.so _libsbml.so generated by this Makfile.  (For BSD/MacOS X
# replace LD_LIBRARY_PATH with DYLD_LIBRARY_PATH.)

# The next set of variable definitions are special to this file and not
# hooks into `makefile-common-actions.mk'.  The values depend in part on
# CSharp conventions and the output of SWIG.
#
outpath        = csharp-files
outpath_win    = csharp-files-win
csharp_files     = $(wildcard $(outpath)/*.cs)
csharp_files_win = $(wildcard $(outpath_win)/*.cs)
csharp_files_win += libsbml_wrap-win.cpp

vs2005_files = \
  $(assembly_info_source) $(assembly_info_source_tr)

# `distfiles' determines the files and directories included in a
# distribution.  The strategy here is that we include the output of SWIG
# (libsbml_wrap.cpp, libsbml_wrap-win.cpp and the csharp files) but not the 
# compiled files.

distfiles   = $(sources) $(extra_sources) $(check_sources) \
  00README.txt Makefile.in $(csharp_files) $(csharp_files_win) \
  $(vs2005_files) CMakeLists.txt Properties/AssemblyInfo.cs.in \
  compile-native-files.cmake csdoc.i swig-binding.cmake.in

tmpfiles = $(wildcard test*.xml*)

# `extra_clean' and `extra_distclean' determine the files and directories
# removed during "make clean" and "make distclean".

extra_clean = $(csproxy_lib) $(dllimport_lib) $(check_runner_exe) \
	      $(tmpfiles) $(sn_keyfile) $(wildcard test.xml.*) out.xml

extra_distclean = libsbml_wrap-win.h local-downcast-extension.i \
	local-downcast-namespaces.i local-packages.i csdoc.i

# library distributions shouldn't have to run SWIG because we provide the
# wrapper file ready-made.

swig_sources =      \
  $(extra_sources)  \
  ../swig/libsbml.h \
  ../swig/libsbml.i


main_sources = \
  $(shell grep '%include sbml' ../swig/libsbml.i | grep -v 'libsbml-version.h' \
    | cut -f2- -d'/' | sed -e 's,^,../../sbml/,g')

# MacOS X is different.  We need to compile the native library file using -bundle.

ifeq "$(HOST_TYPE)" "darwin"
  platform_link_flags = -bundle
  # environment variable MACOSX_DEPLOYMENT_TARGET must be set to 10.3 or later
  # to use -undefined dynamic_lookup.
  macosx_version=$(shell sw_vers -productVersion | cut -d"." -f1,2)
  export MACOSX_DEPLOYMENT_TARGET=${macosx_version}
%.$(CSHARP_EXT): $(objfiles) 
	$(call link_dl_lib,$@)
endif

# 
# 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:
  ifdef SN
    CSC_OPT_KEYFILE = -keyfile:$(sn_keyfile)
  endif
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
  CSC_OPT_KEYFILE = 
endif


# -----------------------------------------------------------------------------
# Primary build actions
# -----------------------------------------------------------------------------

# This whole setup is more or less custom and mostly doesn't use the common
# build directives of `makefile-common-actions.mk'.

.SUFFIXES:
.SUFFIXES: .i .cpp .h .cs .dll .o .obj .so .dylib .lo .la

# The default action is to remake everything.

ifdef USE_CSHARP
  all: Makefile $(csproxy_lib) $(outpath)/libsbml.cs $(outpath_win)/libsbml.cs
else
  all:
	@echo
	@echo "Reconfigure libSBML using --with-csharp to enable CSharp support."; 
	@echo "(--with-cli-interpreter=path and/or --with-csharp-compiler=path may be required.)";
	@echo
	@exit 1
endif

# Until we improve swigdoc.py, the following warnings are spurious and annoying
# and we don't need to see them.

# the compile run disables the following warnings
# -  105: duplicated using statement, due to the patch above 
# -  108: 'method name' hides inherited member 'base member name'. Use the 
#         new keyword if hiding was intended.
# -  114: 'method name' hides inherited member 'base member name'. To make 
#         the current member override that implementation, add the override 
#         keyword. Otherwise add the new keyword.
# - 1570: XML comment on 'class name' has badly formed XML.
# - 1572: XML comment on 'method name' has a param tag for 'parameter name'
#         but there is no parameter by that name.
# - 1573: Parameter 'parameter name' has no matching param tag in the XML 
#         comment for 'method name' (but other parameters do).
# - 1574: XML comment on 'method name' has cref attribute 'method name' 
#         that could not be resolved.
# - 1591: Missing XML comment for publicly visible type or member 'method
#         name'

CSC_NOWARN = -nowarn:105,108,109,114,1570,1572,1573,1574,1591

$(csproxy_lib): $(outpath)/libsbml.cs $(dllimport_lib)
	-"$(SN)" -k $(sn_keyfile)
	"$(CSHARP_COMPILER)" $(CSC_OPT_SHARED) $(CSC_NOWARN) \
	$(CSC_OPT_OUTPUT)$(csproxy_lib) $(CSC_OPT_KEYFILE) $(outpath)/*.cs \
	$(assembly_info_source)

$(outpath)/libsbml.cs: libsbml_wrap.cpp 

$(outpath_win)/libsbml.cs: libsbml_wrap-win.cpp 

# Recreate SWIG files when one of the following conditions is true:
#
#  (1) libsbml_wrap.cpp does not exist
#  (2) libsbml_wrap.cpp exists, but the file is not consistent with the
#       current USE_LAYOUT, USE_COMP, etc., values.
#
# If the last run was made with a package flag like --enable-layout, and this
# run isn't, or vice-versa, the swig wrap files will be wrong for this run.
# However, you can't tell just by looking at file mod times, so you can't use
# normal make dependencies.  So we do this grungy trick of looking inside
# libsbml_wrap.cpp to see what's inside.
#
# The check_foo macros works as follows.  They return a non-empty string
# "do_reswig" if re-swig'ing is called for, and this string is a phony make
# target declared below.  When check_layout is used as a dependency of
# libsbml_wrap.cpp via a call like this,
# 
#  libsbml_wrap.cpp: $(shell $(call check_layout)) ...other dependencies...
#   ...ACTIONS...
#
# what will happen is either check_layout will return nothing, in which
# case the dependency is satisfied and no swig'ing needs to be done, or
# it will return "do_reswig", a phony target that is never satisfied,
# in which case the ...ACTIONS... will be executed.

.PHONY: do_reswig

ifdef USE_COMP
  define check_comp
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -z "`grep getListOfSubmodels libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
else
  define check_comp
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -n "`grep getListOfSubmodels libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
endif

ifdef USE_FBC
  define check_fbc
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -z "`grep ListOfFluxBounds libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
else
  define check_fbc
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -n "`grep ListOfFluxBounds libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
endif

ifdef USE_GROUPS
  define check_groups
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -z "`grep ListOfGroups libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
else
  define check_groups
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -n "`grep ListOfGroups libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
endif

ifdef USE_LAYOUT
  define check_layout
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -z "`grep getListOfLayouts libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
else
  define check_layout
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -n "`grep getListOfLayouts libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
endif

ifdef USE_QUAL
  define check_qual
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -z "`grep ListOfQualitativeSpecies libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
else
  define check_qual
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -n "`grep ListOfQualitativeSpecies libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
endif

ifdef USE_MULTI
  define check_multi
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -z "`grep ListOfSpeciesFeatures libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
else
  define check_multi
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -n "`grep ListOfSpeciesFeatures libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
endif
ifdef USE_RENDER
  define check_render
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -z "`grep ListOfGlobalRenderInformation libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
else
  define check_render
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; \
    if test -n "`grep ListOfGlobalRenderInformation libsbml_wrap.cpp`"; then echo "do_reswig"; fi;
  endef
endif
ifdef USE_L3V2EXTENDEDMATH
  define check_l3v2extendedmath
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; 
  endef
else
  define check_l3v2extendedmath
    if test ! -f libsbml_wrap.cpp; then echo "do_reswig"; exit; fi; 
  endef
endif


# generate C# documentation
csdoc.i: $(main_sources) $(swig_sources) ../swig/swigdoc.py $(wildcard ../swig/*.i)
	../swig/swigdoc.py --language csharp --top ../../.. $(SWIGDOCDEFINES) \
		--master ../swig/libsbml.i --output csdoc.i

# libsbml_wrap.cpp (for non-Windows) and libsbml_wrap-win.cpp (for Windows)
# stand-in for the .cs files.  Their creation results in the creation of the .cs 
# files too -- both are made by running swig.

patch-swig-output:
	@list='$(wildcard $(outpath)/*.cs)'; for file in $$list; do \
	  echo 'using System;' > $(outpath)/.tmpfile; \
	  echo 'using System.Runtime.InteropServices;' >> $(outpath)/.tmpfile; \
	  echo ' ' >> $(outpath)/.tmpfile; \
	  cat $$file >> $(outpath)/.tmpfile; \
	  mv -f $(outpath)/.tmpfile $$file; \
	done

# for non-Windows
libsbml_wrap.cpp $(outpath) : $(swig_sources) $(main_sources) csdoc.i \
  $(shell $(call check_comp)) $(shell $(call check_fbc)) \
  $(shell $(call check_layout)) $(shell $(call check_qual)) \
  $(shell $(call check_groups)) $(shell $(call check_multi)) \
  $(shell $(call check_render))
	@top_srcdir@/config/chk_swig_version.sh || exit
	test -d $(outpath) || mkdir -p $(outpath)
	"$(SWIG)" $(SWIGFLAGS) $(sort $(default_includes) $(INCLUDES)) \
		-c++ -csharp -namespace libsbmlcs -dllimport $(dllimport_name) \
	        -outdir $(outpath) -o libsbml_wrap.cpp libsbml.i
	make patch-swig-output

# for Windows
libsbml_wrap-win.cpp $(outpath_win) : $(swig_sources) $(main_sources) csdoc.i \
  $(shell $(call check_comp)) $(shell $(call check_fbc)) $(shell $(call check_groups)) \
  $(shell $(call check_layout)) $(shell $(call check_qual)) $(shell $(call check_multi)) \
  $(shell $(call check_render))
	@top_srcdir@/config/chk_swig_version.sh || exit
	test -d $(outpath_win) || mkdir -p $(outpath_win)
	"$(SWIG)" $(SWIGFLAGS) $(SWIGFLAGS_WIN) $(sort $(default_includes) $(INCLUDES)) \
		-c++ -csharp -namespace libsbml -dllimport $(dllimport_name) \
	        -outdir $(outpath_win) -o libsbml_wrap-win.cpp libsbml.i

clean-swigfiles: clean
	-rm -rf $(outpath) $(outpath_win) libsbml_wrap.cpp libsbml_wrap-win.cpp


# -----------------------------------------------------------------------------
# Checking.
# -----------------------------------------------------------------------------

check_runner_exe =  $(check_runner_exe_man) $(check_runner_exe_cvt) 
check_runner_exe_man = TestRW.exe
check_runner_exe_cvt = TestRunner.exe

$(check_runner_exe_man): Makefile $(csproxy_lib) $(check_runner_source_man) 
	"$(CSHARP_COMPILER)" $(CSC_OPT_EXE) $(CSC_OPT_OUTPUT)$(check_runner_exe_man) \
	$(CSC_OPT_REF)$(csproxy_lib) $(check_runner_source_man)

$(check_runner_exe_cvt): Makefile $(csproxy_lib) $(check_runner_source_cvt) $(test_sources)
	"$(CSHARP_COMPILER)" $(CSC_OPT_EXE) $(CSC_OPT_OUTPUT)$(check_runner_exe_cvt) \
	$(CSC_OPT_REF)$(csproxy_lib) $(check_runner_source_cvt) $(test_sources)

testsbml_dir     = ../../../examples/sample-models/from-spec/level-2
testdata_dir = ../../sbml/test/test-data
testsbml_files = $(wildcard $(testsbml_dir)/*.xml)

check: $(check_runner_exe) $(shell $(call check_layout)) \
  $(shell $(call check_comp)) $(shell $(call check_fbc)) \
  $(shell $(call check_qual)) $(shell $(call check_groups)) \
  $(shell $(call check_multi)) $(shell $(call check_render)) \
  $(shell $(call check_l3v2extendedmath))
	@echo
	@echo
	@echo Running Tests in $(thisdir)
	@echo -----------------------------------------------------------------
	$(call libsbmlrun,"$(CSHARP_CILINTERPRETER)" $(check_runner_exe_man) $(testsbml_files))
	$(call libsbmlrun,"$(CSHARP_CILINTERPRETER)" $(check_runner_exe_cvt) -d $(testdata_dir) -l ./libsbmlcsP.dll)
	@echo -----------------------------------------------------------------
	@echo

#
# 'make test-files' will reconstruct the test files.  This is not made part
# of 'make check' (yet).
#

test-files:
	$(call test_translator,c,xml math annotation sbml,test)


# -----------------------------------------------------------------------------
# Tags.
# -----------------------------------------------------------------------------

tags: etags ctags


# -----------------------------------------------------------------------------
# Installation.
# -----------------------------------------------------------------------------

install_prefix=$(DESTDIR)$(LIBDIR)/mono/$(assembly_name)

install: $(libraries) $(shell $(call check_layout)) \
  $(shell $(call check_comp)) $(shell $(call check_fbc)) \
  $(shell $(call check_qual)) $(shell $(call check_groups)) \
  $(shell $(call check_l3v2extendedmath))
	-$(GACUTIL) -i $(csproxy_lib) -root $(DESTDIR)$(LIBDIR)
	$(INSTALL_SH) $(csproxy_lib) $(install_prefix)/$(csproxy_lib)
	$(INSTALL_SH) $(dllimport_lib) $(install_prefix)/$(dllimport_lib)
	ln -sf ../../libsbml.$(SHAREDLIBEXT) $(install_prefix)/libsbml.$(SHAREDLIBEXT)

uninstall:
	-$(GACUTIL) -u $(assembly_name) -root $(DESTDIR)$(LIBDIR)
	rm -f $(install_prefix)/$(csproxy_lib)
	rm -f $(install_prefix)/$(dllimport_lib)
	rm -f $(install_prefix)/libsbml.$(SHAREDLIBEXT)

installcheck:


# -----------------------------------------------------------------------------
# Creating distribution (for libSBML maintainers only)
# -----------------------------------------------------------------------------

dist: libsbml_wrap.cpp libsbml_wrap-win.cpp $(outpath) $(outpath_win)
ifneq "$(MAKEFLAGS)" ""
	$(MAKE) -$(MAKEFLAGS) dist-normal
else
	$(MAKE) dist-normal
endif


distcheck: distcheck-normal


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

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


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