aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/e2fsprogs/e2fsprogs/acinclude.m4
blob: c0bd7dbdee936e894a5ef798080025a26de6882f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Extracted from the package's shipped aclocal.m4. Custom macros should be in
# acinclude.m4 so running aclocal doesn't blow them away.
#
# Signed-off-by: Ross Burton <ross.burton@intel.com>

# from http://autoconf-archive.cryp.to/ax_tls.html
#
# This was licensed under the GPL with the following exception:
#
# As a special exception, the respective Autoconf Macro's copyright
# owner gives unlimited permission to copy, distribute and modify the
# configure scripts that are the output of Autoconf when processing
# the Macro. You need not follow the terms of the GNU General Public
# License when using or distributing such scripts, even though
# portions of the text of the Macro appear in them. The GNU General
# Public License (GPL) does govern all other use of the material that
# constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the
# Autoconf Macro released by the Autoconf Macro Archive. When you make
# and distribute a modified version of the Autoconf Macro, you may
# extend this special exception to the GPL to apply to your modified
# version as well.
#
AC_DEFUN([AX_TLS], [
  AC_MSG_CHECKING(for thread local storage (TLS) class)
  AC_CACHE_VAL(ac_cv_tls, [
    ax_tls_keywords="__thread __declspec(thread) none"
    for ax_tls_keyword in $ax_tls_keywords; do
       case $ax_tls_keyword in
          none) ac_cv_tls=none ; break ;;
          *)
             AC_TRY_COMPILE(
                [#include <stdlib.h>
                 static void
                 foo(void) {
                 static ] $ax_tls_keyword [ int bar;
                 exit(1);
                 }],
                 [],
                 [ac_cv_tls=$ax_tls_keyword ; break],
                 ac_cv_tls=none
             )
          esac
    done
])

  if test "$ac_cv_tls" != "none"; then
    dnl AC_DEFINE([TLS], [], [If the compiler supports a TLS storage class define it to that here])
    AC_DEFINE_UNQUOTED([TLS], $ac_cv_tls, [If the compiler supports a TLS storage class define it to that here])
  fi
  AC_MSG_RESULT($ac_cv_tls)
])

# ===========================================================================
#         http://www.nongnu.org/autoconf-archive/check_gnu_make.html
# ===========================================================================
#
# SYNOPSIS
#
#   CHECK_GNU_MAKE()
#
# DESCRIPTION
#
#   This macro searches for a GNU version of make. If a match is found, the
#   makefile variable `ifGNUmake' is set to the empty string, otherwise it
#   is set to "#". This is useful for including a special features in a
#   Makefile, which cannot be handled by other versions of make. The
#   variable _cv_gnu_make_command is set to the command to invoke GNU make
#   if it exists, the empty string otherwise.
#
#   Here is an example of its use:
#
#   Makefile.in might contain:
#
#       # A failsafe way of putting a dependency rule into a makefile
#       $(DEPEND):
#               $(CC) -MM $(srcdir)/*.c > $(DEPEND)
#
#       @ifGNUmake@ ifeq ($(DEPEND),$(wildcard $(DEPEND)))
#       @ifGNUmake@ include $(DEPEND)
#       @ifGNUmake@ endif
#
#   Then configure.in would normally contain:
#
#       CHECK_GNU_MAKE()
#       AC_OUTPUT(Makefile)
#
#   Then perhaps to cause gnu make to override any other make, we could do
#   something like this (note that GNU make always looks for GNUmakefile
#   first):
#
#       if  ! test x$_cv_gnu_make_command = x ; then
#               mv Makefile GNUmakefile
#               echo .DEFAULT: > Makefile ;
#               echo \  $_cv_gnu_make_command \$@ >> Makefile;
#       fi
#
#   Then, if any (well almost any) other make is called, and GNU make also
#   exists, then the other make wraps the GNU make.
#
# LICENSE
#
#   Copyright (c) 2008 John Darrington <j.darrington@elvis.murdoch.edu.au>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved.
#
# Note: Modified by Ted Ts'o to add @ifNotGNUMake@

