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%} |
|
24 : ${HOST_CXXFLAGS=%HOST_CXXFLAGS%} |
|
25 : ${NO_IMPLICIT_TEMPLATES=%NO_IMPLICIT_TEMPLATES%} |
|
26 : ${GCC_IEEE_FP_FLAG=%GCC_IEEE_FP_FLAG%} |
|
27 |
|
28 : ${SH_LD=%SH_LD%} |
|
29 : ${SH_LDFLAGS=%SH_LDFLAGS%} |
|
30 |
|
31 : ${ALL_FFLAGS="$FFLAGS"} |
|
32 |
|
33 : ${ALL_CFLAGS="$INCFLAGS $GCC_IEEE_FP_FLAG $CFLAGS"} |
|
34 |
|
35 : ${ALL_CXXFLAGS="$INCFLAGS $HOST_CXXFLAGS $NO_IMPLICIT_TEMPLATES $GCC_IEEE_FP_FLAG $CXXFLAGS"} |
|
36 |
|
37 # Local variables. |
|
38 |
|
39 usage_msg="usage: mkoctfile [options] file ..." |
|
40 |
|
41 cfiles= |
|
42 ccfiles= |
|
43 f77files= |
|
44 objfiles= |
|
45 octfiles= |
|
46 octfile= |
3088
|
47 incflags= |
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 ;; |
|
79 -h | -? | --help) |
|
80 echo $usage_msg |
|
81 cat << EOF |
2163
|
82 |
3051
|
83 Options: |
|
84 |
|
85 -h, -? --help Print this message. |
3088
|
86 -IDIR Add -IDIR to compile commands. |
3058
|
87 -lLIB Add library LIB to link command. |
3087
|
88 -LDIR Add -LDIR to link command. |
3052
|
89 -o FILE, --output FILE Output file name. Default extension is .oct. |
3058
|
90 -s, --strip Strip output file. |
|
91 -v, --verbose Echo commands as they are executed. |
3051
|
92 |
|
93 FILE Compile or link FILE. Recognized file types are: |
|
94 |
|
95 .c C source |
|
96 .cc C++ source |
|
97 .C C++ source |
|
98 .cpp C++ source |
|
99 .f Fortran source |
|
100 .F Fortran source |
|
101 .o object file |
2163
|
102 |
3051
|
103 EOF |
|
104 exit 0 |
|
105 ;; |
3088
|
106 -I*) |
|
107 incflags="$incflags $1";; |
|
108 ;; |
3087
|
109 -[lL]*) |
3058
|
110 ldflags="$ldflags $1";; |
|
111 ;; |
3051
|
112 -o | --output) |
|
113 shift |
|
114 if [ $# -gt 0 ]; then |
|
115 octfile=`echo $1 | sed 's,\.[^.]*$,,'`.oct |
|
116 else |
|
117 echo "mkoctfile: output file name missing" |
|
118 fi |
|
119 ;; |
3058
|
120 -s | --strip) |
|
121 strip=true |
3051
|
122 ;; |
|
123 *) |
|
124 echo "mkoctfile: unrecognized argument $1" |
|
125 exit 1 |
|
126 ;; |
|
127 esac |
|
128 if [ -n "$file" ]; then |
|
129 if [ -z "$octfile" ]; then |
|
130 octfile=`echo $file | sed 's,\.[^.]*$,,'`.oct |
|
131 fi |
|
132 fi |
|
133 shift |
|
134 done |
2163
|
135 |
3051
|
136 # Compile Fortran, C, and C++ files. Add the name of each object file |
|
137 # that is produced to the overall list of object files. |
2163
|
138 |
3051
|
139 if [ -n "$f77files" ]; then |
|
140 for f in $f77files; do |
|
141 case $f in |
|
142 *.f) |
|
143 b=`echo $f | sed 's,\.f$,,'` |
|
144 ;; |
|
145 *.F) |
|
146 b=`echo $f | sed 's,\.F$,,'` |
|
147 ;; |
|
148 esac |
|
149 o=$b.o |
|
150 objfiles="$objfiles $o" |
|
151 $dbg $F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o |
|
152 eval $F77 -c $FPICFLAG $ALL_FFLAGS $f -o $o |
|
153 done |
|
154 fi |
2163
|
155 |
3051
|
156 if [ -n "$cfiles" ]; then |
|
157 for f in $cfiles; do |
|
158 b=`echo $f | sed 's,\.c$,,'` |
|
159 o=$b.o |
|
160 objfiles="$objfiles $o" |
3088
|
161 $dbg $CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $f -o $o |
|
162 eval $CC -c $CPPFLAGS $CPICFLAG $ALL_CFLAGS $incflags $f -o $o |
3051
|
163 done |
|
164 fi |
2163
|
165 |
3051
|
166 if [ -n "$ccfiles" ]; then |
|
167 for f in $ccfiles; do |
|
168 case $f in |
|
169 *.cc) |
|
170 b=`echo $f | sed 's,\.cc$,,'` |
|
171 ;; |
|
172 *.C) |
|
173 b=`echo $f | sed 's,\.C$,,'` |
|
174 ;; |
|
175 *.cpp) |
|
176 b=`echo $f | sed 's,\.cpp$,,'` |
|
177 ;; |
|
178 esac |
|
179 o=$b.o |
|
180 objfiles="$objfiles $o" |
3088
|
181 $dbg $CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $f -o $o |
|
182 eval $CXX -c $CPPFLAGS $CXXPICFLAG $ALL_CXXFLAGS $incflags $f -o $o |
3051
|
183 done |
|
184 fi |
|
185 |
|
186 # Link all the object files. |
|
187 |
3087
|
188 $dbg $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags |
|
189 eval $SH_LD $SH_LDFLAGS -o $octfile $objfiles $ldflags |
3058
|
190 |
|
191 # Maybe strip it. |
|
192 |
|
193 if $strip; then |
|
194 $dbg strip $octfile |
|
195 eval strip $octfile |
|
196 fi |
|
197 |
|
198 exit 0 |