wmii/util/genconfig

122 lines
2.9 KiB
Plaintext
Raw Normal View History

#!/bin/sh -f
CONFIG="$ROOT/config.mk"
CONFSTR='# Generated by "make config"'
#XXX Ignores lines ending in \
parseconfig() {
cat <<!
/^$CONFSTR/ {exit}
/^( *#| )/ {next}
!
cat <<'!'
/=/ {
gsub(/'/, "'\"'\"'")
sub(/[ ]*=[ ]*/, "='")
print $0"'"
sub(/=.*/, "")
print $0"_orig=\"$"$0"\""
}
!
}
findinc() {
var="$1"; file="$2"; shift 2
for d in "$@"; do
if [ -d "$d" -a -f "$d/$file" ]; then
eval "$var=\"-I$d\""; break; fi
done
}
findlib() {
var="$1"; lib="$2"; shift 2
for d in "$@"; do
if [ -d "$d" -a -f "$d/$lib.so" -o -f "$d/lib$lib.a" ]; then
eval "$var=\"-L$d -l$lib\""; break; fi
done
}
prompt() {
var=$1; shift
eval "def=\$$var; orig=\$${var}_orig"
unset val
if [ -z "$def" -o -n "$force" ]; then
echo "$@"
read -p "$var[$def]= " val
echo
fi
if [ -z "$val" ]; then
val="$def"; fi
if [ "$val" != "$orig" ]; then
CFG="$CFG
$var=$val"; fi
}
eval "$(awk "`parseconfig`" <"$CONFIG")"
CFG="$(sed -n "/^$CONFSTR/q; p" "$CONFIG"; echo "$CONFSTR")"
cat <<!
Configuring for the wmii build.
You'll be prompted for a number of settings which wmii needs to build,
install, and run properly. In most cases, the defaults will be sufficient,
in which case, you may simply press return to accept them.
!
# Guess...
AWKPATH=`which awk`
prompt AWKPATH "Full path to your system's 'awk' program"
prompt PLAN9 "Path of a Plan 9 Port or 9base installation"
force=1
prompt PREFIX Installation prefix
echo "Compilation details (if you don't understand these, just leave the defaults)"
prompt CC C object compiler
prompt LD 'Linker (this should normally not be "ld")'
prompt INCPATH Search path for include files
prompt LIBS Libraries to be linked with every executable
prompt CFLAGS Flags for the C compiler
prompt LDFLAGS Flags for the linker
prompt STATIC Extra linker flags to produce a static executable
unset force
# Make some guesses
#for i in LIBX11 LIBICONV LIBIXP INCX11; do
# eval "unset $i ${i}_orig"; done
libs="$LIBDIR:$(echo "$INCPATH"|sed 's,/include\(:\|$\),/lib\1,g')$(echo "$LDFLAGS"|sed 's,-L\([^ ]*\),:\1,g')"
eval "libs=\"$libs\""
LIBIXP=${LIBIXP%/libixp.a}
oifs="$IFS"
IFS=:
findinc INCX11 X11/Xlib.h $INCS /usr/X11R6/include /usr/x11/include /usr/x11/include /usr/X11/include \
/usr/openwin/include /opt/x11/include /opt/X11/include
findinc INCICONV iconv.h $INCS /usr/local/include
findlib LIBX11 X11 $libs /usr/X11R6/lib /usr/X11/lib /usr/openwin/lib /usr/x11/lib /opt/X11 /opt/x11
findlib LIBICONV iconv $libs
findlib LIBIXP ixp ${ROOT}/libixp $libs
LIBIXP=$(echo "$LIBIXP"|sed 's,^-L\([^ ]*\) -l\([^ ]*\)$,\1/lib\2.a,')
IFS="$oifs"
# Back to prompting
echo Library paths...
prompt INCX11 Compiler flags to find X11 includes
prompt LIBX11 Linker flags to link against libX11
prompt LIBICONV Linker flags to link agains libiconv '(may be left blank if iconv is part of your system libc)'
prompt INCICONV Compiler flags to find iconv.h
prompt LIBIXP Path to libixp.a
echo Writing config.mk
echo "$CFG
" >config.mk
echo Done.