2163
|
1 #! /bin/sh |
|
2 # |
|
3 # mkoctfile -- create a .oct file suitable for dynamic linking by |
|
4 # Octave. |
|
5 |
3051
|
6 # Exit immediately on any error. |
|
7 |
2163
|
8 set -e |
|
9 |
6311
|
10 : ${SED=%OCTAVE_CONF_SED%} |
|
11 |
6086
|
12 OCTAVE_VERSION=%OCTAVE_CONF_VERSION% |
6311
|
13 OCTAVE_PREFIX=%OCTAVE_CONF_PREFIX% |
|
14 |
6682
|
15 DEFAULT_BINDIR=%OCTAVE_BINDIR% |
|
16 DEFAULT_INCLUDEDIR=%OCTAVE_CONF_INCLUDEDIR% |
6311
|
17 DEFAULT_OCTINCLUDEDIR=%OCTAVE_CONF_OCTINCLUDEDIR% |
|
18 DEFAULT_OCTLIBDIR=%OCTAVE_CONF_OCTLIBDIR% |
|
19 |
|
20 if [ -n "$OCTAVE_HOME" ]; then |
6682
|
21 DEFAULT_BINDIR="`echo $DEFAULT_BINDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`" |
|
22 DEFAULT_INCLUDEDIR="`echo $DEFAULT_INCLUDEDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`" |
6319
|
23 DEFAULT_OCTINCLUDEDIR="`echo $DEFAULT_OCTINCLUDEDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`" |
|
24 DEFAULT_OCTLIBDIR="`echo $DEFAULT_OCTLIBDIR | $SED "s,^$OCTAVE_PREFIX,$OCTAVE_HOME,"`" |
6311
|
25 fi |
|
26 |
6682
|
27 : ${BINDIR=$DEFAULT_BINDIR} |
|
28 : ${INCLUDEDIR=$DEFAULT_INCLUDEDIR} |
6311
|
29 : ${OCTINCLUDEDIR=$DEFAULT_OCTINCLUDEDIR} |
|
30 : ${OCTLIBDIR=$DEFAULT_OCTLIBDIR} |
|
31 |
|
32 DEFAULT_INCFLAGS="-I$OCTINCLUDEDIR -I$OCTINCLUDEDIR/octave" |
|
33 if [ "$INCLUDEDIR" != /usr/include ]; then |
|
34 DEFAULT_INCFLAGS="$DEFAULT_INCFLAGS -I$INCLUDEDIR" |
|
35 fi |
|
36 |
|
37 DEFAULT_LFLAGS="-L$OCTLIBDIR" |
5285
|
38 |
3051
|
39 # Default values for these variables are filled in when Octave is |
|
40 # compiled. |
|
41 |
6682
|
42 : ${EXEEXT=%OCTAVE_CONF_EXEEXT%} |
|
43 |
3590
|
44 : ${CPPFLAGS=%OCTAVE_CONF_CPPFLAGS%} |
6311
|
45 : ${INCFLAGS=$DEFAULT_INCFLAGS} |
3847
|
46 : ${F2C=%OCTAVE_CONF_F2C%} |
|
47 : ${F2CFLAGS=%OCTAVE_CONF_F2CFLAGS%} |
3590
|
48 : ${F77=%OCTAVE_CONF_F77%} |
|
49 : ${FFLAGS=%OCTAVE_CONF_FFLAGS%} |
|
50 : ${FPICFLAG=%OCTAVE_CONF_FPICFLAG%} |
|
51 : ${CC=%OCTAVE_CONF_CC%} |
|
52 : ${CFLAGS=%OCTAVE_CONF_CFLAGS%} |
|
53 : ${CPICFLAG=%OCTAVE_CONF_CPICFLAG%} |
|
54 : ${CXX=%OCTAVE_CONF_CXX%} |
|
55 : ${CXXFLAGS=%OCTAVE_CONF_CXXFLAGS%} |
|
56 : ${CXXPICFLAG=%OCTAVE_CONF_CXXPICFLAG%} |
|
57 : ${XTRA_CFLAGS=%OCTAVE_CONF_XTRA_CFLAGS%} |
|
58 : ${XTRA_CXXFLAGS=%OCTAVE_CONF_XTRA_CXXFLAGS%} |
3051
|
59 |
3846
|
60 : ${DEPEND_FLAGS=%OCTAVE_CONF_DEPEND_FLAGS%} |
|
61 : ${DEPEND_EXTRA_SED_PATTERN=%OCTAVE_CONF_DEPEND_EXTRA_SED_PATTERN%} |
|
62 |
4759
|
63 : ${DL_LD=%OCTAVE_CONF_DL_LD%} |
|
64 : ${DL_LDFLAGS=%OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS%} |
3051
|
65 |
3859
|
66 : ${RLD_FLAG=%OCTAVE_CONF_RLD_FLAG%} |
|
67 : ${RDYNAMIC_FLAG=%OCTAVE_CONF_RDYNAMIC_FLAG%} |
4228
|
68 : ${LIBOCTAVE=-loctave} |
|
69 : ${LIBOCTINTERP=-loctinterp} |
|
70 : ${LIBREADLINE=-lreadline} |
|
71 : ${LIBCRUFT=-lcruft} |
3859
|
72 : ${BLAS_LIBS=%OCTAVE_CONF_BLAS_LIBS%} |
|
73 : ${FFTW_LIBS=%OCTAVE_CONF_FFTW_LIBS%} |
|
74 : ${LIBS=%OCTAVE_CONF_LIBS%} |
|
75 : ${FLIBS=%OCTAVE_CONF_FLIBS%} |
|
76 : ${LD_CXX=%OCTAVE_CONF_LD_CXX%} |
|
77 : ${LDFLAGS=%OCTAVE_CONF_LDFLAGS%} |
|
78 : ${LD_STATIC_FLAG=%OCTAVE_CONF_LD_STATIC_FLAG%} |
6311
|
79 : ${LFLAGS=$DEFAULT_LFLAGS} |
3859
|
80 |
3051
|
81 : ${ALL_FFLAGS="$FFLAGS"} |
|
82 |
3131
|
83 : ${ALL_CFLAGS="$INCFLAGS $XTRA_CFLAGS $CFLAGS"} |
3051
|
84 |
3131
|
85 : ${ALL_CXXFLAGS="$INCFLAGS $XTRA_CXXFLAGS $CXXFLAGS"} |
3051
|
86 |
3887
|
87 : ${ALL_LDFLAGS="$LD_STATIC_FLAG $CPICFLAG $LDFLAGS"} |
3859
|
88 |
4228
|
89 : ${OCTAVE_LIBS="$LIBOCTINTERP $LIBOCTAVE $SPECIAL_MATH_LIB $LIBCRUFT"} |
3859
|
90 |
3051
|
91 # Local variables. |
|
92 |
|
93 usage_msg="usage: mkoctfile [options] file ..." |
|
94 |
5285
|
95 version_msg="mkoctfile, version $OCTAVE_VERSION" |
|
96 |
3051
|
97 cfiles= |
|
98 ccfiles= |
|
99 f77files= |
|
100 objfiles= |
6294
|
101 libfiles= |
3051
|
102 octfiles= |
|
103 octfile= |
3860
|
104 outputfile= |
3088
|
105 incflags= |
3180
|
106 defs= |
3051
|
107 ldflags= |
|
108 dbg=: |
4873
|
109 pass_on_options= |
3058
|
110 strip=false |
4199
|
111 no_oct_file_strip_on_this_platform=%NO_OCT_FILE_STRIP% |
3735
|
112 link=true |
3859
|
113 link_stand_alone=false |
5864
|
114 output_ext=".oct" |
3846
|
115 depend=false |
|
116 compile=true |
3051
|
117 |
|
118 if [ $# -eq 0 ]; then |
3847
|
119 echo $usage_msg 1>&2 |
3846
|
120 exit 1 |
2163
|
121 fi |
|
122 |
5285
|
123 if [ $# -eq 1 ]; then |
|
124 case "$1" in |
|
125 -v | --version) |
|
126 echo $version_msg 1>&2 |
|
127 exit 0 |
|
128 ;; |
|
129 esac |
|
130 fi |
|
131 |
3051
|
132 while [ $# -gt 0 ]; do |
|
133 file= |
|
134 case "$1" in |
|
135 *.c) |
|
136 file=$1 |
|
137 cfiles="$cfiles $file" |
|
138 ;; |
|
139 *.cc | *.C | *.cpp) |
|
140 file=$1 |
|
141 ccfiles="$ccfiles $file" |
|
142 ;; |
5970
|
143 *.f | *.F | *.f90 | *.F90) |
3051
|
144 file=$1 |
|
145 f77files="$f77files $file" |
|
146 ;; |
|
147 *.o) |
|
148 file=$1 |
|
149 objfiles="$objfiles $file" |
|
150 ;; |
6294
|
151 *.a) |
|
152 file=$1 |
|
153 libfiles="$libfiles $file" |
|
154 ;; |
3058
|
155 -d | --debug | -v | --verbose) |
3051
|
156 dbg=echo |
|
157 ;; |
3233
|
158 -h | -\? | --help) |
3847
|
159 echo $usage_msg 1>&2 |
3051
|
160 cat << EOF |
2163
|
161 |
3051
|
162 Options: |
|
163 |
3233
|
164 -h, -?, --help Print this message. |
3734
|
165 |
3088
|
166 -IDIR Add -IDIR to compile commands. |
3734
|
167 |
5483
|
168 -idirafter DIR Add -idirafter DIR to compile commands. |
|
169 |
3180
|
170 -DDEF Add -DDEF to compile commands. |
3734
|
171 |
3058
|
172 -lLIB Add library LIB to link command. |
3734
|
173 |
3087
|
174 -LDIR Add -LDIR to link command. |
3734
|
175 |
3846
|
176 -M, --depend Generate dependency files (.d) for C and C++ |
|
177 source files. |
|
178 |
5199
|
179 -RDIR Add -RDIR to link command. |
|
180 |
6153
|
181 -Wl,... Pass flags though the linker like -Wl,-rpath=... |
|
182 |
|
183 -W... Pass flags though the compiler like -Wa,OPTION. |
5199
|
184 |
3859
|
185 -c, --compile Compile, but do not link. |
3735
|
186 |
3859
|
187 -o FILE, --output FILE Output file name. Default extension is .oct |
5864
|
188 (or .mex if --mex is specified) unless linking |
|
189 a stand-alone executable. |
3734
|
190 |
5904
|
191 -g Enable debugging options for compilers. |
|
192 |
3734
|
193 -p VAR, --print VAR Print configuration variable VAR. Recognized |
|
194 variables are: |
|
195 |
5669
|
196 ALL_CFLAGS FFTW_LIBS |
|
197 ALL_CXXFLAGS FLIBS |
|
198 ALL_FFLAGS FPICFLAG |
|
199 ALL_LDFLAGS INCFLAGS |
|
200 BLAS_LIBS LDFLAGS |
|
201 CC LD_CXX |
|
202 CFLAGS LD_STATIC_FLAG |
|
203 CPICFLAG LFLAGS |
|
204 CPPFLAGS LIBCRUFT |
|
205 CXX LIBOCTAVE |
|
206 CXXFLAGS LIBOCTINTERP |
|
207 CXXPICFLAG LIBREADLINE |
|
208 DEPEND_EXTRA_SED_PATTERN LIBS |
|
209 DEPEND_FLAGS OCTAVE_LIBS |
|
210 DL_LD RDYNAMIC_FLAG |
|
211 DL_LDFLAGS RLD_FLAG |
|
212 F2C SED |
|
213 F2CFLAGS XTRA_CFLAGS |
|
214 F77 XTRA_CXXFLAGS |
|
215 FFLAGS |
3859
|
216 |
|
217 --link-stand-alone Link a stand-alone executable file. |
|
218 |
5864
|
219 --mex Assume we are creating a MEX file. Set the |
|
220 default output extension to ".mex". |
|
221 |
3058
|
222 -s, --strip Strip output file. |
3734
|
223 |
3058
|
224 -v, --verbose Echo commands as they are executed. |
3051
|
225 |
|
226 FILE Compile or link FILE. Recognized file types are: |
|
227 |
3847
|
228 .c C source |
|
229 .cc C++ source |
|
230 .C C++ source |
|
231 .cpp C++ source |
5970
|
232 .f Fortran source (fixed form) |
|
233 .F Fortran source (fixed form) |
|
234 .f90 Fortran source (free form) |
|
235 .F90 Fortran source (free form) |
3847
|
236 .o object file |
6294
|
237 .a library file |
2163
|
238 |
3051
|
239 EOF |
|
240 exit 0 |
|
241 ;; |
3088
|
242 -I*) |
3176
|
243 incflags="$incflags $1" |
3088
|
244 ;; |
5483
|
245 -idirafter) |
|
246 shift |
|
247 if [ $# -gt 0 ]; then |
|
248 incflags="$incflags -idirafter $1" |
|
249 else |
|
250 echo "mkoctfile: include directory name misisng name missing" 1>&2 |
|
251 fi |
|
252 ;; |
3180
|
253 -D*) |
|
254 defs="$defs $1" |
|
255 ;; |
6153
|
256 -[lLR]* | -Wl,*) |
3176
|
257 ldflags="$ldflags $1" |
3058
|
258 ;; |
3846
|
259 -M | --depend) |
|
260 depend=true |
|
261 compile=false |
|
262 ;; |
3051
|
263 -o | --output) |
|
264 shift |
|
265 if [ $# -gt 0 ]; then |
3860
|
266 outputfile="$1" |
3051
|
267 else |
3847
|
268 echo "mkoctfile: output file name missing" 1>&2 |
3051
|
269 fi |
|
270 ;; |
3734
|
271 -p | --print) |
|
272 shift |
|
273 if [ $# -gt 0 ]; then |
|
274 eval echo \${$1} |
|
275 exit 0 |
|
276 else |
3847
|
277 echo "mkoctfile: --print requires argument" 1>&2 |
3734
|
278 exit 1 |
|
279 fi |
|
280 ;; |
3058
|
281 -s | --strip) |
4199
|
282 if $no_oct_file_strip_on_this_platform; then |
|
283 echo "mkoctfile: stripping disabled on this platform" 1>&2 |
|
284 else |
|
285 strip=true |
|
286 fi |
3051
|
287 ;; |
3859
|
288 -c | --compile) |
3735
|
289 link=false |
|
290 ;; |
5904
|
291 -g) |
|
292 ALL_CFLAGS="$ALL_CFLAGS -g" |
|
293 ALL_CXXFLAGS="$ALL_CXXFLAGS -g" |
|
294 ALL_FFLAGS="$ALL_FFLAGS -g" |
|
295 ;; |
3859
|
296 --link-stand-alone) |
|
297 link_stand_alone=true |
|
298 ;; |
5864
|
299 --mex) |
6009
|
300 incflags="$incflags -I." |
5864
|
301 output_ext=".mex" |
|
302 ;; |
4873
|
303 -W*) |
|
304 pass_on_options="$pass_on_options $1" |
|
305 ;; |
3051
|
306 *) |
3847
|
307 echo "mkoctfile: unrecognized argument $1" 1>&2 |
3051
|
308 exit 1 |
|
309 ;; |
|
310 esac |
|
311 if [ -n "$file" ]; then |
|
312 if [ -z "$octfile" ]; then |
3859
|
313 octfile="$file" |
3051
|
314 fi |
|
315 fi |
|
316 shift |
|
317 done |
2163
|
318 |
3859
|
319 if $link_stand_alone; then |
3860
|
320 if [ -n "$outputfile" ]; then |
|
321 output_option="-o $outputfile" |
|
322 fi |
3859
|
323 else |
3860
|
324 if [ -n "$outputfile" ]; then |
|
325 octfile="$outputfile" |
|
326 else |
6187
|
327 octfile=`basename $octfile` |
5864
|
328 octfile=`echo $octfile | $SED 's,\.[^.]*$,,'`$output_ext |
3860
|
329 fi |
3859
|
330 fi |
|
331 |
3846
|
332 # Generate dependency files for C and C++ files. |
|
333 |
|
334 if $depend; then |
|
335 if [ -n "$cfiles" ]; then |
|
336 for f in $cfiles; do |
4084
|
337 b=`echo $f | $SED 's,\.c$,,'` |
3846
|
338 d=$b.d |
3847
|
339 cmd="rm -f $d" |
|
340 $dbg $cmd |
|
341 eval $cmd |
4206
|
342 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" |
3846
|
343 $dbg $cmd |
|
344 eval $cmd |
|
345 done |
|
346 fi |
|
347 |
|
348 if [ -n "$ccfiles" ]; then |
|
349 for f in $ccfiles; do |
|
350 case $f in |
3847
|
351 *.cc) |
4084
|
352 b=`echo $f | $SED 's,\.cc$,,'` |
3847
|
353 ;; |
|
354 *.C) |
4084
|
355 b=`echo $f | $SED 's,\.C$,,'` |
3847
|
356 ;; |
|
357 *.cpp) |
4084
|
358 b=`echo $f | $SED 's,\.cpp$,,'` |
3847
|
359 ;; |
3846
|
360 esac |
|
361 d=$b.d |
3847
|
362 cmd="rm -f $d" |
|
363 $dbg $cmd |
|
364 eval $cmd |
4206
|
365 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" |
3846
|
366 $dbg $cmd |
|
367 eval $cmd |
|
368 done |
|
369 fi |
|
370 # If generating dependencies, that's all we do. |
|
371 exit 0 |
|
372 fi |
|
373 |
3051
|
374 # Compile Fortran, C, and C++ files. Add the name of each object file |
|
375 # that is produced to the overall list of object files. |
2163
|
376 |
3051
|
377 if [ -n "$f77files" ]; then |
|
378 for f in $f77files; do |
|
379 case $f in |
|
380 *.f) |
4084
|
381 b=`echo $f | $SED 's,\.f$,,'` |
3051
|
382 ;; |
|
383 *.F) |
4084
|
384 b=`echo $f | $SED 's,\.F$,,'` |
3051
|
385 ;; |
5970
|
386 *.f90) |
|
387 b=`echo $f | $SED 's,\.f90$,,'` |
|
388 ;; |
|
389 *.F90) |
|
390 b=`echo $f | $SED 's,\.F90$,,'` |
|
391 ;; |
3051
|
392 esac |
3847
|
393 if [ -n "$F77" ]; then |
5159
|
394 if [ -n "$outputfile" ]; then |
|
395 if $link; then |
|
396 o=$b.o |
|
397 else |
|
398 o=$outputfile |
|
399 fi |
|
400 else |
|
401 o=$b.o |
|
402 fi |
3847
|
403 objfiles="$objfiles $o" |
5970
|
404 cmd="$F77 -c $FPICFLAG $ALL_FFLAGS $incflags $defs $pass_on_options $f -o $o" |
3847
|
405 $dbg $cmd |
|
406 eval $cmd |
|
407 elif [ -n "$F2C" ]; then |
|
408 c=$b.c |
|
409 cfiles="$cfiles $c" |
|
410 cmd="$F2C $F2CFLAGS < $f > $c" |
|
411 $dbg $cmd |
|
412 eval $cmd |
|
413 else |
|
414 echo "mkoctfile: no way to compile Fortran file $f" 1>&2 |
|
415 fi |
3051
|
416 done |
|
417 fi |
2163
|
418 |
3051
|
419 if [ -n "$cfiles" ]; then |
|
420 for f in $cfiles; do |
3847
|
421 if [ -n "$CC" ]; then |
4084
|
422 b=`echo $f | $SED 's,\.c$,,'` |
5159
|
423 if [ -n "$outputfile" ]; then |
|
424 if $link; then |
|
425 o=$b.o |
|
426 else |
|
427 o=$outputfile |
|
428 fi |
|
429 else |
|
430 o=$b.o |
|
431 fi |
3847
|
432 objfiles="$objfiles $o" |
4873
|
433 cmd="$CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $pass_on_options $incflags $defs $f -o $o" |
3847
|
434 $dbg $cmd |
|
435 eval $cmd |
|
436 else |
|
437 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
438 fi |
3051
|
439 done |
|
440 fi |
2163
|
441 |
3051
|
442 if [ -n "$ccfiles" ]; then |
|
443 for f in $ccfiles; do |
3847
|
444 if [ -n "$CXX" ]; then |
|
445 case $f in |
|
446 *.cc) |
4084
|
447 b=`echo $f | $SED 's,\.cc$,,'` |
3847
|
448 ;; |
|
449 *.C) |
4084
|
450 b=`echo $f | $SED 's,\.C$,,'` |
3847
|
451 ;; |
|
452 *.cpp) |
4084
|
453 b=`echo $f | $SED 's,\.cpp$,,'` |
3847
|
454 ;; |
|
455 esac |
5159
|
456 if [ -n "$outputfile" ]; then |
|
457 if $link; then |
|
458 o=$b.o |
|
459 else |
|
460 o=$outputfile |
|
461 fi |
|
462 else |
|
463 o=$b.o |
|
464 fi |
3847
|
465 objfiles="$objfiles $o" |
4873
|
466 cmd="$CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $pass_on_options $incflags $defs $f -o $o" |
3847
|
467 $dbg $cmd |
|
468 eval $cmd |
|
469 else |
|
470 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
471 fi |
3051
|
472 done |
|
473 fi |
|
474 |
3660
|
475 ## Uncomment the following group of lines if you get `Text file busy' |
|
476 ## errors from ld. This may happen if the .oct file is currently |
|
477 ## running while you are trying to recompile it. We try moving first, |
3733
|
478 ## since on some systems (HP-UX, maybe others) it is possible to |
3660
|
479 ## rename running programs but not remove them. |
|
480 |
3663
|
481 ## if [ -f "$octfile" ]; then |
3847
|
482 ## cmd="mv $octfile $octfile.bak" |
|
483 ## $dbg $cmd |
|
484 ## eval $cmd |
|
485 ## cmd="rm -f $octfile.bak" |
|
486 ## $dbg $cmd |
|
487 ## eval $cmd |
3663
|
488 ## fi |
3659
|
489 |
3051
|
490 # Link all the object files. |
|
491 |
5285
|
492 if $link && [ -n "$objfiles" ]; then |
3859
|
493 if $link_stand_alone; then |
|
494 if [ -n "$LD_CXX" ]; then |
6294
|
495 cmd="$LD_CXX $CPPFLAGS $ALL_CXXFLAGS $RDYNAMIC_FLAG $ALL_LDFLAGS $pass_on_options $output_option $objfiles $libfiles $ldflags $LFLAGS $RLD_FLAG $OCTAVE_LIBS $BLAS_LIBS $FFTW_LIBS $LIBREADLINE $LIBS $FLIBS" |
3859
|
496 $dbg $cmd |
|
497 eval $cmd |
|
498 else |
|
499 echo "mkoctfile: no way to link stand-alone executable file" 1>&2 |
|
500 exit 1 |
|
501 fi |
|
502 else |
4793
|
503 LINK_DEPS="$LFLAGS $OCTAVE_LIBS $LDFLAGS $BLAS_LIBS $FFTW_LIBS $LIBS $FLIBS" |
6294
|
504 cmd="$DL_LD $DL_LDFLAGS $pass_on_options -o $octfile $objfiles $libfiles $ldflags $LINK_DEPS" |
3859
|
505 $dbg $cmd |
|
506 eval $cmd |
|
507 fi |
3058
|
508 |
|
509 # Maybe strip it. |
|
510 |
3847
|
511 if $strip; then |
|
512 cmd="strip $octfile" |
|
513 $dbg $cmd |
|
514 eval $cmd |
|
515 fi |
3735
|
516 fi |
3058
|
517 |
|
518 exit 0 |