endef
# Takes one rootfile or a directory and will return a list of all included files
-define COLLECT_FILES
- BUILDTARGET="$(BUILDTARGET)" \
+COLLECT_FILES = \
BUILD_ARCH="$(BUILD_ARCH)" \
+ BUILDTARGET="$(BUILDTARGET)" \
KVER="$(KVER)" \
- $(DIR_SRC)/src/scripts/archive.files $(1)
-endef
+ $(DIR_SRC)/src/scripts/archive.files $(BUILD_ARCH) $(1) $(2)
# Takes a filelist from standard input and streams a tarball with all files
__FILES_IN = \
# #
###############################################################################
-for i in BUILD_ARCH BUILDTARGET KVER; do
- if [ -z "${!i}" ]; then
- echo "${i} not set" >&2
- exit 1
- fi
-done
-
-FILELIST=()
+find_rootfile() {
+ local path="${1}"
+ local package="${2}"
-for dir in $@; do
- # Skip all objects that do not exist.
- [ -e "${dir}" ] || continue
-
- # Files go directly to the rootfile.
- if [ -f "${dir}" ]; then
- FILELIST+=( "${dir}" )
- continue
- fi
+ local file
- for exclude in ${dir}/${BUILD_ARCH}/*; do
- [ -f "${exclude}" ] || continue
- EXCLUDE="$EXCLUDE $exclude"
+ for file in "${path}/${arch}/${package}" "${path}/${package}"; do
+ if [ -f "${file}" ]; then
+ echo "${file}"
+ break
+ fi
done
+}
- FILELIST+=( "${EXCLUDE}" )
+descend() {
+ local path="${1}"
+ shift
- for include in ${dir}/*; do
- [ -d ${include} ] && continue
- IN=true
- for exclude in ${EXCLUDE}; do
- if [ "$(basename ${exclude})" = "$(basename ${include})" ]; then
- IN=false
- break
+ local packages=( "$@" )
+ local package
+ local file
+
+ # Find all packages
+ if [ "${#packages[@]}" -eq 0 ]; then
+ for file in "${path}/"* "${path}/${arch}"/*; do
+ if [ -f "${file}" ]; then
+ packages+=( "${file##*/}" )
fi
done
- ${IN} && FILELIST+=( "${include}" )
+ fi
+
+ # Return the correct rootfile
+ for package in ${packages[@]}; do
+ find_rootfile "${path}" "${package}"
done
-done
+}
+
+find_rootfiles() {
+ local path="${1}"
+ shift
+
+ # Descend into directories
+ if [ -d "${path}" ]; then
+ descend "${path}" "$@"
+
+ # Or look straight for a file
+ else
+ find_rootfile "${path}" "$@"
+ fi
+}
+
+# This function takes a list of rootfiles from standard input and extracts all files
+read_rootfiles() {
+ xargs -n 64 grep --no-filename -v "^#" | sort -u
+}
+
+substitute_paths() {
+ sed \
+ -e "s/BUILDTARGET/${BUILDTARGET}/g" \
+ -e "s/KVER/${KVER}/g" \
+ -e "s/xxxMACHINExxx/${BUILD_ARCH}/g"
+}
+
+main() {
+ local arch="${1}"
+ shift
+
+ # Find all rootfiles
+ find_rootfiles "$@" | read_rootfiles | substitute_paths
+}
-grep --no-filename -v ^# "${FILELIST[@]}" 2>/dev/null | sort -u | \
- sed -e "s/KVER/${KVER}/g" -e "s/xxxMACHINExxx/${BUILD_ARCH}/g" -e "s/BUILDTARGET/${BUILDTARGET}/g"
+main "$@" || exit $?