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

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

View File

@ -61,6 +61,19 @@ function TAR {
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
function subdirs {
@ -215,6 +228,8 @@ function main {
write
write "CC := ${CC:-cc}"
write "AR := ${AR:-ar}"
write "RANLIB := ${RANLIB:-ranlib}"
write "CFLAGS := ${CFLAGS}"
write "LDFLAGS := ${LDFLAGS}"
write
@ -234,10 +249,18 @@ function main {
write "\n\t@:\n"
fi
typeset -l -a exported_rules
local target_index=1
while (($target_index <= ${#targets[@]})); do
local target="${targets[$target_index]}"
if has "${target}" "${exported_rules[@]}"; then
((target_index++))
continue
else
exported_rules+=("$target")
fi
typeset -a src
src=($(echo ${sources[$target]}))
local installdir="${install[$target]}"

View File

@ -1,45 +1,33 @@
function library.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 -n "${target}: ${target}.so ${target}.a"
write
for i in ${src[@]}; do
targets+=("${i%.c}.o")
type[${i%.c}.o]=ofile
auto[${i%.c}.o]=true
cflags[${i%.c}.o]="-fPIC ${cflags[$target]}"
targets+=("${target}.so" "${target}.a")
for i in ${target}.so ${target}.a; do
auto[$i]=true
sources[$i]="${sources[$target]}"
cflags[$i]="-fPIC ${cflags[$target]}"
ldflags[$i]="${ldflags[$target]}"
done
type[${target}.so]=sharedlib
type[${target}.a]=staticlib
}
function library.install {
local install="${install[$target]:-\$(LIBDIR)}"
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 "${target}.install: ${target}.so.install ${target}.a.install"
write
}
function library.uninstall {
local install="${install[$target]:-\$(LIBDIR)}"
write "${target}.uninstall:"
write "\t@echo '$(RM ${install}/${target})'"
write "\t${Q}rm -f '\$(DESTDIR)${install}/${target}'"
write "${target}.uninstall: ${target}.so.uninstall ${target}.a.uninstall"
write
}
function library.clean {
write "${target}.clean:"
write "\t@echo '$(RM ${target})'"
write "\t${Q}rm -f ${target}"
write "${target}.clean: ${target}.so.clean ${target}.a.clean"
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
version=0.2
version=0.2.1
targets=(build.zsh)
type[build.zsh]=script