diff options
| author | Jakob Kaivo <jkk@ung.org> | 2019-02-09 08:26:00 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2019-02-09 08:26:00 -0500 |
| commit | 984f1e8149ac2f2b66937d2d4964120e7be7ec05 (patch) | |
| tree | 6defa6858496b65d38d62d6349ee7a017acba5a6 /mk.sh | |
| parent | 90412217af76682538c8f32d67faaefaba383436 (diff) | |
merge mkmf/mkdeps functionality into mk.sh
Diffstat (limited to 'mk.sh')
| -rw-r--r-- | mk.sh | 87 |
1 files changed, 87 insertions, 0 deletions
@@ -1,5 +1,9 @@ #!/bin/sh +TOPDIR=$(dirname $0) +DEPS=${TOPDIR}/.deps +SRCDIR=${TOPDIR}/src + classify_source () { NAME=$(basename $1 .c) @@ -97,3 +101,86 @@ get_declaration () { esac } + +stdc_base() { + (grep 'STDC(' $1 | m4 -DSTDC='$1') || echo 0 +} + +posix_base() { + (grep 'POSIX(' $1 | m4 -DPOSIX='$1') || echo 0 +} + +xopen_base() { + (grep 'XOPEN(' $1 | m4 -DXOPEN='$1') || echo 0 +} + +find_all() { + rm -rf "${DEPS}" + mkdir -p "${DEPS}" + find "${SRCDIR}" -name \*.c > "${DEPS}/all.c" + find "${SRCDIR}" -name \*.ref > "${DEPS}/all.ref" + grep '#include <.*>' $(cat "${DEPS}/all.c" "${DEPS}/all.ref") | + sed 's/^.*<\(.*\.h\)>.*/\1/' | sort -u > "${DEPS}/all.h" +} + +version_sources() { + for file in $(cat "${DEPS}/all.c" "${DEPS}/all.ref"); do + printf '%s\n' "$file" + c_version=$(stdc_base "${file}") + p_version=$(posix_base "${file}") + x_version=$(xopen_base "${file}") + + if [ -n "${c_version}" ]; then + mkdir -p "${DEPS}/c.${c_version}" + echo "$file" >> "${DEPS}/c.${c_version}/sources" + fi + + if [ -n "${p_version}" ]; then + mkdir -p "${DEPS}/p.${p_version}" + echo "$file" >> "${DEPS}/p.${p_version}/sources" + fi + + if [ -n "${x_version}" ]; then + mkdir -p "${DEPS}/x.${x_version}" + echo "$file" >> "${DEPS}/x.${x_version}/sources" + fi + done +} + +make_headers_mk() { + rm -f "${TOPDIR}/.headers.mk" + printf '.POSIX:\n.DEFAULT: headers\ninclude config.mk\n\n' > "${TOPDIR}/.headers.mk" + + for header in $(cat "${DEPS}/all.h"); do + printf 'Building dependencies for <%s>\n' "$header" + printf '$(INCDIR)/%s: ' "$header" >> "${TOPDIR}/.headers.mk" + #printf '$(INCDIR)/%s: $$(grep -l "#include <%s>" $$(cat %s/all.c %s/all.ref)\n' "$header" "$header" "${DEPS}" "${DEPS}" >> "${TOPDIR}/.headers.mk" + grep -l "#include <${header}>" $(cat "${DEPS}/all.c" "${DEPS}/all.ref") | sed -e "s#${SRCDIR}#\$(SRCDIR)#" | tr '\n' ' ' >> "${TOPDIR}/.headers.mk" + printf '\n\tsh mkh.sh $@\n\n' >> "${TOPDIR}/.headers.mk" + done + + printf 'headers: ' >> "${TOPDIR}/.headers.mk" + for header in $(cat "${DEPS}/all.h"); do + printf ' \\\n\t$(INCDIR)/%s' "$header" >> "${TOPDIR}/.headers.mk" + done + + printf '\n' >> "${TOPDIR}/.headers.mk" +} + +make_deps_mk() { + rm -f "${TOPDIR}/.deps.mk" + printf '.POSIX:\n.DEFAULT: all\ninclude config.mk\n\n' > "${TOPDIR}/.deps.mk" + + for file in $(cat "${DEPS}/all.c"); do + printf 'Building dependencies from %s\n' "$file" + type=$(classify_source "${file}") + + if [ ${type} = EXTERN -o ${type} = TGFN -o ${type} = FUNCTION ]; then + printf '$(OBJDIR)/%s.o: $(SRCDIR)/%s' "$(basename $file .c)" "$file" >> "${TOPDIR}/.deps.mk" + for header in $(grep '#include' "${file}"); do + printf ' \\\n\t$(INCDIR)/%s' "$header" >> "${TOPDIR}/.deps.mk" + done + printf '\n\t$(CC) $(CFLAGS) -c $(SRCDIR)/%s -o $@\n\n' "$file" >> "${TOPDIR}/.deps.mk" + fi + done +} |
