
. ./libtemo.sh || exit 1

test_start

title Using Autoconf and embedded libusual

longmsg <<-"MSG"
MSG

title2 Fetch libusual

msg Here we close libusual repo, but do not configure nor build it.

usual_clone lib

msg Autoconf setup

cat_file autogen.sh <<"EOF"
	# use prepared autgen logic
	./lib/mk/std-autogen.sh ./lib

	# fetch Antimake template from libusual
	cp lib/mk/antimake.mk antimake.mk.in
EOF

cat_file configure.ac <<"EOF"
	AC_INIT([achello], [0.1], [https://libusual.github.com])
	AC_CONFIG_SRCDIR([prog.c])
	AC_CONFIG_HEADER([lib/usual/config.h])
	AC_PREREQ([2.59])

	AC_USUAL_PORT_CHECK
	AC_USUAL_PROGRAM_CHECK
	AC_USUAL_HEADER_CHECK
	AC_USUAL_TYPE_CHECK
	AC_USUAL_FUNCTION_CHECK

	AC_OUTPUT([antimake.mk])
EOF

msg Here is the source that needs to be linked with libusual:

cat_file prog.c <<"EOF"
	#include <usual/hashing/crc32.h>
	#include <stdio.h>
	#include <string.h>

	int main(void)
	{
		const char *data = "CECSFXX";
		uint32_t crc;

		crc = calc_crc32(data, strlen(data), 0);
		printf("crc: %08x\n", crc);
		return 0;
	}
EOF

msg Antimake based Makefile

cat_file Makefile <<"EOF"
	# the automake-style build description for 'prog'
	noinst_PROGRAMS = prog
	prog_SOURCES = prog.c

	# location of configured libusual
	USUAL_DIR = lib

	# mention that 'prog' wants embedded libusual
	prog_EMBED_LIBUSUAL = 1
	AM_FEATURES = libusual

	# clean configured files
	DISTCLEANFILES = config.status config.log \
			antimake.mk $(USUAL_DIR)/usual/config.h

	# clean generated files
	MAINTAINERCLEANFILES = configure config.guess config.sub install-sh \
			antimake.mk.in $(USUAL_DIR)/usual/config.h.in

	# launch Antimake
	include $(USUAL_DIR)/mk/antimake.mk
EOF

msg Build the project
runq sh ./autogen.sh
runq ./configure
run make
run ls
run ./prog
run make maintainer-clean
run ls

msg Done
