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