diff options
| author | Jakob Kaivo <jkk@ung.org> | 2020-08-14 21:20:03 -0400 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2020-08-14 21:20:03 -0400 |
| commit | 45277e43431b868192c5d313672a49ae54f67ed8 (patch) | |
| tree | 57239fda4f63407e4859d7e44594bfbe228b09e7 /mk | |
| parent | 73a32f2e680f715c4e98dab7460f3e7269ce4085 (diff) | |
begin new dependency builder
Diffstat (limited to 'mk')
| -rw-r--r-- | mk/deps.sh | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/mk/deps.sh b/mk/deps.sh new file mode 100644 index 00000000..351ea6ac --- /dev/null +++ b/mk/deps.sh @@ -0,0 +1,36 @@ +#!/bin/sh +SOURCE=$1 +BASE=$(basename $SOURCE .c) +LIB=$(grep LINK $SOURCE | tr -d 'LINK()') +test -z "$LIB" && LIB="c" + +if ! grep -q "^mk/$BASE.d:" mk/deps.mk 2>&1; then + printf 'all: mk/%s.d\n' $BASE >> mk/deps.mk + printf 'mk/%s.d: %s\n' $BASE $SOURCE >> mk/deps.mk + printf '\tsh mk/deps.sh %s\n\n' $SOURCE >> mk/deps.mk +fi + +if ! grep -q "include mk/$BASE.d" mk/all.mk 2>&1; then + printf 'include mk/%s.d\n' $BASE >> mk/all.mk +fi + +exec > mk/$BASE.d + +C=$(grep -F 'STDC(' $SOURCE | sed -e 's/STDC(//;s/,.*//;s/)$//g') +test -n "$C" && printf 'lib%s_C.%s: lib%s.a(%s.o)\n' $LIB $C $LIB $BASE + +P=$(grep -F 'POSIX(' $SOURCE | sed -e 's/POSIX(//;s/,.*//;s/)$//g') +test -n "$P" && printf 'lib%s_P.%s: lib%s.a(%s.o)\n' $LIB $P $LIB $BASE + +X=$(grep -F 'XOPEN(' $SOURCE | sed -e 's/XOPEN(//;s/,.*//;s/)$//g') +test -n "$X" && printf 'lib%s_X.%s: lib%s.a(%s.o)\n' $LIB $X $LIB $BASE + +printf 'lib%s.a(%s.o): $(OBJDIR)/%s.o\n' $LIB $BASE $BASE +printf '$(OBJDIR)/%s.o: %s\n' $BASE $SOURCE + +# includes + +printf '$(OBJDIR)/%s.o:\n' $BASE +printf '\t@echo [CC] $@\n' +printf '\t@mkdir -p $(@D)\n' +printf '\t@$(CC) -c -o $@ $(CFLAGS) %s\n' $SOURCE |
