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%} |
3590
|
15 : ${F77=%OCTAVE_CONF_F77%} |
|
16 : ${FFLAGS=%OCTAVE_CONF_FFLAGS%} |
|
17 : ${FPICFLAG=%OCTAVE_CONF_FPICFLAG%} |
|
18 : ${CC=%OCTAVE_CONF_CC%} |
|
19 : ${CFLAGS=%OCTAVE_CONF_CFLAGS%} |
|
20 : ${CPICFLAG=%OCTAVE_CONF_CPICFLAG%} |
|
21 : ${CXX=%OCTAVE_CONF_CXX%} |
|
22 : ${CXXFLAGS=%OCTAVE_CONF_CXXFLAGS%} |
|
23 : ${CXXPICFLAG=%OCTAVE_CONF_CXXPICFLAG%} |
|
24 : ${XTRA_CFLAGS=%OCTAVE_CONF_XTRA_CFLAGS%} |
|
25 : ${XTRA_CXXFLAGS=%OCTAVE_CONF_XTRA_CXXFLAGS%} |
3051
|
26 |
3590
|
27 : ${SH_LD=%OCTAVE_CONF_SH_LD%} |
|
28 : ${SH_LDFLAGS=%OCTAVE_CONF_SH_LDFLAGS%} |
3051
|
29 |
|
30 : ${ALL_FFLAGS="$FFLAGS"} |
|
31 |
3131
|
32 : ${ALL_CFLAGS="$INCFLAGS $XTRA_CFLAGS $CFLAGS"} |
3051
|
33 |
3131
|
34 : ${ALL_CXXFLAGS="$INCFLAGS $XTRA_CXXFLAGS $CXXFLAGS"} |
3051
|
35 |
|
36 # Local variables. |
|
37 |
|
38 usage_msg="usage: mkoctfile [options] file ..." |
|
39 |
|
40 cfiles= |
|
41 ccfiles= |
|
42 f77files= |
|
43 objfiles= |
|
44 octfiles= |
|
45 octfile= |
3088
|
46 incflags= |
3180
|
47 defs= |
3051
|
48 ldflags= |
|
49 dbg=: |
3058
|
50 strip=false |
3051
|
51 |
|
52 if [ $# -eq 0 ]; then |
|
53 echo $usage_msg |
|
54 exit 1; |
2163
|
55 fi |
|
56 |
3051
|
57 while [ $# -gt 0 ]; do |
|
58 file= |
|
59 case "$1" in |
|
60 *.c) |
|
61 file=$1 |
|
62 cfiles="$cfiles $file" |
|
63 ;; |
|
64 *.cc | *.C | *.cpp) |
|
65 file=$1 |
|
66 ccfiles="$ccfiles $file" |
|
67 ;; |
|
68 *.f | *.F) |
|
69 file=$1 |
|
70 f77files="$f77files $file" |
|
71 ;; |
|
72 *.o) |
|
73 file=$1 |
|
74 objfiles="$objfiles $file" |
|
75 ;; |
3058
|
76 -d | --debug | -v | --verbose) |
3051
|
77 dbg=echo |
|
78 ;; |
3233
|
79 -h | -\? | --help) |
3051
|
80 echo $usage_msg |
|
81 cat << EOF |
2163
|
82 |
3051
|
83 Options: |
|
84 |
3233
|
85 -h, -?, --help Print this message. |
3734
|
86 |
3088
|
87 -IDIR Add -IDIR to compile commands. |
3734
|
88 |
3180
|
89 -DDEF Add -DDEF to compile commands. |
3734
|
90 |
3058
|
91 -lLIB Add library LIB to link command. |
3734
|
92 |
3087
|
93 -LDIR Add -LDIR to link command. |
3734
|
94 |
3052
|
95 -o FILE, --output FILE Output file name. Default extension is .oct. |
3734
|
96 |
|
97 -p VAR, --print VAR Print configuration variable VAR. Recognized |
|
98 variables are: |
|
99 |
|
100 CPPFLAGS CXX |
|
101 INCFLAGS CXXFLAGS |
|
102 F77 CXXPICFLAG |
|
103 FFLAGS XTRA_CFLAGS |
|
104 FPICFLAG XTRA_CXXFLAGS |
|
105 CC SHLEXT |
|
106 CFLAGS SH_LD |
|
107 CPICFLAG SH_LDFLAGS |
|
108 |
3058
|
109 -s, --strip Strip output file. |
3734
|
110 |
3058
|
111 -v, --verbose Echo commands as they are executed. |
3051
|
112 |
|
113 FILE Compile or link FILE. Recognized file types are: |
|
114 |
|
115 .c C source |
|
116 .cc C++ source |
|
117 .C C++ source |
|
118 .cpp C++ source |
|
119 .f Fortran source |
|
120 .F Fortran source |
|
121 .o object file |
2163
|
122 |
3051
|
123 EOF |
|
124 exit 0 |
|
125 ;; |
3088
|
126 -I*) |
3176
|
127 incflags="$incflags $1" |
3088
|
128 ;; |
3180
|
129 -D*) |
|
130 defs="$defs $1" |
|
131 ;; |
3087
|
132 -[lL]*) |
3176
|
133 ldflags="$ldflags $1" |
3058
|
134 ;; |
3051
|
135 -o | --output) |
|
136 shift |
|
137 if [ $# -gt 0 ]; then |
|
138 octfile=`echo $1 | sed 's,\.[^.]*$,,'`.oct |
|
139 else |
|
140 echo "mkoctfile: output file name missing" |
|
141 fi |
|
142 ;; |
3734
|
143 -p | --print) |
|
144 shift |
|
145 if [ $# -gt 0 ]; then |
|
146 eval echo \${$1} |
|
147 exit 0 |
|
148 else |
|
149 echo "mkprdmod: --print requires argument" |
|
150 exit 1 |
|
151 fi |
|
152 ;; |
3058
|
153 -s | --strip) |
|
154 strip=true |
3051
|
155 ;; |
|
156 *) |
|
157 echo "mkoctfile: unrecognized argument $1" |
|
158 exit 1 |
|
159 ;; |
|
160 esac |
|
161 if [ -n "$file" ]; then |
|
162 if [ -z "$octfile" ]; then |
|
163 octfile=`echo $file | sed 's,\.[^.]*$,,'`.oct |
|
164 fi |
|
165 fi |
|
166 shift |
|
167 done |
2163
|
168 |
3051
|
169 # Compile Fortran, C, and C++ files. Add the name of each object file |
|
170 # that is produced to the overall list of object files. |
2163
|
171 |
3051
|
172 if [ -n "$f77files" ]; then |
|
173 for f in $f77files; do |
|
174 case $f in |
|
175 *.f) |
|
176 b=`echo $f | sed 's,\.f$,,'` |
|
177 ;; |
|
178 *.F) |
|
179 b=`echo $f | sed 's,\.F$,,'` |
|
180 ;; |
|
181 esac |
|
182 o=$b.o |
|
183 objfiles="$objfiles $o" |
|
184 $dbg $F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o |
|
185 eval $F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o |
|
186 done |
|
187 fi |
2163
|
188 |
3051
|
189 if [ -n "$cfiles" ]; then |
|
190 for f in $cfiles; do |
|
191 b=`echo $f | sed 's,\.c$,,'` |
|
192 o=$b.o |
|
193 objfiles="$objfiles $o" |
3180
|
194 $dbg $CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $defs $f -o $o |
|
195 eval $CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $defs $f -o $o |
3051
|
196 done |
|
197 fi |
2163
|
198 |
3051
|
199 if [ -n "$ccfiles" ]; then |
|
200 for f in $ccfiles; do |
|
201 case $f in |
|
202 *.cc) |
|
203 b=`echo $f | sed 's,\.cc$,,'` |
|
204 ;; |
|
205 *.C) |
|
206 b=`echo $f | sed 's,\.C$,,'` |
|
207 ;; |
|
208 *.cpp) |
|
209 b=`echo $f | sed 's,\.cpp$,,'` |
|
210 ;; |
|
211 esac |
|
212 o=$b.o |
|
213 objfiles="$objfiles $o" |
3180
|
214 $dbg $CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $defs $f -o $o |
|
215 eval $CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $defs $f -o $o |
3051
|
216 done |
|
217 fi |
|
218 |
3660
|
219 ## Uncomment the following group of lines if you get `Text file busy' |
|
220 ## errors from ld. This may happen if the .oct file is currently |
|
221 ## running while you are trying to recompile it. We try moving first, |
3733
|
222 ## since on some systems (HP-UX, maybe others) it is possible to |
3660
|
223 ## rename running programs but not remove them. |
|
224 |
3663
|
225 ## if [ -f "$octfile" ]; then |
|
226 ## $dbg "mv $octfile $octfile.bak" |
|
227 ## mv $octfile $octfile.bak |
|
228 ## $dbg "rm -f $octfile.bak" |
|
229 ## rm -f $octfile.bak |
|
230 ## fi |
3659
|
231 |
3051
|
232 # Link all the object files. |
|
233 |
3087
|
234 $dbg $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags |
|
235 eval $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags |
3058
|
236 |
|
237 # Maybe strip it. |
|
238 |
|
239 if $strip; then |
|
240 $dbg strip $octfile |
|
241 eval strip $octfile |
|
242 fi |
|
243 |
|
244 exit 0 |