Annotation of prex/configure, Revision 1.1
1.1 ! nbrk 1: #! /bin/sh
! 2: #
! 3: # Prex configuration script
! 4: #
! 5:
! 6: quit()
! 7: {
! 8: cat >&2 <<ERRORMSG
! 9:
! 10: ERROR: $@
! 11: ERRORMSG
! 12: exit 1
! 13: }
! 14:
! 15: usage()
! 16: {
! 17: if [ -n "$*" ]; then
! 18: echo "configure: $*"
! 19: fi
! 20: cat <<USAGE
! 21:
! 22: Usage: configure [options]
! 23:
! 24: General options:
! 25: --target=TARGET target system
! 26: --cross-compile=PREFIX prefix for cros-compile tools
! 27: --no-debug disable all debug code
! 28:
! 29: Supported targets:
! 30: i386-pc i386-nommu arm-gba
! 31: USAGE
! 32: exit 1
! 33: }
! 34:
! 35: setdefaults()
! 36: {
! 37: [ -d conf ] ||
! 38: quit "configure must be run from the top source level"
! 39:
! 40: target=""
! 41: cross=""
! 42: srcdir=`pwd`
! 43: }
! 44:
! 45: checkpath()
! 46: {
! 47: CONFIG_IN=$srcdir/conf/$arch/config.$arch-$platform
! 48: CMDBOX_IN=$srcdir/conf/etc/cmdbox.conf
! 49: CONFIG_MK=$srcdir/conf/config.mk
! 50: CONFIG_H=$srcdir/conf/config.h
! 51:
! 52: [ -f $CONFIG_IN ] ||
! 53: quit "can not find $CONFIG_IN"
! 54: }
! 55:
! 56: getoptions()
! 57: {
! 58: while [ $# != 0 ]; do
! 59: case $1 in
! 60: --*=*)
! 61: option=`expr "x$1" : 'x\([^=]*\)='`
! 62: optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
! 63: ;;
! 64: --*)
! 65: option=$1
! 66: ;;
! 67: *)
! 68: usage "unrecognized option $1"
! 69: ;;
! 70: esac
! 71:
! 72: case $option in
! 73: --help)
! 74: usage
! 75: ;;
! 76: --target)
! 77: target=$optarg
! 78: ;;
! 79: --cross-compile)
! 80: cross=$optarg
! 81: ;;
! 82: --no-debug)
! 83: nodebug=1
! 84: ;;
! 85: *)
! 86: usage "unrecognized option $1"
! 87: ;;
! 88: esac
! 89: shift
! 90: done
! 91: }
! 92:
! 93: gettarget()
! 94: {
! 95: if [ "x$target" = x ] ; then
! 96: echo "Warning: '--target' option was not specified"
! 97: echo "The target system was set to 'i386-pc'"
! 98: target="i386-pc"
! 99: fi
! 100:
! 101: arch=`expr "x$target" : 'x\([^=]*\)-'`
! 102: platform=`expr "x$target" : 'x[^=]*-\(.*\)'`
! 103:
! 104: case "$arch" in
! 105: i386|arm|ppc|sh|mips)
! 106: ;;
! 107: *)
! 108: quit "Unkown target architecture: $arch"
! 109: ;;
! 110: esac
! 111:
! 112: host_name=`uname -s`
! 113: case $host_name in
! 114: CYGWIN*)
! 115: case $arch in
! 116: i386) cross="i386-elf-" ;;
! 117: arm) cross="arm-elf-" ;;
! 118: ppc) cross="powerpc-eabi-" ;;
! 119: sh) cross="sh-elf-" ;;
! 120: mips) cross="mips-elf-" ;;
! 121: esac
! 122: ;;
! 123: esac
! 124: cc="${cross}gcc"
! 125: }
! 126:
! 127: setparm()
! 128: {
! 129: echo "$1=$2"
! 130: echo "$1=$2" >>$CONFIG_MK
! 131: if [ "$2" = "n" ] ; then
! 132: echo "#undef $1" >>$CONFIG_H
! 133: else
! 134: echo "#define $1 $2" >>$CONFIG_H
! 135: fi
! 136: }
! 137:
! 138: setgccoption()
! 139: {
! 140: if $cc $1 -S -xc /dev/null -o /dev/null > /dev/null 2>&1; then
! 141: echo "CONFIG_CFLAGS+= $1" >>$CONFIG_MK
! 142: fi
! 143: }
! 144:
! 145: parseconfig()
! 146: {
! 147: while read line; do
! 148: word=`expr "x$line" : 'x\(CONFIG_[A-Za-z0-9_=]*\)'`
! 149: param=`expr "x$word" : 'x\([^=]*\)='`
! 150: value=`expr "x$word" : 'x[^=]*=\([A-Za-z0-9]*\)'`
! 151: if [ -n "$param" ] ; then
! 152: setparm "$param" "$value"
! 153: fi
! 154: done < $1
! 155: echo "" >> $CONFIG_MK
! 156: }
! 157:
! 158: main()
! 159: {
! 160: setdefaults
! 161: getoptions "$@"
! 162: gettarget
! 163: checkpath
! 164:
! 165: echo "Processing configuration files..."
! 166:
! 167: echo "#" > $CONFIG_MK
! 168: echo "# Automatically generated file. Don't edit" >> $CONFIG_MK
! 169: echo "#" >> $CONFIG_MK
! 170:
! 171: echo "/*" > $CONFIG_H
! 172: echo " * Automatically generated file. Don't edit" >> $CONFIG_H
! 173: echo " */" >> $CONFIG_H
! 174:
! 175: #
! 176: # Generate configuration parameters
! 177: #
! 178: parseconfig $CONFIG_IN
! 179: parseconfig $CMDBOX_IN
! 180:
! 181: #
! 182: # Check arch/platform setting
! 183: #
! 184: echo "SRCDIR=$srcdir" >> $CONFIG_MK
! 185: echo "ARCH=$arch" >> $CONFIG_MK
! 186: echo "PLATFORM=$platform" >> $CONFIG_MK
! 187: [ "x$cross" != x ] && echo "CROSS_COMPILE=$cross" >> $CONFIG_MK
! 188: [ "x$nodebug" != x ] && echo "NDEBUG=1" >> $CONFIG_MK
! 189: echo "" >> $CONFIG_MK
! 190:
! 191: #
! 192: # Check gcc options
! 193: #
! 194: setgccoption "-fno-stack-protector"
! 195: }
! 196:
! 197: main "$@"
CVSweb