The primary purpose at the moment with regards to C flags is to give
you a _minimal_ set of flags to get a kernel module (or userspace
linux-specific program), not a full set of flags you used to compile
your kernel.
For example:
cc `linux-config --cflags module` mymodule.c
cc `linux-config --cflags module-export` myexportsymsmodule.c
Andrew
-- cut here --
#! /bin/sh
#
# linux-config: Script used to obtain minimal compiler flags to
# compile modules, etc. outside of the kernel tree.
#
# Run without args for usage instructions.
#
# ChangeLog
# ~~~~~~~~~
# October 5, 1998; Andrew T. Veliath <andrewtv@usa.net>
# - Initial version.
# -*- Default values -*-
# Default value of C optimization level (minimum is -O).
default_cflags_opt=-O
# Default source location, must be a directory which contains
# an ``include/linux.''
default_source=/usr
# -*- End default values -*-
usage ()
{
cat <<EOF
Usage: linux-config [OPTION]... [TARGET]
Known values for OPTION are (order is important):
--source=DIR directory with include/linux [$default_source]
--cflags print pre-processor and compiler flags
--cflags-opt=FLAGS C optimizations [$default_cflags_opt]
--help display this help and exit
--version output version used for configuration
Known values for TARGET are:
module kernel module, standalone
module-export kernel module, supporting exported kernel symbols
user user module, for use with linux-specific programs
EOF
exit $1
}
set_cflags_opt ()
{
cflags_opt="$1"
}
set_prefix ()
{
prefix="$1"
includedir=${prefix}/include
linux_includedir=${includedir}/linux
}
print_error ()
{
echo 1>&2 -n "linux-config: error: "
echo 1>&2 "$1"
}
get_linux_version ()
{
local major minor
VERSION=`cat ${linux_includedir}/version.h |\
grep UTS_RELEASE |\
awk '{print $3}' |\
sed -e 's/\"//g'`
major=`echo $VERSION | cut -d. -f1`
minor=`echo $VERSION | cut -d. -f2`
if test -z "$VERSION" -o -z "$major" -o -z "$minor"; then
print_error "cannot determine kernel version"
exit 1
fi
if test $major -lt 2; then
print_error "cannot be used with kernels older than 2.0"
print_error "version found was $VERSION"
exit 1
fi
}
do_sanity_checks ()
{
if test ! -f ${linux_includedir}/autoconf.h; then
print_error "wrong kernel directory or kernel not configured"
print_error "directory was \"${linux_includedir}\""
exit 1
fi
get_linux_version
}
add_linux_cflags ()
{
all_cflags="$all_cflags $cflags_opt -I${includedir} "
}
add_kernel_cflags ()
{
all_cflags="$all_cflags -D__KERNEL__"
if grep "SMP" \
${linux_includedir}/compile.h >/dev/null 2>&1; then
all_cflags="$all_cflags -D__SMP__"
fi
}
add_module_cflags ()
{
all_cflags="-c $all_cflags -DMODULE"
if grep "define CONFIG_MODVERSIONS" \
${linux_includedir}/autoconf.h >/dev/null 2>&1; then
all_cflags="$all_cflags -DMODVERSIONS \
-include ${linux_includedir}/modversions.h"
fi
}
add_module_export_cflags ()
{
all_cflags="$all_cflags -DEXPORT_SYMTAB"
}
# Set defaults
set_cflags_opt $default_cflags_opt
set_prefix $default_source
if test $# -eq 0; then
usage 1
fi
# Process arguments
want_cflags=false
all_cflags=
while test $# -gt 0; do
# Get option arg
case "$1" in
-*=*)
optarg=`echo "$1" |\
sed 's/[-_a-zA-Z0-9]*=//'`
;;
*)
optarg=
;;
esac
# Process arg
case "$1" in
--help)
usage 0
;;
--version)
do_sanity_checks
echo $VERSION
exit 0
;;
--source=*)
set_prefix "$optarg"
;;
--cflags-opt=*)
set_cflags_opt "$optarg"
;;
--cflags)
want_cflags=true
;;
module)
do_sanity_checks
add_linux_cflags
add_kernel_cflags
add_module_cflags
;;
module-export)
do_sanity_checks
add_linux_cflags
add_kernel_cflags
add_module_cflags
add_module_export_cflags
;;
user)
do_sanity_checks
add_linux_cflags
;;
*)
usage 1
;;
esac
shift
done
# Load all the flags
all_flags=
if test "$want_cflags" = "true"; then
all_flags="$all_flags $all_cflags"
fi
# Remove duplicates
filtered_flags=
for i in $all_flags; do
case " $filtered_flags " in
*\ $i\ *) ;;
*) filtered_flags="$filtered_flags $i" ;;
esac
done
test -z "$filtered_flags" && exit 1
echo $filtered_flags
-- cut here --
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/