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