[ccan] embedding ccan in other projects redux

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Tue Aug 18 17:48:34 AEST 2015


Hello I am embeding ccan into my hkl project [1]

Indeed I build a bunch of modules.
A few are public and will be installed into my hkl namespace.
the other will be private.

so I need to install only the public part.

In my case I do a bunch of transformation that you can find in the ccan-update make target, mostly:

1) add namespace
2)make a difference between public and private modules
3) rename the config.h -> ccan_config.h (to avoid problem with autotools config.h)
4) generate the right Makefile.am

Cheers

Frederic

## Update the ccan library

CCAN_PUBLIC_MODULES=darray
CCAN_PRIVATE_MODULES=array_size container_of autodata list
CCAN_LOCAL_REPO=/tmp/ccan
CCAN_LOCAL_EXTRACT=/tmp/ccan.tmp
CCAN_URL=git://git.ozlabs.org/~ccan/ccan
CCAN_CREATE_TREE=rm -rf $(CCAN_LOCAL_EXTRACT) && cd $(CCAN_LOCAL_REPO) && tools/create-ccan-tree -b automake $(CCAN_LOCAL_EXTRACT)
CCAN_DEST=$(top_srcdir)/hkl/
CCAN_TMP_DEST=/tmp/ccan.next
ccan-update:
	@if test -d $(CCAN_LOCAL_REPO); \
	then \
		cd $(CCAN_LOCAL_REPO) && git pull; \
	else \
		git clone $(CCAN_URL) $(CCAN_LOCAL_REPO); \
	fi

	@echo Extracting all the modules
	@$(CCAN_CREATE_TREE) $(CCAN_PUBLIC_MODULES) $(CCAN_PRIVATE_MODULES)

	@rm -rf $(CCAN_TMP_DEST) && mkdir -p $(CCAN_TMP_DEST)
	@rsync -av --exclude=Makefile.am $(CCAN_LOCAL_EXTRACT)/* $(CCAN_TMP_DEST)
	@find $(CCAN_TMP_DEST)/ccan -maxdepth 2 -name '*.[ch]' | xargs sed -i -e 's,ccan/,hkl/ccan/,'
	@find $(CCAN_TMP_DEST)/ccan -maxdepth 2 -name '*.[ch]' | xargs sed -i -e 's,"config.h",<hkl/ccan/ccan_config.h>,'

	@$(CCAN_CREATE_TREE) $(CCAN_PUBLIC_MODULES)

	@echo Generating the Makefile.am
	@(\
		echo "AM_CFLAGS=-I\$$(top_srcdir)"; echo;\
		echo "noinst_PROGRAMS=configurator";\
		echo "ccan_config.h: configurator.c";\
		(\
			echo -e "\t\$$(builddir)/configurator \$$(CC) \$$(CCAN_CFLAGS) > \$$@.tmp && mv \$$@.tmp \$$@";\
		);\
		echo "noinst_LTLIBRARIES=libccan.la";\
		echo "libccan_la_SOURCES = \\";\
		(\
			echo -e "\tccan_config.h \\";\
			cd $(CCAN_TMP_DEST)/ccan && find . -maxdepth 2 -name '*.[ch]'\
				| sed -e 's,^./,\t,;$$!s,$$, \\,'; echo;\
		);\
		echo "ccanincludedir=\$$(includedir)/hkl-@""VMAJ@/hkl/ccan";\
		echo "nobase_ccaninclude_HEADERS= \\";\
		(\
			cd $(CCAN_LOCAL_EXTRACT)/ccan && find . -maxdepth 2 -name '*.[h]'\
				| sed -e 's,^./,\t,;$$!s,$$, \\,';\
		);\
		echo "nodist_ccaninclude_HEADERS=ccan_config.h";\
		echo "EXTRA_DIST=configurator.c";\
		echo "CLEANFILES=configurator ccan_config.h";\
	) > $(CCAN_TMP_DEST)/ccan/Makefile.am

	@echo Extracting the configurator
	@rsync -av $(CCAN_LOCAL_REPO)/tools/configurator/configurator.c $(CCAN_TMP_DEST)/ccan

	@echo purge the previous ccan directory
	cd $(CCAN_DEST) && rm -rf licenses && find ccan -mindepth 1 -type d \! -name ".*" | xargs rm -rf
	rsync -av $(CCAN_TMP_DEST)/* $(top_srcdir)/hkl





[1] https://sources.debian.net/src/hkl/4.99.99.1955-1/
________________________________________
De : ccan [ccan-bounces+picca=synchrotron-soleil.fr at lists.ozlabs.org] de la part de Naveen Nathan [naveen at lastninja.net]
Envoyé : mardi 18 août 2015 09:03
À : ccan at lists.ozlabs.org
Objet : [ccan] embedding ccan in other projects redux

Earlier I had started a discussion about how to approach embedding
specific ccan modules into a Python C extension project. I discussed
the options available with David Gibson over IRC. This email
serves to bring the conversation back to this mailing list.

Two distinct issues were discussed:

(1) ccan modules shouldn't implicitly include a "config.h" for their config.

Another way to say this is each ccan module should stand alone with no shared
dependencies. Instead a top-level build/configurator system will generate the
needed config.h files and glue. In the case of ccan this is done by
specifying the -include compiler directive in the Makefiles.


(2) creating a pathway to make ccan modules embeddable

Instead of an overhaul of the existing build system we can make incremental
progress to allow flexible embedding of ccan into other projects. A few
steps were discussed:

 * Adapt the ccan makefile for easier embedding, so it will just attempt
   to build those modules that are present
 * Implement (1) for ccan using -include directives
 * Make a ccan tool to spit out all config variables used by a module
   (and its dependencies?)
 * Document the existing ccan config options
 * [possible] generate files to help autoconf systems (such as aclocal defs)

I can potentially see create-ccan-tree used as a way to create a
separate ccan tree with a skeleton build environment and specified modules
and dependencies.

Projects embedding ccan would then import the tree into the project,
use the existnig configurator to generate a config.h (or create their own),
or potenitally use supplied aclocal defs.

Sorry if this is a bit long-winded. Would like to hear thoughts or see
if we're missing anything crucial.

Thanks,
Naveen
_______________________________________________
ccan mailing list
ccan at lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan


More information about the ccan mailing list