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