[Devel] Re: [PATCH] Add script to, given a kernel source tree, automatically write the cr.h
Matt Helsley
matthltc at us.ibm.com
Tue Aug 4 16:49:48 PDT 2009
Oren,
Could this script or something like it be useful for user-cr
rather than always using KERNELSRC and KERNELBUILD?
Cheers,
-Matt Helsley
On Tue, Aug 04, 2009 at 04:43:08PM -0700, Matt Helsley wrote:
> Signed-off-by: Matt Helsley <matthltc at us.ibm.com>
> ---
<snip>
> diff --git a/rewrite-cr-header.sh b/rewrite-cr-header.sh
> new file mode 100755
> index 0000000..22f92c7
> --- /dev/null
> +++ b/rewrite-cr-header.sh
> @@ -0,0 +1,64 @@
> +#!/bin/bash
> +#
> +# Rewrite the contents of cr.h
> +#
> +
> +KERNELSRC=../oren
> +
> +################################################################################
> +
> +[ -z "${KERNELSRC}" ] && exit -1
> +mv cr.h cr.h.bak || exit -1
> +
> +(
> +COND='#if'
> +set -e
> +echo '/* AUTOMATICALLY GENERATED by rewrite-cr-header.sh */'
> +
> +#
> +# Include non-__KERNEL__ sections of include/linux/checkpoint.h using
> +# cpp to expand only the directives of the kernel header.
> +#
> +# The first 6 lines of cpp output write some trashy #define/#undef lines
> +# we don't want. Would it be better to throw everything away until we see
> +# "#define _LINUX_CHECKPOINT_H_" ??
> +#
> +cpp -CC -P -U__KERNEL__ -undef -nostdinc -fdirectives-only ${KERNELSRC}/include/linux/checkpoint.h | tail -n '+6'
> +
> +find ${KERNELSRC}/arch -name 'unistd*.h' -print | sort | \
> +while read UNISTDH ; do
> + REGEX='[[:space:]]*#[[:space:]]*define[[:space:]]+__NR_(checkpoint|restart)[[:space:]]+[[:digit:]]+'
> +
> + [ -z "${UNISTDH}" ] && continue
> + KARCH=$(echo "${UNISTDH}" | sed -e 's|.*/arch/\([^/]\+\)/.*|\1|')
> + BITNESS=$(basename "${UNISTDH}" | sed -e 's/unistd_*\([12346]\+\)\.h/\1/')
> +
> + # Map KARCH to something suitable for CPP e.g. __i386__
> + case "${KARCH}" in
> + x86) if [ "${BITNESS}" == "32" ]; then
> + CPPARCH=i386
> + else
> + CPPARCH=x86_64
> + fi
> + ;;
> + s390*) CPPARCH=s390x ;;
> + *) CPPARCH="${KARCH}" ;;
> + esac
> +
> + grep -q -E "${REGEX}" ${UNISTDH} || {
> + echo '/* '"${CPPARCH}"' unsupported. */'
> + continue
> + }
> +
> + echo -e "${COND} __${CPPARCH}__\\n"
> + grep -E "${REGEX}" ${UNISTDH} | \
> + sed -e 's/^[[:space:]]*#define[[:space:]]\+__NR_\([^[:space:]]\+\)[[:space:]]\+\([^[:space:]]\+\).*$/#ifndef __NR_\1\n#define __NR_\1 \2\n#endif\n/'
> + COND='#elif'
> +done
> +echo -e '#else\n#error "Architecture does not have definitons for __NR_(checkpoint|restart)"\n#endif'
> +) > cr.h || {
> + mv -f cr.h.bak cr.h
> + exit -1
> +}
> +
> +rm -f cr.h.bak
> --
> 1.5.6.3
>
>
_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
More information about the Devel
mailing list