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