summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mk.sh87
-rwxr-xr-xmkdeps.sh66
-rwxr-xr-xmkmf.sh118
3 files changed, 87 insertions, 184 deletions
diff --git a/mk.sh b/mk.sh
index c16f3f7b..0da9b5aa 100644
--- a/mk.sh
+++ b/mk.sh
@@ -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
+}
diff --git a/mkdeps.sh b/mkdeps.sh
deleted file mode 100755
index b97e84ce..00000000
--- a/mkdeps.sh
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/bin/sh
-
-TOPDIR=$(dirname $0)
-. ${TOPDIR}/mk.sh
-DEPS=${TOPDIR}/.deps
-SRCDIR=${TOPDIR}/src
-
-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"
- echo 'all:;@echo ok\n' > "${TOPDIR}/.deps.mk"
-}
-
-make_deps_mk
diff --git a/mkmf.sh b/mkmf.sh
deleted file mode 100755
index 6a6174ce..00000000
--- a/mkmf.sh
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/bin/sh
-
-. $(dirname $0)/mk.sh
-
-STANDARD=${1-9899-1990}
-
-if [ ! -f .dep/to-build ]; then
- rm -rf .dep .deps.mk .headers.mk
- mkdir -p .dep
- echo ${STANDARD} > .dep/to-build
-fi
-
-if [ ! -d src/${STANDARD} ]; then
- printf "Standard %s not found.\n" "${STANDARD}"
- exit 1
-fi
-
-if [ -f src/${STANDARD}/DEPS.mk ]; then
- for i in $(grep DEPS src/${STANDARD}/DEPS.mk | cut -d= -f2); do
- sh $0 $i
- done
-
- if grep -q 'CC' src/${STANDARD}/DEPS.mk; then
- grep 'CC' src/${STANDARD}/DEPS.mk > .cc.mk
- fi
-
- if grep -q 'CFLAGS' src/${STANDARD}/DEPS.mk; then
- grep 'CFLAGS' src/${STANDARD}/DEPS.mk | sed -e 's/CFLAGS/STD_CFLAGS/' > .cflags.mk
- fi
-fi
-
-rm -f .dep/${STANDARD}.*
-
-for i in $(find src/${STANDARD} -name \*.c) $(find src/${STANDARD} -name \*.ref); do
- printf '%s\t' "$i"
-
- FILE=$i
- BASE=$i
- if grep -q '^REFERENCE(' $FILE; then
- BASE=$(grep '^REFERENCE(' $i | m4 -DREFERENCE='src/$1')
- fi
- NAME=$(basename $BASE .c)
- TYPE=$(classify_source $BASE)
- HEADER=$(sed -ne 's/.*<\(.*\.h\)>.*/\1/p' $FILE)
- LIB=$(grep '^LINK(' $BASE | m4 -DLINK='lib$1')
- LIB=${LIB:-libc}
-
-
- printf ' <%s>\t' "${HEADER}"
- if [ ! -f .dep/${HEADER}.mk ]; then
- mkdir -p $(dirname .dep/${HEADER}.mk)
- printf '%s_SOURCES = ' $(echo ${HEADER} | tr /. _) > .dep/${HEADER}.mk
- fi
- printf ' \\\n\t%s' "$FILE" >> .dep/${HEADER}.mk
-
- if [ $FILE != $BASE ]; then
- printf ' \\\n\t%s' "$BASE" >> .dep/${HEADER}.mk
- continue
- fi
-
- printf ' %s.a\n' "${LIB}"
- if [ ${TYPE} = EXTERN -o ${TYPE} = FUNCTION -o ${TYPE} = TGFN ]; then
- printf '$(OBJDIR)/%s.o: %s $(INCDIR)/%s' ${NAME} $i ${HEADER}> .dep/${NAME}.o.mk
- for j in $(grep include $i); do
- : # TODO: add each header to depends file here
- done
- printf '\n\t$(CC) $(CFLAGS) -c %s -o $@\n\n' $i >> .dep/${NAME}.o.mk
-
- if [ ! -f .dep/${LIB}.a.mk ]; then
- printf '%s_OBJS =' ${LIB} > .dep/${LIB}.a.mk
- if [ ${LIB} = libc ]; then
- printf ' $(OBJDIR)/$(ARCH)-$(WORDSIZE).o' >> .dep/${LIB}.a.mk
- fi
- fi
- printf ' \\\n\t$(OBJDIR)/%s.o' ${NAME} >> .dep/${LIB}.a.mk
- fi
-done
-
-if [ $(cat .dep/to-build) = ${STANDARD} ]; then
- printf '.POSIX:\n\n' > .deps.mk
- printf 'default: all\n\n' >> .deps.mk
- printf 'include .cc.mk\n' >> .deps.mk
- printf 'include .cflags.mk\n' >> .deps.mk
- printf 'include config.mk\n\n' >> .deps.mk
- printf 'INCLUDES=-I$(INCDIR)\n' >> .deps.mk
- printf 'CFLAGS=$(INCLUDES) $(STD_CFLAGS) -g -fno-builtin -nostdinc -Werror -Wall -Wextra -fPIC\n\n' >> .deps.mk
-
- for i in .dep/lib*.a.mk; do
- LIB=$(basename $i .a.mk)
- cat $i >> .deps.mk
- printf '\n\n%s.a: $(%s_OBJS)\n\t$(AR) r $@ $?\n\n' $LIB $LIB >> .deps.mk
- done
-
- printf '.POSIX:\n\ninclude config.mk\n\n' > .headers.mk
- printf 'default: headers\n\n' >> .headers.mk
- for i in $(find .dep -name \*.h.mk); do
- HDR=$(echo $i | sed -e 's#^.*\.dep/##;s#\.mk$##')
- cat $i >> .headers.mk
- printf '\n\n$(INCDIR)/%s: $(%s_SOURCES)\n' ${HDR} $(echo $HDR | tr /. _) >> .headers.mk
- printf '\tsh mkh.sh $@ $(%s_SOURCES)\n\n' $(echo $HDR | tr /. _) >> .headers.mk
- printf ' $(INCDIR)/%s' ${HDR} >> .dep/all_headers.mk
- done
- printf 'headers:' >> .headers.mk
- cat .dep/all_headers.mk >> .headers.mk
-
- cat .dep/*.o.mk >> .deps.mk
-
- printf '$(OBJDIR)/$(ARCH)-$(WORDSIZE).o: src/9899-1990/nonstd/$(ARCH)-$(WORDSIZE).s\n\t$(CC) $(CFLAGS) -c $? -o $@\n\n' >> .deps.mk
- printf '$(OBJDIR):;mkdir -p $@\n' >> .deps.mk
-
- printf 'all: $(OBJDIR)' >> .deps.mk
- for i in .dep/lib*.a.mk; do
- printf ' %s' $(basename $i .mk) >> .deps.mk
- done
- printf '\n\n' >> .deps.mk
-
- rm -f .dep/to-build
-fi