diff --git a/Makefile b/Makefile index f10476e..a13df16 100644 --- a/Makefile +++ b/Makefile @@ -8,12 +8,6 @@ SHAREDIR := $(PREFIX)/share INCLUDEDIR := $(PREFIX)/include MANDIR := $(SHAREDIR)/man -CC := cc -AR := ar -RANLIB := ranlib -CFLAGS := -LDFLAGS := - Q := @ all: build.zsh build/binary.zsh build/crystal.zsh build/header.zsh build/library.zsh build/livescript.zsh build/man.zsh build/moon.zsh build/ofile.zsh build/sass.zsh build/scdocman.zsh build/script.zsh build/sharedlib.zsh build/staticlib.zsh @@ -320,10 +314,6 @@ help: @echo ' - uninstall Deinstalls the project.' @echo '' @echo 'CLI-modifiable variables:' - @echo ' - CC ${CC}' - @echo ' - CFLAGS ${CFLAGS}' - @echo ' - LDFLAGS ${LDFLAGS}' - @echo ' - DESTDIR ${DESTDIR}' @echo ' - PREFIX ${PREFIX}' @echo ' - BINDIR ${BINDIR}' @echo ' - LIBDIR ${LIBDIR}' diff --git a/build.zsh.in b/build.zsh.in index 2da108a..a92e4c4 100644 --- a/build.zsh.in +++ b/build.zsh.in @@ -75,6 +75,18 @@ function has { return 1 } +function has_array_key { + local element="$1" + + shift 1 + + for key value ($@) { + [[ "$key" == "$element" ]] && return 0 + } + + return 1 +} + # Specialized helpers function get_distfiles { @@ -211,13 +223,6 @@ function main { write - write "CC := ${CC:-cc}" - write "AR := ${AR:-ar}" - write "RANLIB := ${RANLIB:-ranlib}" - write "CFLAGS := ${CFLAGS}" - write "LDFLAGS := ${LDFLAGS}" - write - write "Q := @" write @@ -444,15 +449,12 @@ function main { write " @echo ''" write " @echo '${fg_bold[white]}CLI-modifiable variables:${reset_color}'" - for VAR in CC CFLAGS LDFLAGS DESTDIR; do + for VAR __ in ${variables}; do printf " @echo ' - ${fg_bold[blue]}%-14s${fg[white]} \${$VAR}${reset_color}'\n" "$VAR" >> $Makefile done for VAR __ in ${prefixes}; do printf " @echo ' - ${fg_bold[blue]}%-14s${fg[white]} \${$VAR}${reset_color}'\n" "$VAR" >> $Makefile done - for VAR __ in ${variables}; do - printf " @echo ' - ${fg_bold[blue]}%-14s${fg[white]} \${$VAR}${reset_color}'\n" "$VAR" >> $Makefile - done write " @echo ''" write " @echo '${fg_bold[white]}Project targets: ${reset_color}'" diff --git a/build/binary.zsh b/build/binary.zsh index ac70975..b42577f 100644 --- a/build/binary.zsh +++ b/build/binary.zsh @@ -1,4 +1,18 @@ +function binary.prelude { + has_array_key CC $variables || \ + variables+=(CC "cc") + has_array_key CXX $variables || \ + variables+=(CXX "c++") + has_array_key LD $variables || \ + variables+=(LD "\${CC}") + + for variable in CFLAGS CXXFLAGS LDFLAGS; do + has_array_key $variable $variables || \ + variables+=($variable " ") + done +} + function binary.build { write -n "${target}:" for i in ${src[@]}; do diff --git a/build/crystal.zsh b/build/crystal.zsh index 01077f7..80a025d 100644 --- a/build/crystal.zsh +++ b/build/crystal.zsh @@ -1,15 +1,6 @@ function crystal.prelude { - local has_crflags=false - - for variable value in ${variables[@]}; do - if [[ "$variable" == "CRFLAGS" ]]; then - has_crflags=true - break - fi - done - - if ! $has_crflags; then + if ! has_array_key CRFLAGS; then variables+=(CRFLAGS "--release") fi } diff --git a/build/library.zsh b/build/library.zsh index 6ad88f9..5e4291b 100644 --- a/build/library.zsh +++ b/build/library.zsh @@ -1,4 +1,8 @@ +function library.prelude { + binary.prelude "$@" +} + function library.build { write -n "${target}: ${target}.so ${target}.a $(dirdep $target)" write diff --git a/build/ofile.zsh b/build/ofile.zsh index 1136e69..c8fe8ca 100644 --- a/build/ofile.zsh +++ b/build/ofile.zsh @@ -1,4 +1,8 @@ +function ofile.prelude { + binary.prelude "$@" +} + function ofile.build { local dirname="$(dirname "$target")" write -n "${target}: ${target%.o}.c $(dirdep $target "${target%.o}.c ${sources[$target]}" "${depends[@target]}")"