Libraries are now built properly (both static and dynamic, with symlinks).

This commit is contained in:
Luka Vandervelden 2015-04-07 10:12:17 +02:00
parent b581f07608
commit 41b495b0e8
6 changed files with 192 additions and 33 deletions

View File

@ -1,5 +1,5 @@
PACKAGE = 'build_zsh' PACKAGE = 'build_zsh'
VERSION = '0.2' VERSION = '0.2.1'
PREFIX := /usr/local PREFIX := /usr/local
BINDIR := $(PREFIX)/bin BINDIR := $(PREFIX)/bin
@ -8,12 +8,14 @@ SHAREDIR := $(PREFIX)/share
INCLUDEDIR := $(PREFIX)/include INCLUDEDIR := $(PREFIX)/include
CC := cc CC := cc
AR := ar
RANLIB := ranlib
CFLAGS := CFLAGS :=
LDFLAGS := LDFLAGS :=
Q := @ Q := @
all: build.zsh build/binary.zsh build/library.zsh build/ofile.zsh build/script.zsh all: build.zsh build/binary.zsh build/library.zsh build/ofile.zsh build/script.zsh build/sharedlib.zsh build/staticlib.zsh
build.zsh: build.zsh:
@ -80,6 +82,32 @@ build/script.zsh.uninstall:
@echo ' [RM] $(SHAREDIR)/build.zsh/script.zsh' @echo ' [RM] $(SHAREDIR)/build.zsh/script.zsh'
$(Q)rm -f '$(DESTDIR)$(SHAREDIR)/build.zsh/script.zsh' $(Q)rm -f '$(DESTDIR)$(SHAREDIR)/build.zsh/script.zsh'
build/sharedlib.zsh:
build/sharedlib.zsh.install: build/sharedlib.zsh
@echo ' [IN] $(SHAREDIR)/build.zsh/sharedlib.zsh'
$(Q)mkdir -p '$(DESTDIR)$(SHAREDIR)/build.zsh'
$(Q)install -m0755 build/sharedlib.zsh $(DESTDIR)$(SHAREDIR)/build.zsh/sharedlib.zsh
build/sharedlib.zsh.clean:
build/sharedlib.zsh.uninstall:
@echo ' [RM] $(SHAREDIR)/build.zsh/sharedlib.zsh'
$(Q)rm -f '$(DESTDIR)$(SHAREDIR)/build.zsh/sharedlib.zsh'
build/staticlib.zsh:
build/staticlib.zsh.install: build/staticlib.zsh
@echo ' [IN] $(SHAREDIR)/build.zsh/staticlib.zsh'
$(Q)mkdir -p '$(DESTDIR)$(SHAREDIR)/build.zsh'
$(Q)install -m0755 build/staticlib.zsh $(DESTDIR)$(SHAREDIR)/build.zsh/staticlib.zsh
build/staticlib.zsh.clean:
build/staticlib.zsh.uninstall:
@echo ' [RM] $(SHAREDIR)/build.zsh/staticlib.zsh'
$(Q)rm -f '$(DESTDIR)$(SHAREDIR)/build.zsh/staticlib.zsh'
$(DESTDIR)$(PREFIX): $(DESTDIR)$(PREFIX):
@echo ' [DIR] $(PREFIX)' @echo ' [DIR] $(PREFIX)'
$(Q)mkdir -p $(DESTDIR)$(PREFIX) $(Q)mkdir -p $(DESTDIR)$(PREFIX)
@ -95,12 +123,12 @@ $(DESTDIR)$(SHAREDIR):
$(DESTDIR)$(INCLUDEDIR): $(DESTDIR)$(INCLUDEDIR):
@echo ' [DIR] $(INCLUDEDIR)' @echo ' [DIR] $(INCLUDEDIR)'
$(Q)mkdir -p $(DESTDIR)$(INCLUDEDIR) $(Q)mkdir -p $(DESTDIR)$(INCLUDEDIR)
install: subdirs.install build.zsh.install build/binary.zsh.install build/library.zsh.install build/ofile.zsh.install build/script.zsh.install install: subdirs.install build.zsh.install build/binary.zsh.install build/library.zsh.install build/ofile.zsh.install build/script.zsh.install build/sharedlib.zsh.install build/staticlib.zsh.install
@: @:
subdirs.install: subdirs.install:
uninstall: subdirs.uninstall build.zsh.uninstall build/binary.zsh.uninstall build/library.zsh.uninstall build/ofile.zsh.uninstall build/script.zsh.uninstall uninstall: subdirs.uninstall build.zsh.uninstall build/binary.zsh.uninstall build/library.zsh.uninstall build/ofile.zsh.uninstall build/script.zsh.uninstall build/sharedlib.zsh.uninstall build/staticlib.zsh.uninstall
@: @:
subdirs.uninstall: subdirs.uninstall:
@ -110,7 +138,7 @@ test: all subdirs subdirs.test
subdirs.test: subdirs.test:
clean: build.zsh.clean build/binary.zsh.clean build/library.zsh.clean build/ofile.zsh.clean build/script.zsh.clean clean: build.zsh.clean build/binary.zsh.clean build/library.zsh.clean build/ofile.zsh.clean build/script.zsh.clean build/sharedlib.zsh.clean build/staticlib.zsh.clean
distclean: clean distclean: clean
@ -129,6 +157,8 @@ $(PACKAGE)-$(VERSION).tar.gz: distdir
$(PACKAGE)-$(VERSION)/build/library.zsh \ $(PACKAGE)-$(VERSION)/build/library.zsh \
$(PACKAGE)-$(VERSION)/build/ofile.zsh \ $(PACKAGE)-$(VERSION)/build/ofile.zsh \
$(PACKAGE)-$(VERSION)/build/script.zsh \ $(PACKAGE)-$(VERSION)/build/script.zsh \
$(PACKAGE)-$(VERSION)/build/sharedlib.zsh \
$(PACKAGE)-$(VERSION)/build/staticlib.zsh \
$(PACKAGE)-$(VERSION)/project.zsh \ $(PACKAGE)-$(VERSION)/project.zsh \
$(PACKAGE)-$(VERSION)/Makefile $(PACKAGE)-$(VERSION)/Makefile
@ -140,6 +170,8 @@ $(PACKAGE)-$(VERSION).tar.xz: distdir
$(PACKAGE)-$(VERSION)/build/library.zsh \ $(PACKAGE)-$(VERSION)/build/library.zsh \
$(PACKAGE)-$(VERSION)/build/ofile.zsh \ $(PACKAGE)-$(VERSION)/build/ofile.zsh \
$(PACKAGE)-$(VERSION)/build/script.zsh \ $(PACKAGE)-$(VERSION)/build/script.zsh \
$(PACKAGE)-$(VERSION)/build/sharedlib.zsh \
$(PACKAGE)-$(VERSION)/build/staticlib.zsh \
$(PACKAGE)-$(VERSION)/project.zsh \ $(PACKAGE)-$(VERSION)/project.zsh \
$(PACKAGE)-$(VERSION)/Makefile $(PACKAGE)-$(VERSION)/Makefile
@ -151,11 +183,13 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir
$(PACKAGE)-$(VERSION)/build/library.zsh \ $(PACKAGE)-$(VERSION)/build/library.zsh \
$(PACKAGE)-$(VERSION)/build/ofile.zsh \ $(PACKAGE)-$(VERSION)/build/ofile.zsh \
$(PACKAGE)-$(VERSION)/build/script.zsh \ $(PACKAGE)-$(VERSION)/build/script.zsh \
$(PACKAGE)-$(VERSION)/build/sharedlib.zsh \
$(PACKAGE)-$(VERSION)/build/staticlib.zsh \
$(PACKAGE)-$(VERSION)/project.zsh \ $(PACKAGE)-$(VERSION)/project.zsh \
$(PACKAGE)-$(VERSION)/Makefile $(PACKAGE)-$(VERSION)/Makefile
help: help:
@echo ' :: build_zsh-0.2' @echo ' :: build_zsh-0.2.1'
@echo '' @echo ''
@echo 'Generic targets:' @echo 'Generic targets:'
@echo ' - help Prints this help message.' @echo ' - help Prints this help message.'