AC_DEFUN(
        [CHECK_GNU_MAKE], [ AC_CACHE_CHECK( for GNU make,_cv_gnu_make_command,
                _cv_gnu_make_command='' ;
dnl Search all the common names for GNU make
                for a in "$MAKE" make gmake gnumake ; do
                        if test -z "$a" ; then continue ; fi ;
                        if  ( sh -c "$a --version" 2> /dev/null | grep GNU  2>&1 > /dev/null ) ;  then
                                _cv_gnu_make_command=$a ;
                                break;
                        fi
                done ;
        ) ;
dnl If there was a GNU version, then set @ifGNUmake@ to the empty string, '#' otherwise
        if test  "x$_cv_gnu_make_command" != "x"  ; then
                ifGNUmake='' ;
                ifNotGNUmake='#' ;
        else
                ifGNUmake='#' ;
                ifNotGNUmake='' ;
                AC_MSG_RESULT("Not found");
        fi
        AC_SUBST(ifGNUmake)
        AC_SUBST(ifNotGNUmake)
] )
: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#!/bin/bash
#
# Handle running OE images standalone with QEMU
#
# Copyright (C) 2006-2011 Linux Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

usage() {
    MYNAME=`basename $0`
    echo ""
    echo "Usage: you can run this script with any valid combination"
    echo "of the following options (in any order):"
    echo "  QEMUARCH - the qemu machine architecture to use"
    echo "  KERNEL - the kernel image file to use"
    echo "  ROOTFS - the rootfs image file or nfsroot directory to use"
    echo "  MACHINE=xyz - the machine name (optional, autodetected from KERNEL filename if unspecified)"
    echo "  Simplified QEMU command-line options can be passed with:"
    echo "    nographic - disables video console"
    echo "    serial - enables a serial console on /dev/ttyS0"
    echo "    kvm - enables KVM when running qemux86/qemux86-64 (VT-capable CPU required)"
    echo "  qemuparams=\"xyz\" - specify custom parameters to QEMU"
    echo "  bootparams=\"xyz\" - specify custom kernel parameters during boot"
    echo ""
    echo "Examples:"
    echo "  $MYNAME qemuarm"
    echo "  $MYNAME qemux86-64 core-image-sato ext3"
    echo "  $MYNAME path/to/bzImage-qemux86.bin path/to/nfsrootdir/ serial"
    echo "  $MYNAME qemux86 qemuparams=\"-m 256\""
    echo "  $MYNAME qemux86 bootparams=\"psplash=false\""
    exit 1
}

if [ "x$1" = "x" ]; then
    usage
fi

error() {
    echo "Error: "$*
    usage
}

MACHINE=${MACHINE:=""}
KERNEL=""
FSTYPE=""
ROOTFS=""
LAZY_ROOTFS=""
SCRIPT_QEMU_OPT=""
SCRIPT_QEMU_EXTRA_OPT=""
SCRIPT_KERNEL_OPT=""

# Determine whether the file is a kernel or QEMU image, and set the
# appropriate variables
process_filename() {
    filename=$1

    # Extract the filename extension
    EXT=`echo $filename | awk -F . '{ print \$NF }'`
    case /$EXT/ in
	/bin/)
		# A file ending in .bin is a kernel
		[ -z "$KERNEL" ] && KERNEL=$filename || \
		    error "conflicting KERNEL args [$KERNEL] and [$filename]"
		;;
	/ext[234]/|/jffs2/|/btrfs/)
		# A file ending in a supportted fs type is a rootfs image
		if [ -z "$FSTYPE" -o "$FSTYPE" = "$EXT" ]; then
		    FSTYPE=$EXT
		    ROOTFS=$filename
		else
		    error "conflicting FSTYPE types [$FSTYPE] and [$EXT]"
		fi
		;;
	*)
		error "unknown file arg [$filename]"
		;;
    esac
}

