3 progname=$(basename $0)
7 Usage: $progname [options] <outdir> <depends>...
10 -a, --copy-all copy all files in module tree (not just sources
12 -b, --build-type=TYPE generate build infrastructure of TYPE
13 (one of 'make', 'make+config', 'automake', 'waf')
17 # parse options, setting the following flags
20 opts=$(getopt -o ab: --long copy-all,build-type: -n $progname -- "$@")
29 MODFILES_ARGS="--no-tests --no-other"
47 echo "Internal error!">&2
53 # we need at least two non-option arguments: outdir and a list of ccan
61 # check --build-type argument sanity
63 ''|'make'|'make+config'|'automake'|'waf')
66 echo "Invalid build type '$build_type'" >&2
70 srcdir=$(dirname $0)/../
77 echo "Output directory '$outdir' already exists" >&2
82 # sanity check, we don't want to be overwriting stuff in arbitrary dirs
83 [ $? -eq 0 -a -d "${tmpdir}" ] || exit 1
85 # We'll need the ccan_depends tool, but also a clean source tree. Build
86 # tools/ccan_depends, and store it in $tmpdir for later use
88 echo "Building ccan_depends, modfiles"
89 ccan_depends="$tmpdir/ccan_depends"
90 modfiles="$tmpdir/modfiles"
91 make -s -C "$srcdir" tools/ccan_depends tools/modfiles
92 [ $? -eq 0 ] || exit 1
93 cp "$srcdir/tools/ccan_depends" "$ccan_depends"
94 cp "$srcdir/tools/modfiles" "$modfiles"
96 echo "Cleaning source tree"
97 make -s -C "$srcdir" clean
98 [ $? -eq 0 ] || exit 1
101 trap 'rm -rf $tmpdir' EXIT
105 module_srcdir="$srcdir/$module_dir"
106 module_destdir="$tmpdir/$module_dir"
108 mkdir -p "$module_destdir"
110 license="$module_srcdir/LICENSE"
111 [ -e "$license" ] && cp -a "$license" "$module_destdir"
112 for f in $("$modfiles" $MODULES_ARGS --no-license --git-only "$module_dir"); do
113 mkdir -p $(dirname "$module_destdir"/"$f")
114 cp "$module_srcdir"/$f "$module_destdir"/$f
118 # generate list of directories to copy
119 for module in $modules
121 # ccan_depends takes a directory name
122 module_dir="$srcdir/ccan/$module"
124 # we need the module itself...
127 # .. plus dependencies
128 "$ccan_depends" "$module_dir"
132 echo "Invalid ccan module '$module'?" >&2
140 copy_ccan_module $dir
143 # we're done with the dependency-tracking, remove the tool from our
144 # temporary directory
145 rm "$ccan_depends" "$modfiles"
147 echo "Adding licenses"
148 license_dir="$tmpdir/licenses"
151 find "$tmpdir" -type l -name LICENSE |
154 license_link=$(readlink "$license")
155 licence_file=$(basename "$license_link")
156 license_src="$srcdir/licenses/$licence_file"
157 license_dest="$license_dir/$license_file"
158 cp "$license_src" "$license_dest"
161 echo "Adding build infrastructure"
163 # generate automake Makefile.am
164 automakefile="$tmpdir/Makefile.am"
165 if [ "$build_type" = "automake" ]
168 echo "noinst_LIBRARIES = libccan.a"
169 echo "libccan_a_SOURCES = \\"
171 find ccan -maxdepth 2 -name '*.[ch]' |
172 sed -e 's,^,\t,;$!s,$, \\,'
176 makefile="$tmpdir/Makefile"
177 if [ "$build_type" = "make" -o "$build_type" = "make+config" ]
180 cp "$srcdir/Makefile-ccan" "$tmpdir/"
182 # add top-level Makefile
183 cat > "$makefile" << EOF
186 include Makefile-ccan
190 # optionally add configurator, and relevant parts to top-level Makefile
191 if [ "$build_type" = "make+config" ]
193 echo "Adding configurator"
194 mkdir -p "$tmpdir/tools/configurator"
195 cp -a "$srcdir/tools/configurator" "$tmpdir/tools/"
197 cat >> "$makefile" <<EOF
198 tools/configurator/configurator: tools/configurator/configurator.c
200 config.h: tools/configurator/configurator Makefile Makefile-ccan
201 tools/configurator/configurator \$(CC) \$(CCAN_CFLAGS) > \$@ \\
204 objs = \$(patsubst %.c, %.o, \$(wildcard ccan/*/*.c))
210 if [ "$build_type" = "waf" ]
212 echo "Adding waf wscript"
213 cat > "$tmpdir/wscript" << EOF
215 ctx(features = 'c cstlib',
216 source = ctx.path.ant_glob('**/*.c'),
222 mv "$tmpdir" "$outdir"
223 echo "Done. ccan source tree built in $outdir"