1#! /bin/sh 2 3## This file is part of AutoOpts, a companion to AutoGen. 4## AutoOpts is free software. 5## AutoOpts is Copyright (C) 1992-2018 by Bruce Korb - all rights reserved 6## 7## AutoOpts is available under any one of two licenses. The license 8## in use must be one of these two and the choice is under the control 9## of the user of the license. 10## 11## The GNU Lesser General Public License, version 3 or later 12## See the files "COPYING.lgplv3" and "COPYING.gplv3" 13## 14## The Modified Berkeley Software Distribution License 15## See the file "COPYING.mbsd" 16## 17## These files have the following sha256 sums: 18## 19## 8584710e9b04216a394078dc156b781d0b47e1729104d666658aecef8ee32e95 COPYING.gplv3 20## 4379e7444a0e2ce2b12dd6f5a52a27a4d02d39d247901d3285c88cf0d37f477b COPYING.lgplv3 21## 13aa749a5b0a454917a944ed8fffc530b784f5ead522b1aacaf4ec8aa55a6239 COPYING.mbsd 22 23prog=`basename $0 .sh` 24 25die() { 26 echo "$prog failure: $*" 27 kill -TERM $progpid 28 sleep 1 29 exit 1 30} 31 32init() { 33 PS4='+tpc-${FUNCNAME:-=}-$LINENO> ' 34 progpid=$$ 35 prog=`basename $0` 36 progdir=`\cd \`dirname $0\` >/dev/null ; pwd` 37 readonly progpid progdir prog 38 39 for d in top_srcdir srcdir top_builddir builddir 40 do 41 eval v=\${$d} 42 test -d "$v" || die "$d does not reference a directory" 43 v=`cd $v >/dev/null && pwd` 44 eval ${d}=${v} 45 done 46 . ${top_builddir}/config/shdefs 47} 48 49collect_src() { 50 exec 8>&1 1>&2 51 cd ${builddir} 52 sentinel_file=${1} ; shift 53 cat 1>&8 <<- _EOF_ 54 #define AUTOOPTS_INTERNAL 1 55 #include "autoopts/project.h" 56 57 #include "ao-strs.h" 58 static char const ao_ver_string[] = 59 "${AO_CURRENT}:${AO_REVISION}:${AO_AGE}\n"; 60 _EOF_ 61 62 for f in "$@" 63 do test "X$f" = "Xproject.h" || \ 64 printf '#include "%s"\n' $f 65 done 1>&8 66} 67 68extension_defines() { 69 cd ${builddir}/tpl 70 71 test -f tpl-config.tlib || die "tpl-config.tlib not configured" 72 test -f ${top_builddir}/config.h || die "config.h missing" 73 ${GREP:-grep} 'extension-defines' tpl-config.tlib >/dev/null && return 74 75 txt=`sed -n '/POSIX.*SOURCE/,/does not conform to ANSI C/{ 76 /^#/p 77 } 78 /does not conform to ANSI C/q' ${top_builddir}/config.h` 79 80 { 81 sed '/define *top-build-dir/d;/^;;;/d' tpl-config.tlib 82 cat <<- _EOF_ 83 (define top-build-dir "`cd ${top_builddir} >/dev/null 84 pwd`") 85 (define top-src-dir "`cd ${top_srcdir} >/dev/null 86 pwd`") 87 (define extension-defines 88 "${txt}") \\=] 89 _EOF_ 90 } > tpl-config.$$ 91 mv -f tpl-config.$$ tpl-config.tlib 92} 93 94fix_scripts() { 95 for f in ${srcdir}/tpl/*.sh ${srcdir}/tpl/*.pl 96 do 97 d=`basename $f | sed 's/\.[sp][hl]$//'` 98 st=`sed 1q $f` 99 100 case "$st" in 101 *perl ) echo '#!' `which perl` 102 sed 1d $f 103 ;; 104 105 */sh ) echo '#!' ${POSIX_SHELL} 106 sed 1d $f 107 ;; 108 109 * ) die "Invalid script type: $st" 110 ;; 111 esac > $d 112 chmod 755 $d 113 done 114 115 for f in ${srcdir}/tpl/*.pm 116 do 117 test -f ${f##*/} && continue 118 cp $f ${f##*/} 119 chmod 644 ${f##*/} 120 done 121} 122 123find_shell_prog() { 124 case `uname -s` in 125 SunOS ) 126 while : ; do 127 POSIX_SHELL=`which bash` 128 test -x "${POSIX_SHELL}" && break 129 POSIX_SHELL=/usr/xpg4/bin/sh 130 test -x "${POSIX_SHELL}" && break 131 die "You are hosed. You are on Solaris and have no usable shell." 132 done 133 ;; 134 esac 135} 136 137find_cat_prog() { 138 while : 139 do 140 \unalias -a 141 unset -f command cat which 142 POSIX_CAT=`which cat` 143 test -x "$POSIX_CAT" && break 144 POSIX_CAT=` 145 PATH=\`command -p getconf CS_PATH\` 146 command -v cat ` 147 test -x "${POSIX_CAT}" && break 148 die "cannot locate 'cat' command" 149 done 150 151 formats='man mdoc texi' 152 for f in $formats 153 do 154 for g in $formats 155 do 156 test -f ${f}2${g} || { 157 printf "#! ${POSIX_SHELL}\nexec ${POSIX_CAT} "'${1+"$@"}\n' \ 158 > ${f}2${g} 159 chmod 755 ${f}2${g} 160 } 161 done 162 done 163} 164 165scan_cflags() { 166 libguiledir= 167 while test $# -gt 0 168 do 169 case "$1" in 170 -I ) 171 test -f "$2/libguile/__scm.h" && { 172 libguiledir=$2 173 return 0 174 } 175 ;; 176 -I* ) 177 f=${1#-I} 178 test -f "$f/libguile/__scm.h" && { 179 libguiledir=$f 180 return 0 181 } 182 ;; 183 esac 184 shift 185 done 186 187 libguiledir=/usr/include 188 test -f $libguiledir/libguile/__scm.h && return 0 189 die "The Guile header __scm.h cannot be found" 190} 191 192find_libguiledir() { 193 guile_scm_h= 194 libguiledir=`exec 2>/dev/null ; guile-config info includedir` 195 196 if test -d "${libguiledir}" 197 then 198 test -f ${libguiledir}/libguile.h || { 199 set -- ${libguiledir}/*guile*/. 200 if test -d "${2}" 201 then libguiledir=${2%/.} 202 elif test -d "$1" 203 then libguiledir=${1%/.} 204 fi 205 } 206 207 v=`guile-config --version 2>&1 | sed 's/.* version //'` 208 test -d ${libguiledir}/${v%.*} && v=${v%.*} 209 test -d ${libguiledir}/${v} && libguiledir=${libguiledir}/$v 210 211 else 212 scan_cflags $* 213 fi 214 guile_scm_h=`find ${libguiledir} -type f -name __scm.h` 215} 216 217fix_guile() { 218 cd ${builddir} 219 find_libguiledir ${LGCFLAGS} 220 221 list=`exec 2>/dev/null 222 find ${libguiledir}/libguile* -type f | \ 223 xargs grep -l -E '\<noreturn\>'` 224 225 test -z "$list" && exit 0 226 227 test -d libguile || mkdir libguile || { 228 echo "cannot make libguile directory" 229 exit 1 230 } 1>&2 231 232 noret='\([^a-zA-Z0-9_]\)noreturn\([^a-zA-Z0-9_]\)' 233 nores='\1__noreturn__\2' 234 sedex="s@${noret}@${nores}@" 235 236 echo "Patching files to remove bare 'noreturn' keyword in" \ 237 $list >&2 238 239 for f in $list 240 do 241 g=libguile${f##*/libguile} 242 sed "${sedex}" $f > $g 243 diff -u $f $g >&2 || : 244 done 245 246 test -f libguile.h || cp ${libguiledir}/libguile.h . 247} 248 249init 250collect_src "$@" > ${builddir}/libopts.c 251extension_defines 252fix_scripts 253find_shell_prog 254find_cat_prog 255fix_guile 256touch ${sentinel_file} 257