Debian Codegraph @

windows/deps/mkoctfile

raw
1 #! /bin/sh
2
3 ## Make sure to keep -static-libgcc, -static-libstdc++ and -static-libgfortran
4 ## in DL_LDFLAGS when updating this file.
5 ## Do not add -shared in LDFLAGS (i.e. this file should mimick “mkoctfile
6 ## --link-stand-alone”, see the top of mex/build/configure.ac).
7 ## Also keep BINDIR in DEFAULT_LDFLAGS (for UMFPACK).
8
9 # Exit immediately on any error.
10 set -e
11
12 : ${SED="/bin/sed"}
13
14 # The location where Octave artifacts are going to be copied
15 OCTAVE_PREFIX="/tmp/windeps/sysroot-octave/ucrt64"
16
17 # Get Octave version
18 MKOCTFILE_PATH=$(dirname $(readlink -f "$0"))
19 current_octave_version=$(grep "^OCTAVE_VERSION" "$MKOCTFILE_PATH/versions.mk")
20 eval $(echo "$current_octave_version" | tr -d '[:space:]')
21
22 DEFAULT_BINDIR="$OCTAVE_PREFIX/bin"
23 DEFAULT_INCLUDEDIR="$OCTAVE_PREFIX/include"
24 DEFAULT_LIBDIR="$OCTAVE_PREFIX/lib"
25 DEFAULT_OCTINCLUDEDIR="$OCTAVE_PREFIX/include/octave-${OCTAVE_VERSION}/octave"
26 DEFAULT_OCTLIBDIR="$OCTAVE_PREFIX/lib/octave/${OCTAVE_VERSION}"
27
28 if [ -n "$OCTAVE_HOME" ]; then
29 DEFAULT_BINDIR="`echo $DEFAULT_BINDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
30 DEFAULT_INCLUDEDIR="`echo $DEFAULT_INCLUDEDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
31 DEFAULT_LIBDIR="`echo $DEFAULT_LIBDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
32 DEFAULT_OCTINCLUDEDIR="`echo $DEFAULT_OCTINCLUDEDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
33 DEFAULT_OCTLIBDIR="`echo $DEFAULT_OCTLIBDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`"
34 fi
35
36 : ${BINDIR=$DEFAULT_BINDIR}
37 : ${INCLUDEDIR=$DEFAULT_INCLUDEDIR}
38 : ${LIBDIR=$DEFAULT_LIBDIR}
39 : ${OCTINCLUDEDIR=$DEFAULT_OCTINCLUDEDIR}
40 : ${OCTLIBDIR=$DEFAULT_OCTLIBDIR}
41
42 DEFAULT_INCFLAGS="-I$OCTINCLUDEDIR/.. -I$OCTINCLUDEDIR"
43 if [ "$INCLUDEDIR" != /usr/include ]; then
44 DEFAULT_INCFLAGS="$DEFAULT_INCFLAGS -I$INCLUDEDIR"
45 fi
46
47 DEFAULT_LDFLAGS="-L$OCTLIBDIR"
48 if [ "$LIBDIR" != /usr/lib ]; then
49 DEFAULT_LDFLAGS="$DEFAULT_LDFLAGS -L$LIBDIR"
50 fi
51
52 # Default values for these variables are filled in when Octave is
53 # compiled.
54
55 : ${EXEEXT=""}
56
57 : ${CPPFLAGS=""}
58 : ${INCFLAGS=$DEFAULT_INCFLAGS}
59 : ${F77="x86_64-w64-mingw32-gfortran"}
60 : ${FFLAGS="-g -O2 -std=legacy"}
61 : ${FPICFLAG=""}
62 : ${CC="x86_64-w64-mingw32-gcc"}
63 : ${CFLAGS="-g -O2"}
64 : ${CPICFLAG=""}
65 : ${CXX="x86_64-w64-mingw32-g++"}
66 : ${CXXFLAGS="-g -O2"}
67 : ${CXXPICFLAG=""}
68 : ${XTRA_CFLAGS="-fopenmp"}
69 : ${XTRA_CXXFLAGS="-fopenmp"}
70 : ${AR="x86_64-w64-mingw32-ar"}
71 : ${RANLIB="x86_64-w64-mingw32-ranlib"}
72
73 : ${DEPEND_FLAGS="-M"}
74 : ${DEPEND_EXTRA_SED_PATTERN=""}
75
76 : ${DL_LD="x86_64-w64-mingw32-g++"}
77 : ${DL_LDFLAGS="-shared -static-libgcc -static-libstdc++ -static-libgfortran"}
78
79 : ${RLD_FLAG=""}
80 : ${RDYNAMIC_FLAG=""}
81 : ${LIBOCTAVE=-loctave}
82 : ${LIBOCTINTERP=-loctinterp}
83 : ${READLINE_LIBS=-lreadline}
84 : ${LAPACK_LIBS="-llapack"}
85 : ${BLAS_LIBS="-lblas -lxerbla"}
86 : ${FFTW3_LDFLAGS=""}
87 : ${FFTW3_LIBS="-lfftw3"}
88 : ${FFTW3F_LDFLAGS=""}
89 : ${FFTW3F_LIBS="-lfftw3f"}
90 : ${LIBS="-lpsapi -lgdi32 -lm"}
91 : ${FLIBS="-lm -lgfortran -lmingw32 -lmoldname -lmingwex -lmsvcrt -lquadmath -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32"}
92 : ${LD_CXX="x86_64-w64-mingw32-g++"}
93 : ${LDFLAGS=$DEFAULT_LDFLAGS}
94 : ${LD_STATIC_FLAG=""}
95 : ${LFLAGS=$DEFAULT_LDFLAGS}
96 : ${F77_INTEGER_8_FLAG=""}
97
98 : ${ALL_FFLAGS="$FFLAGS $F77_INTEGER_8_FLAG"}
99
100 : ${ALL_CFLAGS="$INCFLAGS $XTRA_CFLAGS $CFLAGS"}
101
102 : ${ALL_CXXFLAGS="$INCFLAGS $XTRA_CXXFLAGS $CXXFLAGS"}
103
104 : ${ALL_LDFLAGS="$LD_STATIC_FLAG $CPICFLAG $LDFLAGS"}
105
106 : ${OCTAVE_LIBS="$LIBOCTINTERP $LIBOCTAVE $SPECIAL_MATH_LIB"}
107
108 : ${LIBOCTMEX="-loctmex"}
109
110 # Local variables.
111
112 FFTW_LIBS="$FFTW3_LDFLAGS $FFTW3_LIBS $FFTW3F_LDFLAGS $FFTW3F_LIBS"
113
114 usage_msg="usage: mkoctfile [options] file ..."
115
116 version_msg="mkoctfile, version $OCTAVE_VERSION"
117
118 cfiles=
119 ccfiles=
120 f77files=
121 objfiles=
122 libfiles=
123 octfiles=
124 octfile=
125 outputfile=
126 incflags=
127 defs=
128 ldflags=
129 dbg=:
130 pass_on_options=
131 strip=false
132 no_oct_file_strip_on_this_platform=false
133 link=true
134 link_stand_alone=false
135 output_ext=".oct"
136 depend=false
137 compile=true
138
139 if [ $# -eq 0 ]; then
140 echo $usage_msg 1>&2
141 exit 1
142 fi
143
144 if [ $# -eq 1 ]; then
145 case "$1" in
146 -v | -version | --version)
147 echo $version_msg
148 exit 0
149 ;;
150 esac
151 fi
152
153 while [ $# -gt 0 ]; do
154 file=
155 case "$1" in
156 *.c)
157 file=$1
158 cfiles="$cfiles $file"
159 ;;
160 *.cc | *.C | *.cpp)
161 file=$1
162 ccfiles="$ccfiles $file"
163 ;;
164 *.f | *.F | *.f90 | *.F90)
165 file=$1
166 f77files="$f77files $file"
167 ;;
168 *.o)
169 file=$1
170 objfiles="$objfiles $file"
171 ;;
172 *.a)
173 file=$1
174 libfiles="$libfiles $file"
175 ;;
176 -d | -debug | --debug | -v | -verbose | --verbose)
177 dbg=echo
178 ;;
179 -h | -\? | -help | --help)
180 echo $usage_msg 1>&2
181 cat << EOF
182
183 Options:
184
185 -h, -?, --help Print this message.
186
187 -IDIR Add -IDIR to compile commands.
188
189 -idirafter DIR Add -idirafter DIR to compile commands.
190
191 -DDEF Add -DDEF to compile commands.
192
193 -lLIB Add -lLIB to link command.
194
195 -LDIR Add -LDIR to link command.
196
197 -RDIR Add -RDIR to link command.
198
199 -g Enable debugging option for all compilers.
200
201 -pthread Add -pthread to link command.
202
203 -W... Pass flags to the compiler such as -Wa,OPTION.
204
205 -Wl,... Pass flags to the linker such as -Wl,-rpath=...
206
207 -M, --depend Generate dependency files (.d) for C and C++
208 source files.
209
210 -c, --compile Compile, but do not link.
211
212 --link-stand-alone Link a stand-alone executable file.
213
214 -s, --strip Strip output file.
215
216 --mex Create a MEX file.
217 Set the default output extension to ".mex".
218
219 -o FILE, --output FILE Output file name. Default extension is .oct
220 (or .mex if --mex is specified) unless linking
221 a stand-alone executable.
222
223 -p VAR, --print VAR Print configuration variable VAR. Recognized
224 variables are:
225
226 ALL_CFLAGS FFTW3F_LDFLAGS
227 ALL_CXXFLAGS FFTW3F_LIBS
228 ALL_FFLAGS FLIBS
229 ALL_LDFLAGS FPICFLAG
230 BLAS_LIBS INCFLAGS
231 CC LAPACK_LIBS
232 CFLAGS LDFLAGS
233 CPICFLAG LD_CXX
234 CPPFLAGS LD_STATIC_FLAG
235 CXX LFLAGS
236 CXXFLAGS LIBCRUFT
237 CXXPICFLAG LIBOCTAVE
238 DEPEND_EXTRA_SED_PATTERN LIBOCTINTERP
239 DEPEND_FLAGS LIBS
240 DL_LD OCTAVE_LIBS
241 DL_LDFLAGS RDYNAMIC_FLAG
242 EXEEXT READLINE_LIBS
243 F77 RLD_FLAG
244 F77_INTEGER_8_FLAG SED
245 FFLAGS XTRA_CFLAGS
246 FFTW3_LDFLAGS XTRA_CXXFLAGS
247 FFTW3_LIBS
248
249 -v, --verbose Echo commands as they are executed.
250
251 FILE Compile or link FILE. Recognized file types are:
252
253 .c C source
254 .cc C++ source
255 .C C++ source
256 .cpp C++ source
257 .f Fortran source (fixed form)
258 .F Fortran source (fixed form)
259 .f90 Fortran source (free form)
260 .F90 Fortran source (free form)
261 .o object file
262 .a library file
263
264 EOF
265 exit 0
266 ;;
267 -I*)
268 incflags="$incflags $1"
269 ;;
270 -idirafter)
271 shift
272 if [ $# -gt 0 ]; then
273 incflags="$incflags -idirafter $1"
274 else
275 echo "mkoctfile: include directory name missing" 1>&2
276 fi
277 ;;
278 -D*)
279 defs="$defs $1"
280 ;;
281 -[lLR]* | -Wl,*)
282 ldflags="$ldflags $1"
283 ;;
284 -pthread)
285 ldflags="$ldflags $1"
286 ;;
287 -M | -depend | --depend)
288 depend=true
289 compile=false
290 ;;
291 -o | -ouput | --output)
292 shift
293 if [ $# -gt 0 ]; then
294 outputfile="$1"
295 else
296 echo "mkoctfile: output file name missing" 1>&2
297 fi
298 ;;
299 -p | -print | --print)
300 shift
301 if [ $# -gt 0 ]; then
302 eval echo \${$1}
303 exit 0
304 else
305 echo "mkoctfile: --print requires argument" 1>&2
306 exit 1
307 fi
308 ;;
309 -s | -strip | --strip)
310 if $no_oct_file_strip_on_this_platform; then
311 echo "mkoctfile: stripping disabled on this platform" 1>&2
312 else
313 strip=true
314 fi
315 ;;
316 -c | -compile | --compile)
317 link=false
318 ;;
319 -g)
320 ALL_CFLAGS="$ALL_CFLAGS -g"
321 ALL_CXXFLAGS="$ALL_CXXFLAGS -g"
322 ALL_FFLAGS="$ALL_FFLAGS -g"
323 ;;
324 -link-stand-alone | --link-stand-alone)
325 link_stand_alone=true
326 ;;
327 -mex | --mex)
328 incflags="$incflags -I."
329 output_ext=".mex"
330 ;;
331 -W*)
332 pass_on_options="$pass_on_options $1"
333 ;;
334 *)
335 echo "mkoctfile: unrecognized argument $1" 1>&2
336 exit 1
337 ;;
338 esac
339 if [ -n "$file" ]; then
340 if [ -z "$octfile" ]; then
341 octfile="$file"
342 fi
343 fi
344 shift
345 done
346
347 if $link_stand_alone; then
348 if [ -n "$outputfile" ]; then
349 output_option="-o $outputfile"
350 fi
351 else
352 if [ -n "$outputfile" ]; then
353 octfile="$outputfile"
354 case "$octfile" in
355 *$output_ext)
356 ;;
357 *)
358 octfile="$octfile$output_ext"
359 ;;
360 esac
361 else
362 octfile=`basename $octfile`
363 octfile=`echo $octfile | $SED 's,\.[^.]*$,,'`$output_ext
364 fi
365 fi
366
367 # Generate dependency files for C and C++ files.
368
369 if $depend; then
370 if [ -n "$cfiles" ]; then
371 for f in $cfiles; do
372 b=`echo $f | $SED 's,\.c$,,'`
373 d=$b.d
374 cmd="rm -f $d"
375 $dbg $cmd
376 eval $cmd
377 cmd="$CC $DEPEND_FLAGS $CPPFLAGS $ALL_CFLAGS $incflags $def $f | $SED $DEPEND_EXTRA_SED_PATTERN -e 's,^[^:]*/\(.*\.o\):,\1:,' -e 's,$b\.o,pic/& & $d,g' > $d-t && mv $d-t $d"
378 $dbg $cmd
379 eval $cmd
380 done
381 fi
382
383 if [ -n "$ccfiles" ]; then
384 for f in $ccfiles; do
385 case $f in
386 *.cc)
387 b=`echo $f | $SED 's,\.cc$,,'`
388 ;;
389 *.C)
390 b=`echo $f | $SED 's,\.C$,,'`
391 ;;
392 *.cpp)
393 b=`echo $f | $SED 's,\.cpp$,,'`
394 ;;
395 esac
396 d=$b.d
397 cmd="rm -f $d"
398 $dbg $cmd
399 eval $cmd
400 cmd="$CXX $DEPEND_FLAGS $CPPFLAGS $ALL_CXXFLAGS $incflags $defs $f | $SED $DEPEND_EXTRA_SED_PATTERN -e 's,^[^:]*/\(.*\.o\):,\1:,' -e 's,$b\.o,pic/& & $d,g' > $d-t && mv $d-t $d"
401 $dbg $cmd
402 eval $cmd
403 done
404 fi
405 # If generating dependencies, that's all we do.
406 exit 0
407 fi
408
409 # Compile Fortran, C, and C++ files. Add the name of each object file
410 # that is produced to the overall list of object files.
411
412 if [ -n "$f77files" ]; then
413 for f in $f77files; do
414 case $f in
415 *.f)
416 b=`echo $f | $SED 's,.*/,,; s,\.f$,,'`
417 ;;
418 *.F)
419 b=`echo $f | $SED 's,.*/,,; s,\.F$,,'`
420 ;;
421 *.f90)
422 b=`echo $f | $SED 's,.*/,,; s,\.f90$,,'`
423 ;;
424 *.F90)
425 b=`echo $f | $SED 's,.*/,,; s,\.F90$,,'`
426 ;;
427 esac
428 if [ -n "$F77" ]; then
429 if [ -n "$outputfile" ]; then
430 if $link; then
431 o=$b.o
432 else
433 o=$outputfile
434 fi
435 else
436 o=$b.o
437 fi
438 objfiles="$objfiles $o"
439 cmd="$F77 -c $FPICFLAG $ALL_FFLAGS $incflags $defs $pass_on_options $f -o $o"
440 $dbg $cmd
441 eval $cmd
442 else
443 echo "mkoctfile: no way to compile Fortran file $f" 1>&2
444 fi
445 done
446 fi
447
448 if [ -n "$cfiles" ]; then
449 for f in $cfiles; do
450 if [ -n "$CC" ]; then
451 b=`echo $f | $SED 's,.*/,,; s,\.c$,,'`
452 if [ -n "$outputfile" ]; then
453 if $link; then
454 o=$b.o
455 else
456 o=$outputfile
457 fi
458 else
459 o=$b.o
460 fi
461 objfiles="$objfiles $o"
462 cmd="$CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $pass_on_options $incflags $defs $f -o $o"
463 $dbg $cmd
464 eval $cmd
465 else
466 echo "mkoctfile: no way to compile C++ file $f" 1>&2
467 fi
468 done
469 fi
470
471 if [ -n "$ccfiles" ]; then
472 for f in $ccfiles; do
473 if [ -n "$CXX" ]; then
474 case $f in
475 *.cc)
476 b=`echo $f | $SED 's,.*/,,; s,\.cc$,,'`
477 ;;
478 *.C)
479 b=`echo $f | $SED 's,.*/,,; s,\.C$,,'`
480 ;;
481 *.cpp)
482 b=`echo $f | $SED 's,.*/,,; s,\.cpp$,,'`
483 ;;
484 esac
485 if [ -n "$outputfile" ]; then
486 if $link; then
487 o=$b.o
488 else
489 o=$outputfile
490 fi
491 else
492 o=$b.o
493 fi
494 objfiles="$objfiles $o"
495 cmd="$CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $pass_on_options $incflags $defs $f -o $o"
496 $dbg $cmd
497 eval $cmd
498 else
499 echo "mkoctfile: no way to compile C++ file $f" 1>&2
500 fi
501 done
502 fi
503
504 ## Uncomment the following group of lines if you get `Text file busy'
505 ## errors from ld. This may happen if the .oct file is currently
506 ## running while you are trying to recompile it. We try moving first,
507 ## since on some systems (HP-UX, maybe others) it is possible to
508 ## rename running programs but not remove them.
509
510 ## if [ -f "$octfile" ]; then
511 ## cmd="mv $octfile $octfile.bak"
512 ## $dbg $cmd
513 ## eval $cmd
514 ## cmd="rm -f $octfile.bak"
515 ## $dbg $cmd
516 ## eval $cmd
517 ## fi
518
519 # Link all the object files.
520
521 if $link && [ -n "$objfiles" ]; then
522 if $link_stand_alone; then
523 if [ -n "$LD_CXX" ]; then
524 cmd="$LD_CXX $CPPFLAGS $ALL_CXXFLAGS $RDYNAMIC_FLAG $ALL_LDFLAGS $pass_on_options $output_option $objfiles $libfiles $ldflags $LFLAGS $RLD_FLAG $OCTAVE_LIBS $LAPACK_LIBS $BLAS_LIBS $FFTW_LIBS $READLINE_LIBS $LIBS $FLIBS"
525 $dbg $cmd
526 eval $cmd
527 else
528 echo "mkoctfile: no way to link stand-alone executable file" 1>&2
529 exit 1
530 fi
531 else
532 LINK_DEPS="$LFLAGS $OCTAVE_LIBS $LDFLAGS $LAPACK_LIBS $BLAS_LIBS $FFTW_LIBS $LIBS $FLIBS"
533 cmd="$DL_LD $DL_LDFLAGS $pass_on_options -o $octfile $objfiles $libfiles $ldflags $LINK_DEPS"
534 $dbg $cmd
535 eval $cmd
536 fi
537
538 # Maybe strip it.
539
540 if $strip; then
541 cmd="strip $octfile"
542 $dbg $cmd
543 eval $cmd
544 fi
545 fi
546
547 exit 0