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