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