endmenu
menu "Platform Configuration"
- source "$(shell,$(UK_BASE)/support/scripts/uk_build_configure.sh -p '$(KCONFIG_PLAT_DIR)' -o '$(KCONFIG_PLAT_IN)')"
+ source "$(shell,$(UK_BASE)/support/build/config-submenu.sh -q -o '$(KCONFIG_PLAT_IN)' -r '$(KCONFIG_PLAT_BASE)' -l '$(KCONFIG_PLAT_BASE)' -c '$(KCONFIG_EPLAT_DIRS)')"
endmenu
menu "Library Configuration"
- source "$(shell,$(UK_BASE)/support/scripts/uk_build_configure.sh -e '$(KCONFIG_LIB_DIR)' -o '$(KCONFIG_LIB_IN)')"
+ source "$(shell,$(UK_BASE)/support/build/config-submenu.sh -q -o '$(KCONFIG_LIB_IN)' -r '$(KCONFIG_LIB_BASE)' -l '$(KCONFIG_LIB_BASE)' -c '$(KCONFIG_ELIB_DIRS)')"
endmenu
+if !NO_APP
+ source "$(shell,$(UK_BASE)/support/build/config-submenu.sh -q -o '$(KCONFIG_APP_IN)' -t "Application Options" -l '$(KCONFIG_EAPP_DIR)')"
+endif
+
menu "Build Options"
choice
prompt "Optimization level"
# system.
endmenu
-if !NO_APP
- menu "Application Options"
- source "$(shell,$(UK_BASE)/support/scripts/uk_build_configure.sh -a '$(KCONFIG_APP_DIR)')"
- endmenu
-endif
-
config UK_NAME
string "Image name"
default UK_DEFNAME
KCONFIG_AUTOCONFIG := $(KCONFIG_DIR)/auto.conf
KCONFIG_TRISTATE := $(KCONFIG_DIR)/tristate.config
KCONFIG_AUTOHEADER := $(KCONFIG_INCLUDES_DIR)/config.h
-KCONFIG_APP_DIR := $(CONFIG_UK_APP)
KCONFIG_LIB_IN := $(KCONFIG_DIR)/libs.uk
-KCONFIG_DEF_PLATS := $(shell find $(CONFIG_UK_PLAT)/* -maxdepth 0 \
- -type d \( -path $(CONFIG_UK_PLAT)/common -o \
- -path $(CONFIG_UK_PLAT)/drivers \
- \) -prune -o -type d -print)
-KCONFIG_LIB_DIR := $(shell find $(CONFIG_UK_LIB)/* -maxdepth 0 -type d) \
- $(CONFIG_UK_BASE)/lib $(ELIB_DIR)
-KCONFIG_PLAT_DIR := $(KCONFIG_DEF_PLATS) $(EPLAT_DIR) $(CONFIG_UK_PLAT)
-KCONFIG_PLAT_IN := $(KCONFIG_DIR)/plat.uk
+KCONFIG_LIB_BASE := $(CONFIG_UK_BASE)/lib
+KCONFIG_ELIB_DIRS := $(L)
+KCONFIG_PLAT_IN := $(KCONFIG_DIR)/plats.uk
+KCONFIG_PLAT_BASE := $(CONFIG_UK_BASE)/plat
+KCONFIG_EPLAT_DIRS := $(E)
+KCONFIG_APP_IN := $(KCONFIG_DIR)/app.uk
+ifneq ($(CONFIG_UK_BASE),$(CONFIG_UK_APP))
+KCONFIG_EAPP_DIR := $(CONFIG_UK_APP)
+else
+KCONFIG_EAPP_DIR :=
+endif
# Makefile support scripts
SCRIPTS_DIR := $(CONFIG_UK_BASE)/support/scripts
UK_FULLVERSION="$(UK_FULLVERSION)" \
UK_CODENAME="$(UK_CODENAME)" \
UK_ARCH="$(CONFIG_UK_ARCH)" \
- KCONFIG_APP_DIR="$(KCONFIG_APP_DIR)" \
- KCONFIG_LIB_DIR="$(KCONFIG_LIB_DIR)" \
KCONFIG_LIB_IN="$(KCONFIG_LIB_IN)" \
- KCONFIG_PLAT_DIR="$(KCONFIG_PLAT_DIR)" \
+ KCONFIG_LIB_BASE="$(KCONFIG_LIB_BASE)" \
+ KCONFIG_ELIB_DIRS="$(KCONFIG_ELIB_DIRS)" \
KCONFIG_PLAT_IN="$(KCONFIG_PLAT_IN)" \
+ KCONFIG_PLAT_BASE="$(KCONFIG_PLAT_BASE)" \
+ KCONFIG_EPLAT_DIRS="$(KCONFIG_EPLAT_DIRS)" \
+ KCONFIG_APP_IN="$(KCONFIG_APP_IN)" \
+ KCONFIG_EAPP_DIR="$(KCONFIG_EAPP_DIR)" \
UK_NAME="$(CONFIG_UK_NAME)"
PHONY += scriptconfig scriptsyncconfig iscriptconfig kmenuconfig guiconfig \
--- /dev/null
+#!/usr/bin/env bash
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2023, Unikraft GmbH and the Unikraft Authors.
+# Licensed under the BSD-3-Clause License (the "License").
+# You may not use this file except in compliance with the License.
+IFS_ORIG=$IFS
+IFS_NL=$'\n'
+
+usage()
+{
+ echo "Usage: $0 [OPTION]... [LIBRARY PATH]..."
+ echo "Generates a KConfig submenu by looping over Config.uk files"
+ echo ""
+ echo " -h Display help and exit"
+ echo " -q Quiet, do not print warnings to STDERR"
+ echo " -t [TEXT] Generates a submenu with TEXT as title"
+ echo " -l [PATH] Library directory"
+ echo " -c [PATH:PATH:...] Colon separated list of library directories"
+ echo " -r [PATH] Search for library directories in subfolders"
+ echo " -o [PATH] Write to output file instead of STDOUT"
+}
+
+ARG_OUT=
+ARG_PATHS=()
+ARG_TITLE=
+OPT_MODE="concat"
+OPT_QUIET=1
+while getopts :hqt:l:r:c:o: OPT; do
+ case ${OPT} in
+ h)
+ usage
+ exit 0
+ ;;
+ q)
+ OPT_QUIET=0
+ ;;
+ t)
+ ARG_TITLE="${OPTARG}"
+ OPT_MODE="menu"
+ ;;
+ l)
+ ARG_PATHS+=("${OPTARG}")
+ ;;
+ r)
+ if [ ! -z "${OPTARG}" ]; then
+ for P in "${OPTARG}/"*; do
+ [ -d "${P}" ] && ARG_PATHS+=("${P}")
+ done
+ fi
+ ;;
+ c)
+ IFS=':'
+ for P in ${OPTARG}; do
+ IFS=$IFS_ORIG
+ ARG_PATHS+=("${P}")
+ IFS=$IFS_NL
+ done
+ IFS=$IFS_ORIG
+ ;;
+ o)
+ ARG_OUT=("${OPTARG}")
+ ;;
+ \?)
+ echo "Unrecognized option -${OPTARG}" 1>&2
+ usage 1>&2
+ exit 1
+ ;;
+ esac
+done
+shift $(( OPTIND - 1 ))
+
+#
+# Handling OUTPUT
+#
+if [ ! -z "$ARG_OUT" ]; then
+ if [ -e "$ARG_OUT" -a ! -f "$ARG_OUT" ]; then
+ echo "$ARG_OUT already exists but is not a regular file" 1>&2
+ exit 2
+ fi
+ [ -f "$ARG_OUT" ] && rm -f "$ARG_OUT"
+
+ # open fd:7
+ exec 7<>"$ARG_OUT"
+ if [ $? -ne 0 ]; then
+ echo "Failed to open $ARG_OUT as output file" 1>&2
+ exit 1
+ fi
+
+ printf '# Auto generated file. DO NOT EDIT\n' >&7
+else
+ # duplicate stdout to fd:7
+ exec >&7
+fi
+
+#
+# HEADER
+#
+case "${OPT_MODE}" in
+ menu)
+ printf "menu \"%s\"\n" "${ARG_TITLE}" >&7
+ ;;
+ *)
+ ;;
+esac
+
+#
+# BODY
+#
+for ARG_PATH in "${ARG_PATHS[@]}" "$@"; do
+ CONFIG_UK="${ARG_PATH}/Config.uk"
+
+ if [ ! -f "${CONFIG_UK}" ]; then
+ if [ $OPT_QUIET -ne 0 ]; then
+ echo "Could not find \"Config.uk\" under \"${ARG_PATH}\". Skipping..." 1>&2
+ fi
+ continue;
+ fi
+
+ printf "source \"%s\"\n" "$( readlink -f "${CONFIG_UK}" )" >&7
+done
+
+#
+# FOOTER
+#
+case "${OPT_MODE}" in
+ menu)
+ printf "endmenu\n" >&7
+ ;;
+ *)
+ ;;
+esac
+
+# close FD:7 and print filename
+if [ ! -z "$ARG_OUT" ]; then
+ printf '%s\n' "$( readlink -f $ARG_OUT )"
+ exec 7>&-
+fi
+++ /dev/null
-#!/usr/bin/env bash
-
-OPT_BASENAME=`basename $0`
-OPT_STRING="a:e:ho:p:"
-
-read -r -d '' OPT_HELP <<- EOH
- a - The application location
- e - The location of the external libraries
- p - The location of external platforms
- o - The output configuration file
- h - Print Usage
-EOH
-
-print_usage() {
- printf "%s [%s]\n" ${OPT_BASENAME} ${OPT_STRING};
- printf "%s\n" "${OPT_HELP}"
-}
-
-fetch_plats() {
- local files=;
- files=`find ${@} -maxdepth 1 -name "Config.uk"`
- echo ${files}
-}
-
-fetch_libs() {
- local files=;
- files=`find ${@} -maxdepth 1 -name "Config.uk"`
- echo ${files}
-}
-
-fetch_app() {
- local files=;
- files=`find ${1} -maxdepth 1 -name "Config.uk"`
- echo ${files}
-}
-
-config_out_create() {
-
- [[ -f ${2} ]] || touch ${2};
-
- for file in ${1}
- do
- [[ -z `cat ${2} | grep ${file}` ]] && \
- { echo "source \"${file}\"" >> ${2}; }
- done
-}
-
-if [ $# -eq 0 ];
-then
- print_usage
- exit 1;
-fi
-
-[[ -n ${CONFIG_UK_BASE} ]] && UK_BASE=${CONFIG_UK_BASE};
-[[ -n ${UK_BASE} ]] || UK_BASE=$(readlink -f $(dirname $0)/../..)
-
-CONFIG_FILES=;
-
-while getopts ${OPT_STRING} opt
-do
- case ${opt} in
- a)
- APP_DIR="${OPTARG}"
- [[ -d ${APP_DIR} ]] || \
- { echo "Cannot find the application"; exit 1; }
- if [ ${UK_BASE} != ${APP_DIR} ]
- then
- CONFIG_FILES=$(fetch_app ${APP_DIR})
- echo ${CONFIG_FILES};
- else
- CONFIG_FILES=${BUILD_DIR}/app.uk
- [[ -f ${BUILD_DIR}/app.uk ]] || \
- { touch ${CONFIG_FILES}; }
- echo '# external application' >> ${CONFIG_FILES}
- echo 'comment "No external application specified"'\
- >> ${CONFIG_FILES}
- echo ${CONFIG_FILES};
- fi
- exit 0;
- ;;
- e)
- CONFIG_FILES=`fetch_libs "${OPTARG}"`
- ;;
- p)
- CONFIG_FILES=`fetch_plats "${OPTARG}"`
- ;;
- h)
- print_usage;
- exit 0;
- ;;
- o)
- CONFIG_OUT_FILE=${OPTARG}
- ;;
- *)
- print_usage
- exit 1;
- ;;
- esac
-done
-
-config_out_create "${CONFIG_FILES}" ${CONFIG_OUT_FILE}
-echo ${CONFIG_OUT_FILE}