From a75b3fa4b1a1b882c33f533645ddae75c09dd697 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Sun, 28 Nov 2021 18:15:14 +0100 Subject: Switch to mipsel-none-elf, move docs, add template presets --- doc/cmake_reference.md | 69 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 22 deletions(-) (limited to 'doc/cmake_reference.md') diff --git a/doc/cmake_reference.md b/doc/cmake_reference.md index 3b586ab..9e134d9 100644 --- a/doc/cmake_reference.md +++ b/doc/cmake_reference.md @@ -10,15 +10,44 @@ can be done on the command line (`-DCMAKE_TOOLCHAIN_FILE=...`), in `CMakeLists.txt` (before calling `project()`) or using a [preset](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html). -It's recommended to put this snippet in `CMakeLists.txt` to automatically set -the toolchain file according to the `PSN00BSDK_LIBS` environment variable: - -```cmake -if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) - set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) -endif() +It's suggested to have a default preset that sets `CMAKE_TOOLCHAIN_FILE` to +`$env{PSN00BSDK_LIBS}/cmake/sdk.cmake`, so the `PSN00BSDK_LIBS` environment +variable (used by former PSn00bSDK versions) is respected. Such a preset can be +created by placing a `CMakePresets.json` file in the project's root with the +following contents: + +```json +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 20, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default configuration", + "description": "Use this preset to build the project using PSn00bSDK.", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_TOOLCHAIN_FILE": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake", + "PSN00BSDK_TC": "", + "PSN00BSDK_TARGET": "mipsel-none-elf" + } + } + ] +} ``` +To avoid having to pass variables to CMake each time the project is built, a +second presets file named `CMakeUserPresets.json` can be created and populated +with hardcoded values in the `cacheVariables` section. This file can be kept +private (e.g. by adding it to `.gitignore`); CMake will automatically load +presets from it instead of `CMakePresets.json` if it exists. + See the [template](../template/CMakeLists.txt) for an example CMake script showing how to build a simple project. @@ -130,28 +159,24 @@ build script, from the CMake command line when configuring the project - `PSN00BSDK_TARGET` (`STRING`) The GCC toolchain's target triplet. PSn00bSDK assumes the toolchain targets - `mipsel-unknown-elf` by default, however this can be changed to e.g. use a - MIPS toolchain that was compiled for a slightly-different-but-equivalent - target. + `mipsel-none-elf` by default, however this can be changed to e.g. use a MIPS + toolchain that was compiled for a slightly-different-but-equivalent target. The following GCC target triplets have been confirmed to work with PSn00bSDK: - - `mipsel-unknown-elf` - `mipsel-none-elf` + - `mipsel-unknown-elf` + - ~~`mipsel-linux-gnu`~~ (has issues with linking) - `PSN00BSDK_TC` (`PATH`) - Path to the GCC toolchain's installation prefix/directory. By default this is - initialized to the value of the `PSN00BSDK_TC` environment variable (if set). - Note that modifying the environment variable after the project has been - configured will *NOT* update this cache entry unless the project's cache is - cleared manually. - - If not set, CMake will attempt to find the toolchain in the `PATH` - environment variable and store its path in this variable (so the search does - not have to be repeated). + Path to the GCC toolchain's installation prefix/directory. If not set, CMake + will attempt to find the toolchain in the `PATH` environment variable and + store its path in the project's variable cache (so the search does not have + to be repeated). It is recommended to add the toolchain's `bin` subfolder to + `PATH` rather than setting this variable. - **IMPORTANT**: if the toolchain's target is not `mipsel-unknown-elf`, + **IMPORTANT**: if the toolchain's target is not `mipsel-none-elf`, `PSN00BSDK_TARGET` must be set regardless of whether or not `PSN00BSDK_TC` is also set. @@ -204,4 +229,4 @@ the build script. LZP archives as part of the build pipeline. ----------------------------------------- -_Last updated on 2021-09-27 by spicyjpeg_ +_Last updated on 2021-11-24 by spicyjpeg_ -- cgit v1.2.3 From fe42ce7f1c98947baa49427835deb5ce70470afb Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Wed, 29 Dec 2021 17:30:56 +0100 Subject: Fix CMake and CI bugs, set version number, update docs --- .github/workflows/build.yml | 4 ++-- CMakeLists.txt | 33 ++++++++++++++++++++++----------- CMakePresets.json | 9 +++++---- cpack/setup.cmake | 3 +-- cpack/welcome.txt | 3 --- doc/cmake_reference.md | 10 +++++++--- doc/installation.md | 9 ++++----- examples/sound/spustream/main.c | 2 +- libpsn00b/CMakeLists.txt | 1 - libpsn00b/build.json.template | 9 ++++++--- libpsn00b/cmake/internal_setup.cmake | 5 +++-- 11 files changed, 51 insertions(+), 37 deletions(-) delete mode 100644 cpack/welcome.txt (limited to 'doc/cmake_reference.md') diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3cbefb1..a72f5d3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -116,7 +116,7 @@ jobs: - name: Update repo submodules run: | cd sdk - git submodule update --init --recursive --remote + git submodule update --init --recursive - name: Build and package PSn00bSDK run: | @@ -164,7 +164,7 @@ jobs: - name: Update repo submodules run: | cd sdk - git submodule update --init --recursive --remote + git submodule update --init --recursive - name: Build and package PSn00bSDK run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 720ca8c..6a20a0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ include(ExternalProject) project( PSn00bSDK LANGUAGES NONE - VERSION 0.1.0 + VERSION 0.18 DESCRIPTION "Open source PlayStation 1 SDK" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" ) @@ -39,9 +39,15 @@ set( CACHE BOOL "Skip building SDK examples (not required for installation)" ) set( - BUILD_INFO "" - CACHE STRING "Information about this build to be included in build.json" + PSN00BSDK_GIT_TAG "" + CACHE STRING "Git tag or branch name (used by CI)" ) +set( + PSN00BSDK_GIT_COMMIT "" + CACHE STRING "Git commit hash (used by CI)" +) + +string(TIMESTAMP PSN00BSDK_BUILD_DATE UTC) # Forward some important variables to mkpsxiso and to the subprojects (they are # not inherited automatically as they are not environment variables). This also @@ -50,20 +56,24 @@ set( # invoked (ExternalProject_Add() runs the subprojects' install step at build # time). set( - COMMON_ARGS + _common_args -DPSN00BSDK_TC:PATH=${PSN00BSDK_TC} -DPSN00BSDK_TARGET:STRING=${PSN00BSDK_TARGET} -DPSN00BSDK_VERSION:STRING=${PROJECT_VERSION} - -DPSN00BSDK_BUILD_INFO:STRING=${BUILD_INFO} + -DPSN00BSDK_BUILD_DATE:STRING=${PSN00BSDK_BUILD_DATE} + -DPSN00BSDK_GIT_TAG:STRING=${PSN00BSDK_GIT_TAG} + -DPSN00BSDK_GIT_COMMIT:STRING=${PSN00BSDK_GIT_COMMIT} -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} ) set( - SUBPROJECT_ARGS + _sdk_args + ${_common_args} -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_INSTALL_PREFIX:PATH=${PROJECT_BINARY_DIR}/install_tree ) set( - EXAMPLES_ARGS + _examples_args + ${_common_args} -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${PROJECT_BINARY_DIR}/install_tree/${CMAKE_INSTALL_LIBDIR}/libpsn00b/cmake/sdk.cmake -DCMAKE_INSTALL_PREFIX:PATH=${PROJECT_BINARY_DIR}/examples ) @@ -77,26 +87,26 @@ endif() ExternalProject_Add( tools SOURCE_DIR ${PROJECT_SOURCE_DIR}/tools - CMAKE_CACHE_ARGS ${COMMON_ARGS} ${SUBPROJECT_ARGS} + CMAKE_CACHE_ARGS ${_sdk_args} INSTALL_DIR install_tree ) ExternalProject_Add( mkpsxiso SOURCE_DIR ${PROJECT_SOURCE_DIR}/tools/mkpsxiso - CMAKE_CACHE_ARGS ${COMMON_ARGS} ${SUBPROJECT_ARGS} + CMAKE_CACHE_ARGS ${_sdk_args} INSTALL_DIR install_tree ) ExternalProject_Add( libpsn00b SOURCE_DIR ${PROJECT_SOURCE_DIR}/libpsn00b - CMAKE_CACHE_ARGS ${COMMON_ARGS} ${SUBPROJECT_ARGS} + CMAKE_CACHE_ARGS ${_sdk_args} INSTALL_DIR install_tree #DEPENDS tools ) ExternalProject_Add( examples SOURCE_DIR ${PROJECT_SOURCE_DIR}/examples - CMAKE_CACHE_ARGS ${COMMON_ARGS} ${EXAMPLES_ARGS} + CMAKE_CACHE_ARGS ${_examples_args} INSTALL_DIR examples DEPENDS libpsn00b tools mkpsxiso EXCLUDE_FROM_ALL ${SKIP_EXAMPLES} @@ -108,6 +118,7 @@ foreach( _subdir IN ITEMS ${CMAKE_INSTALL_BINDIR} ${CMAKE_INSTALL_LIBDIR} + ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_DATADIR} ) install( diff --git a/CMakePresets.json b/CMakePresets.json index 7c9fdd3..d71c1ae 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -32,10 +32,11 @@ "generator": "Ninja", "binaryDir": "${sourceDir}/../build", "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release", - "BUNDLE_TOOLCHAIN": "ON", - "BUILD_INFO": "Built by GitHub Actions ($env{GITHUB_REF_NAME} $env{GITHUB_SHA})", - "PSN00BSDK_TARGET": "$env{GCC_TARGET}" + "CMAKE_BUILD_TYPE": "Release", + "BUNDLE_TOOLCHAIN": "ON", + "PSN00BSDK_TARGET": "$env{GCC_TARGET}", + "PSN00BSDK_GIT_TAG": "$env{GITHUB_REF_NAME}", + "PSN00BSDK_GIT_COMMIT": "$env{GITHUB_SHA}" } } ] diff --git a/cpack/setup.cmake b/cpack/setup.cmake index 57568bb..a5d71ff 100644 --- a/cpack/setup.cmake +++ b/cpack/setup.cmake @@ -21,7 +21,7 @@ set( ## Bundled components -# "Install" the toolchain and CMake (by pulling files from its their install +# "Install" the toolchain and CMake (by pulling files from their install # locations). This is only useful when building installers, as CPack will pick # up these installation rules and bundle the toolchain in the installers. # NOTE: unfortunately there is no easy way to reuse the toolchain finding logic @@ -105,7 +105,6 @@ set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.md) set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE.md) set(CPACK_PACKAGE_ICON ${CMAKE_CURRENT_LIST_DIR}/icon.ico) set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_LIST_DIR}/description.txt) -set(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_LIST_DIR}/welcome.txt) set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_CURRENT_LIST_DIR}/fakeroot_fix.cmake) set(CPACK_PACKAGE_INSTALL_DIRECTORY PSn00bSDK) diff --git a/cpack/welcome.txt b/cpack/welcome.txt deleted file mode 100644 index e024336..0000000 --- a/cpack/welcome.txt +++ /dev/null @@ -1,3 +0,0 @@ -This installer will set up PSn00bSDK, including prebuilt libraries, CMake scripts as well as several command-line utilities for PlayStation 1 homebrew development. - -NOTE: CMake and the GCC toolchain must be installed separately. diff --git a/doc/cmake_reference.md b/doc/cmake_reference.md index 9e134d9..3c89da3 100644 --- a/doc/cmake_reference.md +++ b/doc/cmake_reference.md @@ -207,9 +207,13 @@ the build script. ## Read-only variables -- `PSN00BSDK_VERSION` +- `PSN00BSDK_VERSION`, `PSN00BSDK_BUILD_DATE`, `PSN00BSDK_GIT_TAG`, + `PSN00BSDK_GIT_COMMIT` - The SDK's version number (`major.minor.patch`). + These variables are loaded from `lib/libpsn00b/build.json` and contain + information about the SDK's version. Note that `PSN00BSDK_GIT_TAG` and + `PSN00BSDK_GIT_COMMIT` are not populated by default when building PSn00bSDK + manually from source, so they might be empty strings. - `PSN00BSDK_TOOLS`, `PSN00BSDK_INCLUDE`, `PSN00BSDK_LDSCRIPTS` @@ -229,4 +233,4 @@ the build script. LZP archives as part of the build pipeline. ----------------------------------------- -_Last updated on 2021-11-24 by spicyjpeg_ +_Last updated on 2021-12-29 by spicyjpeg_ diff --git a/doc/installation.md b/doc/installation.md index ca3aab4..1646653 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -62,7 +62,7 @@ and installed properly. repository to download additional dependencies: ```bash - git submodule update --init --recursive --remote + git submodule update --init --recursive ``` 5. Compile the libraries, tools and examples using CMake: @@ -74,9 +74,8 @@ and installed properly. If you want to install the SDK to a custom location rather than the default one (`C:\Program Files\PSn00bSDK` or `/usr/local` depending on your OS), add - `--install-prefix ` to the first command. Add - `-DPSN00BSDK_TARGET=mipsel-none-elf` if your toolchain targets - `mipsel-none-elf` rather than `mipsel-unknown-elf`. + `--install-prefix ` to the first command. Remember to add + `-DPSN00BSDK_TARGET=mipsel-unknown-elf` if necessary. **NOTE**: Ninja is used by default to build the SDK. If you can't get it to work or don't have it installed, pass `-G "Unix Makefiles"` (or @@ -151,4 +150,4 @@ The toolchain script defines a few CMake macros to create PS1 executables, DLLs and CD images. See the [reference](cmake_reference.md) for details. ----------------------------------------- -_Last updated on 2021-12-23 by spicyjpeg_ +_Last updated on 2021-12-29 by spicyjpeg_ diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c index 2032df5..e268c7d 100644 --- a/examples/sound/spustream/main.c +++ b/examples/sound/spustream/main.c @@ -349,7 +349,7 @@ void start_stream(void) { for (uint32_t i = 0; i < NUM_CHANNELS; i++) { SPU_CHANNELS[i].addr = SPU_RAM_ADDR(BUFFER_START_ADDR + BUFFER_SIZE * i); SPU_CHANNELS[i].freq = SAMPLE_RATE; - SPU_CHANNELS[i].adsr_param = 0xdfee80ff; // or 0x9fc080ff, 0xdff18087 + SPU_CHANNELS[i].adsr_param = 0x1fee80ff; // or 0x9fc080ff, 0xdff18087 } // Unmute the channels and route them for stereo output. You'll want to diff --git a/libpsn00b/CMakeLists.txt b/libpsn00b/CMakeLists.txt index 2b2e76d..829a2f7 100644 --- a/libpsn00b/CMakeLists.txt +++ b/libpsn00b/CMakeLists.txt @@ -73,7 +73,6 @@ install( # Generate build.json. This file is used to determine the SDK version after # installation and may contain additional metadata about the build. -string(TIMESTAMP PSN00BSDK_BUILD_DATE UTC) configure_file( build.json.template build.json ESCAPE_QUOTES diff --git a/libpsn00b/build.json.template b/libpsn00b/build.json.template index 666bb43..374b22a 100644 --- a/libpsn00b/build.json.template +++ b/libpsn00b/build.json.template @@ -1,5 +1,8 @@ { - "version": "${PSN00BSDK_VERSION}", - "build_date": "${PSN00BSDK_BUILD_DATE}", - "build_info": "${PSN00BSDK_BUILD_INFO}" + "version": "${PSN00BSDK_VERSION}", + "build_date": "${PSN00BSDK_BUILD_DATE}", + "git_tag": "${PSN00BSDK_GIT_TAG}", + "git_commit": "${PSN00BSDK_GIT_COMMIT}", + "cmake_version": "${CMAKE_VERSION}", + "host_system": "${CMAKE_HOST_SYSTEM_NAME}" } diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index 1d63e92..7d6bfdd 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -7,13 +7,14 @@ cmake_minimum_required(VERSION 3.20) include(GNUInstallDirs) -# Fetch the SDK version number from build.json. +# Fetch SDK version information from build.json. if(NOT DEFINED PSN00BSDK_VERSION) file(READ ${CMAKE_CURRENT_LIST_DIR}/../build.json _json) string(JSON PSN00BSDK_VERSION GET ${_json} version) string(JSON PSN00BSDK_BUILD_DATE GET ${_json} build_date) - string(JSON PSN00BSDK_BUILD_INFO GET ${_json} build_info) + string(JSON PSN00BSDK_GIT_TAG GET ${_json} git_tag) + string(JSON PSN00BSDK_GIT_COMMIT GET ${_json} git_commit) endif() ## Settings (can be overridden by projects) -- cgit v1.2.3