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