View File

@ -61,6 +61,19 @@ function TAR {
echo "${fg_bold[yellow]} [TAR] ${fg_bold[white]}$@${reset_color}" echo "${fg_bold[yellow]} [TAR] ${fg_bold[white]}$@${reset_color}"
} }
# Generic helpers
function has {
local elem="$1"
shift 1
for i in "$@"; do
[[ "$i" == "$elem" ]] && return 0
done
return 1
}
# Specialized helpers # Specialized helpers
function subdirs { function subdirs {
@ -215,6 +228,8 @@ function main {
write write
write "CC := ${CC:-cc}" write "CC := ${CC:-cc}"
write "AR := ${AR:-ar}"
write "RANLIB := ${RANLIB:-ranlib}"
write "CFLAGS := ${CFLAGS}" write "CFLAGS := ${CFLAGS}"
write "LDFLAGS := ${LDFLAGS}" write "LDFLAGS := ${LDFLAGS}"
write write
@ -234,10 +249,18 @@ function main {
write "\n\t@:\n" write "\n\t@:\n"
fi fi
typeset -l -a exported_rules
local target_index=1 local target_index=1
while (($target_index <= ${#targets[@]})); do while (($target_index <= ${#targets[@]})); do
local target="${targets[$target_index]}" local target="${targets[$target_index]}"
if has "${target}" "${exported_rules[@]}"; then
((target_index++))
continue
else
exported_rules+=("$target")
fi
typeset -a src typeset -a src
src=($(echo ${sources[$target]})) src=($(echo ${sources[$target]}))
local installdir="${install[$target]}" local installdir="${install[$target]}"

View File

@ -1,45 +1,33 @@
function library.build { function library.build {
write -n "${target}:" write -n "${target}: ${target}.so ${target}.a"
for i in ${src[@]}; do
write -n " ${i%.*}.o"
done
write " ${depends[$target]}"
write "\t@echo '$(LD ${target})'"
write -n "\t$Q\$(CC) -o ${target} -shared \$(LDFLAGS)"
write -n " ${src[@]//.c/.o}"
write " ${ldflags[$target]}"
write write
for i in ${src[@]}; do targets+=("${target}.so" "${target}.a")
targets+=("${i%.c}.o")
type[${i%.c}.o]=ofile for i in ${target}.so ${target}.a; do
auto[${i%.c}.o]=true auto[$i]=true
cflags[${i%.c}.o]="-fPIC ${cflags[$target]}" sources[$i]="${sources[$target]}"
cflags[$i]="-fPIC ${cflags[$target]}"
ldflags[$i]="${ldflags[$target]}"
done done
type[${target}.so]=sharedlib
type[${target}.a]=staticlib
} }
function library.install { function library.install {
local install="${install[$target]:-\$(LIBDIR)}" write "${target}.install: ${target}.so.install ${target}.a.install"
write "${target}.install: ${target}"
write "\t@echo '$(IN "${install}/${target}")'"
write "\t${Q}mkdir -p '\$(DESTDIR)${install}'"
write "\t${Q}install -m0755 ${target} \$(DESTDIR)${install}/${target}"
write write
} }
function library.uninstall { function library.uninstall {
local install="${install[$target]:-\$(LIBDIR)}" write "${target}.uninstall: ${target}.so.uninstall ${target}.a.uninstall"
write "${target}.uninstall:"
write "\t@echo '$(RM ${install}/${target})'"
write "\t${Q}rm -f '\$(DESTDIR)${install}/${target}'"
write write
} }
function library.clean { function library.clean {
write "${target}.clean:" write "${target}.clean: ${target}.so.clean ${target}.a.clean"
write "\t@echo '$(RM ${target})'"
write "\t${Q}rm -f ${target}"
write write
} }

68
build/sharedlib.zsh Normal file
View File

@ -0,0 +1,68 @@
function sharedlib.build {
write -n "${target}:"
for i in ${src[@]}; do
write -n " ${i%.*}.o"
done
write " ${depends[$target]}"
write "\t@echo '$(LD ${target})'"
write -n "\t$Q\$(CC) -o ${target} -shared \$(LDFLAGS)"
write -n " ${src[@]//.c/.o}"
write " ${ldflags[$target]}"
write
for i in ${src[@]}; do
targets+=("${i%.c}.o")
type[${i%.c}.o]=ofile
auto[${i%.c}.o]=true
cflags[${i%.c}.o]="${cflags[$target]}"
ldflags[${i%.c}.o]="${ldflags[$target]}"
done
}
function sharedlib.install {
local install="${install[$target]:-\$(LIBDIR)}"
typeset -l -a symlinks
local realtarget="${target}.${version}"
for i in ".${version%.*}" ".${version%.*.*}" ""; do
symlinks+=("${target}${i}")
done
write "${target}.install: ${target}"
write "\t@echo '$(IN "${install}/${realtarget}")'"
write "\t${Q}mkdir -p '\$(DESTDIR)${install}'"
write "\t${Q}install -m0755 ${target} \$(DESTDIR)${install}/${realtarget}"
for l in ${symlinks[@]}; do
write "\t@echo '$(LN "${install}/${l}")'"
write -n "\t${Q}ln -sf '${install}/${realtarget}' "
write "'\$(DESTDIR)/${install}/$l'"
done
write
}
function sharedlib.uninstall {
local install="${install[$target]:-\$(LIBDIR)}"
typeset -l -a symlinks
local realtarget="${target}.${version}"
for i in ".${version%.*}" ".${version%.*.*}" ""; do
symlinks+=("${target}${i}")
done
write "${target}.uninstall:"
for target in ${realtarget} ${symlinks[@]}; do
write "\t@echo '$(RM ${install}/${target})'"
write "\t${Q}rm -f '\$(DESTDIR)${install}/${target}'"
done
write
}
function sharedlib.clean {
write "${target}.clean:"
write "\t@echo '$(RM ${target})'"
write "\t${Q}rm -f ${target}"
write
}

46
build/staticlib.zsh Normal file
View File

@ -0,0 +1,46 @@
function staticlib.build {
write -n "${target}:"
for i in ${src[@]} ${depends[@]}; do
write -n " ${i%.c}.o"
done
write " ${depends[$target]}"
write "\t@echo '$(LD ${target})'"
write -n "\t$Q\$(AR) rc '${target}'"
write " ${src[@]//.c/.o}"
write
for i in ${src[@]}; do
targets+=("${i%.c}.o")
type[${i%.c}.o]=ofile
auto[${i%.c}.o]=true
cflags[${i%.c}.o]="${cflags[$target]}"
done
}
function staticlib.install {
local install="${install[$target]:-\$(LIBDIR)}"
local basename="$(basename "${target}")"
write "${target}.install: ${target}"
write "\t@echo '$(IN "${install}/${basename}")'"
write "\t${Q}mkdir -p '\$(DESTDIR)${install}'"
write "\t${Q}install -m0755 ${target} \$(DESTDIR)${install}/${basename}"
write
}
function staticlib.uninstall {
local install="${install[$target]:-\$(LIBDIR)}"
local basename="$(basename "${target}")"
write "${target}.uninstall:"
write "\t@echo '$(RM ${install}/${basename})'"
write "\t${Q}rm -f '\$(DESTDIR)${install}/${basename}'"
write
}
function staticlib.clean {
write "${target}.clean:"
write "\t@echo '$(RM ${target})'"
write "\t${Q}rm -f ${target}"
write
}

View File

@ -1,6 +1,6 @@
package=build_zsh package=build_zsh
version=0.2 version=0.2.1
targets=(build.zsh) targets=(build.zsh)
type[build.zsh]=script type[build.zsh]=script