aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Ferrell <major@homeonderanged.org>2014-04-08 08:45:26 -0700
committerMark Ferrell <major@homeonderanged.org>2014-04-08 08:45:26 -0700
commit0079cb176a470615cfa87443bfa485d7fc281ffe (patch)
treef19923e7da4ccd4c4d3329b9e5e51c316c398ee9
parent84700fc8052f737534136c622f9efd88702f0222 (diff)
Properly support arguments to sub commands
* We needed some way to detect when a sub-command was being called by the make engine vs by a user so we could properly handle the 'help' command. This involved a lot of decoupling of the make handling out of the top-level 'build' tool and placing it into a newly created 'build-make'. * While we where at it we cleaned up the handling of various targets in makedeps so that 'all/all' is now a valid target, and subsequently, the default target.
-rwxr-xr-xbuild101
-rwxr-xr-xlibexec/build-help5
-rwxr-xr-xlibexec/build-make112
-rwxr-xr-xlibexec/build-make-export2
-rwxr-xr-xlibexec/build-make-package2
-rwxr-xr-xlibexec/build-make-source2
-rwxr-xr-xlibexec/build-makedeps56
7 files changed, 158 insertions, 122 deletions
diff --git a/build b/build
index 73599ff..0277bb3 100755
--- a/build
+++ b/build
@@ -100,11 +100,10 @@ fi
##
# Check to see if we are wrapping a sub-command
-# FIXME support custom commands
BUILDER_COMMAND=
if [ -f "${1}" ]; then
- case "${1}" in
- (*build-*)
+ case "${1##*/}" in
+ (build-*)
BUILDER_COMMAND="${1}"
shift
. "${BUILDER_COMMAND}"
@@ -195,10 +194,10 @@ export BUILDER_CONFIG
MAKE_OPTS="${MAKE_OPTS:--j2}"
export MAKE_OPTS
-# Available to be set in the config
-PROJECT="${PROJECT:-platform}"
-ARCHIVE_FORMAT="${ARCHIVE_FORMAT:-tar.bz2}"
-export PROJECT ARCHIVE_FORMAT
+# Default build target
+# FIXME this should default to all/all
+TARGET="${TARGET:-all/all}"
+export TARGET
# If unspecified go ahead and ask gcc
CBUILD="${CBUILD:-$(build-dumpmachine)}"
@@ -221,88 +220,16 @@ if [ "$#" -gt "0" ]; then
shift 1
fi
-# FIXME Support custom commands somehow..
-if [ ! -x "${BUILDER_LIBDIR}/build-${ACTION}" ]; then
+if command -v "build-make-${ACTION}" 2>&1 > /dev/null; then
+ BUILDER_COMMAND="$(command -v 'build-make')"
+ set -- "${ACTION}" "${@}"
+elif command -v "build-${ACTION}" 2>&1 > /dev/null; then
+ BUILDER_COMMAND="$(command -v "build-${ACTION}")"
+else
error "unknown action '${ACTION}'"
echo "try '${0} help'" >&2
exit 1
fi
+export BUILDER_COMMAND
-# query is a special case
-# FIXME this is semi-busted
-case "${ACTION}" in
- (query) exec "${BUILDER_LIBDIR}/build-query" "${@}";;
- (help) exec "${BUILDER_LIBDIR}/build-help" "${@}";;
-esac
-
-# If no target is given, then base our target on the current working directory,
-# falling back to "${PROJECT}/all" as our default.
-if [ "$#" -lt "1" ]; then
- # Are we somewhere within the pkg structure. If this test succeeds
- # then we are at least in a category directory within the pkgdir. Just
- # being in pkgdir is not enough to change our default argument list
- # handling.
- NAME="all"
- if [ "${PWD##${BUILDER_PKGDIR}/}" != "${PWD}" ]; then
- category="${PWD##${BUILDER_PKGDIR}/}"
- if [ "${category%%/*}" != "${category}" ]; then
- name="${category#*/}"
- category="${category%%/*}"
- NAME="${category}/${name%%/*}"
- else
- NAME="${category}/all"
- fi
- unset category
- unset name
- fi
- set -- "${NAME}"
-fi
-
-for package in "$@"; do
- # If all is specified anywhere in the argument list than just discard
- # everything else.
- if [ "${package}" = "all" ]; then
- continue
- fi
- CATEGORY="${package%%/*}"
- if [ ! -d "${BUILDER_PKGDIR}/${CATEGORY}" ]; then
- die "invalid package category '${CATEGORY}'"
- fi
- if [ "${package##*/}" != "all" ]; then
- if ! build-query --exists "${package}"; then
- exit 1
- fi
- fi
-done
-# sort/uniq the argument list
-set -- $(for package in "$@"; do echo "${package}" ; done | sort | uniq)
-
-# build the Makefile
-trap cleanup EXIT
-BUILDER_MAKEFILE="$(mktemp ${BUILDER_TMPDIR}/builder_makefile.XXXXXXXX)"
-if [ ! -f "${BUILDER_MAKEFILE}" ]; then
- die "failed to generate build dependencies"
-fi
-export BUILDER_MAKEFILE
-"${BUILDER_LIBDIR}/build-makedeps" || die "failed generate build dependencies"
-
-packages=
-for package in "$@"; do
- if [ "${package##*/}" != "all" ]; then
- package="$(build-query --pkgname "${package}")"
- fi
- package="$(echo "${package}"|tr '/-' '__')"
- packages="${packages} ${package}_${ACTION}"
-done
-set -- ${packages}
-unset packages
-
-# The 'tee' command will discard the exit status from 'make', so we have to
-# jump through a few hoops to capture the exit status in a portable fashion.
-BUILDER_PIPE="`mktemp "${BUILDER_TMPDIR}/builder_pipe.XXXXXXXX"`"
-test -f "${BUILDER_PIPE}" || die 'failed to generate log-pipe placeholder'
-rm -f "${BUILDER_PIPE}" && mkfifo "${BUILDER_PIPE}" || die 'failed to create log-pipe'
-tee "${BUILDER_TMPDIR}/builder.log" < "${BUILDER_PIPE}" &
-BUILDER_LOGGER="$!"
-make -r -f "${BUILDER_MAKEFILE}" "${@}" > "${BUILDER_PIPE}" 2>&1
-exit $?
+exec "${BUILDER_COMMAND}" "${@}"
diff --git a/libexec/build-help b/libexec/build-help
index e6f2dc5..d1eefdf 100755
--- a/libexec/build-help
+++ b/libexec/build-help
@@ -4,7 +4,10 @@ while test "$#" -gt '0'; do
case "${1}" in
(--) shift; break;;
(-*) die "unknown option '${1}'";;
- (*) exec build "${1}" --help;;
+ (*) if test -x "${BUILDER_LIBDIR}/build-make-${1}"; then
+ exec build "make-${1}" --help
+ fi
+ exec build "${1}" --help;;
esac
done
diff --git a/libexec/build-make b/libexec/build-make
new file mode 100755
index 0000000..07c2634
--- /dev/null
+++ b/libexec/build-make
@@ -0,0 +1,112 @@
+#!/usr/bin/env build
+
+while test "$#" -gt '0'; do
+ case "${1}" in
+ (-h|-help|--help) usage; exit 0;;
+ (--) shift; break;;
+ (-*) error "unknown optopn '${1}'"
+ echo "try 'build help make'" >&2
+ exit 1;;
+ (*) break;;
+ esac
+done
+
+if test "$#" -eq '0'; then
+ error 'no make action specified'
+ echo "try 'build help make'" >&2
+ exit 1
+fi
+
+BUILDER_MAKE_ACTION="${1}"
+shift
+
+# This allows 'build install --help' to work.
+for arg; do
+ case "${arg}" in
+ (-h|-help|--help) exec build make-"${BUILDER_MAKE_ACTION}" --help;;
+ esac
+done
+
+# If no target is given, then base our target on the current working directory,
+# falling back to "${PROJECT}/all" as our default.
+if test "$#" -eq '0'; then
+ # Are we somewhere within the pkg structure. If this test succeeds
+ # then we are at least in a category directory within the pkgdir. Just
+ # being in pkgdir is not enough to change our default argument list
+ # handling.
+ NAME="${TARGET}"
+ if [ "${PWD##${BUILDER_PKGDIR}/}" != "${PWD}" ]; then
+ category="${PWD##${BUILDER_PKGDIR}/}"
+ if [ "${category%%/*}" != "${category}" ]; then
+ name="${category#*/}"
+ category="${category%%/*}"
+ NAME="${category}/${name%%/*}"
+ else
+ NAME="${category}/all"
+ fi
+ unset category
+ unset name
+ fi
+ set -- "${NAME}"
+fi
+
+# FIXME move this to a sub-command to be used by other tools.
+for package in "$@"; do
+ # If all is specified anywhere in the argument list than just discard
+ # everything else.
+ case "${package}" in
+ (-*|all) continue;;
+ esac
+
+ # FIXME we need a resolver for things like all/all and <category>/all
+ CATEGORY="${package%%/*}"
+ if [ "${CATEGORY}" != 'all' ]; then
+ if [ ! -d "${BUILDER_PKGDIR}/${CATEGORY}" ]; then
+ die "invalid package category '${CATEGORY}'"
+ fi
+ if [ "${package##*/}" != "all" ]; then
+ if ! build-query --exists "${package}"; then
+ exit 1
+ fi
+ fi
+ fi
+done
+
+# sort/uniq the argument list
+# FIXME need a way to "resolve" the package list instead of possibly clobbering
+# it.
+set -- $(for package in "$@"; do echo "${package}" ; done | sort | uniq)
+
+# build the Makefile
+trap cleanup EXIT
+test -d "${BUILDER_TMPDIR}" || mkdir -p "${BUILDER_TMPDIR}"
+BUILDER_MAKEFILE="$(mktemp "${BUILDER_TMPDIR}/builder_makefile.XXXXXXXX")"
+if [ ! -f "${BUILDER_MAKEFILE}" ]; then
+ die "failed to generate build dependencies"
+fi
+export BUILDER_MAKEFILE
+"${BUILDER_LIBDIR}/build-makedeps" || die "failed generate build dependencies"
+
+packages=
+for package in "$@"; do
+ case "${package}" in
+ (*/all);;
+ (*) package="$(build-query --pkgname "${package}")";;
+ esac
+ package="$(echo "${package}"|tr '/-' '__')"
+ packages="${packages} ${package}_${BUILDER_MAKE_ACTION}"
+done
+set -- ${packages}
+unset packages
+
+# The 'tee' command will discard the exit status from 'make', so we have to
+# jump through a few hoops to capture the exit status in a portable fashion.
+BUILDER_PIPE="`mktemp "${BUILDER_TMPDIR}/builder_pipe.XXXXXXXX"`"
+test -f "${BUILDER_PIPE}" || die 'failed to generate log-pipe placeholder'
+rm -f "${BUILDER_PIPE}" && mkfifo "${BUILDER_PIPE}" || die 'failed to create log-pipe'
+tee "${BUILDER_TMPDIR}/builder.log" < "${BUILDER_PIPE}" &
+BUILDER_LOGGER="$!"
+make -r -f "${BUILDER_MAKEFILE}" "${@}" > "${BUILDER_PIPE}" 2>&1
+exit $?
+
+# vim: filetype=sh
diff --git a/libexec/build-make-export b/libexec/build-make-export
index d611088..9cc7f67 100755
--- a/libexec/build-make-export
+++ b/libexec/build-make-export
@@ -32,7 +32,7 @@ fi
cd "${T}"
for url in ${SOURCE_URI}; do
- file="$(build-fetch --name "${url}")"
+ file="$(build-make-fetch --name "${url}")"
test -f "${BUILDER_SRCDIR}/${file}" || die "source does not exist '${file}'"
cp "${BUILDER_SRCDIR}/${file}" "${NAME}-${VERSION}.builder/"
done
diff --git a/libexec/build-make-package b/libexec/build-make-package
index 27940fe..24e364f 100755
--- a/libexec/build-make-package
+++ b/libexec/build-make-package
@@ -69,7 +69,7 @@ if [ -d "${SOURCE_DIR}" -o -L "${SOURCE_DIR}" ]; then
else
# FIXME this stuff needs a lot of work
for url in ${SOURCE_URI}; do
- file="$(build-fetch --name "${url}")"
+ file="$(build-make-fetch --name "${url}")"
if [ ! -f "${BUILDER_SRCDIR}/${file}" ]; then
die "source does not exist '${file}'"
fi
diff --git a/libexec/build-make-source b/libexec/build-make-source
index 4b9e14c..975fa27 100755
--- a/libexec/build-make-source
+++ b/libexec/build-make-source
@@ -34,7 +34,7 @@ build_source_args()
build_source()
{
- file="$(build-fetch --name "${1}")"
+ file="$(build-make-fetch --name "${1}")"
if [ ! -f "${BUILDER_SRCDIR}/${file}" ]; then
die "source does not exist '${file}'"
fi
diff --git a/libexec/build-makedeps b/libexec/build-makedeps
index d19a499..73802f3 100755
--- a/libexec/build-makedeps
+++ b/libexec/build-makedeps
@@ -2,11 +2,11 @@
cat >"${BUILDER_MAKEFILE}" <<EOF
##
# Some generic catchall rules
-all: ${PROJECT}_archive
-all_fetch: ${PROJECT}_all_fetch
-all_archive: ${PROJECT}_all_archive
-all_install: ${PROJECT}_all_install
-all_export: ${PROJECT}_all_export
+all: all_all_archive
+all_fetch: all_all_fetch
+all_archive: all_all_archive
+all_install: all_all_install
+all_export: all_all_export
all_makedeps:
all_source:
@@ -35,6 +35,7 @@ EOF
PACKAGES_CLEAN=
for package in $(echo "${BUILDER_PKGDIR}"/*/*); do
test -d "${package}" || die "no packages defined"
+ package="${package#${BUILDER_PKGDIR}/}"
if ! test -f "${BUILDER_PKGDIR}/${package}/Buildrules"; then
error "no rulesfile for package '${package}'"
continue
@@ -66,7 +67,7 @@ for package in $(echo "${BUILDER_PKGDIR}"/*/*); do
(file://*|/*) package_sources="${package_sources} ${url##file://}";;
# Assume anything else with :// in the name is remote
- (*://*) pkg_src="$(build-fetch --name "${url}")"
+ (*://*) pkg_src="$(build-make-fetch --name "${url}")"
if test "$?" -ne "0"; then
exit 1
fi
@@ -83,14 +84,7 @@ for package in $(echo "${BUILDER_PKGDIR}"/*/*); do
package_bdeps=
for pkg_dep in ${BDEPENDS}; do
if ! test -d "${BUILDER_PKGDIR}/${pkg_dep}"; then
- if ! test -d "${BUILDER_PKGDIR}/${PROJECT}/${pkg_dep}"; then
- if ! build-query --exists "${pkg_dep}"; then
- die "bad BDEPENDS in package '${package}'"
- fi
- elif ! test -f "${BUILDER_PKGDIR}/${PROJECT}/${pkg_dep}/Buildrules"; then
- die "no Buildrules for '${pkg_dep}'"
- fi
- pkg_dep="${PROJECT}/${pkg_dep}"
+ die "bad BDEPENDS in package '${package}'"
elif ! test -f "${BUILDER_PKGDIR}/${pkg_dep}/Buildrules"; then
die "no Buildrules for '${pkg_dep}'"
fi
@@ -100,14 +94,7 @@ for package in $(echo "${BUILDER_PKGDIR}"/*/*); do
package_rdeps=
for pkg_dep in ${RDEPENDS}; do
if ! test -d "${BUILDER_PKGDIR}/${pkg_dep}"; then
- if ! test -d "${BUILDER_PKGDIR}/${PROJECT}/${pkg_dep}"; then
- if ! build-query --exists "${pkg_dep}"; then
- die "bad RDEPENDS in package '${package}'"
- fi
- elif ! test -f "${BUILDER_PKGDIR}/${PROJECT}/${pkg_dep}/Buildrules"; then
- die "no Buildrules for '${pkg_dep}'"
- fi
- pkg_dep="${PROJECT}/${pkg_dep}"
+ die "bad RDEPENDS in package '${package}'"
elif ! test -f "${BUILDER_PKGDIR}/${pkg_dep}/Buildrules"; then
die "no Buildrules for '${pkg_dep}'"
fi
@@ -123,20 +110,20 @@ ${package_make}: ${package_archive}
${package_make}_makedeps:
${package_make}_fetch: ${package_sources}
${package_make}_source: ${package_sources}
- @build-source "${CATEGORY}/${NAME}"
+ @build-make-source "${CATEGORY}/${NAME}"
${package_make}_clean:
- @build-clean "${CATEGORY}/${NAME}"
+ @build-make-clean "${CATEGORY}/${NAME}"
${package_make}_distclean:
- @build-distclean "${CATEGORY}/${NAME}"
+ @build-make-distclean "${CATEGORY}/${NAME}"
${package_make}_package: ${package_archive}
${package_archive}: ${package_sources} ${package_bdeps}
- @build-package "${CATEGORY}/${NAME}"
+ @build-make-package "${CATEGORY}/${NAME}"
${package_make}_install: ${package_install}
${package_install}: ${package_archive} ${package_rdeps}
- @build-install "${CATEGORY}/${NAME}"
+ @build-make-install "${CATEGORY}/${NAME}"
${package_make}_export: ${package_export}
${package_export}: ${package_install}
- @build-export "${CATEGORY}/${NAME}"
+ @build-make-export "${CATEGORY}/${NAME}"
EOF
##
@@ -159,11 +146,11 @@ EOF
# Assume anything else with :// in the name is remote
(*://*)
- var="$(build-fetch --var "${url}")"
+ var="$(build-make-fetch --var "${url}")"
if test -z "$(eval echo -n "\$${var}")"; then
eval "${var}='${url}'"
- echo "${BUILDER_SRCDIR}/$(build-fetch --name "${url}"):"
- echo " @build-fetch \"${url}\""
+ echo "${BUILDER_SRCDIR}/$(build-make-fetch --name "${url}"):"
+ echo " @build-make-fetch \"${url}\""
fi
;;
esac
@@ -195,6 +182,11 @@ ${CATEGORY}_all_install: $(eval echo "\${${CATEGORY}_INSTALL}")
${CATEGORY}_all_export: $(eval echo "\${${CATEGORY}_EXPORT}")
${CATEGORY}_all_clean: $(eval echo "\${${CATEGORY}_CLEAN}")
${CATEGORY}_all_distclean: $(eval echo "\${${CATEGORY}_DISTCLEAN}")
+all_all: ${CATEGORY}_all
+all_all_fetch: ${CATEGORY}_all_fetch
+all_all_archive: ${CATEGORY}_all_archive
+all_all_install: ${CATEGORY}_all_install
+all_all_export: ${CATEGORY}_all_export
EOF
done
@@ -202,6 +194,8 @@ done
cat<<EOF >> "${BUILDER_MAKEFILE}"
all_clean: ${PACKAGES_CLEAN} exports_clean
all_distclean: sysroot_clean artifacts_clean tmpdir_clean exports_clean
+all_all_distclean: all_distclean
+all_all_clean: all_clean
EOF
# vim: filetype=sh