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 |
|
307 o=$b.o |
|
308 objfiles="$objfiles $o" |
4873
|
309 cmd="$F77 -c $FPICFLAG $ALL_FFLAGS $pass_on_options $f -o $o" |
3847
|
310 $dbg $cmd |
|
311 eval $cmd |
|
312 elif [ -n "$F2C" ]; then |
|
313 c=$b.c |
|
314 cfiles="$cfiles $c" |
|
315 cmd="$F2C $F2CFLAGS < $f > $c" |
|
316 $dbg $cmd |
|
317 eval $cmd |
|
318 else |
|
319 echo "mkoctfile: no way to compile Fortran file $f" 1>&2 |
|
320 fi |
3051
|
321 done |
|
322 fi |
2163
|
323 |
3051
|
324 if [ -n "$cfiles" ]; then |
|
325 for f in $cfiles; do |
3847
|
326 if [ -n "$CC" ]; then |
4084
|
327 b=`echo $f | $SED 's,\.c$,,'` |
3847
|
328 o=$b.o |
|
329 objfiles="$objfiles $o" |
4873
|
330 cmd="$CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $pass_on_options $incflags $defs $f -o $o" |
3847
|
331 $dbg $cmd |
|
332 eval $cmd |
|
333 else |
|
334 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
335 fi |
3051
|
336 done |
|
337 fi |
2163
|
338 |
3051
|
339 if [ -n "$ccfiles" ]; then |
|
340 for f in $ccfiles; do |
3847
|
341 if [ -n "$CXX" ]; then |
|
342 case $f in |
|
343 *.cc) |
4084
|
344 b=`echo $f | $SED 's,\.cc$,,'` |
3847
|
345 ;; |
|
346 *.C) |
4084
|
347 b=`echo $f | $SED 's,\.C$,,'` |
3847
|
348 ;; |
|
349 *.cpp) |
4084
|
350 b=`echo $f | $SED 's,\.cpp$,,'` |
3847
|
351 ;; |
|
352 esac |
|
353 o=$b.o |
|
354 objfiles="$objfiles $o" |
4873
|
355 cmd="$CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $pass_on_options $incflags $defs $f -o $o" |
3847
|
356 $dbg $cmd |
|
357 eval $cmd |
|
358 else |
|
359 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
360 fi |
3051
|
361 done |
|
362 fi |
|
363 |
3660
|
364 ## Uncomment the following group of lines if you get `Text file busy' |
|
365 ## errors from ld. This may happen if the .oct file is currently |
|
366 ## running while you are trying to recompile it. We try moving first, |
3733
|
367 ## since on some systems (HP-UX, maybe others) it is possible to |
3660
|
368 ## rename running programs but not remove them. |
|
369 |
3663
|
370 ## if [ -f "$octfile" ]; then |
3847
|
371 ## cmd="mv $octfile $octfile.bak" |
|
372 ## $dbg $cmd |
|
373 ## eval $cmd |
|
374 ## cmd="rm -f $octfile.bak" |
|
375 ## $dbg $cmd |
|
376 ## eval $cmd |
3663
|
377 ## fi |
3659
|
378 |
3051
|
379 # Link all the object files. |
|
380 |
3735
|
381 if $link; then |
3859
|
382 if $link_stand_alone; then |
|
383 if [ -n "$LD_CXX" ]; then |
4873
|
384 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
|
385 $dbg $cmd |
|
386 eval $cmd |
|
387 else |
|
388 echo "mkoctfile: no way to link stand-alone executable file" 1>&2 |
|
389 exit 1 |
|
390 fi |
|
391 else |
4793
|
392 LINK_DEPS="$LFLAGS $OCTAVE_LIBS $LDFLAGS $BLAS_LIBS $FFTW_LIBS $LIBS $FLIBS" |
4873
|
393 cmd="$DL_LD $DL_LDFLAGS $pass_on_options -o $octfile $objfiles $ldflags $LINK_DEPS" |
3859
|
394 $dbg $cmd |
|
395 eval $cmd |
|
396 fi |
3058
|
397 |
|
398 # Maybe strip it. |
|
399 |
3847
|
400 if $strip; then |
|
401 cmd="strip $octfile" |
|
402 $dbg $cmd |
|
403 eval $cmd |
|
404 fi |
3735
|
405 fi |
3058
|
406 |
|
407 exit 0 |