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