Reorganize some of the more random files.
[sod] / lib / sod.m4
diff --git a/lib/sod.m4 b/lib/sod.m4
new file mode 100644 (file)
index 0000000..c90b7a3
--- /dev/null
@@ -0,0 +1,55 @@
+dnl -*-autoconf-*-
+dnl
+dnl Autoconf machinery for packages using Sod
+dnl
+dnl (c) 2019 Straylight/Edgeware
+dnl
+
+dnl ----- Licensing notice --------------------------------------------------
+dnl
+dnl This file is part of the Sensible Object Design, an object system for C.
+dnl
+dnl SOD is free software: you can redistribute it and/or modify it under
+dnl the terms of the GNU General Public License as published by the Free
+dnl Software Foundation; either version 2 of the License, or (at your
+dnl option) any later version.
+dnl
+dnl SOD is distributed in the hope that it will be useful, but WITHOUT ANY
+dnl WARRANTY; without even the implied warranty of MERCHANTABILITY or
+dnl FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with SOD.  If not, write to the Free Software Foundation, Inc.,
+dnl 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#serial 1
+
+### SOD_CHECK([ACTION-IF-LIBRARY-FOUND], [ACTION-IF-LIBRARY-NOT-FOUND])
+###
+### Check that (a) the sod(1) translator and (b) the `libsod' library are
+### available.
+###
+### If sod(1) can't be found, this isn't a problem: we assume that the
+### generated output files are included in the distribution, and use a fake
+### definition which will report an error if the files need rebuilding, as a
+### poor person's version of the `missing' script.
+###
+### If the library can't be found, we have a more serious problem.  The
+### default behaviour is to (let `PKG_CHECK_MODULES') report a fatal error,
+### but packages can override this behaviour by setting ACTION-IF-LIBRARY-
+### NOT-FOUND to something non-empty.  If the library /is/ found then do
+### ACTION-IF-LIBRARY-FOUND; the default is to add the necessary compiler
+### flags to `AM_CFLAGS'.  (You are expected to make your own arrangements to
+### link against `$SOD_LIBS'.)
+AC_DEFUN([SOD_CHECK],
+  [AC_CHECK_PROGS([SOD], [sod], [none])
+   if test "$SOD" = "none"; then
+     AC_MSG_WARN([Sod translator not found: relying on distributed output files!])
+     SOD="echo >&2 \"Sod translator not found!  Can't rebuild \\\`\$[]@'.\" && exit 2; \\#"
+   fi
+   PKG_CHECK_MODULES([SOD], [sod],
+     [m4_default([$1], [AM_CFLAGS="$AM_CFLAGS $SOD_CFLAGS"])],
+     [$2])])
+
+dnl ----- That's all, folks -------------------------------------------------