From a3c4f3ffbed121b02ed44a6ddf6cfdd16e5b05e9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 15 Dec 2021 19:59:01 +0100 Subject: [PATCH] Add simple examples. * examples: New directory. --- ChangeLog | 5 ++ examples/README | 3 ++ .../INSTALL | 8 +++ .../Makefile.am | 28 +++++++++++ .../autoclean.sh | 34 +++++++++++++ .../autogen.sh | 48 ++++++++++++++++++ .../configure.ac | 19 +++++++ .../m4/Makefile.am | 1 + .../src/hello.c | 26 ++++++++++ .../src/local.mk | 7 +++ .../hello-c-gnulib-automakesubdir/INSTALL | 8 +++ .../hello-c-gnulib-automakesubdir/Makefile.am | 28 +++++++++++ .../autoclean.sh | 29 +++++++++++ .../hello-c-gnulib-automakesubdir/autogen.sh | 46 +++++++++++++++++ .../configure.ac | 18 +++++++ .../m4/Makefile.am | 1 + .../hello-c-gnulib-automakesubdir/src/hello.c | 26 ++++++++++ .../src/local.mk | 7 +++ examples/hello-c-gnulib-nonrecursive/INSTALL | 8 +++ .../hello-c-gnulib-nonrecursive/Makefile.am | 28 +++++++++++ .../hello-c-gnulib-nonrecursive/autoclean.sh | 30 ++++++++++++ .../hello-c-gnulib-nonrecursive/autogen.sh | 48 ++++++++++++++++++ .../hello-c-gnulib-nonrecursive/configure.ac | 18 +++++++ .../m4/Makefile.am | 1 + .../hello-c-gnulib-nonrecursive/src/hello.c | 26 ++++++++++ .../hello-c-gnulib-nonrecursive/src/local.mk | 7 +++ examples/hello-c-gnulib/INSTALL | 8 +++ examples/hello-c-gnulib/Makefile.am | 22 +++++++++ examples/hello-c-gnulib/autoclean.sh | 34 +++++++++++++ examples/hello-c-gnulib/autogen.sh | 49 +++++++++++++++++++ examples/hello-c-gnulib/configure.ac | 21 ++++++++ examples/hello-c-gnulib/hello.c | 26 ++++++++++ examples/hello-c-gnulib/m4/Makefile.am | 1 + examples/hello-c-nognulib/INSTALL | 8 +++ examples/hello-c-nognulib/Makefile.am | 19 +++++++ examples/hello-c-nognulib/autoclean.sh | 21 ++++++++ examples/hello-c-nognulib/autogen.sh | 9 ++++ examples/hello-c-nognulib/configure.ac | 15 ++++++ examples/hello-c-nognulib/hello.c | 22 +++++++++ examples/hello-c-nognulib/m4/Makefile.am | 1 + 40 files changed, 764 insertions(+) create mode 100644 examples/README create mode 100644 examples/hello-c-gnulib-automakesubdir-withtests/INSTALL create mode 100644 examples/hello-c-gnulib-automakesubdir-withtests/Makefile.am create mode 100755 examples/hello-c-gnulib-automakesubdir-withtests/autoclean.sh create mode 100755 examples/hello-c-gnulib-automakesubdir-withtests/autogen.sh create mode 100644 examples/hello-c-gnulib-automakesubdir-withtests/configure.ac create mode 100644 examples/hello-c-gnulib-automakesubdir-withtests/m4/Makefile.am create mode 100644 examples/hello-c-gnulib-automakesubdir-withtests/src/hello.c create mode 100644 examples/hello-c-gnulib-automakesubdir-withtests/src/local.mk create mode 100644 examples/hello-c-gnulib-automakesubdir/INSTALL create mode 100644 examples/hello-c-gnulib-automakesubdir/Makefile.am create mode 100755 examples/hello-c-gnulib-automakesubdir/autoclean.sh create mode 100755 examples/hello-c-gnulib-automakesubdir/autogen.sh create mode 100644 examples/hello-c-gnulib-automakesubdir/configure.ac create mode 100644 examples/hello-c-gnulib-automakesubdir/m4/Makefile.am create mode 100644 examples/hello-c-gnulib-automakesubdir/src/hello.c create mode 100644 examples/hello-c-gnulib-automakesubdir/src/local.mk create mode 100644 examples/hello-c-gnulib-nonrecursive/INSTALL create mode 100644 examples/hello-c-gnulib-nonrecursive/Makefile.am create mode 100755 examples/hello-c-gnulib-nonrecursive/autoclean.sh create mode 100755 examples/hello-c-gnulib-nonrecursive/autogen.sh create mode 100644 examples/hello-c-gnulib-nonrecursive/configure.ac create mode 100644 examples/hello-c-gnulib-nonrecursive/m4/Makefile.am create mode 100644 examples/hello-c-gnulib-nonrecursive/src/hello.c create mode 100644 examples/hello-c-gnulib-nonrecursive/src/local.mk create mode 100644 examples/hello-c-gnulib/INSTALL create mode 100644 examples/hello-c-gnulib/Makefile.am create mode 100755 examples/hello-c-gnulib/autoclean.sh create mode 100755 examples/hello-c-gnulib/autogen.sh create mode 100644 examples/hello-c-gnulib/configure.ac create mode 100644 examples/hello-c-gnulib/hello.c create mode 100644 examples/hello-c-gnulib/m4/Makefile.am create mode 100644 examples/hello-c-nognulib/INSTALL create mode 100644 examples/hello-c-nognulib/Makefile.am create mode 100755 examples/hello-c-nognulib/autoclean.sh create mode 100755 examples/hello-c-nognulib/autogen.sh create mode 100644 examples/hello-c-nognulib/configure.ac create mode 100644 examples/hello-c-nognulib/hello.c create mode 100644 examples/hello-c-nognulib/m4/Makefile.am diff --git a/ChangeLog b/ChangeLog index 00761d6145..5048863fa7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-12-15 Bruno Haible + + Add simple examples. + * examples: New directory. + 2021-12-15 Bruno Haible Accommodate non-recursive Automake in a less hacky way. diff --git a/examples/README b/examples/README new file mode 100644 index 0000000000..ba4077afe4 --- /dev/null +++ b/examples/README @@ -0,0 +1,3 @@ +This directory contains small packages that +1) show how to use Gnulib and gnulib-tool (working examples), +2) can be used for doing regression tests, e.g. when modifying gnulib-tool. diff --git a/examples/hello-c-gnulib-automakesubdir-withtests/INSTALL b/examples/hello-c-gnulib-automakesubdir-withtests/INSTALL new file mode 100644 index 0000000000..062762be0f --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir-withtests/INSTALL @@ -0,0 +1,8 @@ +Installation: + ./autogen.sh + ./configure --prefix=/some/prefix + make + make install +Cleanup: + make distclean + ./autoclean.sh diff --git a/examples/hello-c-gnulib-automakesubdir-withtests/Makefile.am b/examples/hello-c-gnulib-automakesubdir-withtests/Makefile.am new file mode 100644 index 0000000000..cb429098cb --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir-withtests/Makefile.am @@ -0,0 +1,28 @@ +# This file is in the public domain. +# +# Makefile configuration - processed by automake. + +# General automake options. +AUTOMAKE_OPTIONS = foreign no-dependencies subdir-objects +ACLOCAL_AMFLAGS = -I m4 -I gnulib-m4 + +# The list of subdirectories containing Makefiles. +SUBDIRS = . tests + +AM_CPPFLAGS = -Ilib -I$(srcdir)/lib + +# Additional files to be distributed. +EXTRA_DIST = autogen.sh autoclean.sh gnulib-m4/gnulib-cache.m4 + +BUILT_SOURCES = +SUFFIXES = +MOSTLYCLEANFILES = +MOSTLYCLEANDIRS = +CLEANFILES = +DISTCLEANFILES = +MAINTAINERCLEANFILES = + +noinst_LIBRARIES = + +include lib/gnulib.mk +include src/local.mk diff --git a/examples/hello-c-gnulib-automakesubdir-withtests/autoclean.sh b/examples/hello-c-gnulib-automakesubdir-withtests/autoclean.sh new file mode 100755 index 0000000000..9fd8d95346 --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir-withtests/autoclean.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for cleaning all autogenerated files. + +test ! -f Makefile || make distclean + +# Generated by aclocal. +rm -f aclocal.m4 + +# Generated by autoconf. +rm -f configure + +# Generated by autoheader. +rm -f config.h.in + +# Generated or brought in by automake. +rm -f Makefile.in +rm -f m4/Makefile.in +rm -f build-aux/compile +rm -f build-aux/depcomp +rm -f build-aux/install-sh +rm -f build-aux/missing +rm -f build-aux/config.guess +rm -f build-aux/config.sub + +# Generated or brought in by gnulib-tool. +rm -rf lib gnulib-m4 tests +rm -f build-aux/ar-lib +rm -f build-aux/run-test +rm -f build-aux/test-driver.diff + +# Generated by autogen.sh. +rm -f build-aux/test-driver diff --git a/examples/hello-c-gnulib-automakesubdir-withtests/autogen.sh b/examples/hello-c-gnulib-automakesubdir-withtests/autogen.sh new file mode 100755 index 0000000000..1fbc64dc6d --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir-withtests/autogen.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for regenerating all autogenerated files. + +# Usage: ./autogen.sh [--skip-gnulib] + +skip_gnulib=false +while :; do + case "$1" in + --skip-gnulib) skip_gnulib=true; shift;; + *) break ;; + esac +done + +if test $skip_gnulib = false; then + if test -n "$GNULIB_SRCDIR"; then + test -d "$GNULIB_SRCDIR" || { + echo "*** GNULIB_SRCDIR is set but does not point to an existing directory." 1>&2 + exit 1 + } + fi + # Now it should contain a gnulib-tool. + GNULIB_TOOL="$GNULIB_SRCDIR/gnulib-tool" + test -f "$GNULIB_TOOL" || { + echo "*** gnulib-tool not found." 1>&2 + exit 1 + } + GNULIB_MODULES=' + unistd + get_ppid_of + ' + $GNULIB_TOOL --lib=libgnu --source-base=lib --m4-base=gnulib-m4 --tests-base=tests \ + --with-tests --makefile-name=gnulib.mk --tests-makefile-name=Makefile.am --automake-subdir \ + --import $GNULIB_MODULES + $GNULIB_TOOL --copy-file build-aux/ar-lib; chmod a+x build-aux/ar-lib + $GNULIB_TOOL --copy-file build-aux/config.guess; chmod a+x build-aux/config.guess + $GNULIB_TOOL --copy-file build-aux/config.sub; chmod a+x build-aux/config.sub + $GNULIB_TOOL --copy-file build-aux/run-test; chmod a+x build-aux/run-test + $GNULIB_TOOL --copy-file build-aux/test-driver.diff +fi + +aclocal -I m4 -I gnulib-m4 +autoconf +autoheader && touch config.h.in +automake -a -c +patch --quiet --forward --reject-file=/dev/null build-aux/test-driver < build-aux/test-driver.diff +rm -rf autom4te.cache diff --git a/examples/hello-c-gnulib-automakesubdir-withtests/configure.ac b/examples/hello-c-gnulib-automakesubdir-withtests/configure.ac new file mode 100644 index 0000000000..d215b18422 --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir-withtests/configure.ac @@ -0,0 +1,19 @@ +dnl This file is in the public domain. +dnl +dnl Configuration file - processed by autoconf. + +AC_INIT([hello-c], [0]) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_SRCDIR([src/hello.c]) +AM_INIT_AUTOMAKE + +AC_CONFIG_HEADERS([config.h]) + +AC_PROG_CC + +gl_EARLY +gl_INIT + +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([tests/Makefile]) +AC_OUTPUT diff --git a/examples/hello-c-gnulib-automakesubdir-withtests/m4/Makefile.am b/examples/hello-c-gnulib-automakesubdir-withtests/m4/Makefile.am new file mode 100644 index 0000000000..1b336ac1a8 --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir-withtests/m4/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = diff --git a/examples/hello-c-gnulib-automakesubdir-withtests/src/hello.c b/examples/hello-c-gnulib-automakesubdir-withtests/src/hello.c new file mode 100644 index 0000000000..239bca7347 --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir-withtests/src/hello.c @@ -0,0 +1,26 @@ +/* This file is in the public domain. + + Source code of the C program. */ + + +/* Every source file that uses Gnulib needs this. */ +#include + +/* Get printf() declaration. */ +#include + +/* Get getpid() declaration. */ +#include + +/* Include Gnulib header files. */ +#include "get_ppid_of.h" + +int +main () +{ + printf ("%s\n", "Hello, world!"); + printf ("This program is running as process number %d.\n", getpid ()); + printf ("The parent process number is %d.\n", get_ppid_of (getpid ())); + + return 0; +} diff --git a/examples/hello-c-gnulib-automakesubdir-withtests/src/local.mk b/examples/hello-c-gnulib-automakesubdir-withtests/src/local.mk new file mode 100644 index 0000000000..69226118b3 --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir-withtests/src/local.mk @@ -0,0 +1,7 @@ + +# The list of programs that are built. +bin_PROGRAMS = src/hello + +# The source files of the 'hello' program. +src_hello_SOURCES = src/hello.c +src_hello_LDADD = lib/libgnu.a diff --git a/examples/hello-c-gnulib-automakesubdir/INSTALL b/examples/hello-c-gnulib-automakesubdir/INSTALL new file mode 100644 index 0000000000..062762be0f --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir/INSTALL @@ -0,0 +1,8 @@ +Installation: + ./autogen.sh + ./configure --prefix=/some/prefix + make + make install +Cleanup: + make distclean + ./autoclean.sh diff --git a/examples/hello-c-gnulib-automakesubdir/Makefile.am b/examples/hello-c-gnulib-automakesubdir/Makefile.am new file mode 100644 index 0000000000..d239c3c68f --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir/Makefile.am @@ -0,0 +1,28 @@ +# This file is in the public domain. +# +# Makefile configuration - processed by automake. + +# General automake options. +AUTOMAKE_OPTIONS = foreign no-dependencies subdir-objects +ACLOCAL_AMFLAGS = -I m4 -I gnulib-m4 + +# The list of subdirectories containing Makefiles. +SUBDIRS = + +AM_CPPFLAGS = -Ilib -I$(srcdir)/lib + +# Additional files to be distributed. +EXTRA_DIST = autogen.sh autoclean.sh gnulib-m4/gnulib-cache.m4 + +BUILT_SOURCES = +SUFFIXES = +MOSTLYCLEANFILES = +MOSTLYCLEANDIRS = +CLEANFILES = +DISTCLEANFILES = +MAINTAINERCLEANFILES = + +noinst_LIBRARIES = + +include lib/gnulib.mk +include src/local.mk diff --git a/examples/hello-c-gnulib-automakesubdir/autoclean.sh b/examples/hello-c-gnulib-automakesubdir/autoclean.sh new file mode 100755 index 0000000000..a767a3fb12 --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir/autoclean.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for cleaning all autogenerated files. + +test ! -f Makefile || make distclean + +# Generated by aclocal. +rm -f aclocal.m4 + +# Generated by autoconf. +rm -f configure + +# Generated by autoheader. +rm -f config.h.in + +# Generated or brought in by automake. +rm -f Makefile.in +rm -f m4/Makefile.in +rm -f build-aux/compile +rm -f build-aux/depcomp +rm -f build-aux/install-sh +rm -f build-aux/missing +rm -f build-aux/config.guess +rm -f build-aux/config.sub + +# Generated or brought in by gnulib-tool. +rm -rf lib gnulib-m4 +rm -f build-aux/ar-lib diff --git a/examples/hello-c-gnulib-automakesubdir/autogen.sh b/examples/hello-c-gnulib-automakesubdir/autogen.sh new file mode 100755 index 0000000000..da650a324b --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir/autogen.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for regenerating all autogenerated files. + +# Usage: ./autogen.sh [--skip-gnulib] + +skip_gnulib=false +while :; do + case "$1" in + --skip-gnulib) skip_gnulib=true; shift;; + *) break ;; + esac +done + +if test $skip_gnulib = false; then + if test -n "$GNULIB_SRCDIR"; then + test -d "$GNULIB_SRCDIR" || { + echo "*** GNULIB_SRCDIR is set but does not point to an existing directory." 1>&2 + exit 1 + } + fi + # Now it should contain a gnulib-tool. + GNULIB_TOOL="$GNULIB_SRCDIR/gnulib-tool" + test -f "$GNULIB_TOOL" || { + echo "*** gnulib-tool not found." 1>&2 + exit 1 + } + GNULIB_MODULES=' + alloca + unistd + get_ppid_of + ' + $GNULIB_TOOL --lib=libgnu --source-base=lib --m4-base=gnulib-m4 \ + --makefile-name=gnulib.mk --automake-subdir \ + --import $GNULIB_MODULES + $GNULIB_TOOL --copy-file build-aux/ar-lib; chmod a+x build-aux/ar-lib + $GNULIB_TOOL --copy-file build-aux/config.guess; chmod a+x build-aux/config.guess + $GNULIB_TOOL --copy-file build-aux/config.sub; chmod a+x build-aux/config.sub +fi + +aclocal -I m4 -I gnulib-m4 +autoconf +autoheader && touch config.h.in +automake -a -c +rm -rf autom4te.cache diff --git a/examples/hello-c-gnulib-automakesubdir/configure.ac b/examples/hello-c-gnulib-automakesubdir/configure.ac new file mode 100644 index 0000000000..d30a9ec1dc --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir/configure.ac @@ -0,0 +1,18 @@ +dnl This file is in the public domain. +dnl +dnl Configuration file - processed by autoconf. + +AC_INIT([hello-c], [0]) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_SRCDIR([src/hello.c]) +AM_INIT_AUTOMAKE + +AC_CONFIG_HEADERS([config.h]) + +AC_PROG_CC + +gl_EARLY +gl_INIT + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/examples/hello-c-gnulib-automakesubdir/m4/Makefile.am b/examples/hello-c-gnulib-automakesubdir/m4/Makefile.am new file mode 100644 index 0000000000..1b336ac1a8 --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir/m4/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = diff --git a/examples/hello-c-gnulib-automakesubdir/src/hello.c b/examples/hello-c-gnulib-automakesubdir/src/hello.c new file mode 100644 index 0000000000..239bca7347 --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir/src/hello.c @@ -0,0 +1,26 @@ +/* This file is in the public domain. + + Source code of the C program. */ + + +/* Every source file that uses Gnulib needs this. */ +#include + +/* Get printf() declaration. */ +#include + +/* Get getpid() declaration. */ +#include + +/* Include Gnulib header files. */ +#include "get_ppid_of.h" + +int +main () +{ + printf ("%s\n", "Hello, world!"); + printf ("This program is running as process number %d.\n", getpid ()); + printf ("The parent process number is %d.\n", get_ppid_of (getpid ())); + + return 0; +} diff --git a/examples/hello-c-gnulib-automakesubdir/src/local.mk b/examples/hello-c-gnulib-automakesubdir/src/local.mk new file mode 100644 index 0000000000..69226118b3 --- /dev/null +++ b/examples/hello-c-gnulib-automakesubdir/src/local.mk @@ -0,0 +1,7 @@ + +# The list of programs that are built. +bin_PROGRAMS = src/hello + +# The source files of the 'hello' program. +src_hello_SOURCES = src/hello.c +src_hello_LDADD = lib/libgnu.a diff --git a/examples/hello-c-gnulib-nonrecursive/INSTALL b/examples/hello-c-gnulib-nonrecursive/INSTALL new file mode 100644 index 0000000000..062762be0f --- /dev/null +++ b/examples/hello-c-gnulib-nonrecursive/INSTALL @@ -0,0 +1,8 @@ +Installation: + ./autogen.sh + ./configure --prefix=/some/prefix + make + make install +Cleanup: + make distclean + ./autoclean.sh diff --git a/examples/hello-c-gnulib-nonrecursive/Makefile.am b/examples/hello-c-gnulib-nonrecursive/Makefile.am new file mode 100644 index 0000000000..d239c3c68f --- /dev/null +++ b/examples/hello-c-gnulib-nonrecursive/Makefile.am @@ -0,0 +1,28 @@ +# This file is in the public domain. +# +# Makefile configuration - processed by automake. + +# General automake options. +AUTOMAKE_OPTIONS = foreign no-dependencies subdir-objects +ACLOCAL_AMFLAGS = -I m4 -I gnulib-m4 + +# The list of subdirectories containing Makefiles. +SUBDIRS = + +AM_CPPFLAGS = -Ilib -I$(srcdir)/lib + +# Additional files to be distributed. +EXTRA_DIST = autogen.sh autoclean.sh gnulib-m4/gnulib-cache.m4 + +BUILT_SOURCES = +SUFFIXES = +MOSTLYCLEANFILES = +MOSTLYCLEANDIRS = +CLEANFILES = +DISTCLEANFILES = +MAINTAINERCLEANFILES = + +noinst_LIBRARIES = + +include lib/gnulib.mk +include src/local.mk diff --git a/examples/hello-c-gnulib-nonrecursive/autoclean.sh b/examples/hello-c-gnulib-nonrecursive/autoclean.sh new file mode 100755 index 0000000000..bb8789d972 --- /dev/null +++ b/examples/hello-c-gnulib-nonrecursive/autoclean.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for cleaning all autogenerated files. + +test ! -f Makefile || make distclean + +# Generated by aclocal. +rm -f aclocal.m4 + +# Generated by autoconf. +rm -f configure + +# Generated by autoheader. +rm -f config.h.in + +# Generated or brought in by automake. +rm -f Makefile.in +rm -f m4/Makefile.in +rm -f build-aux/compile +rm -f build-aux/depcomp +rm -f build-aux/install-sh +rm -f build-aux/missing +rm -f build-aux/config.guess +rm -f build-aux/config.sub + +# Generated or brought in by gnulib-tool. +rm -rf lib gnulib-m4 +rm -f build-aux/ar-lib +rm -f build-aux/prefix-gnulib-mk diff --git a/examples/hello-c-gnulib-nonrecursive/autogen.sh b/examples/hello-c-gnulib-nonrecursive/autogen.sh new file mode 100755 index 0000000000..eb97f95975 --- /dev/null +++ b/examples/hello-c-gnulib-nonrecursive/autogen.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for regenerating all autogenerated files. + +# Usage: ./autogen.sh [--skip-gnulib] + +skip_gnulib=false +while :; do + case "$1" in + --skip-gnulib) skip_gnulib=true; shift;; + *) break ;; + esac +done + +if test $skip_gnulib = false; then + if test -n "$GNULIB_SRCDIR"; then + test -d "$GNULIB_SRCDIR" || { + echo "*** GNULIB_SRCDIR is set but does not point to an existing directory." 1>&2 + exit 1 + } + fi + # Now it should contain a gnulib-tool. + GNULIB_TOOL="$GNULIB_SRCDIR/gnulib-tool" + test -f "$GNULIB_TOOL" || { + echo "*** gnulib-tool not found." 1>&2 + exit 1 + } + GNULIB_MODULES=' + alloca + unistd + get_ppid_of + non-recursive-gnulib-prefix-hack + ' + $GNULIB_TOOL --lib=libgnu --source-base=lib --m4-base=gnulib-m4 \ + --makefile-name=gnulib.mk \ + --import $GNULIB_MODULES + build-aux/prefix-gnulib-mk --lib-name=libgnu lib/gnulib.mk + $GNULIB_TOOL --copy-file build-aux/ar-lib; chmod a+x build-aux/ar-lib + $GNULIB_TOOL --copy-file build-aux/config.guess; chmod a+x build-aux/config.guess + $GNULIB_TOOL --copy-file build-aux/config.sub; chmod a+x build-aux/config.sub +fi + +aclocal -I m4 -I gnulib-m4 +autoconf +autoheader && touch config.h.in +automake -a -c +rm -rf autom4te.cache diff --git a/examples/hello-c-gnulib-nonrecursive/configure.ac b/examples/hello-c-gnulib-nonrecursive/configure.ac new file mode 100644 index 0000000000..d30a9ec1dc --- /dev/null +++ b/examples/hello-c-gnulib-nonrecursive/configure.ac @@ -0,0 +1,18 @@ +dnl This file is in the public domain. +dnl +dnl Configuration file - processed by autoconf. + +AC_INIT([hello-c], [0]) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_SRCDIR([src/hello.c]) +AM_INIT_AUTOMAKE + +AC_CONFIG_HEADERS([config.h]) + +AC_PROG_CC + +gl_EARLY +gl_INIT + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/examples/hello-c-gnulib-nonrecursive/m4/Makefile.am b/examples/hello-c-gnulib-nonrecursive/m4/Makefile.am new file mode 100644 index 0000000000..1b336ac1a8 --- /dev/null +++ b/examples/hello-c-gnulib-nonrecursive/m4/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = diff --git a/examples/hello-c-gnulib-nonrecursive/src/hello.c b/examples/hello-c-gnulib-nonrecursive/src/hello.c new file mode 100644 index 0000000000..239bca7347 --- /dev/null +++ b/examples/hello-c-gnulib-nonrecursive/src/hello.c @@ -0,0 +1,26 @@ +/* This file is in the public domain. + + Source code of the C program. */ + + +/* Every source file that uses Gnulib needs this. */ +#include + +/* Get printf() declaration. */ +#include + +/* Get getpid() declaration. */ +#include + +/* Include Gnulib header files. */ +#include "get_ppid_of.h" + +int +main () +{ + printf ("%s\n", "Hello, world!"); + printf ("This program is running as process number %d.\n", getpid ()); + printf ("The parent process number is %d.\n", get_ppid_of (getpid ())); + + return 0; +} diff --git a/examples/hello-c-gnulib-nonrecursive/src/local.mk b/examples/hello-c-gnulib-nonrecursive/src/local.mk new file mode 100644 index 0000000000..69226118b3 --- /dev/null +++ b/examples/hello-c-gnulib-nonrecursive/src/local.mk @@ -0,0 +1,7 @@ + +# The list of programs that are built. +bin_PROGRAMS = src/hello + +# The source files of the 'hello' program. +src_hello_SOURCES = src/hello.c +src_hello_LDADD = lib/libgnu.a diff --git a/examples/hello-c-gnulib/INSTALL b/examples/hello-c-gnulib/INSTALL new file mode 100644 index 0000000000..062762be0f --- /dev/null +++ b/examples/hello-c-gnulib/INSTALL @@ -0,0 +1,8 @@ +Installation: + ./autogen.sh + ./configure --prefix=/some/prefix + make + make install +Cleanup: + make distclean + ./autoclean.sh diff --git a/examples/hello-c-gnulib/Makefile.am b/examples/hello-c-gnulib/Makefile.am new file mode 100644 index 0000000000..367e8198db --- /dev/null +++ b/examples/hello-c-gnulib/Makefile.am @@ -0,0 +1,22 @@ +# This file is in the public domain. +# +# Makefile configuration - processed by automake. + +# General automake options. +AUTOMAKE_OPTIONS = foreign no-dependencies +ACLOCAL_AMFLAGS = -I m4 -I gnulib-m4 + +# The list of subdirectories containing Makefiles. +SUBDIRS = m4 lib tests + +AM_CPPFLAGS = -Ilib -I$(srcdir)/lib + +# The list of programs that are built. +bin_PROGRAMS = hello + +# The source files of the 'hello' program. +hello_SOURCES = hello.c +hello_LDADD = lib/libgnu.a + +# Additional files to be distributed. +EXTRA_DIST = autogen.sh autoclean.sh gnulib-m4/gnulib-cache.m4 diff --git a/examples/hello-c-gnulib/autoclean.sh b/examples/hello-c-gnulib/autoclean.sh new file mode 100755 index 0000000000..9fd8d95346 --- /dev/null +++ b/examples/hello-c-gnulib/autoclean.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for cleaning all autogenerated files. + +test ! -f Makefile || make distclean + +# Generated by aclocal. +rm -f aclocal.m4 + +# Generated by autoconf. +rm -f configure + +# Generated by autoheader. +rm -f config.h.in + +# Generated or brought in by automake. +rm -f Makefile.in +rm -f m4/Makefile.in +rm -f build-aux/compile +rm -f build-aux/depcomp +rm -f build-aux/install-sh +rm -f build-aux/missing +rm -f build-aux/config.guess +rm -f build-aux/config.sub + +# Generated or brought in by gnulib-tool. +rm -rf lib gnulib-m4 tests +rm -f build-aux/ar-lib +rm -f build-aux/run-test +rm -f build-aux/test-driver.diff + +# Generated by autogen.sh. +rm -f build-aux/test-driver diff --git a/examples/hello-c-gnulib/autogen.sh b/examples/hello-c-gnulib/autogen.sh new file mode 100755 index 0000000000..10702d735b --- /dev/null +++ b/examples/hello-c-gnulib/autogen.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for regenerating all autogenerated files. + +# Usage: ./autogen.sh [--skip-gnulib] + +skip_gnulib=false +while :; do + case "$1" in + --skip-gnulib) skip_gnulib=true; shift;; + *) break ;; + esac +done + +if test $skip_gnulib = false; then + if test -n "$GNULIB_SRCDIR"; then + test -d "$GNULIB_SRCDIR" || { + echo "*** GNULIB_SRCDIR is set but does not point to an existing directory." 1>&2 + exit 1 + } + fi + # Now it should contain a gnulib-tool. + GNULIB_TOOL="$GNULIB_SRCDIR/gnulib-tool" + test -f "$GNULIB_TOOL" || { + echo "*** gnulib-tool not found." 1>&2 + exit 1 + } + GNULIB_MODULES=' + unistd + get_ppid_of + ' + $GNULIB_TOOL --lib=libgnu --source-base=lib --m4-base=gnulib-m4 --tests-base=tests \ + --with-tests \ + --import $GNULIB_MODULES + mkdir -p build-aux + $GNULIB_TOOL --copy-file build-aux/ar-lib; chmod a+x build-aux/ar-lib + $GNULIB_TOOL --copy-file build-aux/config.guess; chmod a+x build-aux/config.guess + $GNULIB_TOOL --copy-file build-aux/config.sub; chmod a+x build-aux/config.sub + $GNULIB_TOOL --copy-file build-aux/run-test; chmod a+x build-aux/run-test + $GNULIB_TOOL --copy-file build-aux/test-driver.diff +fi + +aclocal -I m4 -I gnulib-m4 +autoconf +autoheader && touch config.h.in +automake -a -c +patch --quiet --forward --reject-file=/dev/null build-aux/test-driver < build-aux/test-driver.diff +rm -rf autom4te.cache diff --git a/examples/hello-c-gnulib/configure.ac b/examples/hello-c-gnulib/configure.ac new file mode 100644 index 0000000000..b7bd80fbf8 --- /dev/null +++ b/examples/hello-c-gnulib/configure.ac @@ -0,0 +1,21 @@ +dnl This file is in the public domain. +dnl +dnl Configuration file - processed by autoconf. + +AC_INIT([hello-c], [0]) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_SRCDIR([hello.c]) +AM_INIT_AUTOMAKE + +AC_CONFIG_HEADERS([config.h]) + +AC_PROG_CC + +gl_EARLY +gl_INIT + +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([m4/Makefile]) +AC_CONFIG_FILES([lib/Makefile]) +AC_CONFIG_FILES([tests/Makefile]) +AC_OUTPUT diff --git a/examples/hello-c-gnulib/hello.c b/examples/hello-c-gnulib/hello.c new file mode 100644 index 0000000000..239bca7347 --- /dev/null +++ b/examples/hello-c-gnulib/hello.c @@ -0,0 +1,26 @@ +/* This file is in the public domain. + + Source code of the C program. */ + + +/* Every source file that uses Gnulib needs this. */ +#include + +/* Get printf() declaration. */ +#include + +/* Get getpid() declaration. */ +#include + +/* Include Gnulib header files. */ +#include "get_ppid_of.h" + +int +main () +{ + printf ("%s\n", "Hello, world!"); + printf ("This program is running as process number %d.\n", getpid ()); + printf ("The parent process number is %d.\n", get_ppid_of (getpid ())); + + return 0; +} diff --git a/examples/hello-c-gnulib/m4/Makefile.am b/examples/hello-c-gnulib/m4/Makefile.am new file mode 100644 index 0000000000..1b336ac1a8 --- /dev/null +++ b/examples/hello-c-gnulib/m4/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = diff --git a/examples/hello-c-nognulib/INSTALL b/examples/hello-c-nognulib/INSTALL new file mode 100644 index 0000000000..062762be0f --- /dev/null +++ b/examples/hello-c-nognulib/INSTALL @@ -0,0 +1,8 @@ +Installation: + ./autogen.sh + ./configure --prefix=/some/prefix + make + make install +Cleanup: + make distclean + ./autoclean.sh diff --git a/examples/hello-c-nognulib/Makefile.am b/examples/hello-c-nognulib/Makefile.am new file mode 100644 index 0000000000..0c4300a9c9 --- /dev/null +++ b/examples/hello-c-nognulib/Makefile.am @@ -0,0 +1,19 @@ +# This file is in the public domain. +# +# Makefile configuration - processed by automake. + +# General automake options. +AUTOMAKE_OPTIONS = foreign no-dependencies +ACLOCAL_AMFLAGS = -I m4 + +# The list of subdirectories containing Makefiles. +SUBDIRS = m4 + +# The list of programs that are built. +bin_PROGRAMS = hello + +# The source files of the 'hello' program. +hello_SOURCES = hello.c + +# Additional files to be distributed. +EXTRA_DIST = autogen.sh autoclean.sh diff --git a/examples/hello-c-nognulib/autoclean.sh b/examples/hello-c-nognulib/autoclean.sh new file mode 100755 index 0000000000..8de4aa5c3f --- /dev/null +++ b/examples/hello-c-nognulib/autoclean.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for cleaning all autogenerated files. + +test ! -f Makefile || make distclean + +# Generated by aclocal. +rm -f aclocal.m4 + +# Generated by autoconf. +rm -f configure + +# Generated or brought in by automake. +rm -f Makefile.in +rm -f m4/Makefile.in +rm -f build-aux/compile +rm -f build-aux/install-sh +rm -f build-aux/missing +rm -f build-aux/config.guess +rm -f build-aux/config.sub diff --git a/examples/hello-c-nognulib/autogen.sh b/examples/hello-c-nognulib/autogen.sh new file mode 100755 index 0000000000..a20bbb9a75 --- /dev/null +++ b/examples/hello-c-nognulib/autogen.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# This file is in the public domain. +# +# Script for regenerating all autogenerated files. + +aclocal -I m4 +autoconf +automake -a -c +rm -rf autom4te.cache diff --git a/examples/hello-c-nognulib/configure.ac b/examples/hello-c-nognulib/configure.ac new file mode 100644 index 0000000000..fbb158a8cd --- /dev/null +++ b/examples/hello-c-nognulib/configure.ac @@ -0,0 +1,15 @@ +dnl This file is in the public domain. +dnl +dnl Configuration file - processed by autoconf. + +AC_INIT([hello-c], [0]) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_SRCDIR([hello.c]) +AM_INIT_AUTOMAKE + +AC_PROG_CC +AC_CHECK_HEADERS([unistd.h]) + +AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([m4/Makefile]) +AC_OUTPUT diff --git a/examples/hello-c-nognulib/hello.c b/examples/hello-c-nognulib/hello.c new file mode 100644 index 0000000000..d1c79ae328 --- /dev/null +++ b/examples/hello-c-nognulib/hello.c @@ -0,0 +1,22 @@ +/* This file is in the public domain. + + Source code of the C program. */ + + +/* Get printf() declaration. */ +#include + +/* Get getpid() declaration. */ +#if HAVE_UNISTD_H +# include +#endif + +int +main () +{ + printf ("%s\n", "Hello, world!"); + printf ("This program is running as process number %d.", getpid ()); + putchar ('\n'); + + return 0; +} diff --git a/examples/hello-c-nognulib/m4/Makefile.am b/examples/hello-c-nognulib/m4/Makefile.am new file mode 100644 index 0000000000..1b336ac1a8 --- /dev/null +++ b/examples/hello-c-nognulib/m4/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = -- 2.39.5