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 |
|
13 : ${CPPFLAGS=%CPPFLAGS%} |
|
14 : ${INCFLAGS=%INCFLAGS%} |
|
15 : ${F77=%F77%} |
|
16 : ${FFLAGS=%FFLAGS%} |
|
17 : ${FPICFLAG=%FPICFLAG%} |
|
18 : ${CC=%CC%} |
|
19 : ${CFLAGS=%CFLAGS%} |
|
20 : ${CPICFLAG=%CPICFLAG%} |
|
21 : ${CXX=%CXX%} |
|
22 : ${CXXFLAGS=%CXXFLAGS%} |
|
23 : ${CXXPICFLAG=%CXXPICFLAG%} |
3131
|
24 : ${XTRA_CFLAGS=%XTRA_CFLAGS%} |
|
25 : ${XTRA_CXXFLAGS=%XTRA_CXXFLAGS%} |
3051
|
26 |
|
27 : ${SH_LD=%SH_LD%} |
|
28 : ${SH_LDFLAGS=%SH_LDFLAGS%} |
|
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= |
3051
|
47 ldflags= |
|
48 dbg=: |
3058
|
49 strip=false |
3051
|
50 |
|
51 if [ $# -eq 0 ]; then |
|
52 echo $usage_msg |
|
53 exit 1; |
2163
|
54 fi |
|
55 |
3051
|
56 while [ $# -gt 0 ]; do |
|
57 file= |
|
58 case "$1" in |
|
59 *.c) |
|
60 file=$1 |
|
61 cfiles="$cfiles $file" |
|
62 ;; |
|
63 *.cc | *.C | *.cpp) |
|
64 file=$1 |
|
65 ccfiles="$ccfiles $file" |
|
66 ;; |
|
67 *.f | *.F) |
|
68 file=$1 |
|
69 f77files="$f77files $file" |
|
70 ;; |
|
71 *.o) |
|
72 file=$1 |
|
73 objfiles="$objfiles $file" |
|
74 ;; |
3058
|
75 -d | --debug | -v | --verbose) |
3051
|
76 dbg=echo |
|
77 ;; |
|
78 -h | -? | --help) |
|
79 echo $usage_msg |
|
80 cat << EOF |
2163
|
81 |
3051
|
82 Options: |
|
83 |
|
84 -h, -? --help Print this message. |
3088
|
85 -IDIR Add -IDIR to compile commands. |
3058
|
86 -lLIB Add library LIB to link command. |
3087
|
87 -LDIR Add -LDIR to link command. |
3052
|
88 -o FILE, --output FILE Output file name. Default extension is .oct. |
3058
|
89 -s, --strip Strip output file. |
|
90 -v, --verbose Echo commands as they are executed. |
3051
|
91 |
|
92 FILE Compile or link FILE. Recognized file types are: |
|
93 |
|
94 .c C source |
|
95 .cc C++ source |
|
96 .C C++ source |
|
97 .cpp C++ source |
|
98 .f Fortran source |
|
99 .F Fortran source |
|
100 .o object file |
2163
|
101 |
3051
|
102 EOF |
|
103 exit 0 |
|
104 ;; |
3088
|
105 -I*) |
|
106 incflags="$incflags $1";; |
|
107 ;; |
3087
|
108 -[lL]*) |
3058
|
109 ldflags="$ldflags $1";; |
|
110 ;; |
3051
|
111 -o | --output) |
|
112 shift |
|
113 if [ $# -gt 0 ]; then |
|
114 octfile=`echo $1 | sed 's,\.[^.]*$,,'`.oct |
|
115 else |
|
116 echo "mkoctfile: output file name missing" |
|
117 fi |
|
118 ;; |
3058
|
119 -s | --strip) |
|
120 strip=true |
3051
|
121 ;; |
|
122 *) |
|
123 echo "mkoctfile: unrecognized argument $1" |
|
124 exit 1 |
|
125 ;; |
|
126 esac |
|
127 if [ -n "$file" ]; then |
|
128 if [ -z "$octfile" ]; then |
|
129 octfile=`echo $file | sed 's,\.[^.]*$,,'`.oct |
|
130 fi |
|
131 fi |
|
132 shift |
|
133 done |
2163
|
134 |
3051
|
135 # Compile Fortran, C, and C++ files. Add the name of each object file |
|
136 # that is produced to the overall list of object files. |
2163
|
137 |
3051
|
138 if [ -n "$f77files" ]; then |
|
139 for f in $f77files; do |
|
140 case $f in |
|
141 *.f) |
|
142 b=`echo $f | sed 's,\.f$,,'` |
|
143 ;; |
|
144 *.F) |
|
145 b=`echo $f | sed 's,\.F$,,'` |
|
146 ;; |
|
147 esac |
|
148 o=$b.o |
|
149 objfiles="$objfiles $o" |
|
150 $dbg $F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o |
|
151 eval $F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o |
|
152 done |
|
153 fi |
2163
|
154 |
3051
|
155 if [ -n "$cfiles" ]; then |
|
156 for f in $cfiles; do |
|
157 b=`echo $f | sed 's,\.c$,,'` |
|
158 o=$b.o |
|
159 objfiles="$objfiles $o" |
3088
|
160 $dbg $CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $f -o $o |
|
161 eval $CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $f -o $o |
3051
|
162 done |
|
163 fi |
2163
|
164 |
3051
|
165 if [ -n "$ccfiles" ]; then |
|
166 for f in $ccfiles; do |
|
167 case $f in |
|
168 *.cc) |
|
169 b=`echo $f | sed 's,\.cc$,,'` |
|
170 ;; |
|
171 *.C) |
|
172 b=`echo $f | sed 's,\.C$,,'` |
|
173 ;; |
|
174 *.cpp) |
|
175 b=`echo $f | sed 's,\.cpp$,,'` |
|
176 ;; |
|
177 esac |
|
178 o=$b.o |
|
179 objfiles="$objfiles $o" |
3088
|
180 $dbg $CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $f -o $o |
|
181 eval $CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $f -o $o |
3051
|
182 done |
|
183 fi |
|
184 |
|
185 # Link all the object files. |
|
186 |
3087
|
187 $dbg $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags |
|
188 eval $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags |
3058
|
189 |
|
190 # Maybe strip it. |
|
191 |
|
192 if $strip; then |
|
193 $dbg strip $octfile |
|
194 eval strip $octfile |
|
195 fi |
|
196 |
|
197 exit 0 |