123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- #!/bin/bash
- if ROOT=$(pwd) && HOST_SYSTEM=$(uname -s) && HOST_ARCH=$(uname -p)
- then
- #
- # Rewrite uname values to a pair from these sets
- #
- # HOST_SYSTEM := { MacOSX, Linux, Nt, Solaris, FreeBSD, NetBSD, Irix, Plan9 }
- #
- # HOST_ARCH := { 386, mips, power, sparc }
- #
- case ${HOST_SYSTEM} in
- Windows*|CYGWIN*|MINGW*)
- HOST_SYSTEM="Nt"
- ;;
- Darwin)
- HOST_SYSTEM="MacOSX"
- ;;
- SunOS)
- HOST_SYSTEM="Solaris"
- ;;
- esac
- if [ "unknown" = "${HOST_ARCH}" ]
- then
- HOST_ARCH=$(uname -m)
- fi
- case ${HOST_ARCH} in
- ppc|powerpc)
- HOST_ARCH="power"
- ;;
- x86|x86_32|i386|i586|i686|486|586|686|x86_64)
- HOST_ARCH="386"
- ;;
- esac
- #
- # Initialize configuration
- #
- SYSHOST=${HOST_SYSTEM}
- SYSTARG=${HOST_SYSTEM}
- OBJTYPE=${HOST_ARCH}
- #
- # Optionally modify configuration
- #
- while [ -n "${1}" ]
- do
- case $1 in
- *clean)
- rm -f mkconfig env bin
- #1>&2 echo ok
- exit 0
- ;;
- --host)
- shift
- HOST_SYSTEM=$1
- shift
- SYSHOST=${HOST_SYSTEM}
- SYSTARG=${HOST_SYSTEM}
- ;;
- --target)
- shift
- SYSTARG=$1
- shift
- ;;
- --object)
- shift
- OBJTYPE=$1
- shift
- ;;
- --help|-help|-h|-?)
- cat<<EOF>&2
- Configuration options (in order)
- --host <Host system type> (eg, MacOSX, Linux, Nt, Solaris, FreeBSD, NetBSD, Plan9)
- --target <Target system type> (eg, MacOSX, Linux, Nt, Solaris, FreeBSD, NetBSD, Irix, Plan9)
- --object <Target object type> (eg, 386, mips, power, sparc)
- Usage
- Configuration options must be employed in the order shown above.
- Running with no arguments should produce a valid result.
- Please contribute to this project by ensuring that any found bugs
- have been reported via
- http://code.google.com/p/ken-cc/issues/list
- for your configuration
- HOST_SYSTEM=${HOST_SYSTEM}
- HOST_ARCH=${HOST_ARCH}
- Cleaning (or unconfiguring)
- Run
- ./configure clean
- or
- ./configure --clean
- to remove the products of this script.
- EOF
- exit 1
- ;;
- esac
- done
- #
- # Host bin
- #
- BINDIR=${HOST_SYSTEM}/${HOST_ARCH}
- #
- # Target bin
- #
- OBJDIR=${SYSTARG}/${OBJTYPE}
- #
- # Sanity testing...
- #
- if [ -z "${SYSHOST}" ]||[ -z "${SYSTARG}" ]||[ -z "${OBJTYPE}" ]
- then
- cat<<EOF>&2
- Input error
- EOF
- exit 1
- elif [ ! -d "${BINDIR}" ]
- then
- cat<<EOF>&2
- Host type selection error in one or both of
- HOST_SYSTEM '${HOST_SYSTEM}'
- HOST_ARCH '${HOST_ARCH}'
- EOF
- exit 1
- elif [ ! -d "${OBJDIR}" ]
- then
- cat<<EOF>&2
- Target type selection error in one or both of
- TARGET '${SYSTARG}'
- OBJECT '${OBJTYPE}'
- EOF
- exit 1
- else
- #
- # Generate configuration
- #
- cat<<EOF>mkconfig
- #
- # Set the following 4 variables. The host system is the system where
- # the software will be built; the target system is where it will run.
- # They are almost always the same.
- # On Nt systems, the ROOT path MUST be of the form 'drive:/path'
- ROOT=${ROOT}
- # build system OS type
- SYSHOST=${SYSHOST}
- # target system OS type
- SYSTARG=${SYSTARG}
- # target system object type
- OBJTYPE=${OBJTYPE}
- #
- # no changes required beyond this point
- #
- OBJDIR=\$SYSTARG/\$OBJTYPE
- <\$ROOT/mkfiles/mkhost-\$SYSHOST # variables appropriate for host system
- <\$ROOT/mkfiles/mkfile-\$SYSTARG-\$OBJTYPE # variables used to build target object type
- EOF
- fi
- #
- # Report product
- #
- cat<<EOF
- Successfully configured and wrote 'mkconfig'
- EOF
- #
- # Configure host binaries into 'env' path
- #
- if [ -e bin ]
- then
- rm -f bin
- fi
- if ln -s ${BINDIR}/bin bin
- then
- cat<<EOF
- Successfully configured host path '$(pwd)/bin'
- EOF
- else
- cat<<EOF>&2
- Error linking host path 'ln -s ${BINDIR}/bin bin'
- EOF
- exit 1
- fi
- #
- # Configure 'env' script
- #
- ewd=$(pwd)
- ebp=${ewd}/bin
- cat<<EOF>env
- #
- # Generated by ${ewd}/configure. See ./configure --help.
- #
- # Usage
- # Run
- # . ./env
- # or
- # source ./env
- #
- # in this directory
- # to initialize this development environment
- #
- PATH=${ebp}:\$(echo \${PATH} | sed 's%${ebp}:%%g; s%:${ebp}%%g')
- #
- # Convenience for running commands outside 'mk'...
- #
- ROOT=${ROOT}
- #
- # Conveniences for sourcing and targeting commands as in 'mk'...
- #
- SYSTARG=${SYSTARG}
- OBJTYPE=${OBJTYPE}
- OBJDIR=\${SYSTARG}/\${OBJTYPE}
- EOF
- cat<<EOF>&2
- Employ command ". ./env" in this directory to initialize usage,
- or PREPEND "$(pwd)/bin" to your PATH.
- EOF
- exit 0
- else
- cat<<EOF>&2
- Error running commands 'pwd' or 'uname'.
- Unable to configure.
- EOF
- exit 1
- fi
|