Skip to content

Commit

Permalink
adding fcc and mcc scripts from Thomas Hahn
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Voigt authored and Alexander Voigt committed Jun 22, 2016
1 parent 8503065 commit dc275e5
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 0 deletions.
72 changes: 72 additions & 0 deletions config/fcc
@@ -0,0 +1,72 @@
#! /bin/sh
# script to compile C programs that need to be linked
# against libraries
# last modified 3 Feb 15 th

args=
compileonly=
objs=
ldflags=
fldflags=

cc="${REALCC:-cc}"
cxx="${REALCXX:-c++}"
test `basename $0` = f++ && cc="$cxx"
case `$cxx --version 2>&1` in
*clang*) cxx="$cxx -stdlib=libstdc++" ;;
esac

while test $# -gt 0 ; do
case "$1" in
-st | -b32 | -b64)
;; # ignore mcc-specific flags
-arch)
shift
;;
-lstdc++)
cc="$cxx"
;; # or else -static-libstdc++ has no effect
-Wno-long-double)
;; # mcc adds this on Macs & gcc 4 doesn't like it
-L*CompilerAdditions*)
ldflags="$ldflags '$1'"
mldir=`echo "$1" | sed '
s/^-L//
s/Links.MathLink.DeveloperKit/Libraries/
s/CompilerAdditions.*$//'`
case "$cc" in
*-m32*) mldir=`echo "$mldir" | sed 's/-x86-64//g'` ;;
esac
test -f "$mldir/libuuid.a" && {
ldflags="$ldflags '-L$mldir'"
fldflags="$fldflags -luuid"
}
;;
-[Ll]* | -Wl*)
ldflags="$ldflags '$1'"
;;
*.tm.o)
objs="'$1' $objs"
;;
*.a | *.o | *.so)
objs="$objs '$1'"
;;
*.cc)
args="$args '$1'"
cc="$cxx"
;;
-c)
compileonly="-c"
;;
-o)
args="$args -o '$2'"
shift
;;
*)
args="$args '$1'"
;;
esac
shift
done

eval "set -x ; exec $cc $args ${compileonly:-$objs $ldflags $fldflags}"
119 changes: 119 additions & 0 deletions config/mcc
@@ -0,0 +1,119 @@
#! /bin/sh
# this script jumps in if there is no working mcc on the path:
# - on Mac OS it (hopefully) figures out the location of mcc,
# - on Cygwin it substitutes mcc completely
# last modified 16 Jan 15 th

MATH_CMD=${MATH:-math}

sdkpath()
{
mathcmd="$1"
shift
mathcmd=`IFS=:
PATH="$PATH:$*" which $mathcmd`

eval `"$mathcmd" -run '
Print["sysid=\"", $SystemID, "\""];
Print["topdir=\"", $TopDirectory, "\""];
Exit[]' < /dev/null | tr '\r' ' ' | tail -2`

# check whether Cygwin's dlltool can handle 64-bit DLLs
test "$sysid" = Windows-x86-64 && {
${DLLTOOL:-dlltool} --help | grep x86-64 > /dev/null || sysid=Windows
}

topdir=`cd "$topdir" ; echo $PWD`

for sdk in \
"$topdir/SystemFiles/Links/MathLink/DeveloperKit/$sysid/CompilerAdditions" \
"$topdir/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions" \
"$topdir/AddOns/MathLink/DeveloperKit/$sysid/CompilerAdditions" ; do
test -d "$sdk" && return
done

echo "MathLink SDK not found" 1>&2
exit 1
}


cygmcc()
{
sdkpath "${MATH_CMD}" \
"`cygpath '$ProgramW6432'`/Wolfram Research/Mathematica"/* \
"`cygpath '$PROGRAMFILES'`/Wolfram Research/Mathematica"/* \
"/cygdrive/c/Program Files/Wolfram Research/Mathematica"/* \
"/cygdrive/c/Program Files (x86)/Wolfram Research/Mathematica"/*

for sdk in "$sdk"/m* ; do
break
done

cache=MLcyg-cache
test -d $cache || mkdir $cache

for libname in "$sdk"/lib/ml*m.lib ; do
:
done
dllname=`basename "$libname" m.lib`
OSbits=32
case "$dllname" in
*64*) OSbits=64 ;;
esac

lib="$cache/${dllname}m"
test -f "$lib.a" || {
( echo "EXPORTS"
${NM:-nm} -C --defined-only "$libname" | awk '/ T [^.]/ { print $3 }'
) > "$lib.def"
${DLLTOOL:-dlltool} -k --dllname "$dllname.dll" \
--def "$lib.def" --output-lib "$lib.a"
}

tmp=
args="-DWIN$OSbits -I'$sdk/include'"
for arg in "$@" ; do
case "$arg" in
*.tm)
cp "$arg" "$arg.tm"
"$sdk"/bin/mprep -lines -o "$arg.c" "$arg.tm"
tmp="$tmp '$arg.c' '$arg.tm'"
args="$args '$arg.c'" ;;
*)
args="$args '$arg'" ;;
esac
done

trap "rm -f $tmp" 0 1 2 3 15
eval "set -x ; ${CC:-gcc} $args $lib.a -mwindows"
}


macmcc()
{
sdkpath MathKernel \
/Applications/Mathematica*/Contents/MacOS \
$HOME/Desktop/Mathematica*/Contents/MacOS
exec "$sdk/mcc" "$@"
}


defaultmcc()
{
sdkpath "${MATH_CMD}" \
/usr/local/bin \
/usr/local/Wolfram/bin \
/usr/local/Wolfram/Mathematica/*/Executables \
/opt/Wolfram/bin \
/opt/Wolfram/Mathematica/*/Executables
exec "$sdk/mcc" "$@"
}


shopt -s nullglob 2> /dev/null

case `uname -s` in
Darwin) macmcc "$@" ;;
CYG*) cygmcc "$@" ;;
*) defaultmcc "$@" ;;
esac
7 changes: 7 additions & 0 deletions config/module.mk
@@ -1,5 +1,7 @@
DIR := config
MODNAME := config
FCC := $(DIR)/fcc
FXX := $(DIR)/f++

CONFIG_HDR := \
$(DIR)/config.h
Expand Down Expand Up @@ -36,6 +38,10 @@ FLEXIBLESUSY_GIT_COMMIT_FILE := \
REMOVE_EXPORT_MARKERS := \
$(DIR)/remove_export_markers.sh

$(FXX): $(FCC)
-rm -f $@
ln -s $(notdir $<) $@

.PHONY: all-$(MODNAME) clean-$(MODNAME) distclean-$(MODNAME)

all-$(MODNAME):
Expand All @@ -60,6 +66,7 @@ clean-$(MODNAME)-obj:

clean-$(MODNAME): clean-$(MODNAME)-dep clean-$(MODNAME)-obj
-rm -f $(DEPGEN_EXE)
-rm -f $(FXX)

distclean-$(MODNAME): clean-$(MODNAME)
-rm -f $(CONFIG_HDR)
Expand Down

0 comments on commit dc275e5

Please sign in to comment.