Update. o/
- “help” virtual target added to Makefiles. That target also prints the current Makefile configuration, so that users can make sure they’re exporting the right variables. - Some fixes and minor new variables to help making tests or re-use automated rules, although those could be done in a completely clean way, and it’s presently not being done… - Better dependencies tracking with C-like binaries. - Maybe something else. Those were old modifications that I just pushed.master
parent
7be1efdd03
commit
dd63cd87e1
|
@ -0,0 +1,131 @@
|
|||
PACKAGE = 'build_zsh'
|
||||
VERSION = '0.2'
|
||||
|
||||
PREFIX := /usr/local
|
||||
BINDIR := $(PREFIX)/bin
|
||||
LIBDIR := $(PREFIX)/lib
|
||||
SHAREDIR := $(PREFIX)/share
|
||||
INCLUDEDIR := $(PREFIX)/include
|
||||
|
||||
CC := cc
|
||||
CFLAGS :=
|
||||
LDFLAGS :=
|
||||
|
||||
Q := @
|
||||
|
||||
all: build.zsh
|
||||
|
||||
build.zsh:
|
||||
|
||||
build.zsh.install: build.zsh
|
||||
@echo '[01;31m [IN] [01;37m$(BINDIR)/build.zsh[00m'
|
||||
$(Q)mkdir -p '$(DESTDIR)$(BINDIR)/build.zsh'
|
||||
$(Q)install -m0755 build.zsh $(DESTDIR)$(BINDIR)/build.zsh
|
||||
|
||||
build.zsh.clean:
|
||||
|
||||
build.zsh.uninstall:
|
||||
@echo '[01;37m [RM] [01;37m$(BINDIR)/build.zsh[00m'
|
||||
$(Q)rm -f '$(DESTDIR)$(BINDIR)/build.zsh'
|
||||
|
||||
$(DESTDIR)$(PREFIX):
|
||||
@echo '[01;35m [DIR] [01;37m$(PREFIX)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(PREFIX)
|
||||
$(DESTDIR)$(BINDIR):
|
||||
@echo '[01;35m [DIR] [01;37m$(BINDIR)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(BINDIR)
|
||||
$(DESTDIR)$(LIBDIR):
|
||||
@echo '[01;35m [DIR] [01;37m$(LIBDIR)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(LIBDIR)
|
||||
$(DESTDIR)$(SHAREDIR):
|
||||
@echo '[01;35m [DIR] [01;37m$(SHAREDIR)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(SHAREDIR)
|
||||
$(DESTDIR)$(INCLUDEDIR):
|
||||
@echo '[01;35m [DIR] [01;37m$(INCLUDEDIR)[00m'
|
||||
$(Q)mkdir -p $(DESTDIR)$(INCLUDEDIR)
|
||||
install: subdirs.install build.zsh.install
|
||||
@:
|
||||
|
||||
subdirs.install:
|
||||
|
||||
uninstall: subdirs.uninstall build.zsh.uninstall
|
||||
@:
|
||||
|
||||
subdirs.uninstall:
|
||||
|
||||
test: all subdirs subdirs.test
|
||||
@:
|
||||
|
||||
subdirs.test:
|
||||
|
||||
clean: build.zsh.clean
|
||||
|
||||
distclean: clean
|
||||
|
||||
dist: dist-gz dist-xz dist-bz2
|
||||
$(Q)rm -- $(PACKAGE)-$(VERSION)
|
||||
|
||||
distdir:
|
||||
$(Q)rm -rf -- $(PACKAGE)-$(VERSION)
|
||||
$(Q)ln -s -- . $(PACKAGE)-$(VERSION)
|
||||
|
||||
dist-gz: $(PACKAGE)-$(VERSION).tar.gz
|
||||
$(PACKAGE)-$(VERSION).tar.gz: distdir
|
||||
@echo '[01;33m [TAR] [01;37m$(PACKAGE)-$(VERSION).tar.gz[00m'
|
||||
$(Q)tar czf $(PACKAGE)-$(VERSION).tar.gz \
|
||||
$(PACKAGE)-$(VERSION)/build/binary.zsh \
|
||||
$(PACKAGE)-$(VERSION)/build/script.zsh \
|
||||
$(PACKAGE)-$(VERSION)/project.zsh \
|
||||
$(PACKAGE)-$(VERSION)/Makefile
|
||||
|
||||
dist-xz: $(PACKAGE)-$(VERSION).tar.xz
|
||||
$(PACKAGE)-$(VERSION).tar.xz: distdir
|
||||
@echo '[01;33m [TAR] [01;37m$(PACKAGE)-$(VERSION).tar.xz[00m'
|
||||
$(Q)tar cJf $(PACKAGE)-$(VERSION).tar.xz \
|
||||
$(PACKAGE)-$(VERSION)/build/binary.zsh \
|
||||
$(PACKAGE)-$(VERSION)/build/script.zsh \
|
||||
$(PACKAGE)-$(VERSION)/project.zsh \
|
||||
$(PACKAGE)-$(VERSION)/Makefile
|
||||
|
||||
dist-bz2: $(PACKAGE)-$(VERSION).tar.bz2
|
||||
$(PACKAGE)-$(VERSION).tar.bz2: distdir
|
||||
@echo '[01;33m [TAR] [01;37m$(PACKAGE)-$(VERSION).tar.bz2[00m'
|
||||
$(Q)tar cjf $(PACKAGE)-$(VERSION).tar.bz2 \
|
||||
$(PACKAGE)-$(VERSION)/build/binary.zsh \
|
||||
$(PACKAGE)-$(VERSION)/build/script.zsh \
|
||||
$(PACKAGE)-$(VERSION)/project.zsh \
|
||||
$(PACKAGE)-$(VERSION)/Makefile
|
||||
|
||||
help:
|
||||
@echo '[01;37m :: build_zsh-0.2[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mGeneric targets:[00m'
|
||||
@echo '[00m - [01;32mhelp [37mPrints this help message.[00m'
|
||||
@echo '[00m - [01;32mall [37mBuilds all targets.[00m'
|
||||
@echo '[00m - [01;32mdist [37mCreates tarballs of the files of the project.[00m'
|
||||
@echo '[00m - [01;32minstall [37mInstalls the project.[00m'
|
||||
@echo '[00m - [01;32mclean [37mRemoves compiled files.[00m'
|
||||
@echo '[00m - [01;32muninstall [37mDeinstalls the project.[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mCLI-modifiable variables:[00m'
|
||||
@echo ' - [01;34mCC [37m${CC}[00m'
|
||||
@echo ' - [01;34mCFLAGS [37m${CFLAGS}[00m'
|
||||
@echo ' - [01;34mLDFLAGS [37m${LDFLAGS}[00m'
|
||||
@echo ' - [01;34mDESTDIR [37m${DESTDIR}[00m'
|
||||
@echo ' - [01;34mPREFIX [37m${PREFIX}[00m'
|
||||
@echo ' - [01;34mBINDIR [37m${BINDIR}[00m'
|
||||
@echo ' - [01;34mLIBDIR [37m${LIBDIR}[00m'
|
||||
@echo ' - [01;34mSHAREDIR [37m${SHAREDIR}[00m'
|
||||
@echo ' - [01;34mINCLUDEDIR [37m${INCLUDEDIR}[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mProject targets: [00m'
|
||||
@echo ' - [01;33mbuild.zsh [37mscript[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mMakefile options:[00m'
|
||||
@echo ' - gnu: true'
|
||||
@echo ' - colors: true'
|
||||
@echo ''
|
||||
@echo '[01;37mRebuild the Makefile with:[00m'
|
||||
@echo ' zsh ./build.zsh -c -g'
|
||||
.PHONY: all subdirs clean distclean dist install uninstall help
|
||||
|
69
build.zsh
69
build.zsh
|
@ -5,6 +5,8 @@
|
|||
# (stuff *will* break if you add non-C things as targets)
|
||||
# - Clean some more (or a lot). I mean, this script could even be reused if
|
||||
# it were cleaner, more readable and somewhat more documented.
|
||||
# - Using subdirs creates trouble. Really. Don’t do it unless it’s for
|
||||
# completely separate, independent sub-projects.
|
||||
#
|
||||
# WARNINGS and LIMITATIONS:
|
||||
# - Using a relative path in DESTDIR= *will* fail.
|
||||
|
@ -108,12 +110,6 @@ function get_distfiles {
|
|||
fi
|
||||
done
|
||||
|
||||
for target in ${targets[@]}; do
|
||||
if exists "${type[$target]}.distfiles"; then
|
||||
"${type[$target]}.distfiles"
|
||||
fi
|
||||
done
|
||||
|
||||
for dir in ${subdirs[@]}; do
|
||||
(
|
||||
unset dist sources depends subdirs
|
||||
|
@ -221,9 +217,11 @@ function main {
|
|||
write "Q := @"
|
||||
write
|
||||
|
||||
write -n "all: "
|
||||
(( ${#targets[@]} > 0 )) && write -n " ${targets[@]}"
|
||||
(( ${#subdirs[@]} > 0 )) && write -n " subdirs"
|
||||
if [[ -z "${all}" ]] || (( ${#all[@]} == 0 )); then
|
||||
all=(${targets[@]} $((( ${#subdirs[@]} > 0 )) && echo subdirs))
|
||||
fi
|
||||
|
||||
write -n "all: ${all[@]}"
|
||||
|
||||
if $gnu; then
|
||||
write "\n"
|
||||
|
@ -328,6 +326,9 @@ function main {
|
|||
write -n " ${target}.test"
|
||||
fi
|
||||
done
|
||||
for target in ${tests[@]}; do
|
||||
write -n " ${target}"
|
||||
done
|
||||
write "\n\t@:\n"
|
||||
|
||||
write "subdirs.test:"
|
||||
|
@ -393,6 +394,52 @@ function main {
|
|||
done
|
||||
fi
|
||||
|
||||
write "help:"
|
||||
|
||||
if [[ -n "$package" ]]; then
|
||||
write " @echo '${fg_bold[white]} :: $package-$version${reset_color}'"
|
||||
write " @echo ''"
|
||||
fi
|
||||
|
||||
write " @echo '${fg_bold[white]}Generic targets:${reset_color}'"
|
||||
typeset -la help
|
||||
help=(
|
||||
help "Prints this help message."
|
||||
all "Builds all targets."
|
||||
dist "Creates tarballs of the files of the project."
|
||||
install "Installs the project."
|
||||
clean "Removes compiled files."
|
||||
uninstall "Deinstalls the project."
|
||||
)
|
||||
for rule message in ${help[@]}; do
|
||||
printf " @echo '${reset_color} - ${fg_bold[green]}%-14s${fg[white]}$message${reset_color}'\n" \
|
||||
"$rule" >> $Makefile
|
||||
done
|
||||
|
||||
write " @echo ''"
|
||||
write " @echo '${fg_bold[white]}CLI-modifiable variables:${reset_color}'"
|
||||
for VAR in CC CFLAGS LDFLAGS DESTDIR; 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
|
||||
|
||||
write " @echo ''"
|
||||
write " @echo '${fg_bold[white]}Project targets: ${reset_color}'"
|
||||
for T in ${targets[@]}; do
|
||||
printf " @echo ' - ${fg_bold[yellow]}%-14s${fg[white]}${type[$T]}${reset_color}'\n" "$T" >> $Makefile
|
||||
done
|
||||
|
||||
write " @echo ''"
|
||||
write " @echo '${fg_bold[white]}Makefile options:${reset_color}'"
|
||||
printf " @echo ' - %-14s$gnu'\n" "gnu:" >> $Makefile
|
||||
printf " @echo ' - %-14s$colors'\n" "colors:" >> $Makefile
|
||||
|
||||
write " @echo ''"
|
||||
write " @echo '${fg_bold[white]}Rebuild the Makefile with:${reset_color}'"
|
||||
write " @echo ' zsh ./build.zsh$($colors && echo -n " -c")$($gnu && echo -n " -g")'"
|
||||
|
||||
for i in ${subdirs[@]}; do
|
||||
(
|
||||
cd $i
|
||||
|
@ -403,7 +450,7 @@ function main {
|
|||
)
|
||||
done
|
||||
|
||||
write ".PHONY: all subdirs clean distclean dist install uninstall"
|
||||
write ".PHONY: all subdirs clean distclean dist install uninstall help"
|
||||
write
|
||||
}
|
||||
|
||||
|
@ -411,10 +458,12 @@ export Makefile=Makefile
|
|||
export MAKE='$(MAKE)'
|
||||
export Q='$(Q)'
|
||||
export gnu=false
|
||||
export colors=false
|
||||
|
||||
while (($# > 0)); do
|
||||
case "$1" in
|
||||
-c|--colors)
|
||||
export colors=true
|
||||
autoload -U colors
|
||||
colors
|
||||
;;
|
||||
|
|
|
@ -6,21 +6,27 @@ function binary.build {
|
|||
done
|
||||
write " ${depends[$target]}"
|
||||
write "\t@echo '$(LD ${target})'"
|
||||
write "\t$Q\$(CC) -o ${target} \$(LDFLAGS) ${ldflags[$target]} ${src[@]//.c/.o}"
|
||||
write -n "\t$Q\$(CC) -o ${target} \$(LDFLAGS)"
|
||||
write -n " ${src[@]//.c/.o}"
|
||||
write " ${ldflags[$target]}"
|
||||
write
|
||||
|
||||
for i in ${src[@]}; do
|
||||
local dirname="$(dirname "$i")"
|
||||
|
||||
write -n "${i%.c}.o: ${i}"
|
||||
|
||||
for h in *.h; do
|
||||
if grep -q "#include \"$h\"" $i; then
|
||||
write -n " $h"
|
||||
fi
|
||||
sed '/^#include "/!d;s/^#include "//;s/"$//' $i | while read h; do
|
||||
h="$dirname/$h"
|
||||
|
||||
write -n " $h"
|
||||
done
|
||||
write
|
||||
|
||||
write "\t@echo '$(CC ${i%.c}.o)'"
|
||||
write "\t$Q\$(CC) \$(CFLAGS) ${cflags[$target]} -c ${i}"
|
||||
write -n "\t$Q\$(CC) \$(CFLAGS) ${cflags[$target]} -c ${i} "
|
||||
write -n " ${cflags[$target]}"
|
||||
write " -o ${i%.c}.o"
|
||||
write
|
||||
done
|
||||
}
|
||||
|
@ -29,6 +35,7 @@ function binary.install {
|
|||
local install="${install[$target]:-\$(BINDIR)}"
|
||||
write "${target}.install: ${target}"
|
||||
write "\t@echo '$(IN "${install}/${target}")'"
|
||||
write "\t${Q}mkdir -p '\$(DESTDIR)${install}/${target}'"
|
||||
write "\t${Q}install -m0755 ${target} \$(DESTDIR)${install}/${target}"
|
||||
write
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
package=build_zsh
|
||||
version=0.1
|
||||
version=0.2
|
||||
|
||||
targets=(build.zsh)
|
||||
type[build.zsh]=script
|
||||
|
|
Loading…
Reference in New Issue