summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Williams <peterw@src.gnome.org>2000-04-24 20:52:59 +0000
committerPeter Williams <peterw@src.gnome.org>2000-04-24 20:52:59 +0000
commit10af3925025fec92d8618bb63690750c722879ea (patch)
treee7798ff305304e36d5aceb421ba66c92607ce5f4
parent0645faaf9180301eea01de138cfe17772a975554 (diff)
downloadgnome-common-10af3925025fec92d8618bb63690750c722879ea.tar.gz
First revision for the new configuration stuff.
svn path=/branches/unlabeled-1.1.2/; revision=1198
-rw-r--r--macros/balsa-offset-tool.m4143
-rw-r--r--macros/offset-tool.sh.in234
2 files changed, 377 insertions, 0 deletions
diff --git a/macros/balsa-offset-tool.m4 b/macros/balsa-offset-tool.m4
new file mode 100644
index 0000000..f0cda7e
--- /dev/null
+++ b/macros/balsa-offset-tool.m4
@@ -0,0 +1,143 @@
+dnl Set up the Balsa offset tool
+dnl BALSA_OFFSET_TOOL( fragment name, file1 file2 file3, [extra defs], [tool home], [tool name] )
+dnl $1 is the make fragment location to look at
+dnl $2 is the list of files to examine for offset inputs and hints
+dnl $3 is the optional list of extra variable settings to pass to the offset tool. You're
+dnl probably interested in overriding CFLAGS here. You're given ${top_srcdir} and
+dnl ${top_builddir} to work from; don't forget to quote tehm
+dnl $4 is the optional subdirectory of srcdir to find the tool in; defaults to macros
+dnl $5 is the optional filename of the tool (not the infile); defaults to offset-tool.sh
+dnl AC_SUBST's BALSA_OFFSET_MAKERULES which should be placed in a Makefile somewhere
+dnl BALSA_OFFSET_SRCPATH which goes from top_builddir to the top srcdir
+dnl BALSA_OFFSET_TOOL_HOME which records the fourth option
+dnl BALSA_OFFSET_TOOL_NAME which records the fifth option
+dnl BALSA_OFFSET_TOOL_DEFSFILE which records the name of the definitions file,
+dnl relative to top_builddir
+dnl BALSA_OFFSET_TOOL_DOTS how to get to top_builddir from where the
+dnl makefragment is
+dnl
+dnl Issues:
+dnl
+dnl I can't think of a way to make this compatible with cross-compiling. We can build
+dnl a proper executable with the correct offsets, but we can't run it. If we had some way of
+dnl poking at the binary, we could find the values, but that is hard.
+dnl
+dnl You should be able to specify the defs file's name, I'm just too lazy right now.
+dnl The current code assumes that the tool-name has a -tool in it to calculate the defs file's
+dnl name.
+dnl
+dnl All that config.status stuff is a bit complicated.
+dnl
+dnl Some dependencies might be missing or not quite right.
+
+dnl serial 1
+AC_DEFUN([BALSA_OFFSET_TOOL],[
+ AC_MSG_CHECKING([for offset tool Makefile fragment location])
+ AC_MSG_RESULT($1)
+
+ AC_MSG_CHECKING([for inputs to offset header])
+ AC_MSG_RESULT($2)
+
+ if test x"$4" = x ; then
+ BALSA_OFFSET_TOOL_HOME=macros
+ else
+ BALSA_OFFSET_TOOL_HOME='$4'
+ fi
+
+ if test x"$5" = x ; then
+ BALSA_OFFSET_TOOL_NAME=offset-tool.sh
+ else
+ BALSA_OFFSET_TOOL_NAME='$5'
+ fi
+
+ if test ! -r ${srcdir}/${BALSA_OFFSET_TOOL_HOME}/${BALSA_OFFSET_TOOL_NAME}.in ; then
+ AC_MSG_ERROR([Cannot locate ${srcdir}/${BALSA_OFFSET_TOOL_HOME}/${BALSA_OFFSET_TOOL_NAME}.in])
+ fi
+
+ BALSA_OFFSET_TOOL_DEFSFILE=`echo "${BALSA_OFFSET_TOOL_HOME}/${BALSA_OFFSET_TOOL_NAME}" |sed -e 's,-tool,-defs,'`
+
+ ifelse($3,[],[
+ define([cat_command],[])
+ ],[
+ define([cat_command],[
+ #Don't collide with the EOF inside the AC_OUTPUT_COMMANDS that we're in
+ cat <<BOTEOF >${BALSA_OFFSET_TOOL_DEFSFILE}
+$3
+BOTEOF
+])
+ ])
+
+ changequote(<<,>>)dnl Clobbers my regexes!
+
+ #Make everything relative to the make fragment
+
+ frag_dots=`echo $1 |sed -e 's,\(.*/\)[^/]*,\1,' -e 's,[^/]*/,../,g'`
+ frag_basename=`echo $1 |sed -e 's,.*/\([^/]*\),\1,'`
+ frag_subdir=`echo $1 |sed -e 's,\(.*/\)[^/]*,\1,'`
+
+ changequote([,])dnl
+
+ #Transform the input names into relative from make fragment to srcdir
+
+ case "${srcdir}" in
+ /*)
+ infile_prefix=
+ ;;
+ *)
+ infile_prefix="${frag_dots}"
+ ;;
+ esac
+
+ new_infiles=
+ for ping in "$2" ; do
+ new_infiles="${new_infiles} ${infile_prefix}${srcdir}/${ping}"
+ done
+ new_infiles=`echo ${new_infiles} |sed -e 's,^ ,,'`
+
+ #We use ${0} to confuse M4... heh heh
+
+ AC_OUTPUT_COMMANDS([
+ #Only generate the fragment and stuff if the Makefile that includes it is
+ #being rebuilt
+ cfgmf="${BALSA_OFFSET_FRAG_DIR}Makefile"
+ ping=`echo ${CONFIG_FILES} |grep ${cfgmf}`
+ if test x"${ping}" != x -a x"${BALSA_OFFSET_TOOL_NO_RECURSE}" != xyes ; then
+ chmod +x ${BALSA_OFFSET_TOOL_HOME}/${BALSA_OFFSET_TOOL_NAME}
+
+ ])
+
+ AC_OUTPUT_COMMANDS(cat_command)
+
+ AC_OUTPUT_COMMANDS([
+
+ echo creating $1
+ (cd ${BALSA_OFFSET_FRAG_DIR} && ${SHELL} ${BALSA_OFFSET_TOOL_DOTS}${BALSA_OFFSET_TOOL_HOME}/${BALSA_OFFSET_TOOL_NAME} \
+ --makerules --fragname ${BALSA_OFFSET_FRAG_BASE} ${BALSA_OFFSET_SRCFILES} >${BALSA_OFFSET_FRAG_BASE})
+
+ #Recreate the makefile with the new fragment included
+ CONFIG_FILES=${cfgmf} CONFIG_HEADERS= BALSA_OFFSET_TOOL_NO_RECURSE=yes ${0}
+ fi
+ ],[
+ BALSA_OFFSET_TOOL_HOME="${BALSA_OFFSET_TOOL_HOME}"
+ BALSA_OFFSET_TOOL_NAME="${BALSA_OFFSET_TOOL_NAME}"
+ BALSA_OFFSET_TOOL_DEFSFILE="${BALSA_OFFSET_TOOL_DEFSFILE}"
+ BALSA_OFFSET_TOOL_DOTS="${frag_dots}"
+ BALSA_OFFSET_SRCFILES="${new_infiles}"
+ BALSA_OFFSET_FRAG_BASE="${frag_basename}"
+ BALSA_OFFSET_FRAG_DIR="${frag_subdir}"
+ ])
+
+ undefine([cat_command])
+
+ BALSA_OFFSET_SRCPATH="${srcdir}"
+ BALSA_OFFSET_TOOL_DOTS="${frag_dots}"
+ BALSA_OFFSET_MAKERULES=$1
+
+ AC_SUBST_FILE(BALSA_OFFSET_MAKERULES)
+
+ AC_SUBST(BALSA_OFFSET_TOOL_DEFSFILE)
+ AC_SUBST(BALSA_OFFSET_TOOL_HOME)
+ AC_SUBST(BALSA_OFFSET_TOOL_NAME)
+ AC_SUBST(BALSA_OFFSET_TOOL_DOTS)
+ AC_SUBST(BALSA_OFFSET_SRCPATH)
+]) \ No newline at end of file
diff --git a/macros/offset-tool.sh.in b/macros/offset-tool.sh.in
new file mode 100644
index 0000000..fa97d18
--- /dev/null
+++ b/macros/offset-tool.sh.in
@@ -0,0 +1,234 @@
+#!/bin/sh
+#
+# offset-tool.sh (C)2000 Peter Williams
+#
+# This tool is used to pregenerate structure offset
+# data for use with Balsa's configuration, because
+# it's really constant data although GCC, at least,
+# doesn't think so.
+
+srcdir="@srcdir@"
+top_srcdir="@top_srcdir@"
+real_top_srcdir="@BALSA_OFFSET_SRCPATH@"
+offset_tool_home="@BALSA_OFFSET_TOOL_HOME@"
+top_dots="@BALSA_OFFSET_TOOL_DOTS@"
+tool_defs="@BALSA_OFFSET_TOOL_DEFSFILE@"
+CPP="@CPP@"
+SHELL="@SHELL@"
+CC="@CC@"
+DEFS="@DEFS@"
+CFLAGS="@CFLAGS@"
+mid_file=offset-tool.c
+
+case "${top_srcdir}" in
+/*)
+ test -f ../../config.status && top_builddir="../.."
+ test -f ../config.status && top_builddir=".."
+ test -f config.status && top_builddir="."
+ ;;
+*)
+ test -d ../../${real_top_srcdir} && top_builddir="../.."
+ test -d ../${real_top_srcdir} && top_builddir=".."
+ test -d ./${real_top_srcdir} && top_builddir="."
+ ;;
+esac
+
+case "${real_top_srcdir}" in
+/*)
+ header_dots="${real_top_srcdir}"
+ ;;
+*)
+ header_dots="${top_dots}${real_top_srcdir}"
+ ;;
+esac
+
+# Backup top srcdir to be what we want it to be
+
+tmp="${top_srcdir}"
+top_srcdir="${header_dots}"
+
+if test -r "${top_builddir}/${tool_defs}" ; then
+ . "${top_builddir}/${tool_defs}"
+fi
+
+# Restore the backup
+
+top_srcdir="${tmp}"
+
+usage()
+{
+ echo "Usage: offset-tool.sh (--help|--create|--makerules|--headername) [--fragname=<fragment name>] <filenames...>"
+ echo "Look at $(top_srcdir)/${offset_tool_home}/offset-tool.sh.in for more information"
+ exit 1
+}
+
+if test -z "$1" ; then
+ usage
+fi
+
+mode=`echo $1 |sed -e 's,^--,,'`
+
+case $mode in
+help)
+ usage
+ ;;
+create)
+ ;;
+makerules)
+ ;;
+headername)
+ ;;
+*)
+ echo "Unknown mode $mode"
+ usage
+ ;;
+esac
+
+shift
+
+fragname=
+
+while test $# -gt 0 ; do
+ case "${1}" in
+ --fragname=*)
+ fragname=`echo ${1} |sed -e 's,.*=\(.*\),\1,'`; shift ;;
+ --fragname)
+ shift; fragname="${1}" ; shift ;;
+ --)
+ shift; break ;;
+ -*)
+ usage ;;
+ *)
+ break ;;
+ esac
+done
+
+test x"$fragname" = x && fragname=Makefragment.offset-tool
+infiles=$*
+
+test x"$mode" = xmakerules || echo "Scanning these files for config offsets: $infiles"
+
+header=`cat $infiles |grep "OFFSET HEADER" |sed -e 's,# *include *\"\(.*\)\".*,\1,' |sed -e '1!d'`
+if test x"$header" = x ; then
+ echo "Couldn't determine the configuration header." 1>&2
+ exit 2
+fi
+
+if test x"$mode" = xcreate ; then
+ echo Removing old header ...
+ echo "/* Nothing */" >${header}
+
+ echo Getting needed defines ...
+ defines=`${CPP} ${CFLAGS} $infiles |grep "BALSA_OFFSET_" |sed -e 's|^.*BALSA_OFFSET_\([a-zA-Z0-9_]*\)_ELEM_\([a-zA-Z0-9_]*\).*$|\1--\2|'`
+ # Helpers will be in comments, don't chomp them.
+ helpers=`cat $infiles |grep "OFFSET DEF" |sed -e 's|^.*OFFSET DEF *\[\[\(.*\)\]\].*$|\1|'`
+
+ echo Generating ${mid_file} ...
+ cat <<EOF >${mid_file}
+/* This file generated by offset-tool.sh. Do not edit! */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef STDC_HEADERS
+#include <stdio.h>
+#else
+extern void printf( char *, ... );
+#endif
+
+EOF
+
+ echo >>${mid_file}
+ echo "$helpers" >>${mid_file}
+ echo >>${mid_file}
+
+ cat <<EOF >>${mid_file}
+
+#ifndef offsetof
+#define offsetof( type, member ) ( (int) ( (char *) ( &( ( (type *) 0 )->member ) ) ) )
+#endif
+
+int main( int argc, char **argv )
+{
+ printf( "/* This file generated by ${mid_file}, generated by offset-tool.sh. Do not edit!*/\n" );
+ printf( "/* Scanned from files: $infiles */\n\n" );
+
+ printf( "#ifndef _OFFSET_TOOL_HEADER_FILE\n" );
+ printf( "#define _OFFSET_TOOL_HEADER_FILE\n\n" );
+
+EOF
+
+ for ping in $defines ; do
+ type=`echo $ping |sed -e 's|--.*$||'`
+ member=`echo $ping |sed -e 's|^.*--||'`
+
+ cat <<EOF >>${mid_file}
+ printf( "#define BALSA_OFFSET_${type}_ELEM_${member} %d\n", offsetof( $type, $member ) );
+EOF
+ done
+
+ cat <<EOF >>${mid_file}
+
+ printf( "\n\n#endif\n" );
+ return 0;
+}
+EOF
+
+ mid_exe=`echo ${mid_file} |sed -e 's,\.c,,'`
+ if test x`echo ${mid_exe} |grep '^/'` = x ; then
+ mid_exe="./${mid_exe}"
+ fi
+
+ echo "Building ${mid_exe} ..."
+ ${SHELL} libtool --mode=link ${CC} -o ${mid_exe} ${DEFS} ${CFLAGS} ${mid_file} || {
+ echo "Error compiling ${mid_file}"
+ exit 2
+ }
+
+ echo "Running ${mid_exe} >${header}"
+ ${mid_exe} >${header} || {
+ echo "Error running ${mid_exe} made from ${mid_file}"
+ exit 3
+ }
+
+ echo "Cleaning up..."
+ rm -f ${mid_file} ${mid_exe}
+
+ res=$?
+ echo "Done creating ${header}"
+ exit $res
+fi
+
+if test x"$mode" = xmakerules ; then
+ # FIXME bleah
+ tab=`echo -e '\t'`
+
+ cat <<EOF
+${header}: \$(top_builddir)/${offset_tool_home}/offset-tool.sh ${infiles}
+${tab}\$(SHELL) \$(top_builddir)/${offset_tool_home}/offset-tool.sh --create ${infiles}
+
+${fragname}: \$(top_builddir)/${offset_tool_home}/offset-tool.sh
+${tab}\$(SHELL) \$(top_builddir)/${offset_tool_home}/offset-tool.sh --makerules --fragname ${fragname} ${infiles} >${fragname}
+
+\$(top_builddir)/${offset_tool_home}/offset-tool.sh: \$(top_builddir)/config.status \$(top_srcdir)/${offset_tool_home}/offset-tool.sh.in
+${tab}(cd \$(top_builddir) && CONFIG_FILES="${offset_tool_home}/offset-tool.sh" CONFIG_HEADERS= \$(SHELL) ./config.status)
+${tab}chmod +x \$(top_builddir)/${offset_tool_home}/offset-tool.sh
+
+offset-clean:
+${tab}rm -f ${header}
+
+offset-realclean:
+${tab}rm -f \$(top_builddir)/${offset_tool_home}/offset-tool.sh ${fragname}
+EOF
+ exit 0
+fi
+
+if x"$mode" = xheadername; then
+ echo ${header}
+ exit 0
+fi
+
+echo "Unhandled mode: $mode" 1>&2
+exit 1
+