From cf53aa93026690d779dad1c9ff7e48e60274acba Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Sat, 3 May 2014 13:42:55 +0300 Subject: [PATCH] mk: refresh libusual2.temo --- mk/temos/Makefile | 4 +- mk/temos/expected/libusual2.txt | 103 ++++++++++++++++++++++++++++++++ mk/temos/src/libusual2.temo | 54 +---------------- 3 files changed, 108 insertions(+), 53 deletions(-) create mode 100644 mk/temos/expected/libusual2.txt diff --git a/mk/temos/Makefile b/mk/temos/Makefile index 60b0d4c..46c6db7 100644 --- a/mk/temos/Makefile +++ b/mk/temos/Makefile @@ -5,7 +5,7 @@ TEMOS = \ antimake1 antimake2 antimake3 antimake4 antimake5 antimake6 \ - libusual1 libusual3 libusual4 libusual5 libusual6 \ + libusual1 libusual2 libusual3 libusual4 libusual5 libusual6 \ @@ -49,7 +49,7 @@ qtest: $(OUT) output/%.txt: src/%.temo libtemo.sh @mkdir -p output @printf "$< ... " - @bash $< > $@ && { cmp -s $@ $(call ExpFile,$<) && echo ok || echo failed; } \ + @bash $< > $@ 2>&1 && { cmp -s $@ $(call ExpFile,$<) && echo ok || echo failed; } \ || { echo "$< failed:" ; tail $(call OutFile,$<); exit 1; } html/%.html: output/%.txt diff --git a/mk/temos/expected/libusual2.txt b/mk/temos/expected/libusual2.txt new file mode 100644 index 0000000..a39b430 --- /dev/null +++ b/mk/temos/expected/libusual2.txt @@ -0,0 +1,103 @@ + += Embedding libusual as part of the source. = + + +Here we build libusual as part of top-level tree. +This gives the advantage of building only the modules +that are actually used in main tree and without the +intermediate `libusual.a` step. + +This method is for projects that are developed +in parallel with libusual. Not recommended for +casual usage. + + +== Configure libusual == + + +Here we configure libusual, but do not build it. + +--------------------------------- +$ git clone git://github.com/libusual/libusual.git lib +Cloning into 'lib'... +done. +$ cd lib +$ ./autogen.sh +[...] +$ ./configure +[...] +$ cd .. +--------------------------------- + +== Prepare own code == + + +Here is the source that needs to be linked with libusual: + +.File: prog.c +[source,c] +----------------------------------- +#include +#include +#include + +int main(void) +{ + const char *data = "CECSFXX"; + uint32_t crc; + + crc = calc_crc32(data, strlen(data), 0); + printf("crc: %08x\n", crc); + return 0; +} +----------------------------------- + +== Build with Antimake. == + + +Antimake is build framework on plain GNU Make that reads +build instructons with Automake syntax. It has also hooks +for libusual integration. + +Here is Makefile that uses Antimake: + +.File: Makefile +[source,makefile] +----------------------------------- +# 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 + +# Load Antimake plugin that handles libusual embedding +AM_FEATURES = libusual + +# launch Antimake +include $(USUAL_DIR)/mk/antimake.mk +----------------------------------- + +Build the project + +--------------------------------- +$ make + CC prog.c + CC lib/usual/hashing/crc32.c + CC lib/usual/base.c + CCLD prog +$ ls +Makefile lib prog prog.c +$ ./prog +crc: 12345678 +$ make clean + CLEAN prog +$ ls +Makefile lib prog.c +--------------------------------- + +Done + diff --git a/mk/temos/src/libusual2.temo b/mk/temos/src/libusual2.temo index e7b91ba..c399f7a 100644 --- a/mk/temos/src/libusual2.temo +++ b/mk/temos/src/libusual2.temo @@ -49,57 +49,7 @@ cat_file prog.c <<"EOF" } EOF -title2 Old way, with plain Make - -msg Here is corresponding Makefile: - -cat_file Makefile <<"EOF" - CC = gcc - CFLAGS = -O -g -Wall - - # here we describe our program - SRCS = prog.c - OBJS = $(SRCS:.c=.o) - - # here we link to libusual - USUAL_DIR = ./lib - USUAL_LOCAL_SRCS = $(SRCS) - CPPFLAGS = $(USUAL_CPPFLAGS) - OBJS += $(USUAL_OBJS) - - # this looks what modules are used by files in USUAL_LOCAL_SRCS - # and fills the USUAL_OBJS variable based on that - include $(USUAL_DIR)/Setup.mk - - all: prog - - prog: $(OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o $@ - - %.o: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - - # special rule to build - %.o: $(USUAL_DIR)/usual/%.c - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - - clean: - rm -f *.o prog -EOF - -msg Build the project -run make -run ls -run ./prog -run make clean -run ls - -longmsg <<-"MSG" - It's quite complex and that is even without trying to get - dependencies rigth. See next section for preferred way. -MSG - -title2 New way, with Antimake. +title2 Build with Antimake. longmsg <<-"MSG" Antimake is build framework on plain GNU Make that reads @@ -119,6 +69,8 @@ cat_file Makefile <<"EOF" # mention that 'prog' wants embedded libusual prog_EMBED_LIBUSUAL = 1 + + # Load Antimake plugin that handles libusual embedding AM_FEATURES = libusual # launch Antimake -- 2.39.5