#!/bin/sh # simple risu configure script # # Copyright (c) 2013 Linaro Limited # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # # Contributors: # Claudio Fontana (Linaro) - initial implementation # Locate the directory where this configure script is SRCDIR="$(cd "$(dirname "$0")"; pwd)" # Temporary directory used for files created by this script. # Like autoconf (and like QEMU) we put this directory in the # build directory, which means we can just give it a fixed name and # blow it away when configure is run, and we don't need to jump # through complicated hoops to delete it when configure exits # abnormally (it may be useful for debug purposes on an # abnormal exit). tmp_dir="config-temp" rm -rf "$tmp_dir" mkdir -p "$tmp_dir" if [ $? -ne 0 ]; then echo "ERROR: could not create temporary directory" exit 1 fi compile() { $CC $CFLAGS -c -o ${1}.o ${1}.c 2>/dev/null } link() { $LD $LDFLAGS -l${2} -o ${1} ${1}.o 2>/dev/null } check_define() { c=${tmp_dir}/check_define_${1} cat > ${c}.c <&2 exit 1 fi } check_type() { c=${tmp_dir}/check_type_${1} cat > ${c}.c < #include #include #include int main(void) { $1 thisone; return 0; } EOF compile $c } check_lib() { c=${tmp_dir}/check_lib${1} cat > ${c}.c < #include <$2.h> int main(void) { $3; return 0; } EOF compile $c && link $c $1 } generate_config() { cfg=config.h echo "generating config.h..." echo "/* config.h - generated by the 'configure' script */" > $cfg echo "#ifndef CONFIG_H" >> $cfg echo "#define CONFIG_H 1" >> $cfg if check_lib z zlib "zlibVersion()"; then echo "#define HAVE_ZLIB 1" >> $cfg LDFLAGS=-lz fi echo "#endif /* CONFIG_H */" >> $cfg echo "...done" } generate_makefilein() { m=Makefile.in echo "generating Makefile.in..." echo "# Makefile.in - generated by the 'configure' script" > $m echo "ARCH:=${ARCH}" >> $m echo "CC:=${CC}" >> $m echo "CPPFLAGS:=${CPPFLAGS}" >> $m echo "LDFLAGS:=${LDFLAGS}" >> $m echo "AS:=${AS}" >> $m echo "OBJCOPY:=${OBJCOPY}" >> $m echo "OBJDUMP:=${OBJDUMP}" >> $m echo "STATIC:=${STATIC}" >> $m echo "SRCDIR:=${SRCDIR}" >> $m echo "BUILD_INC:=${BUILD_INC}" >> $m echo "...done" } usage() { cat < AS assembler command OBJCOPY object copy utility command OBJDUMP object dump utility command EOF } # STARTUP: entry point STATIC="" for opt do case "$opt" in --help | -h) usage; exit 0;; --static | -s) STATIC="-static" ;; esac done CC="${CC-${CROSS_PREFIX}gcc}" AS="${AS-${CROSS_PREFIX}as}" LD="${LD-${CROSS_PREFIX}ld}" OBJCOPY="${OBJCOPY-${CROSS_PREFIX}objcopy}" OBJDUMP="${OBJDUMP-${CROSS_PREFIX}objdump}" if test "x${ARCH}" = "x"; then guess_arch fi # Are we in a separate build tree? If so, link the Makefile # so that 'make' works. if test ! -e Makefile || test -s Makefile; then echo "linking Makefile..." BUILD_INC="-I $(pwd)" ln -sf "${SRCDIR}/Makefile" . fi generate_config generate_makefilein rm -r "$tmp_dir" echo "type 'make' to start the build" exit 0