-# 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