Bug fix in the default target setting when not using "build.mk" script.
[dotmk.git] / build.sh
blob3436dd38a4f6be39a8869a44b3bfeee2d57e9198
1 #!/bin/sh -ex
3 build()
5 mkfile="$1"
7 exec 9>&1
8 exec 1>"${MKDIR}/${mkfile}"
10 cat << EOF
11 # ${mkfile}
13 EOF
14 sed -e 's/^/# /' "${TOPDIR}/LICENSE"
15 cat << EOF
17 ifndef ${mkfile}
18 ${mkfile}= y
20 EOF
21 cat "${SRCDIR}/default-head.mk"
22 echo
23 cat "${SRCDIR}/${mkfile}"
24 echo
25 cat "${SRCDIR}/default-tail.mk"
26 cat << EOF
28 endif # ndef ${mkfile}
29 EOF
31 exec 1>&9-
34 cleandir()
36 dir="${1}"
38 find "${dir}" -mindepth 1 -maxdepth 1 -and ! -name .gitignore -print0 | xargs -0 rm -fr
39 mkdir -p "${MKDIR}"
42 automakefile()
44 makefile="Makefile"
45 prog="`basename "${PWD}"`"
47 exec 9>&1
48 exec 1>"${makefile}"
50 cat << EOF
51 # ${makefile}
53 PROGS= ${prog}
55 ${prog}_SRCS= \\
56 EOF
58 tmpfile="`mktemp "/tmp/${0##*/}-$$.XXXXXX"`"
59 find . -name '*.c' -or -iname '*.cpp' -or -iname '*.cxx' -or -iname '*.c++' > "${tmpfile}"
60 head -n -1 < "${tmpfile}" | sed -e 's/^/\t/;s/$/ \\/'
61 tail -n 1 < "${tmpfile}" | sed -e 's/^/\t/'
63 for incdir in ./include; do
64 [ -d "${incdir}" ] || continue
65 echo "${incdir}"
66 done > "${tmpfile}"
68 if [ -s "${tmpfile}" ]; then
69 echo
70 echo "${prog}_INCDIRS= \\"
71 head -n -1 < "${tmpfile}" | sed -e 's/^/\t/;s/$/ \\/'
72 tail -n 1 < "${tmpfile}" | sed -e 's/^/\t/'
75 cat << EOF
77 include ${MKDIR}/build.mk
78 EOF
79 exec 1>&9-
81 rm -f "${tmpfile}"
83 cat "${makefile}"
86 MKDIR="mk"
87 TOPDIR="`dirname "${0}"`"
88 SRCDIR="${TOPDIR}/src"
90 cleandir "${MKDIR}"
92 build build.mk
93 build subdir.mk
95 [ -f Makefile ] || automakefile