
. ./libtemo.sh || exit 1

test_start

title Use installed libusual with antimake.

longmsg <<-MSG
	Install libusual and link against it.
MSG

title2 Build libusual

usual_clone libusual

run cd libusual

runq ./autogen.sh
runq './configure --disable-shared --prefix=`pwd`/../inst'
runq make
runq make install
run cd ..

title2 Build our own code

msg Now we prepare our own code.

msg First, this is the source file:
cat_file prog.c <<"EOF"
	#include <stdio.h>
	#include <string.h>
	#include <usual/hashing/crc32.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 Here is corresponding Makefile:
cat_file Makefile <<"EOF"
	# temo hacks to support local install, not needed otherwise
	PKG_CONFIG = PKG_CONFIG_PATH=$(CURDIR)/inst/lib/pkgconfig pkg-config

	# use pkg-config to get libusual info
	USUAL_CPPFLAGS = $(shell $(PKG_CONFIG) libusual --cflags)
	USUAL_LDFLAGS = $(shell $(PKG_CONFIG) libusual --libs-only-L)
	USUAL_LIBS = $(shell $(PKG_CONFIG) libusual --libs-only-l)

	# Generic Antimake
	bin_PROGRAMS = prog
	prog_SOURCES = prog.c
	prog_CPPFLAGS = $(USUAL_CPPFLAGS)
	prog_LDFLAGS = $(USUAL_LDFLAGS)
	prog_LDADD = $(USUAL_LIBS)

	# use installed Antimake
	ANTIMAKE = $(shell $(PKG_CONFIG) libusual --variable=antimake)
	include $(ANTIMAKE)
EOF

msg Build the project

run make
run ls
run ./prog

msg Done!
