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 ;; |
|
115 *.f | *.F) |
|
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 |
|
198 .f Fortran source |
|
199 .F Fortran source |
|
200 .o object file |
2163
|
201 |
3051
|
202 EOF |
|
203 exit 0 |
|
204 ;; |
3088
|
205 -I*) |
3176
|
206 incflags="$incflags $1" |
3088
|
207 ;; |
5483
|
208 -idirafter) |
|
209 shift |
|
210 if [ $# -gt 0 ]; then |
|
211 incflags="$incflags -idirafter $1" |
|
212 else |
|
213 echo "mkoctfile: include directory name misisng name missing" 1>&2 |
|
214 fi |
|
215 ;; |
3180
|
216 -D*) |
|
217 defs="$defs $1" |
|
218 ;; |
5199
|
219 -[lLR]*) |
3176
|
220 ldflags="$ldflags $1" |
3058
|
221 ;; |
3846
|
222 -M | --depend) |
|
223 depend=true |
|
224 compile=false |
|
225 ;; |
3051
|
226 -o | --output) |
|
227 shift |
|
228 if [ $# -gt 0 ]; then |
3860
|
229 outputfile="$1" |
3051
|
230 else |
3847
|
231 echo "mkoctfile: output file name missing" 1>&2 |
3051
|
232 fi |
|
233 ;; |
3734
|
234 -p | --print) |
|
235 shift |
|
236 if [ $# -gt 0 ]; then |
|
237 eval echo \${$1} |
|
238 exit 0 |
|
239 else |
3847
|
240 echo "mkoctfile: --print requires argument" 1>&2 |
3734
|
241 exit 1 |
|
242 fi |
|
243 ;; |
3058
|
244 -s | --strip) |
4199
|
245 if $no_oct_file_strip_on_this_platform; then |
|
246 echo "mkoctfile: stripping disabled on this platform" 1>&2 |
|
247 else |
|
248 strip=true |
|
249 fi |
3051
|
250 ;; |
3859
|
251 -c | --compile) |
3735
|
252 link=false |
|
253 ;; |
5904
|
254 -g) |
|
255 ALL_CFLAGS="$ALL_CFLAGS -g" |
|
256 ALL_CXXFLAGS="$ALL_CXXFLAGS -g" |
|
257 ALL_FFLAGS="$ALL_FFLAGS -g" |
|
258 ;; |
3859
|
259 --link-stand-alone) |
|
260 link_stand_alone=true |
|
261 ;; |
5864
|
262 --mex) |
|
263 output_ext=".mex" |
|
264 ;; |
4873
|
265 -W*) |
|
266 pass_on_options="$pass_on_options $1" |
|
267 ;; |
3051
|
268 *) |
3847
|
269 echo "mkoctfile: unrecognized argument $1" 1>&2 |
3051
|
270 exit 1 |
|
271 ;; |
|
272 esac |
|
273 if [ -n "$file" ]; then |
|
274 if [ -z "$octfile" ]; then |
3859
|
275 octfile="$file" |
3051
|
276 fi |
|
277 fi |
|
278 shift |
|
279 done |
2163
|
280 |
3859
|
281 if $link_stand_alone; then |
3860
|
282 if [ -n "$outputfile" ]; then |
|
283 output_option="-o $outputfile" |
|
284 fi |
3859
|
285 else |
3860
|
286 if [ -n "$outputfile" ]; then |
|
287 octfile="$outputfile" |
|
288 else |
5864
|
289 octfile=`echo $octfile | $SED 's,\.[^.]*$,,'`$output_ext |
3860
|
290 fi |
3859
|
291 fi |
|
292 |
3846
|
293 # Generate dependency files for C and C++ files. |
|
294 |
|
295 if $depend; then |
|
296 if [ -n "$cfiles" ]; then |
|
297 for f in $cfiles; do |
4084
|
298 b=`echo $f | $SED 's,\.c$,,'` |
3846
|
299 d=$b.d |
3847
|
300 cmd="rm -f $d" |
|
301 $dbg $cmd |
|
302 eval $cmd |
4206
|
303 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
|
304 $dbg $cmd |
|
305 eval $cmd |
|
306 done |
|
307 fi |
|
308 |
|
309 if [ -n "$ccfiles" ]; then |
|
310 for f in $ccfiles; do |
|
311 case $f in |
3847
|
312 *.cc) |
4084
|
313 b=`echo $f | $SED 's,\.cc$,,'` |
3847
|
314 ;; |
|
315 *.C) |
4084
|
316 b=`echo $f | $SED 's,\.C$,,'` |
3847
|
317 ;; |
|
318 *.cpp) |
4084
|
319 b=`echo $f | $SED 's,\.cpp$,,'` |
3847
|
320 ;; |
3846
|
321 esac |
|
322 d=$b.d |
3847
|
323 cmd="rm -f $d" |
|
324 $dbg $cmd |
|
325 eval $cmd |
4206
|
326 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
|
327 $dbg $cmd |
|
328 eval $cmd |
|
329 done |
|
330 fi |
|
331 # If generating dependencies, that's all we do. |
|
332 exit 0 |
|
333 fi |
|
334 |
3051
|
335 # Compile Fortran, C, and C++ files. Add the name of each object file |
|
336 # that is produced to the overall list of object files. |
2163
|
337 |
3051
|
338 if [ -n "$f77files" ]; then |
|
339 for f in $f77files; do |
|
340 case $f in |
|
341 *.f) |
4084
|
342 b=`echo $f | $SED 's,\.f$,,'` |
3051
|
343 ;; |
|
344 *.F) |
4084
|
345 b=`echo $f | $SED 's,\.F$,,'` |
3051
|
346 ;; |
|
347 esac |
3847
|
348 if [ -n "$F77" ]; then |
5159
|
349 if [ -n "$outputfile" ]; then |
|
350 if $link; then |
|
351 o=$b.o |
|
352 else |
|
353 o=$outputfile |
|
354 fi |
|
355 else |
|
356 o=$b.o |
|
357 fi |
3847
|
358 objfiles="$objfiles $o" |
4873
|
359 cmd="$F77 -c $FPICFLAG $ALL_FFLAGS $pass_on_options $f -o $o" |
3847
|
360 $dbg $cmd |
|
361 eval $cmd |
|
362 elif [ -n "$F2C" ]; then |
|
363 c=$b.c |
|
364 cfiles="$cfiles $c" |
|
365 cmd="$F2C $F2CFLAGS < $f > $c" |
|
366 $dbg $cmd |
|
367 eval $cmd |
|
368 else |
|
369 echo "mkoctfile: no way to compile Fortran file $f" 1>&2 |
|
370 fi |
3051
|
371 done |
|
372 fi |
2163
|
373 |
3051
|
374 if [ -n "$cfiles" ]; then |
|
375 for f in $cfiles; do |
3847
|
376 if [ -n "$CC" ]; then |
4084
|
377 b=`echo $f | $SED 's,\.c$,,'` |
5159
|
378 if [ -n "$outputfile" ]; then |
|
379 if $link; then |
|
380 o=$b.o |
|
381 else |
|
382 o=$outputfile |
|
383 fi |
|
384 else |
|
385 o=$b.o |
|
386 fi |
3847
|
387 objfiles="$objfiles $o" |
4873
|
388 cmd="$CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $pass_on_options $incflags $defs $f -o $o" |
3847
|
389 $dbg $cmd |
|
390 eval $cmd |
|
391 else |
|
392 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
393 fi |
3051
|
394 done |
|
395 fi |
2163
|
396 |
3051
|
397 if [ -n "$ccfiles" ]; then |
|
398 for f in $ccfiles; do |
3847
|
399 if [ -n "$CXX" ]; then |
|
400 case $f in |
|
401 *.cc) |
4084
|
402 b=`echo $f | $SED 's,\.cc$,,'` |
3847
|
403 ;; |
|
404 *.C) |
4084
|
405 b=`echo $f | $SED 's,\.C$,,'` |
3847
|
406 ;; |
|
407 *.cpp) |
4084
|
408 b=`echo $f | $SED 's,\.cpp$,,'` |
3847
|
409 ;; |
|
410 esac |
5159
|
411 if [ -n "$outputfile" ]; then |
|
412 if $link; then |
|
413 o=$b.o |
|
414 else |
|
415 o=$outputfile |
|
416 fi |
|
417 else |
|
418 o=$b.o |
|
419 fi |
3847
|
420 objfiles="$objfiles $o" |
4873
|
421 cmd="$CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $pass_on_options $incflags $defs $f -o $o" |
3847
|
422 $dbg $cmd |
|
423 eval $cmd |
|
424 else |
|
425 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
426 fi |
3051
|
427 done |
|
428 fi |
|
429 |
3660
|
430 ## Uncomment the following group of lines if you get `Text file busy' |
|
431 ## errors from ld. This may happen if the .oct file is currently |
|
432 ## running while you are trying to recompile it. We try moving first, |
3733
|
433 ## since on some systems (HP-UX, maybe others) it is possible to |
3660
|
434 ## rename running programs but not remove them. |
|
435 |
3663
|
436 ## if [ -f "$octfile" ]; then |
3847
|
437 ## cmd="mv $octfile $octfile.bak" |
|
438 ## $dbg $cmd |
|
439 ## eval $cmd |
|
440 ## cmd="rm -f $octfile.bak" |
|
441 ## $dbg $cmd |
|
442 ## eval $cmd |
3663
|
443 ## fi |
3659
|
444 |
3051
|
445 # Link all the object files. |
|
446 |
5285
|
447 if $link && [ -n "$objfiles" ]; then |
3859
|
448 if $link_stand_alone; then |
|
449 if [ -n "$LD_CXX" ]; then |
4873
|
450 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
|
451 $dbg $cmd |
|
452 eval $cmd |
|
453 else |
|
454 echo "mkoctfile: no way to link stand-alone executable file" 1>&2 |
|
455 exit 1 |
|
456 fi |
|
457 else |
4793
|
458 LINK_DEPS="$LFLAGS $OCTAVE_LIBS $LDFLAGS $BLAS_LIBS $FFTW_LIBS $LIBS $FLIBS" |
4873
|
459 cmd="$DL_LD $DL_LDFLAGS $pass_on_options -o $octfile $objfiles $ldflags $LINK_DEPS" |
3859
|
460 $dbg $cmd |
|
461 eval $cmd |
|
462 fi |
3058
|
463 |
|
464 # Maybe strip it. |
|
465 |
3847
|
466 if $strip; then |
|
467 cmd="strip $octfile" |
|
468 $dbg $cmd |
|
469 eval $cmd |
|
470 fi |
3735
|
471 fi |
3058
|
472 |
|
473 exit 0 |