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 |
3051
|
10 # Default values for these variables are filled in when Octave is |
|
11 # compiled. |
|
12 |
4084
|
13 : ${SED=%OCTAVE_CONF_SED%} |
|
14 |
3590
|
15 : ${CPPFLAGS=%OCTAVE_CONF_CPPFLAGS%} |
3591
|
16 : ${INCFLAGS=%OCTAVE_CONF_MKOCTFILE_INCFLAGS%} |
3847
|
17 : ${F2C=%OCTAVE_CONF_F2C%} |
|
18 : ${F2CFLAGS=%OCTAVE_CONF_F2CFLAGS%} |
3590
|
19 : ${F77=%OCTAVE_CONF_F77%} |
|
20 : ${FFLAGS=%OCTAVE_CONF_FFLAGS%} |
|
21 : ${FPICFLAG=%OCTAVE_CONF_FPICFLAG%} |
|
22 : ${CC=%OCTAVE_CONF_CC%} |
|
23 : ${CFLAGS=%OCTAVE_CONF_CFLAGS%} |
|
24 : ${CPICFLAG=%OCTAVE_CONF_CPICFLAG%} |
|
25 : ${CXX=%OCTAVE_CONF_CXX%} |
|
26 : ${CXXFLAGS=%OCTAVE_CONF_CXXFLAGS%} |
|
27 : ${CXXPICFLAG=%OCTAVE_CONF_CXXPICFLAG%} |
|
28 : ${XTRA_CFLAGS=%OCTAVE_CONF_XTRA_CFLAGS%} |
|
29 : ${XTRA_CXXFLAGS=%OCTAVE_CONF_XTRA_CXXFLAGS%} |
3051
|
30 |
3846
|
31 : ${DEPEND_FLAGS=%OCTAVE_CONF_DEPEND_FLAGS%} |
|
32 : ${DEPEND_EXTRA_SED_PATTERN=%OCTAVE_CONF_DEPEND_EXTRA_SED_PATTERN%} |
|
33 |
4759
|
34 : ${DL_LD=%OCTAVE_CONF_DL_LD%} |
|
35 : ${DL_LDFLAGS=%OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS%} |
3051
|
36 |
3859
|
37 : ${RLD_FLAG=%OCTAVE_CONF_RLD_FLAG%} |
|
38 : ${RDYNAMIC_FLAG=%OCTAVE_CONF_RDYNAMIC_FLAG%} |
4228
|
39 : ${LIBOCTAVE=-loctave} |
|
40 : ${LIBOCTINTERP=-loctinterp} |
|
41 : ${LIBREADLINE=-lreadline} |
|
42 : ${LIBCRUFT=-lcruft} |
3859
|
43 : ${BLAS_LIBS=%OCTAVE_CONF_BLAS_LIBS%} |
|
44 : ${FFTW_LIBS=%OCTAVE_CONF_FFTW_LIBS%} |
|
45 : ${LIBS=%OCTAVE_CONF_LIBS%} |
|
46 : ${FLIBS=%OCTAVE_CONF_FLIBS%} |
|
47 : ${LD_CXX=%OCTAVE_CONF_LD_CXX%} |
|
48 : ${LDFLAGS=%OCTAVE_CONF_LDFLAGS%} |
|
49 : ${LD_STATIC_FLAG=%OCTAVE_CONF_LD_STATIC_FLAG%} |
|
50 : ${LFLAGS=%OCTAVE_CONF_MKOCTFILE_LFLAGS%} |
|
51 |
3051
|
52 : ${ALL_FFLAGS="$FFLAGS"} |
|
53 |
3131
|
54 : ${ALL_CFLAGS="$INCFLAGS $XTRA_CFLAGS $CFLAGS"} |
3051
|
55 |
3131
|
56 : ${ALL_CXXFLAGS="$INCFLAGS $XTRA_CXXFLAGS $CXXFLAGS"} |
3051
|
57 |
3887
|
58 : ${ALL_LDFLAGS="$LD_STATIC_FLAG $CPICFLAG $LDFLAGS"} |
3859
|
59 |
4228
|
60 : ${OCTAVE_LIBS="$LIBOCTINTERP $LIBOCTAVE $SPECIAL_MATH_LIB $LIBCRUFT"} |
3859
|
61 |
3051
|
62 # Local variables. |
|
63 |
|
64 usage_msg="usage: mkoctfile [options] file ..." |
|
65 |
|
66 cfiles= |
|
67 ccfiles= |
|
68 f77files= |
|
69 objfiles= |
|
70 octfiles= |
|
71 octfile= |
3860
|
72 outputfile= |
3088
|
73 incflags= |
3180
|
74 defs= |
3051
|
75 ldflags= |
|
76 dbg=: |
4873
|
77 pass_on_options= |
3058
|
78 strip=false |
4199
|
79 no_oct_file_strip_on_this_platform=%NO_OCT_FILE_STRIP% |
3735
|
80 link=true |
3859
|
81 link_stand_alone=false |
3846
|
82 depend=false |
|
83 compile=true |
3051
|
84 |
|
85 if [ $# -eq 0 ]; then |
3847
|
86 echo $usage_msg 1>&2 |
3846
|
87 exit 1 |
2163
|
88 fi |
|
89 |
3051
|
90 while [ $# -gt 0 ]; do |
|
91 file= |
|
92 case "$1" in |
|
93 *.c) |
|
94 file=$1 |
|
95 cfiles="$cfiles $file" |
|
96 ;; |
|
97 *.cc | *.C | *.cpp) |
|
98 file=$1 |
|
99 ccfiles="$ccfiles $file" |
|
100 ;; |
|
101 *.f | *.F) |
|
102 file=$1 |
|
103 f77files="$f77files $file" |
|
104 ;; |
|
105 *.o) |
|
106 file=$1 |
|
107 objfiles="$objfiles $file" |
|
108 ;; |
3058
|
109 -d | --debug | -v | --verbose) |
3051
|
110 dbg=echo |
|
111 ;; |
3233
|
112 -h | -\? | --help) |
3847
|
113 echo $usage_msg 1>&2 |
3051
|
114 cat << EOF |
2163
|
115 |
3051
|
116 Options: |
|
117 |
3233
|
118 -h, -?, --help Print this message. |
3734
|
119 |
3088
|
120 -IDIR Add -IDIR to compile commands. |
3734
|
121 |
3180
|
122 -DDEF Add -DDEF to compile commands. |
3734
|
123 |
3058
|
124 -lLIB Add library LIB to link command. |
3734
|
125 |
3087
|
126 -LDIR Add -LDIR to link command. |
3734
|
127 |
3846
|
128 -M, --depend Generate dependency files (.d) for C and C++ |
|
129 source files. |
|
130 |
3859
|
131 -c, --compile Compile, but do not link. |
3735
|
132 |
3859
|
133 -o FILE, --output FILE Output file name. Default extension is .oct |
|
134 unless linking a stand-alone executable. |
3734
|
135 |
|
136 -p VAR, --print VAR Print configuration variable VAR. Recognized |
|
137 variables are: |
|
138 |
4102
|
139 CPPFLAGS CPICFLAG |
|
140 INCFLAGS CXX |
|
141 F2C CXXFLAGS |
|
142 F2CFLAGS CXXPICFLAG |
|
143 F77 XTRA_CFLAGS |
|
144 FFLAGS XTRA_CXXFLAGS |
|
145 FPICFLAG SHLEXT |
4759
|
146 CC DL_LD |
|
147 CFLAGS DL_LDFLAGS |
3859
|
148 |
4102
|
149 LD_CXX LFLAGS |
|
150 LDFLAGS LD_STATIC_FLAG |
|
151 RLD_FLAG RDYNAMIC_FLAG |
|
152 |
|
153 LIBOCTAVE LIBCRUFT |
|
154 LIBOCTINTERP OCTAVE_LIBS |
|
155 BLAS_LIBS FFTW_LIBS |
|
156 LIBS FLIBS |
3859
|
157 |
|
158 --link-stand-alone Link a stand-alone executable file. |
|
159 |
3058
|
160 -s, --strip Strip output file. |
3734
|
161 |
3058
|
162 -v, --verbose Echo commands as they are executed. |
3051
|
163 |
4873
|
164 -W Pass flags though the compiler like -Wl,-rpath=... |
|
165 |
3051
|
166 FILE Compile or link FILE. Recognized file types are: |
|
167 |
3847
|
168 .c C source |
|
169 .cc C++ source |
|
170 .C C++ source |
|
171 .cpp C++ source |
|
172 .f Fortran source |
|
173 .F Fortran source |
|
174 .o object file |
2163
|
175 |
3051
|
176 EOF |
|
177 exit 0 |
|
178 ;; |
3088
|
179 -I*) |
3176
|
180 incflags="$incflags $1" |
3088
|
181 ;; |
3180
|
182 -D*) |
|
183 defs="$defs $1" |
|
184 ;; |
3087
|
185 -[lL]*) |
3176
|
186 ldflags="$ldflags $1" |
3058
|
187 ;; |
3846
|
188 -M | --depend) |
|
189 depend=true |
|
190 compile=false |
|
191 ;; |
3051
|
192 -o | --output) |
|
193 shift |
|
194 if [ $# -gt 0 ]; then |
3860
|
195 outputfile="$1" |
3051
|
196 else |
3847
|
197 echo "mkoctfile: output file name missing" 1>&2 |
3051
|
198 fi |
|
199 ;; |
3734
|
200 -p | --print) |
|
201 shift |
|
202 if [ $# -gt 0 ]; then |
|
203 eval echo \${$1} |
|
204 exit 0 |
|
205 else |
3847
|
206 echo "mkoctfile: --print requires argument" 1>&2 |
3734
|
207 exit 1 |
|
208 fi |
|
209 ;; |
3058
|
210 -s | --strip) |
4199
|
211 if $no_oct_file_strip_on_this_platform; then |
|
212 echo "mkoctfile: stripping disabled on this platform" 1>&2 |
|
213 else |
|
214 strip=true |
|
215 fi |
3051
|
216 ;; |
3859
|
217 -c | --compile) |
3735
|
218 link=false |
|
219 ;; |
3859
|
220 --link-stand-alone) |
|
221 link_stand_alone=true |
|
222 ;; |
4873
|
223 -W*) |
|
224 pass_on_options="$pass_on_options $1" |
|
225 ;; |
3051
|
226 *) |
3847
|
227 echo "mkoctfile: unrecognized argument $1" 1>&2 |
3051
|
228 exit 1 |
|
229 ;; |
|
230 esac |
|
231 if [ -n "$file" ]; then |
|
232 if [ -z "$octfile" ]; then |
3859
|
233 octfile="$file" |
3051
|
234 fi |
|
235 fi |
|
236 shift |
|
237 done |
2163
|
238 |
3859
|
239 if $link_stand_alone; then |
3860
|
240 if [ -n "$outputfile" ]; then |
|
241 output_option="-o $outputfile" |
|
242 fi |
3859
|
243 else |
3860
|
244 if [ -n "$outputfile" ]; then |
|
245 octfile="$outputfile" |
|
246 else |
4084
|
247 octfile=`echo $octfile | $SED 's,\.[^.]*$,,'`.oct |
3860
|
248 fi |
3859
|
249 fi |
|
250 |
3846
|
251 # Generate dependency files for C and C++ files. |
|
252 |
|
253 if $depend; then |
|
254 if [ -n "$cfiles" ]; then |
|
255 for f in $cfiles; do |
4084
|
256 b=`echo $f | $SED 's,\.c$,,'` |
3846
|
257 d=$b.d |
3847
|
258 cmd="rm -f $d" |
|
259 $dbg $cmd |
|
260 eval $cmd |
4206
|
261 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
|
262 $dbg $cmd |
|
263 eval $cmd |
|
264 done |
|
265 fi |
|
266 |
|
267 if [ -n "$ccfiles" ]; then |
|
268 for f in $ccfiles; do |
|
269 case $f in |
3847
|
270 *.cc) |
4084
|
271 b=`echo $f | $SED 's,\.cc$,,'` |
3847
|
272 ;; |
|
273 *.C) |
4084
|
274 b=`echo $f | $SED 's,\.C$,,'` |
3847
|
275 ;; |
|
276 *.cpp) |
4084
|
277 b=`echo $f | $SED 's,\.cpp$,,'` |
3847
|
278 ;; |
3846
|
279 esac |
|
280 d=$b.d |
3847
|
281 cmd="rm -f $d" |
|
282 $dbg $cmd |
|
283 eval $cmd |
4206
|
284 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
|
285 $dbg $cmd |
|
286 eval $cmd |
|
287 done |
|
288 fi |
|
289 # If generating dependencies, that's all we do. |
|
290 exit 0 |
|
291 fi |
|
292 |
3051
|
293 # Compile Fortran, C, and C++ files. Add the name of each object file |
|
294 # that is produced to the overall list of object files. |
2163
|
295 |
3051
|
296 if [ -n "$f77files" ]; then |
|
297 for f in $f77files; do |
|
298 case $f in |
|
299 *.f) |
4084
|
300 b=`echo $f | $SED 's,\.f$,,'` |
3051
|
301 ;; |
|
302 *.F) |
4084
|
303 b=`echo $f | $SED 's,\.F$,,'` |
3051
|
304 ;; |
|
305 esac |
3847
|
306 if [ -n "$F77" ]; then |
5159
|
307 if [ -n "$outputfile" ]; then |
|
308 if $link; then |
|
309 o=$b.o |
|
310 else |
|
311 o=$outputfile |
|
312 fi |
|
313 else |
|
314 o=$b.o |
|
315 fi |
3847
|
316 objfiles="$objfiles $o" |
4873
|
317 cmd="$F77 -c $FPICFLAG $ALL_FFLAGS $pass_on_options $f -o $o" |
3847
|
318 $dbg $cmd |
|
319 eval $cmd |
|
320 elif [ -n "$F2C" ]; then |
|
321 c=$b.c |
|
322 cfiles="$cfiles $c" |
|
323 cmd="$F2C $F2CFLAGS < $f > $c" |
|
324 $dbg $cmd |
|
325 eval $cmd |
|
326 else |
|
327 echo "mkoctfile: no way to compile Fortran file $f" 1>&2 |
|
328 fi |
3051
|
329 done |
|
330 fi |
2163
|
331 |
3051
|
332 if [ -n "$cfiles" ]; then |
|
333 for f in $cfiles; do |
3847
|
334 if [ -n "$CC" ]; then |
4084
|
335 b=`echo $f | $SED 's,\.c$,,'` |
5159
|
336 if [ -n "$outputfile" ]; then |
|
337 if $link; then |
|
338 o=$b.o |
|
339 else |
|
340 o=$outputfile |
|
341 fi |
|
342 else |
|
343 o=$b.o |
|
344 fi |
3847
|
345 objfiles="$objfiles $o" |
4873
|
346 cmd="$CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $pass_on_options $incflags $defs $f -o $o" |
3847
|
347 $dbg $cmd |
|
348 eval $cmd |
|
349 else |
|
350 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
351 fi |
3051
|
352 done |
|
353 fi |
2163
|
354 |
3051
|
355 if [ -n "$ccfiles" ]; then |
|
356 for f in $ccfiles; do |
3847
|
357 if [ -n "$CXX" ]; then |
|
358 case $f in |
|
359 *.cc) |
4084
|
360 b=`echo $f | $SED 's,\.cc$,,'` |
3847
|
361 ;; |
|
362 *.C) |
4084
|
363 b=`echo $f | $SED 's,\.C$,,'` |
3847
|
364 ;; |
|
365 *.cpp) |
4084
|
366 b=`echo $f | $SED 's,\.cpp$,,'` |
3847
|
367 ;; |
|
368 esac |
5159
|
369 if [ -n "$outputfile" ]; then |
|
370 if $link; then |
|
371 o=$b.o |
|
372 else |
|
373 o=$outputfile |
|
374 fi |
|
375 else |
|
376 o=$b.o |
|
377 fi |
3847
|
378 objfiles="$objfiles $o" |
4873
|
379 cmd="$CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $pass_on_options $incflags $defs $f -o $o" |
3847
|
380 $dbg $cmd |
|
381 eval $cmd |
|
382 else |
|
383 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
384 fi |
3051
|
385 done |
|
386 fi |
|
387 |
3660
|
388 ## Uncomment the following group of lines if you get `Text file busy' |
|
389 ## errors from ld. This may happen if the .oct file is currently |
|
390 ## running while you are trying to recompile it. We try moving first, |
3733
|
391 ## since on some systems (HP-UX, maybe others) it is possible to |
3660
|
392 ## rename running programs but not remove them. |
|
393 |
3663
|
394 ## if [ -f "$octfile" ]; then |
3847
|
395 ## cmd="mv $octfile $octfile.bak" |
|
396 ## $dbg $cmd |
|
397 ## eval $cmd |
|
398 ## cmd="rm -f $octfile.bak" |
|
399 ## $dbg $cmd |
|
400 ## eval $cmd |
3663
|
401 ## fi |
3659
|
402 |
3051
|
403 # Link all the object files. |
|
404 |
3735
|
405 if $link; then |
3859
|
406 if $link_stand_alone; then |
|
407 if [ -n "$LD_CXX" ]; then |
4873
|
408 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
|
409 $dbg $cmd |
|
410 eval $cmd |
|
411 else |
|
412 echo "mkoctfile: no way to link stand-alone executable file" 1>&2 |
|
413 exit 1 |
|
414 fi |
|
415 else |
4793
|
416 LINK_DEPS="$LFLAGS $OCTAVE_LIBS $LDFLAGS $BLAS_LIBS $FFTW_LIBS $LIBS $FLIBS" |
4873
|
417 cmd="$DL_LD $DL_LDFLAGS $pass_on_options -o $octfile $objfiles $ldflags $LINK_DEPS" |
3859
|
418 $dbg $cmd |
|
419 eval $cmd |
|
420 fi |
3058
|
421 |
|
422 # Maybe strip it. |
|
423 |
3847
|
424 if $strip; then |
|
425 cmd="strip $octfile" |
|
426 $dbg $cmd |
|
427 eval $cmd |
|
428 fi |
3735
|
429 fi |
3058
|
430 |
|
431 exit 0 |