3 progname=$(basename $0)
7 Usage: $progname [options] <outdir> <depends>...
10 -t, --exclude-tests exclude test/ directories from ccan modules
11 -c, --exclude-configurator exclude configurator. config.h must be
12 supplied by another method (eg, autotools)
16 # parse options, setting the following flags
20 opts=$(getopt -o tc --long exclude-tests,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
92 # generate list of directories to copy
93 for module in $modules
95 # ccan_depends takes a directory name
96 module_dir="$srcdir/ccan/$module"
98 # we need the module itself...
101 # .. plus dependencies
102 "$ccan_depends" "$module_dir"
106 echo "Invalid ccan module '$module'?" >&2
113 module_srcdir="$srcdir/$dir"
114 module_destdir="$tmpdir/$dir"
116 mkdir -p "$(dirname "$module_destdir")"
117 cp -a "$module_srcdir" "$module_destdir"
118 if [ -n "$exclude_tests" ]
120 rm -rf "$module_destdir/test"
124 # we're done with the dependency-tracking, remove the tool from our
125 # temporary directory
128 echo "Adding licenses"
129 license_dir="$tmpdir/licenses"
132 find "$tmpdir" -type l -name LICENSE |
135 license_link=$(readlink "$license")
136 licence_file=$(basename "$license_link")
137 license_src="$srcdir/licenses/$licence_file"
138 license_dest="$license_dir/$license_file"
139 cp "$license_src" "$license_dest"
143 echo "Adding build infrastructure"
144 cp "$srcdir/Makefile-ccan" "$tmpdir/"
146 # add top-level Makefile
147 top_makefile="$tmpdir/Makefile"
148 cat > "$top_makefile" << EOF
151 include Makefile-ccan
154 # optionally add configurator, and relevant parts to top-level Makefile
155 if [ -z "$exclude_configurator" ]
157 echo "Adding configurator"
158 mkdir -p "$tmpdir/tools/configurator"
159 cp -a "$srcdir/tools/configurator" "$tmpdir/tools/"
161 cat >> "$top_makefile" <<EOF
162 tools/configurator/configurator: tools/configurator/configurator.c
164 config.h: tools/configurator/configurator Makefile Makefile-ccan
165 tools/configurator/configurator \$(CC) \$(CCAN_CFLAGS) > \$@ \\
168 objs = \$(patsubst %.c, %.o, \$(wildcard ccan/*/*.c))
174 mv "$tmpdir" "$outdir"
175 echo "Done. ccan source tree built in $outdir"