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%} |
4102
|
51 : ${INCLUDE_LINK_DEPS=%OCTAVE_CONF_INCLUDE_LINK_DEPS%} |
3859
|
52 |
3051
|
53 : ${ALL_FFLAGS="$FFLAGS"} |
|
54 |
3131
|
55 : ${ALL_CFLAGS="$INCFLAGS $XTRA_CFLAGS $CFLAGS"} |
3051
|
56 |
3131
|
57 : ${ALL_CXXFLAGS="$INCFLAGS $XTRA_CXXFLAGS $CXXFLAGS"} |
3051
|
58 |
3887
|
59 : ${ALL_LDFLAGS="$LD_STATIC_FLAG $CPICFLAG $LDFLAGS"} |
3859
|
60 |
4228
|
61 : ${OCTAVE_LIBS="$LIBOCTINTERP $LIBOCTAVE $SPECIAL_MATH_LIB $LIBCRUFT"} |
3859
|
62 |
3051
|
63 # Local variables. |
|
64 |
|
65 usage_msg="usage: mkoctfile [options] file ..." |
|
66 |
|
67 cfiles= |
|
68 ccfiles= |
|
69 f77files= |
|
70 objfiles= |
|
71 octfiles= |
|
72 octfile= |
3860
|
73 outputfile= |
3088
|
74 incflags= |
3180
|
75 defs= |
3051
|
76 ldflags= |
|
77 dbg=: |
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 INCLUDE_LINK_DEPS |
3859
|
150 |
4102
|
151 LD_CXX LFLAGS |
|
152 LDFLAGS LD_STATIC_FLAG |
|
153 RLD_FLAG RDYNAMIC_FLAG |
|
154 |
|
155 LIBOCTAVE LIBCRUFT |
|
156 LIBOCTINTERP OCTAVE_LIBS |
|
157 BLAS_LIBS FFTW_LIBS |
|
158 LIBS FLIBS |
3859
|
159 |
|
160 --link-stand-alone Link a stand-alone executable file. |
|
161 |
3058
|
162 -s, --strip Strip output file. |
3734
|
163 |
3058
|
164 -v, --verbose Echo commands as they are executed. |
3051
|
165 |
|
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 ;; |
3051
|
223 *) |
3847
|
224 echo "mkoctfile: unrecognized argument $1" 1>&2 |
3051
|
225 exit 1 |
|
226 ;; |
|
227 esac |
|
228 if [ -n "$file" ]; then |
|
229 if [ -z "$octfile" ]; then |
3859
|
230 octfile="$file" |
3051
|
231 fi |
|
232 fi |
|
233 shift |
|
234 done |
2163
|
235 |
3859
|
236 if $link_stand_alone; then |
3860
|
237 if [ -n "$outputfile" ]; then |
|
238 output_option="-o $outputfile" |
|
239 fi |
3859
|
240 else |
3860
|
241 if [ -n "$outputfile" ]; then |
|
242 octfile="$outputfile" |
|
243 else |
4084
|
244 octfile=`echo $octfile | $SED 's,\.[^.]*$,,'`.oct |
3860
|
245 fi |
3859
|
246 fi |
|
247 |
3846
|
248 # Generate dependency files for C and C++ files. |
|
249 |
|
250 if $depend; then |
|
251 if [ -n "$cfiles" ]; then |
|
252 for f in $cfiles; do |
4084
|
253 b=`echo $f | $SED 's,\.c$,,'` |
3846
|
254 d=$b.d |
3847
|
255 cmd="rm -f $d" |
|
256 $dbg $cmd |
|
257 eval $cmd |
4206
|
258 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
|
259 $dbg $cmd |
|
260 eval $cmd |
|
261 done |
|
262 fi |
|
263 |
|
264 if [ -n "$ccfiles" ]; then |
|
265 for f in $ccfiles; do |
|
266 case $f in |
3847
|
267 *.cc) |
4084
|
268 b=`echo $f | $SED 's,\.cc$,,'` |
3847
|
269 ;; |
|
270 *.C) |
4084
|
271 b=`echo $f | $SED 's,\.C$,,'` |
3847
|
272 ;; |
|
273 *.cpp) |
4084
|
274 b=`echo $f | $SED 's,\.cpp$,,'` |
3847
|
275 ;; |
3846
|
276 esac |
|
277 d=$b.d |
3847
|
278 cmd="rm -f $d" |
|
279 $dbg $cmd |
|
280 eval $cmd |
4206
|
281 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
|
282 $dbg $cmd |
|
283 eval $cmd |
|
284 done |
|
285 fi |
|
286 # If generating dependencies, that's all we do. |
|
287 exit 0 |
|
288 fi |
|
289 |
3051
|
290 # Compile Fortran, C, and C++ files. Add the name of each object file |
|
291 # that is produced to the overall list of object files. |
2163
|
292 |
3051
|
293 if [ -n "$f77files" ]; then |
|
294 for f in $f77files; do |
|
295 case $f in |
|
296 *.f) |
4084
|
297 b=`echo $f | $SED 's,\.f$,,'` |
3051
|
298 ;; |
|
299 *.F) |
4084
|
300 b=`echo $f | $SED 's,\.F$,,'` |
3051
|
301 ;; |
|
302 esac |
3847
|
303 if [ -n "$F77" ]; then |
|
304 o=$b.o |
|
305 objfiles="$objfiles $o" |
|
306 cmd="$F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o" |
|
307 $dbg $cmd |
|
308 eval $cmd |
|
309 elif [ -n "$F2C" ]; then |
|
310 c=$b.c |
|
311 cfiles="$cfiles $c" |
|
312 cmd="$F2C $F2CFLAGS < $f > $c" |
|
313 $dbg $cmd |
|
314 eval $cmd |
|
315 else |
|
316 echo "mkoctfile: no way to compile Fortran file $f" 1>&2 |
|
317 fi |
3051
|
318 done |
|
319 fi |
2163
|
320 |
3051
|
321 if [ -n "$cfiles" ]; then |
|
322 for f in $cfiles; do |
3847
|
323 if [ -n "$CC" ]; then |
4084
|
324 b=`echo $f | $SED 's,\.c$,,'` |
3847
|
325 o=$b.o |
|
326 objfiles="$objfiles $o" |
|
327 cmd="$CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $defs $f -o $o" |
|
328 $dbg $cmd |
|
329 eval $cmd |
|
330 else |
|
331 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
332 fi |
3051
|
333 done |
|
334 fi |
2163
|
335 |
3051
|
336 if [ -n "$ccfiles" ]; then |
|
337 for f in $ccfiles; do |
3847
|
338 if [ -n "$CXX" ]; then |
|
339 case $f in |
|
340 *.cc) |
4084
|
341 b=`echo $f | $SED 's,\.cc$,,'` |
3847
|
342 ;; |
|
343 *.C) |
4084
|
344 b=`echo $f | $SED 's,\.C$,,'` |
3847
|
345 ;; |
|
346 *.cpp) |
4084
|
347 b=`echo $f | $SED 's,\.cpp$,,'` |
3847
|
348 ;; |
|
349 esac |
|
350 o=$b.o |
|
351 objfiles="$objfiles $o" |
|
352 cmd="$CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $defs $f -o $o" |
|
353 $dbg $cmd |
|
354 eval $cmd |
|
355 else |
|
356 echo "mkoctfile: no way to compile C++ file $f" 1>&2 |
|
357 fi |
3051
|
358 done |
|
359 fi |
|
360 |
3660
|
361 ## Uncomment the following group of lines if you get `Text file busy' |
|
362 ## errors from ld. This may happen if the .oct file is currently |
|
363 ## running while you are trying to recompile it. We try moving first, |
3733
|
364 ## since on some systems (HP-UX, maybe others) it is possible to |
3660
|
365 ## rename running programs but not remove them. |
|
366 |
3663
|
367 ## if [ -f "$octfile" ]; then |
3847
|
368 ## cmd="mv $octfile $octfile.bak" |
|
369 ## $dbg $cmd |
|
370 ## eval $cmd |
|
371 ## cmd="rm -f $octfile.bak" |
|
372 ## $dbg $cmd |
|
373 ## eval $cmd |
3663
|
374 ## fi |
3659
|
375 |
3051
|
376 # Link all the object files. |
|
377 |
3735
|
378 if $link; then |
3859
|
379 if $link_stand_alone; then |
|
380 if [ -n "$LD_CXX" ]; then |
4229
|
381 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
|
382 $dbg $cmd |
|
383 eval $cmd |
|
384 else |
|
385 echo "mkoctfile: no way to link stand-alone executable file" 1>&2 |
|
386 exit 1 |
|
387 fi |
|
388 else |
4102
|
389 LINK_DEPS= |
|
390 if $INCLUDE_LINK_DEPS ; then |
|
391 LINK_DEPS="$LFLAGS $LIBOCTAVE $LIBCRUFT $LIBOCTINTERP $BLAS_LIBS $FFTW_LIBS" |
|
392 fi |
4759
|
393 cmd="$DL_LD $DL_LDFLAGS -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 |