X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fcreate-ccan-tree;h=c03933400320342f91ee609d1337fa45864114fb;hp=88644b78651b267281e4abab2a375693f262caec;hb=25b7406d11ea3703be864097af66ce95611dde72;hpb=70a438e87551b1e0775e3c785bc07a71cb4de314 diff --git a/tools/create-ccan-tree b/tools/create-ccan-tree index 88644b78..c0393340 100755 --- a/tools/create-ccan-tree +++ b/tools/create-ccan-tree @@ -7,18 +7,17 @@ usage() { Usage: $progname [options] ... options: - -a, --copy-all copy all files in module tree (not just - sources required for build) - -c, --exclude-configurator exclude configurator. config.h must be - supplied by another method (eg, autotools) + -a, --copy-all copy all files in module tree (not just sources + required for build) + -b, --build-type=TYPE generate build infrastructure of TYPE + (one of 'make', 'make+config', 'automake', 'waf') EOF } # parse options, setting the following flags -copy_all= -exclude_configurator= +build_type= -opts=$(getopt -o ac --long copy-all,exclude-configurator -n $progname -- "$@") +opts=$(getopt -o ab: --long copy-all,build-type: -n $progname -- "$@") if [ $? != 0 ] then @@ -27,17 +26,18 @@ then fi eval set -- "$opts" +MODFILES_ARGS="--no-tests --no-other" while : do case "$1" in -a|--copy-all) - copy_all=1 + MODFILES_ARGS="" shift ;; - -c|--exclude-configurator) - exclude_configurator=1 - shift + -b|--build-type) + build_type="$2" + shift 2 ;; --) shift @@ -58,6 +58,15 @@ then exit 1 fi +# check --build-type argument sanity +case "$build_type" in + ''|'make'|'make+config'|'automake'|'waf') + ;; + *) + echo "Invalid build type '$build_type'" >&2 + exit 1 +esac + srcdir=$(dirname $0)/../ outdir="$1" shift @@ -76,11 +85,13 @@ tmpdir="$(mktemp -d)" # We'll need the ccan_depends tool, but also a clean source tree. Build # tools/ccan_depends, and store it in $tmpdir for later use -echo "Building ccan_depends" +echo "Building ccan_depends, modfiles" ccan_depends="$tmpdir/ccan_depends" -make -s -C "$srcdir" tools/ccan_depends +modfiles="$tmpdir/modfiles" +make -s -C "$srcdir" tools/ccan_depends tools/modfiles [ $? -eq 0 ] || exit 1 cp "$srcdir/tools/ccan_depends" "$ccan_depends" +cp "$srcdir/tools/modfiles" "$modfiles" echo "Cleaning source tree" make -s -C "$srcdir" clean @@ -94,18 +105,14 @@ copy_ccan_module() { module_srcdir="$srcdir/$module_dir" module_destdir="$tmpdir/$module_dir" - if [ -n "$copy_all" ] - then - # bulk copy - mkdir -p "$(dirname "$module_destdir")" - cp -a "$module_srcdir" "$module_destdir" - else - mkdir -p "$module_destdir" - # only copy sources & license - license="$module_srcdir/LICENSE" - cp -a "$module_srcdir"/*.[ch] "$module_destdir" - [ -e "$license" ] && cp -a "$license" "$module_destdir" - fi + mkdir -p "$module_destdir" + # Copy license + license="$module_srcdir/LICENSE" + [ -e "$license" ] && cp -a "$license" "$module_destdir" + for f in $("$modfiles" $MODULES_ARGS --no-license --git-only "$module_dir"); do + mkdir -p $(dirname "$module_destdir"/"$f") + cp "$module_srcdir"/$f "$module_destdir"/$f + done } # generate list of directories to copy @@ -135,7 +142,7 @@ done # we're done with the dependency-tracking, remove the tool from our # temporary directory -rm "$ccan_depends" +rm "$ccan_depends" "$modfiles" echo "Adding licenses" license_dir="$tmpdir/licenses" @@ -151,26 +158,43 @@ do cp "$license_src" "$license_dest" done -# add ccan Makefile echo "Adding build infrastructure" -cp "$srcdir/Makefile-ccan" "$tmpdir/" -# add top-level Makefile -top_makefile="$tmpdir/Makefile" -cat > "$top_makefile" << EOF +# generate automake Makefile.am +automakefile="$tmpdir/Makefile.am" +if [ "$build_type" = "automake" ] +then + ( + echo "noinst_LIBRARIES = libccan.a" + echo "libccan_a_SOURCES = \\" + cd "$tmpdir" + find ccan -maxdepth 2 -name '*.[ch]' | + sed -e 's,^,\t,;$!s,$, \\,' + ) > "$automakefile" +fi + +makefile="$tmpdir/Makefile" +if [ "$build_type" = "make" -o "$build_type" = "make+config" ] +then + # add ccan Makefile + cp "$srcdir/Makefile-ccan" "$tmpdir/" + + # add top-level Makefile + cat > "$makefile" << EOF all: libccan.a include Makefile-ccan EOF +fi # optionally add configurator, and relevant parts to top-level Makefile -if [ -z "$exclude_configurator" ] +if [ "$build_type" = "make+config" ] then echo "Adding configurator" mkdir -p "$tmpdir/tools/configurator" cp -a "$srcdir/tools/configurator" "$tmpdir/tools/" - cat >> "$top_makefile" <> "$makefile" < "$tmpdir/wscript" << EOF +def build(ctx): + ctx(features = 'c cstlib', + source = ctx.path.ant_glob('**/*.c'), + target = 'ccan', + includes = '.') +EOF +fi + mv "$tmpdir" "$outdir" echo "Done. ccan source tree built in $outdir"