cleanup
[libt2n] / example-codegen / Makefile.am
index 4318ca6..3cc4d3d 100644 (file)
@@ -1,59 +1,89 @@
 INCLUDES = -I$(top_srcdir)/src @BOOST_CPPFLAGS@ @CPPUNIT_CFLAGS@ -I$(top_srcdir)/codegen
-
 LDADD = $(top_builddir)/src/libt2n.la @BOOST_SERIALIZATION_LIB@ @BOOST_LDFLAGS@
 
+# list your command groups
 CMDGROUPS = default other
 
+# for each command group list the files to parse for LIBT2N_EXPORT
+default_GROUP = default.cpp
+# example of a command group using multiple cpp files
+other_GROUP = other-1.cpp other-2.cpp
+
+# headers declaring data types used as rpc arguments must be listed manually
+# (in this example the class Foo)
+include_HEADERS = foo.hxx
+
 # unfortunately we can't set those from variables
 # because they are parsed by automake
 
 libdefault_la_SOURCES = default_client.cpp
 libother_la_SOURCES = other_client.cpp
-noinst_LTLIBRARIES = libdefault.la libother.la
+lib_LTLIBRARIES = libdefault.la libother.la
 
+# build an example server and client
 client_SOURCES = client.cpp
 client_LDADD = $(LDADD) libdefault.la libother.la
 
 server_SOURCES = server.cpp \
-       other.cpp other_server.cpp \
-       default.cpp default_server.cpp \
-       foo.hxx
+       $(other_GROUP) other_server.cpp \
+       $(default_GROUP) default_server.cpp
 
 noinst_PROGRAMS = client server
 
+# test script
 
-# always the same:
+TESTS = test
 
-codegen.stamp: $(CMDGROUPS:%=%.cpp) $(top_builddir)/codegen/codegen
-# assuming we have some unix like shell
-       echo BUILT_SOURCES: $(BUILT_SOURCES)
-       for i in $(CMDGROUPS); do \
-               cp -v $(top_srcdir)/codegen/codegen-stubhead.hxx $${i}_common.hxx; \
-               cp -v $(top_srcdir)/codegen/codegen-stubhead.hxx $${i}_server.hxx; \
-       done
-# todo use tmp file for xml file
-       for i in $(CMDGROUPS); do \
-               gccxml $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $${i}.cpp -fxml=$${i}.xml; \
-               $(top_builddir)/codegen/codegen $${i}.cpp $${i} $${i}.xml; \
-       done; touch $@
 
-# assuming we have gnu make?
-BUILT_SOURCES = $(foreach i, $(CMDGROUPS), $(foreach j, _common.hxx _common.cpp _client.hxx _client.cpp _server.hxx _server.cpp, $(i)$(j)) )
 
-$(BUILT_SOURCES) : codegen.stamp
 
-TESTS = test
+# always the same:
+
+include_HEADERS += $(foreach i, $(CMDGROUPS), $(i)_client.hxx $(i).hxx)
 
-CLEANFILES = $(BUILT_SOURCES) codegen.stamp
+#IFILES=$(foreach i, $(CMDGROUPS), $(foreach j, $($(i)_GROUP), $(j)))
 
-# TODO:
-# howto generate Makefile(.in) from something like this:
+-include $(foreach i, $(CMDGROUPS), .deps/group_$(i).P)
 
-# CMDGROUPS = default other
+.deps/group_%.P : Makefile.am
+       echo $@ : $($*_GROUP) > .deps/group_$*.P
 
-# default_SOURCES = default-1.cpp default-2.cpp
-# other_SOURCES = other.cpp
+%.stamp : .deps/group_%.P $(top_builddir)/codegen/codegen
+# assuming we have some unix like shell (maybe even bash)
+       echo BUILT_SOURCES: $(BUILT_SOURCES)
+# temporarily create _common.hxx file (will be overwritten by codegen below)
+       echo '#include "codegen-stubhead.hxx"' > $*_common.hxx;
+       echo '#include "$*.hxx"' >> $*_common.hxx;
+# todo use tmp file for xml file
+       for i in $($*_GROUP); do \
+               gccxml $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $${i} -fxml=$${i%*.cpp}.xml; \
+       done; \
+       $(top_builddir)/codegen/codegen $* $($*_GROUP:.cpp=.xml) && touch $@
 
-# TESTS = test
+# assuming we have gnu make?
+BUILT_SOURCES = $(foreach i, $(CMDGROUPS), $(foreach j, _common.hxx _common.cpp _client.hxx _client.cpp _server.hxx _server.cpp, $(i)$(j)) )
 
-# server_SOURCES = server.cpp default foo.hxx
+STAMPS=$(CMDGROUPS:=.stamp)
+$(BUILT_SOURCES) : $(STAMPS)
+
+# Install the pkg-config files:
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = $(CMDGROUPS:=.pc)
+
+# .pc files (one pc file for each command group)
+%.pc : $(top_srcdir)/codegen/clientlib.pc.in Makefile
+       sed \
+       -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' \
+       $< >$*.pc
+
+CLEANFILES = $(BUILT_SOURCES) $(STAMPS) $(pkgconfig_DATA)
+
+# didn't work (same problem as with _LTLIBRARIES [parsing by automake],
+# this time _OBJECTS was not correct)
+# server_SOURCES = server.cpp \
+#      $(foreach i, $(CMDGROUPS), $(foreach j, $($(i)_GROUP), $(j))) \
+#      $(foreach i, $(CMDGROUPS), $(i)_server.cpp)