[dense-linear-algebra-libraries/linalg.git] / blis / frame / compat / cblas / integrate-cblas-tarball.sh
1 #!/bin/bash
2 #
3 # BLIS
4 # An object-based framework for developing high-performance BLAS-like
5 # libraries.
6 #
7 # Copyright (C) 2014, The University of Texas at Austin
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are
11 # met:
12 # - Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # - Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # - Neither the name of The University of Texas at Austin nor the names
18 # of its contributors may be used to endorse or promote products
19 # derived from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #
33 #
35 #
36 # bump-version.sh
37 #
38 # Field G. Van Zee
39 #
42 print_usage()
43 {
44 #local script_name
46 # Get the script name
47 #script_name=${0##*/}
49 # Echo usage info
50 echo " "
51 echo " "$script_name
52 echo " "
53 echo " Field G. Van Zee"
54 echo " "
55 echo " Unpacks a CBLAS tarball and performs whatever preprocessing is"
56 echo " necessary and appropriate in order to integrate the CBLAS source"
57 echo " code into BLIS."
58 echo " "
59 echo " IMPORTANT: This script is designed to be run from the following"
60 echo " directory:"
61 echo " "
62 echo " frame/compat/cblas"
63 echo " "
64 echo " Usage:"
65 echo " ${script_name} tarball"
66 echo " "
67 echo " Arguments:"
68 echo " "
69 echo " tarball The name of the CBLAS package that will be unpacked."
70 echo " If tarball is not in the current directory, the full"
71 echo " directory path should be given."
72 echo " "
74 # Exit with non-zero exit status
75 exit 1
76 }
79 main()
80 {
81 # -- BEGIN GLOBAL VARIABLE DECLARATIONS --
83 # The name of the script, stripped of any preceeding path.
84 script_name=${0##*/}
86 # The name and path of the CBLAS tarball.
87 tarball_path=
89 # The name of the CBLAS directory after it is unpacked.
90 cblas_dir=CBLAS
92 # The name of the sub-directory that we will create and into which
93 # we will copy the source code for CBLAS wrappers.
94 src_dir=src
96 # -- END GLOBAL VARIABLE DECLARATIONS --
99 # Process our command line options.
100 while getopts ":h" opt; do
101 case $opt in
102 h ) print_usage ;;
103 \? ) print_usage
104 esac
105 done
106 shift $(($OPTIND - 1))
109 # Check the number of arguments after command line option processing.
110 if [ $# = "1" ]; then
112 tarball_path=$1
113 echo "${script_name}: preparing to extract from '${tarball_path}'."
115 else
116 print_usage
117 fi
119 # Check that src_dir does not already exist. If it does, abort.
120 if [ -d ${src_dir} ] ; then
122 echo "${script_name}: found '${src_dir}' directory; please remove before proceeding."
123 return 0
124 fi
126 # Un-tar and un-gzip the tarball.
127 echo "${script_name}: extracting '${tarball_path}'."
128 echo "${script_name}: expecting unpacked directory to be named '${cblas_dir}'."
129 tar xzf ${tarball_path}
131 # Create the directory into which we will copy the source code for the
132 # CBLAS wrappers.
133 echo "${script_name}: creating local '${src_dir}' directory."
134 mkdir -p ${src_dir}
136 # Copy the cblas.h header file.
137 echo "${script_name}: copying cblas.h from '${cblas_dir}/include' to '${src_dir}'."
138 cp ${cblas_dir}/include/cblas.h ${src_dir}/cblas.h
140 # Copy the cblas_f77.h header file, removing all prototypes.
141 echo "${script_name}: copying cblas_f77.h from '${cblas_dir}/include' to '${src_dir}'"
142 cp ${cblas_dir}/include/cblas_f77.h ${src_dir}/cblas_f77.h
144 # Create some temporary files to facilitate #including BLIS-specific
145 # cpp macros.
146 echo "${script_name}: creating temporary files."
147 echo "#include \"bli_config.h\"" > include_bli_config.h
148 echo "#include \"bli_system.h\"" > include_bli_system.h
149 echo "#include \"bli_type_defs.h\"" > include_bli_type_defs.h
150 echo "#include \"bli_cblas.h\"" > include_bli_cblas.h
151 echo "#ifdef BLIS_ENABLE_CBLAS" > ifdef_cblas.h
152 echo "#endif" > endif_cblas.h
154 # Process each CBLAS source file.
155 echo "${script_name}: copying source from '${cblas_dir}/src' to '${src_dir}' with"
156 echo "${script_name}: '#ifdef BLIS_ENABLE_CBLAS' guard:"
157 for cbl_src_filepath in ${cblas_dir}/src/cblas_*.c; do
159 # Strip the path to obtain just the filename.
160 cbl_src_file=${cbl_src_filepath##*/}
162 # Append the ifdef and prepend the endif macro statements to the
163 # current file and output to its new location in ${src_dir}.
164 echo "${script_name}: ...copying/BLIS-ifying ${cbl_src_file}"
165 cat include_bli_config.h \
166 include_bli_system.h \
167 include_bli_type_defs.h \
168 include_bli_cblas.h \
169 ifdef_cblas.h \
170 ${cbl_src_filepath} \
171 endif_cblas.h > ${src_dir}/${cbl_src_file}
172 done
174 # Remove the temporary files.
175 echo "${script_name}: cleaning up temporary files."
176 rm -f include_bli_config.h
177 rm -f include_bli_system.h
178 rm -f include_bli_type_defs.h
179 rm -f include_bli_cblas.h
180 rm -f ifdef_cblas.h
181 rm -f endif_cblas.h
183 # Process some bugfixes to syntax errors present in the CBLAS source.
185 echo "${script_name}: fixing syntax errors in CBLAS source:"
187 fix_file ${src_dir}/cblas_chpmv.c "s/ F77_K=K,//g"
188 fix_file ${src_dir}/cblas_chpmv.c "s/ F77_lda=lda,//g"
190 fix_file ${src_dir}/cblas_zhpmv.c "s/ F77_K=K,//g"
191 fix_file ${src_dir}/cblas_zhpmv.c "s/ F77_lda=lda,//g"
193 fix_file ${src_dir}/cblas_ssyr2.c "s/F77__lda/F77_lda/g"
194 fix_file ${src_dir}/cblas_dsyr2.c "s/F77__lda/F77_lda/g"
196 fix_file ${src_dir}/cblas_strsm.c "s/F77_N=M/F77_M=M/g"
198 # Now process some optional fixes that eliminate compiler warnings.
200 echo "${script_name}: fixing compiler warnings in CBLAS source:"
202 incx_string="s/, incx=incX//g"
203 incy_string="s/, incy=incY//g"
205 fix_file ${src_dir}/cblas_cgbmv.c "${incx_string}"
206 fix_file ${src_dir}/cblas_cgemv.c "${incx_string}"
207 fix_file ${src_dir}/cblas_cgerc.c "${incy_string}"
208 fix_file ${src_dir}/cblas_chbmv.c "${incx_string}"
209 fix_file ${src_dir}/cblas_chemv.c "${incx_string}"
210 fix_file ${src_dir}/cblas_cher.c "${incx_string}"
211 fix_file ${src_dir}/cblas_cher2.c "${incx_string}"
212 fix_file ${src_dir}/cblas_cher2.c "${incy_string}"
213 fix_file ${src_dir}/cblas_chpmv.c "${incx_string}"
214 fix_file ${src_dir}/cblas_chpr.c "${incx_string}"
215 fix_file ${src_dir}/cblas_chpr2.c "${incx_string}"
216 fix_file ${src_dir}/cblas_chpr2.c "${incy_string}"
218 fix_file ${src_dir}/cblas_zgbmv.c "${incx_string}"
219 fix_file ${src_dir}/cblas_zgemv.c "${incx_string}"
220 fix_file ${src_dir}/cblas_zgerc.c "${incy_string}"
221 fix_file ${src_dir}/cblas_zhbmv.c "${incx_string}"
222 fix_file ${src_dir}/cblas_zhemv.c "${incx_string}"
223 fix_file ${src_dir}/cblas_zher.c "${incx_string}"
224 fix_file ${src_dir}/cblas_zher2.c "${incx_string}"
225 fix_file ${src_dir}/cblas_zher2.c "${incy_string}"
226 fix_file ${src_dir}/cblas_zhpmv.c "${incx_string}"
227 fix_file ${src_dir}/cblas_zhpr.c "${incx_string}"
228 fix_file ${src_dir}/cblas_zhpr2.c "${incx_string}"
229 fix_file ${src_dir}/cblas_zhpr2.c "${incy_string}"
231 # Now that we're done with everything, we can remove the CBLAS directory.
232 echo "${script_name}: removing '${cblas_dir}' directory."
233 rm -rf ${cblas_dir}
236 # Exit peacefully.
237 return 0
238 }
241 fix_file()
242 {
243 # Get the first function argument: the filename and path to fix.
244 local filepath="$1"
246 # Get the second function argument: the sed command to apply.
247 local sedstring="$2"
249 filename=${filepath##*/}
251 echo "${script_name}: ...fixing ${filename} with 'sed -e ${sedstring}'"
253 cat ${filepath} | sed -e "${sedstring}" > ${filepath}.new
254 mv ${filepath}.new ${filepath}
255 }
258 # The script's main entry point, passing all parameters given.
259 main "$@"