diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-08-06 09:41:15 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-08-06 10:11:32 +0100 |
commit | 51bd27afa147f78c8f4f3778cee725b6444e7eb0 (patch) | |
tree | 8adad0c6c053ce285ab29ec191f329535438e23c | |
parent | 5dd29d7e2da8684ea46c8f1baba42e6dc64f1351 (diff) |
[boilerplate/test] Convert make-*-constructors to shell
Remove the intermediate C program that was a nuisance whilst
cross-compiling and replace it with a simple shell script that is just a
combination of cat + sed.
-rw-r--r-- | boilerplate/Makefile.am | 17 | ||||
-rw-r--r-- | boilerplate/make-cairo-boilerplate-constructors.c | 163 | ||||
-rw-r--r-- | boilerplate/make-cairo-boilerplate-constructors.sh | 24 | ||||
-rw-r--r-- | build/configure.ac.tools | 8 | ||||
-rw-r--r-- | test/Makefile.am | 11 | ||||
-rw-r--r-- | test/make-cairo-test-constructors.c | 162 | ||||
-rw-r--r-- | test/make-cairo-test-constructors.sh | 24 |
7 files changed, 56 insertions, 353 deletions
diff --git a/boilerplate/Makefile.am b/boilerplate/Makefile.am index c8b5d41b..cb92c2bc 100644 --- a/boilerplate/Makefile.am +++ b/boilerplate/Makefile.am @@ -48,21 +48,12 @@ endif libcairoboilerplate_la_LIBADD += $(CAIROBOILERPLATE_LIBS) -# we need to workaround the introduction of CC_FOR_BUILD with older builds -make-cairo-boilerplate-constructors$(EXEEXT): make-cairo-boilerplate-constructors.c - if test -n "$(CC_FOR_BUILD)"; then \ - $(CC_FOR_BUILD) $^ -o $@; \ - else \ - $(CC) $^ -o $@; \ - fi - -cairo-boilerplate-constructors.c: Makefile $(enabled_cairo_boilerplate_sources) make-cairo-boilerplate-constructors$(EXEEXT) - echo '(cd $(srcdir) && $(top_builddir)/boilerplate/make-cairo-boilerplate-constructors$(EXEEXT) $(enabled_cairo_boilerplate_sources)) > $@' - ./make-cairo-boilerplate-constructors$(EXEEXT) $(srcdir) $(enabled_cairo_boilerplate_sources) > $@ +cairo-boilerplate-constructors.c: Makefile $(enabled_cairo_boilerplate_sources) make-cairo-boilerplate-constructors.sh + (cd $(srcdir) && sh ./make-cairo-boilerplate-constructors.sh $(enabled_cairo_boilerplate_sources)) > $@ BUILT_SOURCES += cairo-boilerplate-constructors.c -EXTRA_DIST += $(BUILT_SOURCES) make-cairo-boilerplate-constructors.c -CLEANFILES += $(BUILT_SOURCES) make-cairo-boilerplate-constructors +EXTRA_DIST += $(BUILT_SOURCES) make-cairo-boilerplate-constructors.sh +CLEANFILES += $(BUILT_SOURCES) test: check diff --git a/boilerplate/make-cairo-boilerplate-constructors.c b/boilerplate/make-cairo-boilerplate-constructors.c deleted file mode 100644 index b954492c..00000000 --- a/boilerplate/make-cairo-boilerplate-constructors.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright © 2009 Joonas Pihlaja - * Copyright © 2009 Chris Wilson - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ -/* Usage: - * ./make-cairo-boilerplate-constructors [sources.c...] >cairo-boilerplate-constructors.c - * - * Parses invocations of the CAIRO_BOILERPLATE macro from the source files - * given on the command line, gathers names of targets, and outputs a C - * file with one function _cairo_boilerplate_register_targets() which - * calls the functions _register_<target>() in reverse order. - */ - -/* Keep this file ANSI compliant without any special needs. */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <limits.h> - -#define NAME "make-cairo-boilerplate-constructors.c" - -static struct name { - struct name *next; - char name[1]; -} *head; - -static void * -xmalloc (size_t n) -{ - void *bytes = malloc(n); - if (!bytes) { - fprintf (stderr, "Out of memory\n"); - exit(2); - } - return bytes; -} - -static void -add_name (const char *name) -{ - struct name *node; - int len; - - len = strlen (name); - node = xmalloc (sizeof (struct name) + len); - memcpy (node->name, name, len + 1); - - node->next = head; - head = node; -} - -static int -scan_file (const char *filename, - FILE *fp) -{ - int line_num = 0; - char linebuf[1024]; - int fail = 0; - - while (fgets (linebuf, sizeof (linebuf)-1, fp)) { - char *macro; - char *name; - size_t length; - - line_num++; - linebuf[sizeof (linebuf)-1] = 0; - - macro = strstr (linebuf, "CAIRO_BOILERPLATE"); - if (!macro) - continue; - macro += strlen ("CAIRO_BOILERPLATE"); - - length = strspn (macro, " ("); - if (length == 0) - continue; - name = macro + length; - - length = strspn (name, - "_" - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789"); - name[length] = 0; - - if (length == 0) { - fprintf (stderr, "%s:%d: CAIRO_BOILERPLATE invocation " - "can't be parsed by " NAME"\n", - filename, line_num); - fail = 1; - continue; - } - - add_name (name); - } - - return fail; -} - -int -main (int argc, char **argv) -{ - char buf[PATH_MAX]; - int i; - int fail = 0; - struct name *node; - - for (i = 2; i < argc; i++) { - FILE *fp; - - snprintf (buf, sizeof (buf), "%s/%s", argv[1], argv[i]); - - fp = fopen (buf, "r"); - if (fp != NULL) { - fail |= scan_file (argv[i], fp); - fclose (fp); - } else - fail = 1; - } - if (fail) - exit(1); - - puts ("/* WARNING: Autogenerated file - see " NAME "! */"); - puts (""); - puts ("#include \"cairo-boilerplate-private.h\""); - puts (""); - - for (node = head; node; node = node->next) { - printf ("extern void _register_%s (void);\n", - node->name); - } - puts(""); - - puts ("void _cairo_boilerplate_register_all (void);"); - puts(""); - - puts ("void"); - puts ("_cairo_boilerplate_register_all (void)"); - puts ("{"); - for (node = head; node; node = node->next) { - printf (" _register_%s ();\n", node->name); - } - puts ("}"); - - return 0; -} diff --git a/boilerplate/make-cairo-boilerplate-constructors.sh b/boilerplate/make-cairo-boilerplate-constructors.sh new file mode 100644 index 00000000..2c7fc85e --- /dev/null +++ b/boilerplate/make-cairo-boilerplate-constructors.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +cat <<HERE +/* WARNING: Autogenerated file - see $0! */ + +#include "cairo-boilerplate-private.h" + +void _cairo_boilerplate_register_all (void); + +HERE + +cat "$@" | sed '/^CAIRO_BOILERPLATE/!d; s/CAIRO_BOILERPLATE.*(\(.*\),.*/extern void _register_\1 (void);/' + +cat <<HERE + +void +_cairo_boilerplate_register_all (void) +{ +HERE + +cat "$@" | sed '/^CAIRO_BOILERPLATE/!d; s/CAIRO_BOILERPLATE.*(\(.*\),.*/ _register_\1 ();/' + +echo "}" + diff --git a/build/configure.ac.tools b/build/configure.ac.tools index 2fd09409..a24dbcec 100644 --- a/build/configure.ac.tools +++ b/build/configure.ac.tools @@ -8,14 +8,6 @@ AC_PROG_CXX dnl required for BeOS (and cannot be a conditional dependency) AM_PROG_CC_C_O AC_C_INLINE -# Set reasonable defaults for the tools in case we are cross-compiling -if test "${build}" != "${host}" ; then - CC_FOR_BUILD=${CC_FOR_BUILD-cc} -else - CC_FOR_BUILD=${CC} -fi -AC_SUBST(CC_FOR_BUILD) - dnl =========================================================================== PKG_PROG_PKG_CONFIG() diff --git a/test/Makefile.am b/test/Makefile.am index 6e03910c..a0523932 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -69,11 +69,8 @@ test_sources += $(test) TESTS += cairo-test-suite$(EXEEXT) -make-cairo-test-constructors$(EXEEXT): make-cairo-test-constructors.c - $(CC_FOR_BUILD) $^ -o $@ - -cairo-test-constructors.c: Makefile $(test_sources) make-cairo-test-constructors$(EXEEXT) - ./make-cairo-test-constructors$(EXEEXT) $(srcdir) $(test_sources) > $@ +cairo-test-constructors.c: Makefile $(test_sources) make-cairo-test-constructors.sh + (cd $(srcdir) && sh ./make-cairo-test-constructors.sh $(test_sources)) > $@ cairo_test_suite_SOURCES = \ $(cairo_test_suite_sources) \ @@ -121,8 +118,8 @@ cairo_test_trace_DEPENDENCIES = \ endif BUILT_SOURCES += cairo-test-constructors.c -EXTRA_DIST += $(BUILT_SOURCES) $(noinst_SCRIPTS) COPYING make-cairo-test-constructors.c -CLEANFILES += $(BUILT_SOURCES) make-cairo-test-constructors +EXTRA_DIST += $(BUILT_SOURCES) $(noinst_SCRIPTS) COPYING make-cairo-test-constructors.sh +CLEANFILES += $(BUILT_SOURCES) # All tests which have a reference image go here. REFERENCE_IMAGES = \ diff --git a/test/make-cairo-test-constructors.c b/test/make-cairo-test-constructors.c deleted file mode 100644 index 15c64705..00000000 --- a/test/make-cairo-test-constructors.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright © 2009 Joonas Pihlaja - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ -/* Usage: - * ./make-cairo-test-constructors [tests.c...] >cairo-test-constructors.c - * - * Parses invocations of the CAIRO_TEST macro from the source files - * given on the command line, gathers names of tests, and outputs a C - * file with one function _cairo_test_runner_register_tests() which - * calls the functions _register_<testname>() in reverse order. - */ - -/* Keep this file ANSI compliant without any special needs. */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <limits.h> - -#define NAME "make-cairo-test-constructors.c" - -static struct name { - struct name *next; - char name[1]; -} *head; - -static void * -xmalloc (size_t n) -{ - void *bytes = malloc(n); - if (!bytes) { - fprintf (stderr, "Out of memory\n"); - exit(2); - } - return bytes; -} - -static void -add_name (const char *name) -{ - struct name *node; - int len; - - len = strlen (name); - node = xmalloc (sizeof (struct name) + len); - memcpy (node->name, name, len + 1); - - node->next = head; - head = node; -} - -static int -scan_file (const char *filename, - FILE *fp) -{ - int line_num = 0; - char linebuf[1024]; - int fail = 0; - - while (fgets (linebuf, sizeof (linebuf)-1, fp)) { - char *macro; - char *name; - size_t length; - - line_num++; - linebuf[sizeof (linebuf)-1] = 0; - - macro = strstr (linebuf, "CAIRO_TEST"); - if (!macro) - continue; - macro += strlen ("CAIRO_TEST"); - - length = strspn (macro, " ("); - if (length == 0) - continue; - name = macro + length; - - length = strspn (name, - "_" - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789"); - name[length] = 0; - - if (length == 0) { - fprintf (stderr, "%s:%d: CAIRO_TEST invocation " - "can't be parsed by " NAME "\n", - filename, line_num); - fail = 1; - continue; - } - - add_name (name); - } - - return fail; -} - -int -main (int argc, char **argv) -{ - char buf[PATH_MAX]; - int i; - int fail = 0; - struct name *node; - - for (i = 2; i < argc; i++) { - FILE *fp; - - snprintf (buf, sizeof (buf), "%s/%s", argv[1], argv[i]); - - fp = fopen (buf, "r"); - if (fp) { - fail |= scan_file (argv[i], fp); - fclose (fp); - } else - fail = 1; - } - if (fail) - exit(1); - - puts ("/* WARNING: Autogenerated file - see " NAME "! */"); - puts (""); - puts ("#include \"cairo-test-private.h\""); - puts (""); - - for (node = head; node; node = node->next) { - printf ("extern void _register_%s (void);\n", - node->name); - } - puts(""); - - puts ("void _cairo_test_runner_register_tests (void);"); - puts(""); - - puts ("void"); - puts ("_cairo_test_runner_register_tests (void)"); - puts ("{"); - for (node = head; node; node = node->next) { - printf (" _register_%s ();\n", node->name); - } - puts ("}"); - - return 0; -} diff --git a/test/make-cairo-test-constructors.sh b/test/make-cairo-test-constructors.sh new file mode 100644 index 00000000..d0325e87 --- /dev/null +++ b/test/make-cairo-test-constructors.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +cat <<HERE +/* WARNING: Autogenerated file - see $0! */ + +#include "cairo-test-private.h" + +void _cairo_test_runner_register_tests (void); + +HERE + +cat "$@" | sed '/^CAIRO_TEST/!d; s/CAIRO_TEST.*(\(.*\),.*/extern void _register_\1 (void);/' +cat <<HERE + +void +_cairo_test_runner_register_tests (void) +{ +HERE + +cat "$@" | sed '/^CAIRO_TEST/!d; s/CAIRO_TEST.*(\(.*\),.*/ _register_\1 ();/' + +echo "}" + + |