# Parse command line args without requiring specific ordering. It's a
# bit more complex, but offers a great user experience.
KVM_ENABLED="no"
while true; do
    arg=${1}
    case "$arg" in
        "qemux86" | "qemux86-64" | "qemuarm" | "qemumips" | "qemumips64" | "qemush4"  | "qemuppc")
            [ -z "$MACHINE" ] && MACHINE=$arg || \
                error "conflicting MACHINE types [$MACHINE] and [$arg]"
            ;;
        "ext2" | "ext3" | "jffs2" | "nfs" | "btrfs")
            [ -z "$FSTYPE" -o "$FSTYPE" = "$arg" ] && FSTYPE=$arg || \
                error "conflicting FSTYPE types [$FSTYPE] and [$arg]"
            ;;
        *-image*)
            [ -z "$ROOTFS" ] || \
		error "conflicting ROOTFS args [$ROOTFS] and [$arg]"
            if [ -f "$arg" ]; then
                process_filename $arg
            elif [ -d "$arg" ]; then
                # Handle the case where the nfsroot dir has -image-
                # in the pathname
                echo "Assuming $arg is an nfs rootfs"
                FSTYPE=nfs
                ROOTFS=$arg
            else
                ROOTFS=$arg
                LAZY_ROOTFS="true"
            fi
            ;;
        "nographic")
            SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -nographic"
            SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT console=ttyS0"
            ;;
        "serial")
            SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -serial stdio"
            SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT console=ttyS0"
            ;;
        "qemuparams="*)
            SCRIPT_QEMU_EXTRA_OPT="${arg##qemuparams=}"

            # Warn user if they try to specify serial or kvm options
            # to use simplified options instead
            serial_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-serial\)'`
            kvm_option=`expr "$SCRIPT_QEMU_EXTRA_OPT" : '.*\(-enable-kvm\)'`
            [ ! -z "$serial_option" -o ! -z "$kvm_option" ] && \
                error "Please use simplified serial or kvm options instead"
            ;;
        "bootparams="*)
            SCRIPT_KERNEL_OPT="$SCRIPT_KERNEL_OPT ${arg##bootparams=}"
            ;;
        "audio")
            if [ "x$MACHINE" = "xqemux86" -o "x$MACHINE" = "xqemux86-64" ]; then
                echo "Enabling audio in qemu."
                echo "Please install snd_intel8x0 or snd_ens1370 driver in linux guest."
                QEMU_AUDIO_DRV="alsa"
                SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -soundhw ac97,es1370"
            fi
            ;;
        "kvm")
            KVM_ENABLED="yes"
            KVM_CAPABLE=`grep -q 'vmx\|smx' /proc/cpuinfo && echo 1`
            ;;
        "") break ;;
        *)
            # A directory name is an nfs rootfs
            if [ -d "$arg" ]; then
                echo "Assuming $arg is an nfs rootfs"
                if [ -z "$FSTYPE" -o "$FSTYPE" = "nfs" ]; then
                    FSTYPE=nfs
                else
                    error "conflicting FSTYPE types [$arg] and nfs"
                fi

                if [ -z "$ROOTFS" ]; then
                    ROOTFS=$arg
                else
                    error "conflicting ROOTFS args [$ROOTFS] and [$arg]"
                fi
            elif [ -f "$arg" ]; then
                process_filename $arg
            else
                error "unable to classify arg [$arg]"
            fi
            ;;
    esac
    shift
done

if [ ! -c /dev/net/tun ] ; then
	echo "TUN control device /dev/net/tun is unavailable; you may need to enable TUN (e.g. sudo modprobe tun)"
	exit 1
elif [ ! -w /dev/net/tun ] ; then
	echo "TUN control device /dev/net/tun is not writable, please fix (e.g. sudo chmod 666 /dev/net/tun)"
	exit 1
fi

YOCTO_KVM_WIKI="https://wiki.yoctoproject.org/wiki/How_to_enable_KVM_for_Poky_qemu"
# Detect KVM configuration
if [ "x$KVM_ENABLED" = "xyes" ]; then
    if [ -z "$KVM_CAPABLE" ]; then
        echo "You are trying to enable KVM on a cpu without VT support."
        echo "Remove kvm from the command-line, or refer"
        echo "$YOCTO_KVM_WIKI";
        exit 1;
    fi
    if [ "x$MACHINE" != "xqemux86" -a "x$MACHINE" != "xqemux86-64" ]; then
        echo "KVM only support x86 & x86-64. Remove kvm from the command-line";
        exit 1;
    fi
    if [ ! -e /dev/kvm ]; then
        echo "Missing KVM device. Have you inserted kvm modules?"
        echo "For further help see"
        echo "$YOCTO_KVM_WIKI";
        exit 1;
    fi
    if 9<>/dev/kvm ; then
        SCRIPT_QEMU_OPT="$SCRIPT_QEMU_OPT -enable-kvm"
    else
        echo "You have no rights on /dev/kvm."
        echo "Please change the ownership of this file as described at"
        echo "$YOCTO_KVM_WIKI";
        exit 1;
    fi
