Browse Source

Merge branch 'master' of ozlabs.org:ccan

Rusty Russell 13 years ago
parent
commit
9f5e1ef758
1 changed files with 77 additions and 27 deletions
  1. 77 27
      tools/create-ccan-tree

+ 77 - 27
tools/create-ccan-tree

@@ -7,18 +7,18 @@ usage() {
 Usage: $progname [options] <outdir> <depends>...
 Usage: $progname [options] <outdir> <depends>...
 
 
 options:
 options:
-  -t, --exclude-tests         exclude test/ directories from ccan modules
-  -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
 EOF
 }
 }
 
 
 # parse options, setting the following flags
 # parse options, setting the following flags
-exclude_tests=
-exclude_configurator=
+copy_all=
+build_type=
 
 
-opts=$(getopt -o tc --long exclude-tests,exclude-configurator -n $progname \
-		-- "$@")
+opts=$(getopt -o ab: --long copy-all,build-type: -n $progname -- "$@")
 
 
 if [ $? != 0 ]
 if [ $? != 0 ]
 then
 then
@@ -31,13 +31,13 @@ eval set -- "$opts"
 while :
 while :
 do
 do
 	case "$1" in
 	case "$1" in
-		-t|--exclude-tests)
-			exclude_tests=1
+		-a|--copy-all)
+			copy_all=1
 			shift
 			shift
 			;;
 			;;
-		-c|--exclude-configurator)
-			exclude_configurator=1
-			shift
+		-b|--build-type)
+			build_type="$2"
+			shift 2
 			;;
 			;;
 		--)
 		--)
 			shift
 			shift
@@ -58,6 +58,15 @@ then
 	exit 1
 	exit 1
 fi
 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)/../
 srcdir=$(dirname $0)/../
 outdir="$1"
 outdir="$1"
 shift
 shift
@@ -89,6 +98,25 @@ make -s -C "$srcdir" clean
 # clean up on error
 # clean up on error
 trap 'rm -rf $tmpdir' EXIT
 trap 'rm -rf $tmpdir' EXIT
 
 
+copy_ccan_module() {
+	module_dir="$1"
+	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
+}
+
 # generate list of directories to copy
 # generate list of directories to copy
 for module in $modules
 for module in $modules
 do
 do
@@ -110,15 +138,8 @@ done |
 sort -u |
 sort -u |
 while read dir
 while read dir
 do
 do
-	module_srcdir="$srcdir/$dir"
-	module_destdir="$tmpdir/$dir"
 	echo "Adding $dir"
 	echo "Adding $dir"
-	mkdir -p "$(dirname "$module_destdir")"
-	cp -a "$module_srcdir" "$module_destdir"
-	if [ -n "$exclude_tests" ]
-	then
-		rm -rf "$module_destdir/test"
-	fi
+	copy_ccan_module $dir
 done
 done
 
 
 # we're done with the dependency-tracking, remove the tool from our
 # we're done with the dependency-tracking, remove the tool from our
@@ -139,26 +160,43 @@ do
 	cp "$license_src" "$license_dest"
 	cp "$license_src" "$license_dest"
 done
 done
 
 
-# add ccan Makefile
 echo "Adding build infrastructure"
 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
 all: libccan.a
 
 
 include Makefile-ccan
 include Makefile-ccan
 EOF
 EOF
+fi
 
 
 # optionally add configurator, and relevant parts to top-level Makefile
 # optionally add configurator, and relevant parts to top-level Makefile
-if [ -z "$exclude_configurator" ]
+if [ "$build_type" = "make+config" ]
 then
 then
 	echo "Adding configurator"
 	echo "Adding configurator"
 	mkdir -p "$tmpdir/tools/configurator"
 	mkdir -p "$tmpdir/tools/configurator"
 	cp -a "$srcdir/tools/configurator" "$tmpdir/tools/"
 	cp -a "$srcdir/tools/configurator" "$tmpdir/tools/"
 
 
-	cat >> "$top_makefile" <<EOF
+	cat >> "$makefile" <<EOF
 tools/configurator/configurator: tools/configurator/configurator.c
 tools/configurator/configurator: tools/configurator/configurator.c
 
 
 config.h: tools/configurator/configurator Makefile Makefile-ccan
 config.h: tools/configurator/configurator Makefile Makefile-ccan
@@ -171,6 +209,18 @@ objs = \$(patsubst %.c, %.o, \$(wildcard ccan/*/*.c))
 EOF
 EOF
 fi
 fi
 
 
+if [ "$build_type" = "waf" ]
+then
+	echo "Adding waf wscript"
+	cat > "$tmpdir/wscript" << EOF
+def build(ctx):
+    ctx(features     = 'c cstlib',
+        source       = ctx.path.ant_glob('**/*.c'),
+        target       = 'ccan',
+        includes     = '.')
+EOF
+fi
+
 mv "$tmpdir" "$outdir"
 mv "$tmpdir" "$outdir"
 echo "Done. ccan source tree built in $outdir"
 echo "Done. ccan source tree built in $outdir"