| 1 |
#!/bin/sh |
| 2 |
# Create a loadable object from a C++ function defined in a .cpp file |
| 3 |
# $Id$ |
| 4 |
thecommand="$0" |
| 5 |
dircommand=`dirname "$0"` |
| 6 |
|
| 7 |
FFVERSION='@VERSION@' |
| 8 |
FFCXXFLAGS='@CXXFLAGS@ @CPPFLAGS@ @UMFPACK_CPPFLAGS@ @HDF5_CPPFLAGS@' |
| 9 |
FFFFLAGS='@FFLAGS@' |
| 10 |
# change FH 22/12/2022 |
| 11 |
FFFLIBS='@FF_LIBS@' |
| 12 |
FFCXX11FLAGS='@CXX11FLAGS@' |
| 13 |
FFLDFLAGS='@LDFLAGS@' |
| 14 |
MPIPROG="@MPIPROG@" |
| 15 |
INCFF= |
| 16 |
if [ "@ENABLE_FFCS@" != "yes" ] ;then ffcs=0; else ffcs=1;fi |
| 17 |
if [ -z "$CXX" ] ; then CXX='@CXX@' ; fi |
| 18 |
if [ -z "$MPICXX" ] ; then MPICXX="@MPICXX@" ; fi |
| 19 |
if [ -z "$MPI_LIB" ] ; then MPI_LIB="@MPI_LIB@" ; fi |
| 20 |
if [ -z "$F77" ] ; then F77="@F77@" ; fi |
| 21 |
if [ "$CXX" = '@'CXX'@' ] ; then CXX=""; fi |
| 22 |
if [ "$MPICXX" = '@'MPICXX'@' ] ; then MPICXX=""; fi |
| 23 |
if [ "$F77" = '@'F77'@' ] ; then F77=""; fi |
| 24 |
if [ "$FFCXXFLAGS" = '@'CXXFLAGS'@' ] ; then FFCXXFLAGS=""; fi |
| 25 |
if [ "$FFFFLAGS" = '@'FF_FLAGS'@' ] ; then FFFFLAGS=""; fi |
| 26 |
if [ "$FFFLIBS" = '@'FLIBS'@' ] ; then FFFLIBS=""; fi |
| 27 |
if [ "$FFVERSION" = '@'VERSION'@' ] ; then FFVERSION=""; fi |
| 28 |
if [ -z "$INCFF" ] ; then |
| 29 |
if [ -f "@INCFF@/ff++.hpp" ] ; then |
| 30 |
INCFF="'-I@INCFF@'" |
| 31 |
elif [ -f "${dircommand}/include/ff++.hpp" ]; then |
| 32 |
INCFF="'-I${dircommand}/include'" |
| 33 |
elif [ -f ../seq/include/ff++.hpp ]; then |
| 34 |
INCFF="-I../seq/include" |
| 35 |
elif [ -f "@FFAPPLI_INC@/ff++.hpp" ] ; then |
| 36 |
INCFF="'-I@FFAPPLI_INC@'" |
| 37 |
elif [ -f '@ff_prefix_dir@/include/ff++.hpp' ] ; then |
| 38 |
INCFF="'-I@ff_prefix_dir@/include'" |
| 39 |
elif [ -f '/usr/include/freefem++/ff++.hpp' ] ; then |
| 40 |
INCFF="'-I/usr/include/freefem++'" |
| 41 |
else |
| 42 |
ff=`which freefem++.exe`; |
| 43 |
ffinc=`dirname "$ff"`/seq/include |
| 44 |
if [ -f "$ffinc/ff++.hpp" ]; then |
| 45 |
INCFF=-I"'$ffinc'"; |
| 46 |
else |
| 47 |
echo " erreur PB include freefem++ directory " ; |
| 48 |
exit 1; |
| 49 |
fi |
| 50 |
fi |
| 51 |
fi |
| 52 |
do="yes" |
| 53 |
DEBUG="" |
| 54 |
CONLY="false" |
| 55 |
uu=`uname -s` |
| 56 |
INC="" |
| 57 |
LIBS="" |
| 58 |
DLL="" |
| 59 |
bin="." |
| 60 |
out="" |
| 61 |
files="" |
| 62 |
fileso="" |
| 63 |
OTHER=""; |
| 64 |
WIN32=""; |
| 65 |
|
| 66 |
case "$uu" in |
| 67 |
CYGWIN*|MINGW*|MSYS*) |
| 68 |
if [ -z "@WIN32DLLTARGET@" ] ; then |
| 69 |
onwin32=1; uu="cygwin-version"; |
| 70 |
else |
| 71 |
onwin32=1; uu="win32"; # pure windows |
| 72 |
fi |
| 73 |
WIN32="win32-" |
| 74 |
wff=`which FreeFem++.exe` |
| 75 |
dff=`dirname "$wff"` |
| 76 |
if [ "$bin" = "." -a -f ../../src/bin-win32/libff.dll ]; then |
| 77 |
bin=../../src/bin-win32 |
| 78 |
elif [ "$bin" = "." -a -f ../src/bin-win32/libff.dll ]; then |
| 79 |
bin=../src/bin-win32 |
| 80 |
elif [ -f "$dff/libff.dll" ]; then |
| 81 |
# modif for install on cygwin |
| 82 |
bin="$dff" |
| 83 |
elif [ "$bin" = "." -a -f ../libff.dll ]; then |
| 84 |
bin=.. |
| 85 |
elif [ "$bin" = "." -a -f ../../libff.dll ]; then |
| 86 |
bin=../.. |
| 87 |
elif [ "$bin" = "." -a -f ../../../libff.dll ]; then |
| 88 |
bin=../../.. |
| 89 |
fi;; |
| 90 |
esac |
| 91 |
autodep="" |
| 92 |
withmpi="" |
| 93 |
args="" |
| 94 |
|
| 95 |
while [ $# -ne 0 ] ; do |
| 96 |
argsp=$args |
| 97 |
args="$args '$1'" |
| 98 |
case "$1" in |
| 99 |
-[h?]*) echo usage $0 "[-n] [-g] [-win32] [-l libfile] [-I includedir] files" |
| 100 |
echo " -auto : build automaticaly the dependance (in test FH) " |
| 101 |
echo " -n : do nothing just print" |
| 102 |
echo " -g : compile with -g option add remove optimisation" |
| 103 |
echo " -c : compile only" |
| 104 |
echo " -mpi: with mpi" |
| 105 |
echo " -nompi: without $MPI_LIB links " |
| 106 |
echo " -O* : compile with -O* option" |
| 107 |
echo " -cygwin: compile for cygwin/win32 OS (Window XP, ...)" |
| 108 |
echo " -win32: compile for win32 OS (Window XP, ...) default under cygwin" |
| 109 |
echo " -l files add files to the ld process (link)" |
| 110 |
echo " -I dir add dir in include seach dir for compilation" |
| 111 |
echo " -b dir to change the default install dir " |
| 112 |
echo " -dll file add dll and this file copie in the install dir" |
| 113 |
echo " -o outputfile without suffix" |
| 114 |
echo " file.{cpp,cp,cxx,c,f,F}" |
| 115 |
exit 0; |
| 116 |
;; |
| 117 |
LIBFF=*) LIBFF=`echo $1|sed 's/[A-Z0-9]*=//'` ;; |
| 118 |
F77=*) F77=`echo $1|sed 's/[A-Z0-9]*=//'` ;; |
| 119 |
CXX=*) CXX=`echo $1|sed 's/[A-Z0-9]*=//'` ;; |
| 120 |
MPICXX=*) MPICXX=`echo $1|sed 's/[A-Z0-9]*=//'`;withmpi=yes ;; |
| 121 |
F77=*) F77=`echo $1|sed 's/[A-Z0-9]*=//'` ;; |
| 122 |
CXXFLAGS=*) CXXFLAGS=`echo $1|sed 's/[A-Z0-9]*=//'` ;; |
| 123 |
FFLAGS=*) FFLAGS=`echo $1|sed 's/[A-Z0-9]*=//'` ;; |
| 124 |
MPI_LIB=*) MPI_LIB=`echo $1|sed 's/[A-Z0-9]*=//'` ;; |
| 125 |
-std=*) CXXFLAGS="$1 $CXXFLAGS" ;; |
| 126 |
-auto) autodep=yes;args=$argsp;; |
| 127 |
-mpi) withmpi=yes;; |
| 128 |
-nompi) MPI_LIB='';withmpi='';; |
| 129 |
-n) do="no";; |
| 130 |
-g) DEBUG="$DEBUG $1"; |
| 131 |
FFCXXFLAGS=`echo $FFCXXFLAGS| sed -e 's/-O[0-9]*//g' -e 's/-DNDEBUG//g' ` ;; |
| 132 |
-c) CONLY=yes;; |
| 133 |
-O*) DEBUG="$DEBUG $1";; |
| 134 |
-cygwin) onwin32=1; uu="cygwin-version";; |
| 135 |
-win32) onwin32=1; uu="win32";; |
| 136 |
-b) bin=$2 ; shift;; |
| 137 |
-I*) INC="$INC '$1'";; |
| 138 |
-D*) INC="$INC '$1'";; |
| 139 |
-dll) DLL="$DLL '$2'";shift;; |
| 140 |
-[Ll]*) LIBS="$LIBS '$1'" ;; # FFCS - 27/10/11 - need quotes for MPICH libraries in 'Program Files' under Windows |
| 141 |
*.a) LIBS="$LIBS $1" ;; |
| 142 |
*.so) LIBS="$LIBS $1" ;; |
| 143 |
*.dll) if [ -f "$1" ] ; then LIBS="$LIBS '$1'" |
| 144 |
elif [ -f "$bin/$1" ] ; then LIBS="$LIBS '$bin/$1'" |
| 145 |
else |
| 146 |
echo " erreur file not found $1" ; |
| 147 |
exit 1; |
| 148 |
fi;; |
| 149 |
-Wl*) LIBS="$LIBS $1" ;; |
| 150 |
*.cpp) files="$files '$1'"; o=`basename "$1" .cpp` ; fileso="$fileso '$o.o'"; args=$argsp;; |
| 151 |
*.cp) files="$files '$1'"; o=`basename "$1" .cp` ; fileso="$fileso '$o.o'"; args=$argsp;; |
| 152 |
*.cxx) files="$files '$1'"; o=`basename "$1" .cxx` ; fileso="$fileso '$o.o'"; args=$argsp;; |
| 153 |
*.c) files="$files '$1'"; o=`basename "$1" .c` ; fileso="$fileso '$o.o'"; args=$argsp;; |
| 154 |
*.f) ffiles="$ffiles '$1'"; o=`basename "$1" .f` ; fileso="$fileso '$o.o'";; |
| 155 |
*.f90) ffiles="$ffiles '$1'"; o=`basename "$1" .f90` ; fileso="$fileso '$o.o'";; |
| 156 |
*.F) ffiles="$ffiles '$1'"; o=`basename "$1" .F` ; fileso="$fileso '$o.o'";; |
| 157 |
*.o) fileso="$fileso '$1'"; o=`basename "$1" .o` ;; |
| 158 |
-o) out="$2"; shift;; |
| 159 |
*) OTHER="$OTHER $1";; |
| 160 |
esac |
| 161 |
shift |
| 162 |
done |
| 163 |
|
| 164 |
# remove old file... FH sep 2013.. |
| 165 |
SUF=@DYLIB_SUFFIX@ |
| 166 |
|
| 167 |
if [ -n "$autodep" ] ; then |
| 168 |
# echo "$thecommand" $args `eval "'$dircommand/ff-get-dep'" -ff $files` |
| 169 |
argsdep=`eval "'$dircommand/ff-get-dep'" -ff $files` |
| 170 |
|
| 171 |
error=`echo "$argsdep"| grep ERROR` |
| 172 |
if [ -n "$error" ] ; then |
| 173 |
echo " WARNING in auto dependance seach ( missing plugin $2) . sorry : $error " |
| 174 |
|
| 175 |
# FFCS - 28/11/11 - we need to stop compiling as soon as there is an error because we want a fixed set of features in |
| 176 |
# FFCS |
| 177 |
# return a error when FFCS enable .. FH. |
| 178 |
echo " -- $error " >>Missing-plugins-@[email protected] |
| 179 |
exit $ffcs; |
| 180 |
fi |
| 181 |
echo eval "$thecommand" $args $argsdep |
| 182 |
eval "$thecommand" $args $argsdep |
| 183 |
|
| 184 |
# FFCS needs an error exit code to make sure that all libraries are correctly compiled |
| 185 |
exit $?; |
| 186 |
fi |
| 187 |
|
| 188 |
if [ -n "$onwin32" -a ! -f "$bin/libff.dll" ] ; then |
| 189 |
echo " Error the file libff.dll must be exist in '$bin' the install directory," |
| 190 |
echo " to link on windows OS " |
| 191 |
echo " Use the parameter -b to set the correct install directory " |
| 192 |
exit 1; |
| 193 |
fi |
| 194 |
|
| 195 |
if [ -z "$out" ] ; then out=$o ; fi; |
| 196 |
if [ -f "$out.$SUF" ] ; then rm $out.$SUF ; fi |
| 197 |
|
| 198 |
|
| 199 |
# Default compiler |
| 200 |
if [ -z "$CXX" ];then CXX=g++ ; fi |
| 201 |
if [ -n "$withmpi" -a -z "$MPICXX" ] ; then echo $0: Sorry NO MPI; exit 0; fi |
| 202 |
if [ -n "$withmpi" ]; then CXX=$MPICXX;fi |
| 203 |
|
| 204 |
test "$withmpi" = "yes" && WMPI_LIB="$MPI_LIB" |
| 205 |
|
| 206 |
# build a mpi version of the plugin if the plugin do exist un mpi dir |
| 207 |
# and if the mpi version exist "$MPIPROG" and if |
| 208 |
OWMPI="" |
| 209 |
test -d ../mpi -a -n "$MPIPROG" -a "$withmpi" != "yes" -a ! -f "../mpi/$out.cpp" && OWMPI="../mpi/$out.$SUF" |
| 210 |
test -f "$OWMPI" -a -n "$OWMPI" && rm "$OWMPI" |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
INC="$INCFF $INC" |
| 215 |
SHARED="-shared" |
| 216 |
case "$WIN32$uu" in |
| 217 |
Darwin*) |
| 218 |
# echo "export MACOSX_DEPLOYMENT_TARGET=10.3" |
| 219 |
# export MACOSX_DEPLOYMENT_TARGET=10.4 |
| 220 |
# SUF=dylib |
| 221 |
SHARED="-bundle -undefined dynamic_lookup" |
| 222 |
|
| 223 |
if [ -f "$LIBFF" ] ; then |
| 224 |
echo " xcode interface with $LIBFF" |
| 225 |
SHARED="-bundle" |
| 226 |
out=`dirname "$LIBFF"`/$out |
| 227 |
LIBS="$LIBFF $LIBS" |
| 228 |
OWMPI= |
| 229 |
fi |
| 230 |
;; |
| 231 |
win32-CYGWIN*|win32-win32) |
| 232 |
echo " Window without cygwin " |
| 233 |
WMPI_LIB='' |
| 234 |
b="$bin" |
| 235 |
LIBS=" '$b/libff.dll' $LIBS $DLL" |
| 236 |
|
| 237 |
# FFCS - 17/10/12 - --unresolved-symbols=ignore-all is not understood by the current mingw64 compilers |
| 238 |
SHARED="-shared -Wl,--enable-auto-import" |
| 239 |
|
| 240 |
# FFCS - 17/10/12 - -mno-cygwin is not understood by the current mingw64 compilers |
| 241 |
###FLAGS=' -mno-cygwin ' |
| 242 |
# SUF=dll |
| 243 |
;; |
| 244 |
win32-cygwin-version) |
| 245 |
echo " cygwin-version " |
| 246 |
WMPI_LIB='' |
| 247 |
b=$bin |
| 248 |
FLAGS=' ' |
| 249 |
LIBS="'$b/libff.dll' $LIBS $DLL" |
| 250 |
# SUF=dll |
| 251 |
;; |
| 252 |
FreeBSD|NetBSD) |
| 253 |
SHARED="-shared" |
| 254 |
FLAGS='-fPIC';; |
| 255 |
# 64 bit Linux needs -fPIC (ALH) |
| 256 |
SunOS) |
| 257 |
SHARED="-shared" |
| 258 |
FLAGS='-fPIC';; |
| 259 |
# 64 bit Linux needs -fPIC (ALH) |
| 260 |
Linux) |
| 261 |
FLAGS='-fPIC' |
| 262 |
SHARED="-shared " ;; |
| 263 |
*) |
| 264 |
echo "sorry unknown achitecture "`uname` |
| 265 |
exit 1;; |
| 266 |
esac |
| 267 |
|
| 268 |
|
| 269 |
#FLAGS="$FLAGS $DEBUG $FFCXXFLAGS" |
| 270 |
# change F. H Version 3.17 |
| 271 |
FLAGS="$FLAGS $DEBUG" |
| 272 |
|
| 273 |
if [ -n "$ffiles$files$fileso" ] ; then |
| 274 |
if [ -n "$WIN32" -a ! -f "$bin/libff.dll" ]; then |
| 275 |
echo " Sorry, no freefem .dll file (libff.dll) in $bin dir " |
| 276 |
echo " try with -b dir-path where the file libff.dll exist" |
| 277 |
exit 1; |
| 278 |
fi |
| 279 |
if [ "$files" ] ;then |
| 280 |
echo $CXX -c $FLAGS $CXXFLAGS $INC $PIC $FFCXXFLAGS $files $LDFLAGS |
| 281 |
if [ $do = yes ] ; then |
| 282 |
eval $CXX -c $INC $FLAGS $CXXFLAGS $PIC $FFCXXFLAGS $files $LDFLAGS |
| 283 |
ret=$?; if [ $ret -ne 0 ] ; then exit $ret ;fi |
| 284 |
fi |
| 285 |
echo |
| 286 |
fi |
| 287 |
if [ "$ffiles" ] ;then |
| 288 |
echo $F77 -c $FLAGS $FFLAGS $FFFFLAGS $INC $PIC $ffiles |
| 289 |
LIBS="$FFFLIBS $LIBS" |
| 290 |
if [ $do = yes ] ; then |
| 291 |
eval $F77 -c $INC $FFLAGS $FLAGS $FFFFLAGS $PIC $ffiles |
| 292 |
ret=$?; if [ $ret -ne 0 ] ; then exit $ret ;fi |
| 293 |
fi |
| 294 |
echo |
| 295 |
fi |
| 296 |
if [ "$CONLY" != yes ]; then |
| 297 |
echo $CXX $FFLDFLAGS $SHARED $FLAGS $CXXFLAGS $FFCXXFLAGS $fileso -o $out.$SUF $LIBS $DLL $OTHER $WMPI_LIB $LDFLAGS |
| 298 |
if [ $do = yes ] ; then |
| 299 |
eval $CXX $FFLDFLAGS $SHARED $FLAGS $CXXFLAGS $FFCXXFLAGS $fileso -o $out.$SUF $LIBS $DLL $OTHER $WMPI_LIB $LDFLAGS |
| 300 |
ret=$?; if [ $ret -ne 0 ] ; then exit $ret ;fi |
| 301 |
fi |
| 302 |
echo |
| 303 |
if [ "$bin" != "." ]; then |
| 304 |
echo cp $out.$SUF $bin |
| 305 |
test $do = yes && cp $out.$SUF "$bin" |
| 306 |
fi |
| 307 |
if [ -n "$DLL" ] ; then |
| 308 |
echo cp $DLL $bin |
| 309 |
test $do = yes && cp $DLL "$bin" |
| 310 |
fi |
| 311 |
if [ -n "$OWMPI" ] ; then |
| 312 |
echo $CXX $FFLDFLAGS $SHARED $FLAGS $CXXFLAGS $FFCXXFLAGS $fileso -o $OWMPI $LIBS $DLL $OTHER $MPI_LIB $LDFLAGS |
| 313 |
if [ $do = yes ] ; then |
| 314 |
eval $CXX $FFLDFLAGS $SHARED $FLAGS $CXXFLAGS $FFCXXFLAGS $fileso -o $OWMPI $LIBS $DLL $OTHER $MPI_LIB $LDFLAGS |
| 315 |
ret=$?; if [ $ret -ne 0 ] ; then exit $ret ;fi |
| 316 |
fi |
| 317 |
echo |
| 318 |
fi |
| 319 |
fi |
| 320 |
fi |