fi

# Report errors for missing combinations of options
if [ -z "$MACHINE" -a -z "$KERNEL" ]; then
    error "you must specify at least a MACHINE or KERNEL argument"
fi
if [ "$FSTYPE" = "nfs" -a -z "$ROOTFS" ]; then
    error "NFS booting without an explicit ROOTFS path is not yet supported"
fi

if [ -z "$MACHINE" ]; then
    MACHINE=`basename $KERNEL | sed 's/.*-\(qemux86-64\|qemux86\|qemuarm\|qemumips64\|qemumips\|qemuppc\|qemush4\).*/\1/'`
    if [ -z "$MACHINE" ]; then
        error "Unable to set MACHINE from kernel filename [$KERNEL]"
    fi
    echo "Set MACHINE to [$MACHINE] based on kernel [$KERNEL]"
fi
machine2=`echo $MACHINE | tr 'a-z' 'A-Z' | sed 's/-/_/'`
# MACHINE is now set for all cases

# Defaults used when these vars need to be inferred
QEMUX86_DEFAULT_KERNEL=bzImage-qemux86.bin
QEMUX86_DEFAULT_FSTYPE=ext3

QEMUX86_64_DEFAULT_KERNEL=bzImage-qemux86-64.bin
QEMUX86_64_DEFAULT_FSTYPE=ext3

QEMUARM_DEFAULT_KERNEL=zImage-qemuarm.bin
QEMUARM_DEFAULT_FSTYPE=ext3

QEMUMIPS_DEFAULT_KERNEL=vmlinux-qemumips.bin
QEMUMIPS_DEFAULT_FSTYPE=ext3

QEMUMIPS64_DEFAULT_KERNEL=vmlinux-qemumips64.bin
QEMUMIPS64_DEFAULT_FSTYPE=ext3

QEMUSH4_DEFAULT_KERNEL=vmlinux-qemumips.bin
QEMUSH4_DEFAULT_FSTYPE=ext3

QEMUPPC_DEFAULT_KERNEL=vmlinux-qemuppc.bin
QEMUPPC_DEFAULT_FSTYPE=ext3

AKITA_DEFAULT_KERNEL=zImage-akita.bin
AKITA_DEFAULT_FSTYPE=jffs2

SPITZ_DEFAULT_KERNEL=zImage-spitz.bin
SPITZ_DEFAULT_FSTYPE=ext3

setup_tmpdir() {
    if [ -z "$OE_TMPDIR" ]; then
        # Try to get OE_TMPDIR from bitbake
        type -P bitbake &>/dev/null || {
            echo "In order for this script to dynamically infer paths";
            echo "to kernels or filesystem images, you either need";
            echo "bitbake in your PATH or to source oe-init-build-env";
            echo "before running this script" >&2;
            exit 1; }

        # We have bitbake in PATH, get OE_TMPDIR from bitbake
        OE_TMPDIR=`bitbake -e | grep ^TMPDIR=\" | cut -d '=' -f2 | cut -d '"' -f2`
        if [ -z "$OE_TMPDIR" ]; then
            echo "Error: this script needs to be run from your build directory,"
            echo "or you need to explicitly set OE_TMPDIR in your environment"
            exit 1
        fi
    fi
}

setup_sysroot() {
    # Toolchain installs set up $OECORE_NATIVE_SYSROOT in their
    # environment script. If that variable isn't set, we're
    # either in an in-tree build scenario or the environment
    # script wasn't source'd.
    if [ -z "$OECORE_NATIVE_SYSROOT" ]; then
        setup_tmpdir
        BUILD_ARCH=`uname -m`
        BUILD_OS=`uname | tr '[A-Z]' '[a-z]'`
        BUILD_SYS="$BUILD_ARCH-$BUILD_OS"

        OECORE_NATIVE_SYSROOT=$OE_TMPDIR/sysroots/$BUILD_SYS
    fi 
}

