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