From 7ffb3c8afa302a3b38237525bfd3a768dfb691ab Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Sun, 9 Jun 2019 19:19:50 +0200 Subject: [PATCH] Improved dependency handling for build-directories. --- Makefile | 4 +++- build.zsh.in | 8 ++++++++ build/binary.zsh | 2 +- build/crystal.zsh | 2 +- build/header.zsh | 2 +- build/man.zsh | 2 +- build/ofile.zsh | 2 +- build/script.zsh | 2 +- build/sharedlib.zsh | 2 +- build/staticlib.zsh | 2 +- 10 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 08d7c40..78be2b6 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ Q := @ all: build.zsh build/binary.zsh build/crystal.zsh build/header.zsh build/library.zsh build/man.zsh build/moon.zsh build/ofile.zsh build/script.zsh build/sharedlib.zsh build/staticlib.zsh @: -build.zsh: build.zsh.in +build.zsh: build.zsh.in . @echo ' SED > build.zsh' $(Q)sed -e 's&@LIBDIR@&$(LIBDIR)&;s&@BINDIR@&$(BINDIR)&;s&@SHAREDIR@&$(SHAREDIR)&;' build.zsh.in > 'build.zsh' $(Q)chmod +x 'build.zsh' @@ -168,6 +168,8 @@ build/staticlib.zsh.uninstall: @echo ' RM > $(SHAREDIR)/build.zsh/staticlib.zsh' $(Q)rm -f '$(DESTDIR)$(SHAREDIR)/build.zsh/staticlib.zsh' +build: + $(Q)mkdir -p build $(DESTDIR)$(PREFIX): @echo ' DIR > $(PREFIX)' $(Q)mkdir -p $(DESTDIR)$(PREFIX) diff --git a/build.zsh.in b/build.zsh.in index d2ff1fa..207ba50 100644 --- a/build.zsh.in +++ b/build.zsh.in @@ -172,6 +172,14 @@ function duplicated { return 1 } +function dirdep { + dirname="$(dirname "$1")" + + if [[ "$dirname" != "." ]]; then + echo "$dirname" + fi +} + for dir in "@SHAREDIR@/build.zsh" ./build; do [[ -d "$dir" ]] && { for i in "$dir"/*.zsh; do diff --git a/build/binary.zsh b/build/binary.zsh index 4dddbad..0fccf4c 100644 --- a/build/binary.zsh +++ b/build/binary.zsh @@ -4,7 +4,7 @@ function binary.build { for i in ${src[@]}; do write -n " ${i%.*}.o" done - write " ${depends[$target]} $(dirname $target)" + write " ${depends[$target]} $(dirdep $target)" write "\t@echo '$(LD ${target})'" write -n "\t$Q\$(CC) -o ${target} \$(LDFLAGS)" write -n " ${src[@]//.c/.o}" diff --git a/build/crystal.zsh b/build/crystal.zsh index dee1f7a..62c45c0 100644 --- a/build/crystal.zsh +++ b/build/crystal.zsh @@ -1,6 +1,6 @@ function crystal.build { - write "${target}: ${src[@]} ${depends[$target]} $(dirname $target)" + write "${target}: ${src[@]} ${depends[$target]} $(dirdep $target)" write "\t@echo '${fg_bold[magenta]} CR > ${fg_bold[white]}$target${reset_color}'" write "\t${Q}crystal ${src[@]} -o '${target}'" diff --git a/build/header.zsh b/build/header.zsh index 73c071d..0f54d4e 100644 --- a/build/header.zsh +++ b/build/header.zsh @@ -10,7 +10,7 @@ function header.install { basename="$(basename "${target}")" fi - write "${target}.install: ${target} $(dirname $target)" + write "${target}.install: ${target} $(dirdep $target)" write "\t@echo '$(IN "${install}/${basename}")'" write "\t${Q}mkdir -p '\$(DESTDIR)${install}'" write "\t${Q}install -m0644 ${target} \$(DESTDIR)${install}/${basename}" diff --git a/build/man.zsh b/build/man.zsh index 4b41af7..a31ec55 100644 --- a/build/man.zsh +++ b/build/man.zsh @@ -11,7 +11,7 @@ function man.build { write -n "${target}:" if [[ -n "${S}" ]]; then - write " $S $(dirname $target)" + write " $S $(dirdep $target)" write "\t@echo '$(SED "${target}" | sed 's|SED|MAN|')'" write "\t${Q}pandoc -s --from markdown --to man '$S' -o '${target}'" fi diff --git a/build/ofile.zsh b/build/ofile.zsh index 185a975..9f02334 100644 --- a/build/ofile.zsh +++ b/build/ofile.zsh @@ -1,7 +1,7 @@ function ofile.build { local dirname="$(dirname "$target")" - write -n "${target}: ${target%.o}.c $(dirname $target)" + write -n "${target}: ${target%.o}.c $(dirdep $target)" sed '/^#include "/!d;s/^#include "//;s/"$//' "${target%.o}.c" | \ while read h; do diff --git a/build/script.zsh b/build/script.zsh index 2827d7e..bc974a7 100644 --- a/build/script.zsh +++ b/build/script.zsh @@ -11,7 +11,7 @@ function script.build { write -n "${target}:" if [[ -n "${S}" ]]; then - write " $S $(dirname $target)" + write " $S $(dirdep $target)" write "\t@echo '$(SED "${target}")'" write -n "\t${Q}sed -e '" write -n "s&@LIBDIR@&\$(LIBDIR)&;" diff --git a/build/sharedlib.zsh b/build/sharedlib.zsh index 1992f84..4cff424 100644 --- a/build/sharedlib.zsh +++ b/build/sharedlib.zsh @@ -4,7 +4,7 @@ function sharedlib.build { for i in ${src[@]}; do write -n " ${i%.*}.o" done - write " ${depends[$target]} $(dirname $target)" + write " ${depends[$target]} $(dirdep $target)" write "\t@echo '$(LD ${target})'" write -n "\t$Q\$(CC) -o ${target} -shared \$(LDFLAGS)" write -n " ${src[@]//.c/.o}" diff --git a/build/staticlib.zsh b/build/staticlib.zsh index a6d6345..e4f44f4 100644 --- a/build/staticlib.zsh +++ b/build/staticlib.zsh @@ -4,7 +4,7 @@ function staticlib.build { for i in ${src[@]} ${depends[@]}; do write -n " ${i%.c}.o" done - write " ${depends[$target]} $(dirname $target)" + write " ${depends[$target]} $(dirdep $target)" write "\t@echo '$(LD ${target})'" write -n "\t$Q\$(AR) rc '${target}'" write " ${src[@]//.c/.o}"