Install libusual and link against it.
Build libusual
$ git clone git://github.com/libusual/libusual.git libusual Cloning into 'libusual'... done. $ cd libusual $ ./autogen.sh [...] $ ./configure --disable-shared --prefix=`pwd`/../inst [...] $ make [...] $ make install [...] $ cd ..
Build our own code
Now we prepare our own code.
First, this is the source file:
File: prog.c
#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; }
Autoconf setup
File: autogen.sh
# use prepared autgen logic ../../std-autogen.sh ../../.. # fetch Antimake template from libusual cp ../../antimake.mk antimake.mk.in
File: extra.mk.in
USUAL_ANTIMAKE = @USUAL_ANTIMAKE@ USUAL_CFLAGS = @USUAL_CFLAGS@ USUAL_LIBS = @USUAL_LIBS@
File: configure.ac
AC_INIT([achello], [0.1], [https://libusual.github.com]) AC_CONFIG_HEADER([config.h]) AC_CONFIG_SRCDIR([prog.c]) AC_PREREQ([2.59]) AC_USUAL_INIT AC_USUAL_PROGRAM_CHECK PKG_CHECK_MODULES(USUAL, libusual) _PKG_CONFIG([USUAL_ANTIMAKE], [variable=antimake], [libusual]) AC_SUBST([USUAL_ANTIMAKE]) AC_OUTPUT([antimake.mk extra.mk])
Here is the source that needs to be linked with libusual:
File: prog.c
#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; }
Antimake based Makefile
File: Makefile
# the automake-style build description for 'prog' noinst_PROGRAMS = prog prog_SOURCES = prog.c prog_CPPFLAGS = $(USUAL_CFLAGS) prog_LDADD = $(USUAL_LIBS) # clean configured files DISTCLEANFILES = config.status config.log extra.mk antimake.mk config.h # clean generated files MAINTAINERCLEANFILES = configure config.guess config.sub install-sh \ antimake.mk.in extra.mk.in config.h.in EXTRA_DIST = Makefile $(MAINTAINERCLEANFILES) # launch Antimake include extra.mk include antimake.mk
Build the project
$ sh ./autogen.sh $ PKG_CONFIG_PATH=`pwd`/inst/lib/pkgconfig ./configure [...] $ make CC prog.c CCLD prog $ ls Makefile config.guess config.status extra.mk libusual antimake.mk config.h config.sub extra.mk.in prog antimake.mk.in config.h.in configure inst prog.c autogen.sh config.log configure.ac install-sh $ ./prog crc: 12345678 $ make am-show-distfiles Makefile antimake.mk.in config.guess config.h.in config.sub configure extra.mk.in install-sh prog.c $ make maintainer-clean CLEAN prog MAINTAINERCLEAN maintainer-clean $ ls Makefile autogen.sh configure.ac inst libusual prog.c
Done!