check_DATA = atlocal
CLEANFILES += atlocal
+# Note: to reliably test linking against the installed library we directly
+# refer to the just-installed .la file, rather than more typical library flags
+# (-Lfoo -lfoo). Otherwise libtool can pick up libcdecl.la from the current
+# working directory which defeats the point of an install check.
+EXTRA_PROGRAMS = t/installcheck
+t_installcheck_CPPFLAGS = -I$(DESTDIR)$(includedir)
+t_installcheck_LDADD = $(DESTDIR)$(libdir)/libcdecl.la
+t_installcheck_CFLAGS =
+t_installcheck_SHORTNAME = x
+
+installcheck-local:
+ rm -f t/installcheck$(EXEEXT)
+ $(MAKE) $(AM_MAKEFLAGS) t/installcheck$(EXEEXT)
+ t/installcheck$(EXEEXT) | diff - $(srcdir)/t/installcheck.exp
+.PHONY: installcheck-local
+EXTRA_DIST += t/installcheck.c t/installcheck.exp
+CLEANFILES += t/installcheck$(EXEEXT)
+
include $(top_srcdir)/lib/gnulib.mk
include $(top_srcdir)/common/snippet/glconfig.mk
include $(top_srcdir)/common/snippet/autotest.mk
--- /dev/null
+/*
+ * Post-installation sanity check for libcdecl.
+ *
+ * Copyright © 2023 Nick Bowler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <cdecl.h>
+
+int main(void)
+{
+ extern int puts(const char *);
+
+ struct cdecl_declarator decl_array, decl_null = {0};
+ struct cdecl_declspec spec = {0, CDECL_TYPE_INT};
+ struct cdecl decl = {0, &spec, &decl_array};
+ char buf[100];
+
+ decl_array.child = &decl_null;
+ decl_array.type = CDECL_DECL_ARRAY;
+ decl_array.u.array.length = 1234567890;
+ decl_array.u.array.vla = NULL;
+
+ cdecl_explain(buf, sizeof buf, &decl);
+ puts(buf);
+}