From 7f43535628b782bd82c4fbdd1b8f23d7782b0337 Mon Sep 17 00:00:00 2001 From: Jens Thiele Date: Tue, 5 Dec 2006 16:22:55 +0000 Subject: [PATCH] added example using generated and installed example library --- example-codegen/README | 14 ++++++++++---- example-codegen/TODO | 16 +++++++++++++--- example-codegen/codegen.make | 9 ++++++--- example-libusage/Makefile.am | 10 ++++++++++ example-libusage/README | 1 + example-libusage/client.cpp | 30 ++++++++++++++++++++++++++++++ test-build-install-use | 20 ++++++++++++++++++-- 7 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 example-libusage/Makefile.am create mode 100644 example-libusage/README create mode 100644 example-libusage/client.cpp diff --git a/example-codegen/README b/example-codegen/README index 08ce9d1..2fe7e02 100644 --- a/example-codegen/README +++ b/example-codegen/README @@ -3,12 +3,18 @@ This example may be build during the build of libt2n or it may be build seperate installed version of libt2n. To build it seperately using a installed version of libt2n: -autoreconf -i && ./configure && make && make distcheck +autoreconf && ./configure && make && make distcheck -if it does not work try something like: +if it does not work you may have to move the example-codegen out of the libt2n directory and +pass some options to autoreconf +I use something like: tar xzvf libt2n-0.1.tar.gz mv libt2n-0.1/example-codegen . cd example-codegen -# get configure script created and missing autotools stuff -aclocal && automake -a && autoreconf -i +# get configure script created and missing autotools helper files installed +# if you installed libt2n in some non-standard directory you might have to pass +# -M pathtolibt2n.m4 +autoreconf -f -i ./configure && make && make distcheck + +tar xzvf libt2n-0.1.tar.gz && mv libt2n-0.1/example-codegen . && cd example-codegen && autoreconf -f -i -M /tmp/jens-delme/usr/share/aclocal && ./configure && dmake && dmake distcheck diff --git a/example-codegen/TODO b/example-codegen/TODO index 0b0a556..39fc78d 100644 --- a/example-codegen/TODO +++ b/example-codegen/TODO @@ -12,13 +12,23 @@ now we use the first solution - would be nice to reduce amount of changed files (codegen output is often the same as the existing files - something similar to ccache for codegen - but not overwriting output files if they are the same) -- howto include the part after "# always the same:" in all makefiles using the codegenerator +- howto include the part after "# always the same:" in all makefiles (using the codegenerator) (we now use make's include) - lib name should be group name + suffix/prefix -- at the moment make dist from within a clean source will not work - (this is related to the nodist problem / old automake version) - the example should not get installed (but still it should show how to build a lib that gets installed :-( (overwriting install: doesn't work) +- at the moment make dist from within a clean source will not work + (this is related to the nodist problem / old automake version) + this is caused by BUILT_SOURCES not working for make dist(check?) + and the dependency generation + + distcheck -> dist -> distdir -> DISTFILES + + all -> all-redirect -> all-am -> Makefile -> BUILT_SOURCES => bene + + => how to add dependency on BUILT_SOURCES for dist? + the real problem is that make dist should not depend on BUILT_SOURCES + unfortunately we can't fix this as long as we use a old automake version - add (standalone) example using generated client library (=> depends on installed example) example consists of: the same client.cpp but provides a configure.in and Makefile.am diff --git a/example-codegen/codegen.make b/example-codegen/codegen.make index ee63091..2464a0f 100644 --- a/example-codegen/codegen.make +++ b/example-codegen/codegen.make @@ -27,6 +27,8 @@ libt2ngroup_%.P : Makefile.am $(LIBT2N_CODEGEN) $* $($*_GROUP:.cpp=.xml) && touch $@ LIBT2N_CODEGEN_BUILT = $(foreach i, $(CMDGROUPS), $(foreach j, _common.hxx _common.cpp _client.hxx _client.cpp _server.hxx _server.cpp, $(i)$(j)) ) + +# using BUILT_SOURCES is a bit problematic (see also automake manual) BUILT_SOURCES += $(LIBT2N_CODEGEN_BUILT) LIBT2N_STAMPS=$(CMDGROUPS:=.libt2nstamp) @@ -39,11 +41,12 @@ pkgconfig_DATA = $(CMDGROUPS:=.pc) # .pc files (one pc file for each command group) %.pc : $(LIBT2N_CLIENT_PCTEMPLATE) Makefile sed \ - -e 's,@CMDGROUP@,$*,g' \ + -e 's,\@CMDGROUP\@,$*,g' \ -e 's,\@prefix\@,$(prefix),g' \ -e 's,\@exec_prefix\@,$(exec_prefix),g' \ -e 's,\@libdir\@,$(libdir),g' \ -e 's,\@includedir\@,$(includedir),g' \ + -e 's,\@VERSION\@,$(VERSION),g' \ $< >$*.pc CLEANFILES += $(LIBT2N_CODEGEN_BUILT) $(LIBT2N_STAMPS) $(pkgconfig_DATA) @@ -55,8 +58,8 @@ CLEANFILES += $(LIBT2N_CODEGEN_BUILT) $(LIBT2N_STAMPS) $(pkgconfig_DATA) # $(foreach i, $(CMDGROUPS), $(i)_server.cpp) # we have got an old automake version (1.4-p5) which doesn't support nodist_ -# => we use the dist-hook -dist-hook: +# => we use this hack using the dist-hook +dist-hook: $(LIBT2N_CODEGEN_BUILT) rm -vf $(foreach i, $(LIBT2N_CODEGEN_BUILT), $(distdir)/$(i)) EXTRA_DIST += codegen.make diff --git a/example-libusage/Makefile.am b/example-libusage/Makefile.am new file mode 100644 index 0000000..5adf4a5 --- /dev/null +++ b/example-libusage/Makefile.am @@ -0,0 +1,10 @@ +# not a GNU package. You can remove this line, if +# you have all needed files, that a GNU package needs +AUTOMAKE_OPTIONS = foreign + +INCLUDES = @DEFAULT_CFLAGS@ +LDADD = @DEFAULT_LIBS@ + +client_SOURCES = client.cpp + +bin_PROGRAMS = client diff --git a/example-libusage/README b/example-libusage/README new file mode 100644 index 0000000..1f39f2b --- /dev/null +++ b/example-libusage/README @@ -0,0 +1 @@ +example how to use a installed library generated using libt2n-codegen diff --git a/example-libusage/client.cpp b/example-libusage/client.cpp new file mode 100644 index 0000000..7a98309 --- /dev/null +++ b/example-libusage/client.cpp @@ -0,0 +1,30 @@ +/*************************************************************************** + * Copyright (C) 2004 by Intra2net AG * + * info@intra2net.com * + * * + ***************************************************************************/ + +#include + +// include generated library header +#include "default_client.hxx" + +int main(int argc, char** argv) +{ + libt2n::socket_client_connection sc("./socket"); + cmd_group_default_client cc(sc); + + bool throwok=false; + try + { + cc.testfunc("throw"); + }catch(libt2n::t2n_runtime_error &e){ + throwok=(std::string(e.what())=="throw me around"); + } + + return ( throwok + && ( cc.testfunc("hello") == "hello, testfunc() was here" ) + && ( cc.testfunc_ref("hello") == "hello, testfunc() was here" ) + && ( cc.t2(10) == 10 ) ) + ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/test-build-install-use b/test-build-install-use index 15c0ddf..8bba385 100755 --- a/test-build-install-use +++ b/test-build-install-use @@ -6,14 +6,21 @@ set -o nounset INSTDIR="/tmp/jens-delme" mkdir "$INSTDIR" INSTPREFIX="/tmp/jens-delme/usr" -MAKE="dmake -d" +MAKE="dmake" ./configure --prefix="$INSTPREFIX" +# todo: at the moment running make dist on clean source does not work +$MAKE +#$MAKE distcheck $MAKE dist $MAKE install +echo "OK: library and code generator compiled and installed" + VERSION="0.1" TARFILE="libt2n-$VERSION.tar.gz" cp "$TARFILE" "$INSTDIR" +EXAMPLE_LIBUSAGE="example-libusage" +cp -af "$EXAMPLE_LIBUSAGE" "$INSTDIR" # now build example-client using installed libt2n cd "$INSTDIR" @@ -41,7 +48,16 @@ tar xzvf "$TARFILE" mv "libt2n-$VERSION/example-codegen" . cd example-codegen autoreconf -f -i -M "$INSTDIR/usr/share/aclocal" -./configure +./configure --prefix="$INSTPREFIX" # todo: at the moment running make dist on clean source does not work $MAKE $MAKE distcheck +$MAKE install +cd .. +echo "OK: example using installed libt2n works" + +# now compile client using the installed default lib +cd "$EXAMPLE_LIBUSAGE" +autoreconf -f -i -M "$INSTDIR/usr/share/aclocal" +./configure --prefix="$INSTPREFIX" +$MAKE distcheck -- 1.7.1