3 progname=$(basename $0)
7 Usage: $progname [options] <outdir> <depends>...
10 -a, --copy-all copy all files in module tree (not just
11 sources required for build)
12 -c, --exclude-configurator exclude configurator. config.h must be
13 supplied by another method (eg, autotools)
17 # parse options, setting the following flags
21 opts=$(getopt -o ac --long copy-all,exclude-configurator -n $progname -- "$@")
38 -c|--exclude-configurator)
39 exclude_configurator=1
47 echo "Internal error!">&2
53 # we need at least two non-option arguments: outdir and a list of ccan
61 srcdir=$(dirname $0)/../
68 echo "Output directory '$outdir' already exists" >&2
73 # sanity check, we don't want to be overwriting stuff in arbitrary dirs
74 [ $? -eq 0 -a -d "${tmpdir}" ] || exit 1
76 # We'll need the ccan_depends tool, but also a clean source tree. Build
77 # tools/ccan_depends, and store it in $tmpdir for later use
79 echo "Building ccan_depends"
80 ccan_depends="$tmpdir/ccan_depends"
81 make -s -C "$srcdir" tools/ccan_depends
82 [ $? -eq 0 ] || exit 1
83 cp "$srcdir/tools/ccan_depends" "$ccan_depends"
85 echo "Cleaning source tree"
86 make -s -C "$srcdir" clean
87 [ $? -eq 0 ] || exit 1
90 trap 'rm -rf $tmpdir' EXIT
94 module_srcdir="$srcdir/$module_dir"
95 module_destdir="$tmpdir/$module_dir"
100 mkdir -p "$(dirname "$module_destdir")"
101 cp -a "$module_srcdir" "$module_destdir"
103 mkdir -p "$module_destdir"
104 # only copy sources & license
105 license="$module_srcdir/LICENSE"
106 cp -a "$module_srcdir"/*.[ch] "$module_destdir"
107 [ -e "$license" ] && cp -a "$license" "$module_destdir"
111 # generate list of directories to copy
112 for module in $modules
114 # ccan_depends takes a directory name
115 module_dir="$srcdir/ccan/$module"
117 # we need the module itself...
120 # .. plus dependencies
121 "$ccan_depends" "$module_dir"
125 echo "Invalid ccan module '$module'?" >&2
133 copy_ccan_module $dir
136 # we're done with the dependency-tracking, remove the tool from our
137 # temporary directory
140 echo "Adding licenses"
141 license_dir="$tmpdir/licenses"
144 find "$tmpdir" -type l -name LICENSE |
147 license_link=$(readlink "$license")
148 licence_file=$(basename "$license_link")
149 license_src="$srcdir/licenses/$licence_file"
150 license_dest="$license_dir/$license_file"
151 cp "$license_src" "$license_dest"
155 echo "Adding build infrastructure"
156 cp "$srcdir/Makefile-ccan" "$tmpdir/"
158 # add top-level Makefile
159 top_makefile="$tmpdir/Makefile"
160 cat > "$top_makefile" << EOF
163 include Makefile-ccan
166 # optionally add configurator, and relevant parts to top-level Makefile
167 if [ -z "$exclude_configurator" ]
169 echo "Adding configurator"
170 mkdir -p "$tmpdir/tools/configurator"
171 cp -a "$srcdir/tools/configurator" "$tmpdir/tools/"
173 cat >> "$top_makefile" <<EOF
174 tools/configurator/configurator: tools/configurator/configurator.c
176 config.h: tools/configurator/configurator Makefile Makefile-ccan
177 tools/configurator/configurator \$(CC) \$(CCAN_CFLAGS) > \$@ \\
180 objs = \$(patsubst %.c, %.o, \$(wildcard ccan/*/*.c))
186 mv "$tmpdir" "$outdir"
187 echo "Done. ccan source tree built in $outdir"