Target directory creation.

(eg. `bin/` is created for a `bin/hello` target)
This commit is contained in:
Luka Vandervelden 2019-05-28 19:05:17 +02:00
parent ac042da757
commit 10f3708e4e
11 changed files with 23 additions and 10 deletions

View File

@ -337,6 +337,19 @@ function main {
((target_index++)) ((target_index++))
done done
typeset -l -a target_directories
for target in "${targets[@]}"; do
directory="${target%/*}"
if [[ "$target" =~ .*/ ]] && ! has "${directory}" "${target_directories[@]}"; then
target_directories+=(${directory})
fi
done
for dir in ${target_directories[@]}; do
write "${dir}:"
write "\t${Q}mkdir -p ${dir}"
done
for dir in ${directories[@]}; do for dir in ${directories[@]}; do
write "\$(DESTDIR)${dir}:" write "\$(DESTDIR)${dir}:"
write "\t@echo '$(DIR ${dir})'" write "\t@echo '$(DIR ${dir})'"

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]}" write " ${depends[$target]} $(dirname $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]}" write "${target}: ${src[@]} ${depends[$target]} $(dirname $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}" write "${target}.install: ${target} $(dirname $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

@ -1,6 +1,6 @@
function library.build { function library.build {
write -n "${target}: ${target}.so ${target}.a" write -n "${target}: ${target}.so ${target}.a $(dirname $target)"
write write
write "\t@:" write "\t@:"

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" write " $S $(dirname $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

@ -15,7 +15,7 @@ function moon.build {
fi fi
if [[ -n "${S}" ]]; then if [[ -n "${S}" ]]; then
write " ${S}" write " ${S} $(dirname $target)"
write "\t@echo '$(MOON "${target}")'" write "\t@echo '$(MOON "${target}")'"
if [[ -z "${install[$target]}" ]]; then if [[ -z "${install[$target]}" ]]; then
write "\t${Q}echo '#!/usr/bin/env lua' > '${target}'" write "\t${Q}echo '#!/usr/bin/env lua' > '${target}'"

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" write -n "${target}: ${target%.o}.c $(dirname $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" write " $S $(dirname $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]}" write " ${depends[$target]} $(dirname $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]}" write " ${depends[$target]} $(dirname $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}"