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. |
3088
|
86 -IDIR Add -IDIR to compile commands. |
3180
|
87 -DDEF Add -DDEF to compile commands. |
3058
|
88 -lLIB Add library LIB to link command. |
3087
|
89 -LDIR Add -LDIR to link command. |
3052
|
90 -o FILE, --output FILE Output file name. Default extension is .oct. |
3058
|
91 -s, --strip Strip output file. |
|
92 -v, --verbose Echo commands as they are executed. |
3051
|
93 |
|
94 FILE Compile or link FILE. Recognized file types are: |
|
95 |
|
96 .c C source |
|
97 .cc C++ source |
|
98 .C C++ source |
|
99 .cpp C++ source |
|
100 .f Fortran source |
|
101 .F Fortran source |
|
102 .o object file |
2163
|
103 |
3051
|
104 EOF |
|
105 exit 0 |
|
106 ;; |
3088
|
107 -I*) |
3176
|
108 incflags="$incflags $1" |
3088
|
109 ;; |
3180
|
110 -D*) |
|
111 defs="$defs $1" |
|
112 ;; |
3087
|
113 -[lL]*) |
3176
|
114 ldflags="$ldflags $1" |
3058
|
115 ;; |
3051
|
116 -o | --output) |
|
117 shift |
|
118 if [ $# -gt 0 ]; then |
|
119 octfile=`echo $1 | sed 's,\.[^.]*$,,'`.oct |
|
120 else |
|
121 echo "mkoctfile: output file name missing" |
|
122 fi |
|
123 ;; |
3058
|
124 -s | --strip) |
|
125 strip=true |
3051
|
126 ;; |
|
127 *) |
|
128 echo "mkoctfile: unrecognized argument $1" |
|
129 exit 1 |
|
130 ;; |
|
131 esac |
|
132 if [ -n "$file" ]; then |
|
133 if [ -z "$octfile" ]; then |
|
134 octfile=`echo $file | sed 's,\.[^.]*$,,'`.oct |
|
135 fi |
|
136 fi |
|
137 shift |
|
138 done |
2163
|
139 |
3051
|
140 # Compile Fortran, C, and C++ files. Add the name of each object file |
|
141 # that is produced to the overall list of object files. |
2163
|
142 |
3051
|
143 if [ -n "$f77files" ]; then |
|
144 for f in $f77files; do |
|
145 case $f in |
|
146 *.f) |
|
147 b=`echo $f | sed 's,\.f$,,'` |
|
148 ;; |
|
149 *.F) |
|
150 b=`echo $f | sed 's,\.F$,,'` |
|
151 ;; |
|
152 esac |
|
153 o=$b.o |
|
154 objfiles="$objfiles $o" |
|
155 $dbg $F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o |
|
156 eval $F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o |
|
157 done |
|
158 fi |
2163
|
159 |
3051
|
160 if [ -n "$cfiles" ]; then |
|
161 for f in $cfiles; do |
|
162 b=`echo $f | sed 's,\.c$,,'` |
|
163 o=$b.o |
|
164 objfiles="$objfiles $o" |
3180
|
165 $dbg $CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $defs $f -o $o |
|
166 eval $CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $defs $f -o $o |
3051
|
167 done |
|
168 fi |
2163
|
169 |
3051
|
170 if [ -n "$ccfiles" ]; then |
|
171 for f in $ccfiles; do |
|
172 case $f in |
|
173 *.cc) |
|
174 b=`echo $f | sed 's,\.cc$,,'` |
|
175 ;; |
|
176 *.C) |
|
177 b=`echo $f | sed 's,\.C$,,'` |
|
178 ;; |
|
179 *.cpp) |
|
180 b=`echo $f | sed 's,\.cpp$,,'` |
|
181 ;; |
|
182 esac |
|
183 o=$b.o |
|
184 objfiles="$objfiles $o" |
3180
|
185 $dbg $CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $defs $f -o $o |
|
186 eval $CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $defs $f -o $o |
3051
|
187 done |
|
188 fi |
|
189 |
3660
|
190 ## Uncomment the following group of lines if you get `Text file busy' |
|
191 ## errors from ld. This may happen if the .oct file is currently |
|
192 ## running while you are trying to recompile it. We try moving first, |
|
193 ## since on somee systems (HP-UX, maybe others) it is possible to |
|
194 ## rename running programs but not remove them. |
|
195 |
3663
|
196 ## if [ -f "$octfile" ]; then |
|
197 ## $dbg "mv $octfile $octfile.bak" |
|
198 ## mv $octfile $octfile.bak |
|
199 ## $dbg "rm -f $octfile.bak" |
|
200 ## rm -f $octfile.bak |
|
201 ## fi |
3659
|
202 |
3051
|
203 # Link all the object files. |
|
204 |
3087
|
205 $dbg $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags |
|
206 eval $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags |
3058
|
207 |
|
208 # Maybe strip it. |
|
209 |
|
210 if $strip; then |
|
211 $dbg strip $octfile |
|
212 eval strip $octfile |
|
213 fi |
|
214 |
|
215 exit 0 |