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