# Locate a rootfs image to boot which matches our expected
# machine and fstype. 
findimage() {
    where=$1
    machine=$2
    extension=$3

    # Sort rootfs candidates by modification time - the most
    # recently created one is the one we most likely want to boot.
    filenames=`ls -t $where/*-image*$machine.$extension 2>/dev/null | xargs`
    for name in $filenames; do
        case $name in
        *core-image-sato* | \
        *core-image-lsb* | \
        *core-image-basic* | \
        *core-image-minimal* )
            ROOTFS=$name
            return
            ;;
        esac
    done

    echo "Couldn't find a $machine rootfs image in $where."
    exit 1
}

if [ -e "$ROOTFS" -a -z "$FSTYPE" ]; then
    # Extract the filename extension
    EXT=`echo $ROOTFS | awk -F . '{ print \$NF }'`
    if [ "x$EXT" = "xext2" -o "x$EXT" = "xext3" -o \
          "x$EXT" = "xjffs2" -o "x$EXT" = "xbtrfs" ]; then
        FSTYPE=$EXT
    else
        echo "Note: Unable to determine filesystem extension for $ROOTFS"
        echo "We will use the default FSTYPE for $MACHINE"
        # ...which is done further below...
    fi
fi

if [ -z "$KERNEL" ]; then
    setup_tmpdir
    eval kernel_file=\$${machine2}_DEFAULT_KERNEL
    KERNEL=$OE_TMPDIR/deploy/images/$kernel_file

    if [ -z "$KERNEL" ]; then
        error "Unable to determine default kernel for MACHINE [$MACHINE]"
    fi
fi
# KERNEL is now set for all cases

if [ -z "$FSTYPE" ]; then
    eval FSTYPE=\$${machine2}_DEFAULT_FSTYPE

    if [ -z "$FSTYPE" ]; then
        error "Unable to determine default fstype for MACHINE [$MACHINE]"
    fi
fi

# FSTYPE is now set for all cases

# Handle cases where a ROOTFS type is given instead of a filename, e.g.
# core-image-sato
if [ "$LAZY_ROOTFS" = "true" ]; then
    setup_tmpdir
    echo "Assuming $ROOTFS really means $OE_TMPDIR/deploy/images/$ROOTFS-$MACHINE.$FSTYPE"
    ROOTFS=$OE_TMPDIR/deploy/images/$ROOTFS-$MACHINE.$FSTYPE
fi

if [ -z "$ROOTFS" ]; then
    setup_tmpdir
    T=$OE_TMPDIR/deploy/images
    eval rootfs_list=\$${machine2}_DEFAULT_ROOTFS
    findimage $T $MACHINE $FSTYPE

    if [ -z "$ROOTFS" ]; then
        error "Unable to determine default rootfs for MACHINE [$MACHINE]"
    fi
fi
# ROOTFS is now set for all cases

echo ""
echo "Continuing with the following parameters:"
echo "KERNEL: [$KERNEL]"
echo "ROOTFS: [$ROOTFS]"
echo "FSTYPE: [$FSTYPE]"

setup_sysroot
# OECORE_NATIVE_SYSROOT is now set for all cases

# We can't run without a libGL.so
libgl='no'

[ -e /usr/lib/libGL.so -a -e /usr/lib/libGLU.so ] && libgl='yes'
[ -e /usr/lib64/libGL.so -a -e /usr/lib64/libGLU.so ] && libgl='yes'
[ -e /usr/lib/*-linux-gnu/libGL.so -a -e /usr/lib/*-linux-gnu/libGLU.so ] && libgl='yes'

if [ "$libgl" != 'yes' ]; then
    echo "You need libGL.so and libGLU.so to exist in your library path to run the QEMU emulator.
    Ubuntu package names are: libgl1-mesa-dev and libglu1-mesa-dev.
    Fedora package names are: mesa-libGL mesa-libGLU."
    exit 1;
fi

INTERNAL_SCRIPT="$0-internal"
if [ ! -f "$INTERNAL_SCRIPT" -o ! -r "$INTERNAL_SCRIPT" ]; then
INTERNAL_SCRIPT=`which runqemu-internal`
fi

. $INTERNAL_SCRIPT