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