Improved dependency handling for build-directories.

This commit is contained in:
Luka Vandervelden 2019-06-09 19:19:50 +02:00
parent 10f3708e4e
commit 7ffb3c8afa
10 changed files with 19 additions and 9 deletions

View File

@ -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 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' @echo ' SED > build.zsh'
$(Q)sed -e 's&@LIBDIR@&$(LIBDIR)&;s&@BINDIR@&$(BINDIR)&;s&@SHAREDIR@&$(SHAREDIR)&;' build.zsh.in > 'build.zsh' $(Q)sed -e 's&@LIBDIR@&$(LIBDIR)&;s&@BINDIR@&$(BINDIR)&;s&@SHAREDIR@&$(SHAREDIR)&;' build.zsh.in > 'build.zsh'
$(Q)chmod +x 'build.zsh' $(Q)chmod +x 'build.zsh'
@ -168,6 +168,8 @@ build/staticlib.zsh.uninstall:
@echo ' RM > $(SHAREDIR)/build.zsh/staticlib.zsh' @echo ' RM > $(SHAREDIR)/build.zsh/staticlib.zsh'
$(Q)rm -f '$(DESTDIR)$(SHAREDIR)/build.zsh/staticlib.zsh' $(Q)rm -f '$(DESTDIR)$(SHAREDIR)/build.zsh/staticlib.zsh'
build:
$(Q)mkdir -p build
$(DESTDIR)$(PREFIX): $(DESTDIR)$(PREFIX):
@echo ' DIR > $(PREFIX)' @echo ' DIR > $(PREFIX)'
$(Q)mkdir -p $(DESTDIR)$(PREFIX) $(Q)mkdir -p $(DESTDIR)$(PREFIX)

View File

@ -172,6 +172,14 @@ function duplicated {
return 1 return 1
} }
function dirdep {
dirname="$(dirname "$1")"
if [[ "$dirname" != "." ]]; then
echo "$dirname"
fi
}
for dir in "@SHAREDIR@/build.zsh" ./build; do for dir in "@SHAREDIR@/build.zsh" ./build; do
[[ -d "$dir" ]] && { [[ -d "$dir" ]] && {
for i in "$dir"/*.zsh; do for i in "$dir"/*.zsh; do

View File

@ -4,7 +4,7 @@ function binary.build {
for i in ${src[@]}; do for i in ${src[@]}; do
write -n " ${i%.*}.o" write -n " ${i%.*}.o"
done done
write " ${depends[$target]} $(dirname $target)" write " ${depends[$target]} $(dirdep $target)"
write "\t@echo '$(LD ${target})'" write "\t@echo '$(LD ${target})'"
write -n "\t$Q\$(CC) -o ${target} \$(LDFLAGS)" write -n "\t$Q\$(CC) -o ${target} \$(LDFLAGS)"
write -n " ${src[@]//.c/.o}" write -n " ${src[@]//.c/.o}"

View File

@ -1,6 +1,6 @@
function crystal.build { 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@echo '${fg_bold[magenta]} CR > ${fg_bold[white]}$target${reset_color}'"
write "\t${Q}crystal ${src[@]} -o '${target}'" write "\t${Q}crystal ${src[@]} -o '${target}'"

View File

@ -10,7 +10,7 @@ function header.install {
basename="$(basename "${target}")" basename="$(basename "${target}")"
fi fi
write "${target}.install: ${target} $(dirname $target)" write "${target}.install: ${target} $(dirdep $target)"
write "\t@echo '$(IN "${install}/${basename}")'" write "\t@echo '$(IN "${install}/${basename}")'"
write "\t${Q}mkdir -p '\$(DESTDIR)${install}'" write "\t${Q}mkdir -p '\$(DESTDIR)${install}'"
write "\t${Q}install -m0644 ${target} \$(DESTDIR)${install}/${basename}" write "\t${Q}install -m0644 ${target} \$(DESTDIR)${install}/${basename}"

View File

@ -11,7 +11,7 @@ function man.build {
write -n "${target}:" write -n "${target}:"
if [[ -n "${S}" ]]; then if [[ -n "${S}" ]]; then
write " $S $(dirname $target)" write " $S $(dirdep $target)"
write "\t@echo '$(SED "${target}" | sed 's|SED|MAN|')'" write "\t@echo '$(SED "${target}" | sed 's|SED|MAN|')'"
write "\t${Q}pandoc -s --from markdown --to man '$S' -o '${target}'" write "\t${Q}pandoc -s --from markdown --to man '$S' -o '${target}'"
fi fi

View File

@ -1,7 +1,7 @@
function ofile.build { function ofile.build {
local dirname="$(dirname "$target")" 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" | \ sed '/^#include "/!d;s/^#include "//;s/"$//' "${target%.o}.c" | \
while read h; do while read h; do

View File

@ -11,7 +11,7 @@ function script.build {
write -n "${target}:" write -n "${target}:"
if [[ -n "${S}" ]]; then if [[ -n "${S}" ]]; then
write " $S $(dirname $target)" write " $S $(dirdep $target)"
write "\t@echo '$(SED "${target}")'" write "\t@echo '$(SED "${target}")'"
write -n "\t${Q}sed -e '" write -n "\t${Q}sed -e '"
write -n "s&@LIBDIR@&\$(LIBDIR)&;" write -n "s&@LIBDIR@&\$(LIBDIR)&;"

View File

@ -4,7 +4,7 @@ function sharedlib.build {
for i in ${src[@]}; do for i in ${src[@]}; do
write -n " ${i%.*}.o" write -n " ${i%.*}.o"
done done
write " ${depends[$target]} $(dirname $target)" write " ${depends[$target]} $(dirdep $target)"
write "\t@echo '$(LD ${target})'" write "\t@echo '$(LD ${target})'"
write -n "\t$Q\$(CC) -o ${target} -shared \$(LDFLAGS)" write -n "\t$Q\$(CC) -o ${target} -shared \$(LDFLAGS)"
write -n " ${src[@]//.c/.o}" write -n " ${src[@]//.c/.o}"

View File

@ -4,7 +4,7 @@ function staticlib.build {
for i in ${src[@]} ${depends[@]}; do for i in ${src[@]} ${depends[@]}; do
write -n " ${i%.c}.o" write -n " ${i%.c}.o"
done done
write " ${depends[$target]} $(dirname $target)" write " ${depends[$target]} $(dirdep $target)"
write "\t@echo '$(LD ${target})'" write "\t@echo '$(LD ${target})'"
write -n "\t$Q\$(AR) rc '${target}'" write -n "\t$Q\$(AR) rc '${target}'"
write " ${src[@]//.c/.o}" write " ${src[@]//.c/.o}"