diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4f901fb..c93d01a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -13,18 +13,25 @@ }, { "label": "Build", - "detail": "Does a full build of the OS161 kernel", + "detail": "Does a full build of OS161", "type": "shell", - "dependsOrder": "sequence", - "dependsOn":[ - "Configure OS Tree", - "Compile Userland", - "Configure Kernel", - "Compile Kernel" - ], + "command": "./build.sh -p ${input:tree_path} -k ${input:kernel}", + "options": { + "cwd": "${env:WORKSPACE_DIR}/scripts" + }, "problemMatcher": [], "group": "build" }, + { + "label": "Clean Build", + "detail": "Restore the source tree to a pristine state and remove all generated files", + "type": "shell", + "command": "./clean_build.sh", + "options": { + "cwd": "${env:WORKSPACE_DIR}/scripts" + }, + "problemMatcher": [] + }, { "label": "Run Kernel", "detail": "Run the OS161 kernel", @@ -39,39 +46,29 @@ "label": "Configure OS Tree", "detail": "Configures the OS tree with the provided path", "type": "shell", - "command": "./configure --ostree=${input:tree_path}", + "command": "./configure_os_tree.sh -p ${input:tree_path}", "options": { - "cwd": "${env:WORKSPACE_DIR}/os161/src", + "cwd": "${env:WORKSPACE_DIR}/scripts/build_helpers", }, "problemMatcher": [], }, { "label": "Compile Userland", "detail": "Compiles userland in src/", - "command": "bmake && bmake install", + "command": "./compile_userland.sh", "type": "shell", "options": { - "cwd": "${env:WORKSPACE_DIR}/os161/src", + "cwd": "${env:WORKSPACE_DIR}/scripts/build_helpers", }, "problemMatcher": [], }, { - "label": "Configure Kernel", - "detail": "Configures the type of kernel to be compiled", - "command": "./config ${input:kernel}", - "type": "shell", - "options": { - "cwd": "${env:WORKSPACE_DIR}/os161/src/kern/conf" - }, - "problemMatcher": [] - }, - { - "label": "Compile Kernel", - "detail": "Compile the kernel with the configured type", - "command": "bmake depend && bmake && bmake install", + "label": "Configure and Compile Kernel", + "detail": "Configure and compile a specified kernel", + "command": "./configure_and_compile_kernel.sh -k ${input:kernel}", "type": "shell", "options": { - "cwd": "${env:WORKSPACE_DIR}/os161/src/kern/compile/${input:kernel}", + "cwd": "${env:WORKSPACE_DIR}/scripts/build_helpers", }, "problemMatcher": [] }, diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..dbfe65b --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,49 @@ +#/bin/bash + +function helpMessage() { + echo "Usage: ./build.sh [OPTIONS]..." + echo "Builds OS161" + echo "Example: ./build.sh -k DUMBVM" + echo "" + echo "Options" + echo -e "\t-k: The kernel to configure and compile. Must be one of:" \ + "DUMBVM, DUMBVM-OPT, GENERIC, GENERIC-OPT, SYNCHPROBS" + echo -e "\t-p: The absolute path to the OS tree (optional). Default: ${WORKSPACE_DIR}/os161/root" + echo -e "\t-h: Display this message" +} + +ostree_path="" +kernel="" + +default_ostree_path=${WORKSPACE_DIR}/os161/root + +# Grab CLI arguments +while getopts ":hk:p:" flag; do + case ${flag} in + h) helpMessage; exit 0 ;; + k) kernel=${OPTARG} ;; + p) ostree_path=${OPTARG} ;; + \?) echo "Invalid option: -${OPTARG}"; helpMessage; exit 1 ;; + *) echo "Unhandled option: -${OPTARG}"; helpMessage; exit 1 ;; + esac +done + +# Assert that the kernel argument is non-empty +if [[ -z ${kernel} ]]; then + echo "ERROR: Option -k is missing or argument value is empty" + helpMessage + exit 1 +fi + +# If os tree path is empty, set to default path +if [[ -z ${ostree_path} ]]; then + ostree_path=${default_ostree_path} +fi + +# Perform the build process +scripts_directory=${WORKSPACE_DIR}/scripts +bash ${scripts_directory}/build_helpers/configure_os_tree.sh -p ${ostree_path} +bash ${scripts_directory}/build_helpers/compile_userland.sh +bash ${scripts_directory}/build_helpers/configure_and_compile_kernel.sh -k ${kernel} + +echo "Build done" diff --git a/scripts/build_helpers/compile_userland.sh b/scripts/build_helpers/compile_userland.sh new file mode 100755 index 0000000..2db4470 --- /dev/null +++ b/scripts/build_helpers/compile_userland.sh @@ -0,0 +1,27 @@ +#/bin/bash + +function helpMessage() { + echo "Usage: ./compile_userland.sh" + echo "Compile userland" +} + +# Grab CLI arguments +while getopts ":h" flag; do + case ${flag} in + h) helpMessage; exit 0 ;; + \?) echo "Invalid option: -${OPTARG}"; helpMessage; exit 1 ;; + *) echo "Unhandled option: -${OPTARG}"; helpMessage; exit 1 ;; + esac +done + +prev_dir=$(pwd) +if [[ -d ${OS161_SRC} ]]; then + cd ${OS161_SRC} + bmake -j$(nproc) + bmake install +else + echo "Cannot compile userland because ${OS161_SRC} does not exist." +fi + +cd ${prev_dir} +echo "Done compiling userland" diff --git a/scripts/build_helpers/configure_and_compile_kernel.sh b/scripts/build_helpers/configure_and_compile_kernel.sh new file mode 100755 index 0000000..a1f9bb5 --- /dev/null +++ b/scripts/build_helpers/configure_and_compile_kernel.sh @@ -0,0 +1,54 @@ +#/bin/bash + +function helpMessage() { + echo "Usage: ./configure_and_compile_kernel.sh [OPTIONS]..." + echo "Configures and compiles a kernel" + echo "Example: ./configure_and_compile_kernel.sh -k DUMBVM" + echo "" + echo "Options" + echo -e "\t-k: The kernel to configure and compile. Must be one of:" \ + "DUMBVM, DUMBVM-OPT, GENERIC, GENERIC-OPT, SYNCHPROBS" + echo -e "\t-h: Display this message" +} + +kernel="" + +# Grab CLI arguments +while getopts ":hk:" flag; do + case ${flag} in + h) helpMessage; exit 0 ;; + k) kernel=${OPTARG} ;; + \?) echo "Invalid option: -${OPTARG}"; helpMessage; exit 1 ;; + *) echo "Unhandled option: -${OPTARG}"; helpMessage; exit 1 ;; + esac +done + +# Assert that the kernel argument is non-empty +if [[ -z ${kernel} ]]; then + echo "ERROR: Option -k is missing or argument value is empty" + helpMessage + exit 1 +fi + +prev_dir=$(pwd) +kernel_conf_dir=${OS161_SRC}/kern/conf +kernel_dir=${OS161_SRC}/kern/compile/${kernel} + +if [[ -d ${kernel_conf_dir} && ! -z ${kernel} ]]; then + cd ${kernel_conf_dir} + ./config ${kernel} +else + echo "Cannot configure kernel ${kernel} because ${kernel_dir} does not exist." +fi + +if [[ -d ${kernel_dir} && ! -z ${kernel} ]]; then + cd ${kernel_dir} + bmake depend + bmake -j$(nproc) + bmake install +else + echo "Cannot compile kernel ${kernel} because ${kernel_dir} does not exist." +fi + +cd ${prev_dir} +echo "Done configuring and compiling the kernel" diff --git a/scripts/build_helpers/configure_os_tree.sh b/scripts/build_helpers/configure_os_tree.sh new file mode 100755 index 0000000..bdc7753 --- /dev/null +++ b/scripts/build_helpers/configure_os_tree.sh @@ -0,0 +1,44 @@ +#/bin/bash + +# Most of the devcontainer is configured to use the "default" directory, +# so it's advised to not change it unless you really want to change it +function helpMessage() { + echo "Usage: ./configure_os_tree.sh [OPTIONS]..." + echo "Configures the OS Tree" + echo "Example: ./configure_os_tree.sh -p /workspace/os161/root" + echo "" + echo "Options" + echo -e "\t-p: The absolute path to the OS tree (optional). Default: ${WORKSPACE_DIR}/os161/root" + echo -e "\t-h: Display this message" +} + +ostree_path="" +default_ostree_path=${WORKSPACE_DIR}/os161/root + +# Grab CLI arguments +while getopts ":hp:" flag; do + case ${flag} in + h) helpMessage; exit 0 ;; + p) ostree_path=${OPTARG} ;; + \?) echo "Invalid option: -${OPTARG}"; helpMessage; exit 1 ;; + *) echo "Unhandled option: -${OPTARG}"; helpMessage; exit 1 ;; + esac +done + +prev_dir=$(pwd) + +# If first argument empty, set to default path +if [[ -z ${ostree_path} ]]; then + ostree_path=${default_ostree_path} +fi + +# Set the ostree path +if [[ -d ${OS161_SRC} ]]; then + cd ${OS161_SRC} + ./configure --ostree=${ostree_path} +else + echo "Cannot configure os tree because ${OS161_SRC} does not exist." +fi + +cd ${prev_dir} +echo "Done configuring OS tree path" diff --git a/scripts/clean_build.sh b/scripts/clean_build.sh new file mode 100755 index 0000000..f8cb7fe --- /dev/null +++ b/scripts/clean_build.sh @@ -0,0 +1,33 @@ +#/bin/bash + +# Removes all generated files +prev_dir=$(pwd) + +# Clean src directory +if [[ -d ${OS161_SRC} ]]; then + echo "Cleaning src directory" + cd ${OS161_SRC} + bmake clean + bmake distclean +else + echo "Cannot clean ${OS161_SRC}. It does not exist." +fi + +# Clean kern/compile directories +compile_directory=${OS161_SRC}/kern/compile +if [[ -d ${compile_directory} ]]; then + cd ${compile_directory} + kernel_directories=$(ls -d *) + + for subdir in ${kernel_directories}; do + echo "Cleaning ${subdir}" + cd ${compile_directory}/${subdir} + bmake clean + done +else + echo "Cannot clean ${compile_directory}. It does not exist." +fi + +cd ${prev_dir} + +echo "Clean done!" diff --git a/scripts/setup.sh b/scripts/setup.sh index edbcb01..f905d10 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -17,7 +17,7 @@ function install() { } if [[ -d $OS161_DEPENDENCIES_DIR/tools ]]; then - echo "${OS161_DEPENDENCIES_DIR}/tools already exists. Delete the tools directory " + \ + echo "${OS161_DEPENDENCIES_DIR}/tools already exists. Delete the tools directory" \ "if rebuilding is desired. Skipping build..." else install