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
21 opts=$(getopt -o ab: --long copy-all,build-type: -n $progname -- "$@")
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"
89 ccan_depends="$tmpdir/ccan_depends"
90 make -s -C "$srcdir" tools/ccan_depends
91 [ $? -eq 0 ] || exit 1
92 cp "$srcdir/tools/ccan_depends" "$ccan_depends"
94 echo "Cleaning source tree"
95 make -s -C "$srcdir" clean
96 [ $? -eq 0 ] || exit 1
99 trap 'rm -rf $tmpdir' EXIT
103 module_srcdir="$srcdir/$module_dir"
104 module_destdir="$tmpdir/$module_dir"
106 if [ -n "$copy_all" ]
109 mkdir -p "$(dirname "$module_destdir")"
110 cp -a "$module_srcdir" "$module_destdir"
112 mkdir -p "$module_destdir"
113 # only copy sources & license
114 license="$module_srcdir/LICENSE"
115 cp -a "$module_srcdir"/*.[ch] "$module_destdir"
116 [ -e "$license" ] && cp -a "$license" "$module_destdir"
120 # generate list of directories to copy
121 for module in $modules
123 # ccan_depends takes a directory name
124 module_dir="$srcdir/ccan/$module"
126 # we need the module itself...
129 # .. plus dependencies
130 "$ccan_depends" "$module_dir"
134 echo "Invalid ccan module '$module'?" >&2
142 copy_ccan_module $dir
145 # we're done with the dependency-tracking, remove the tool from our
146 # temporary directory
149 echo "Adding licenses"
150 license_dir="$tmpdir/licenses"
153 find "$tmpdir" -type l -name LICENSE |
156 license_link=$(readlink "$license")
157 licence_file=$(basename "$license_link")
158 license_src="$srcdir/licenses/$licence_file"
159 license_dest="$license_dir/$license_file"
160 cp "$license_src" "$license_dest"
163 echo "Adding build infrastructure"
165 # generate automake Makefile.am
166 automakefile="$tmpdir/Makefile.am"
167 if [ "$build_type" = "automake" ]
170 echo "noinst_LIBRARIES = libccan.a"
171 echo "libccan_a_SOURCES = \\"
173 find ccan -maxdepth 2 -name '*.[ch]' |
174 sed -e 's,^,\t,;$!s,$, \\,'
178 makefile="$tmpdir/Makefile"
179 if [ "$build_type" = "make" -o "$build_type" = "make+config" ]
182 cp "$srcdir/Makefile-ccan" "$tmpdir/"
184 # add top-level Makefile
185 cat > "$makefile" << EOF
188 include Makefile-ccan
192 # optionally add configurator, and relevant parts to top-level Makefile
193 if [ "$build_type" = "make+config" ]
195 echo "Adding configurator"
196 mkdir -p "$tmpdir/tools/configurator"
197 cp -a "$srcdir/tools/configurator" "$tmpdir/tools/"
199 cat >> "$makefile" <<EOF
200 tools/configurator/configurator: tools/configurator/configurator.c
202 config.h: tools/configurator/configurator Makefile Makefile-ccan
203 tools/configurator/configurator \$(CC) \$(CCAN_CFLAGS) > \$@ \\
206 objs = \$(patsubst %.c, %.o, \$(wildcard ccan/*/*.c))
212 if [ "$build_type" = "waf" ]
214 echo "Adding waf wscript"
215 cat > "$tmpdir/wscript" << EOF
217 ctx(features = 'c cstlib',
218 source = ctx.path.ant_glob('**/*.c'),
224 mv "$tmpdir" "$outdir"
225 echo "Done. ccan source tree built in $outdir"