diff options
| author | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2021-09-12 19:39:19 +0200 |
|---|---|---|
| committer | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2021-09-12 19:39:19 +0200 |
| commit | 71496627f90071a2fda809b5460d9c1f99373968 (patch) | |
| tree | 8c04e31c23ee378e5002f91e0162575f917eab29 | |
| parent | cea06fba6de344333365d7ee623ad30d152636a6 (diff) | |
| download | psn00bsdk-71496627f90071a2fda809b5460d9c1f99373968.tar.gz | |
Updated docs, moved install guide to INSTALL.md
| -rw-r--r-- | INSTALL.md | 100 | ||||
| -rw-r--r-- | README.md | 103 | ||||
| -rw-r--r-- | doc/cmake_reference.md | 203 | ||||
| -rw-r--r-- | doc/dev notes.txt | 56 | ||||
| -rw-r--r-- | psn00bsdk-setup.mk | 121 | ||||
| -rw-r--r-- | toolchain.txt | 42 |
6 files changed, 387 insertions, 238 deletions
diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..974ee0a --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,100 @@ + +# Getting started with PSn00bSDK + +## Building and installing + +The instructions below are for Windows and Linux. Building on macOS hasn't been +tested but should work. + +1. Install a host C compiler toolchain if you don't already have one (this is + required to build the tools). You can use MSVC or MinGW on Windows, or + install the `build-essential` package provided by most Linux distros. + +2. Install Git and CMake. Note that some Linux distros ship relatively old + versions of CMake, so make sure you have at least CMake 3.21. You may also + want to grab [Ninja](https://ninja-build.org) (it is a single executable, you + have to copy it to any directory listed in the `PATH` environment variable) + as a faster alternative to `make`. + +3. Build and install a GCC toolchain for `mipsel-unknown-elf`. As GCC is + notoriously hard to compile under Windows, you may download a precompiled + version from [Lameguy64's website](http://lameguy64.net?page=psn00bsdk) + and extract it to the root of your C drive instead. See + [toolchain.txt](toolchain.txt) for details on compiling GCC. + +4. Set the `PSN00BSDK_TC` environment variable to point to the location you + installed or extracted the toolchain to. The default is + `C:\Program Files\PSn00bSDK\mips-unknown-elf` on Windows or + `/usr/local/mips-unknown-elf` on Linux; installing to a different path is + not recommended. + +5. Clone/download the PSn00bSDK repo and run the following commands: + + ```bash + cmake -S . -B ./build -G Ninja --install-prefix INSTALL_PATH + cmake --build ./build + cmake --install ./build + ``` + + Replace `INSTALL_PATH` with the directory you want PSn00bSDK to be installed + to (default is `C:\Program Files\PSn00bSDK` or `/usr/local`), and remove + `-G Ninja` if you want to use `make` instead (not recommended). The following + subdirectories will be created: + + - `INSTALL_PATH/bin` + - `INSTALL_PATH/lib/libpsn00b` + - `INSTALL_PATH/share/psn00bsdk` + +6. Set the `PSN00BSDK_LIBS` environment variable to + `INSTALL_PATH/lib/libpsn00b` and add `INSTALL_PATH/bin` to `PATH`. + +Although not strictly required, you'll probably want to install a PS1 emulator +with debugging capabilities such as [no$psx](https://problemkaputt.de/psx.htm) +(Windows only) or [pcsx-redux](https://github.com/grumpycoders/pcsx-redux). +**Avoid ePSXe and anything based on MAME** as they are inaccurate. + +## Building installer packages + +CPack can be used to build NSIS-based installers on Windows or DEB/RPM packages +on Linux, plus zipped packages on all platforms. Note that currently none of the +built packages include the GCC toolchain, thus their usefulness is limited. + +1. Follow steps 1-4 above to set up the toolchain, then install NSIS on Windows + or `dpkg` and `rpm` on Linux. + +2. Run the following commands from the PSn00bSDK directory: + + ```bash + cmake -S . -B ./build -G Ninja + cmake --build ./build -t package + ``` + + All built packages will be copied to the `build/cpack` folder. + +## Creating a project + +1. Copy the contents of `INSTALL_PATH/share/psn00bsdk/template` (or the + `template` folder within the repo) to your new project's root directory. + +2. Configure and build the template by running: + + ```bash + cmake -S . -B ./build -G Ninja + cmake --build ./build + cmake --install ./build + ``` + + If you did everything correctly there should be a `template.bin` CD image in + the `build` folder. Test it in an emulator to ensure it works. + +Note that, even though the template relies on the `PSN00BSDK_LIBS` environment +variable to locate the SDK by default, you can also specify the path directly +on the CMake command line by adding +`-DCMAKE_TOOLCHAIN_FILE=INSTALL_PATH/lib/libpsn00b/cmake/sdk.cmake` (replace +`INSTALL_PATH` as usual) to the first command. + +The toolchain script defines a few CMake macros to create PS1 executables, DLLs +and CD images. See the [reference](doc/cmake_reference.md) for details. + +----------------------------------------- +_Last updated on 2021-09-12 by spicyjpeg_ @@ -79,102 +79,14 @@ As of August 16, 2021 ## Obtaining PSn00bSDK +PSn00bSDK has switched to a CMake-based build and installation system. See +[INSTALL.md](INSTALL.md) for details. + Because PSn00bSDK is updated semi-regularly due to this project being in a work-in-progress state, it is better to obtain this SDK from source and building it yourself in the long run. Pre-compiled packages for Debian and -Msys2 are being planned however. - -A precompiled copy of the GCC 7.4.0 toolchain for Windows is available -in the PSn00bSDK page of Lameguy64's website -( http://lameguy64.net/?page=psn00bsdk ). This should make building PSn00bSDK -under Windows a bit easier, as the GCC toolchain is quite difficult to -compile correctly under Windows than it is on Linux and BSDs. - - -## Building the SDK - -You may set one of the following variables either with set/export or on the -make command line, to specify various parameters in building PSn00bSDK and -projects made with it as you see fit. - -* ``PSN00BSDK_TC`` specifies the base directory of the GCC toolchain to - build PSn00bSDK with, otherwise the makefile assumes you have the path to - the toolchain binaries in one of your PATH directories. Alternatively, - ``GCC_BASE`` can be specified in place of ``PSN00BSDK_TC``. If not - specified psn00bsdk-setup.mk assumes the toolchain is at - C:\mipsel-unknown-elf in Win32 or /usr/local/mipsel-unknown-elf in Linux. -* ``GCC_VERSION`` specifies the GCC version number. This is only used for - building the libc library. If not defined, it will be auto-detected by - searching ``PSN00BSDK_TC`` or ``GCC_BASE`` for a valid GCC installation. -* ``PSN00BSDK_LIBS`` specifies the target directory you wish to install - the compiled libpsn00b libraries to. If not defined, compiled - libraries are consolidated to the libpsn00b directory and - psn00bsdk-setup.mk assumes the SDK libraries are at ../psn00bsdk/libpsn00b. - - -### Windows: -1. Download the following: - * MSys2 (32-bit or 64-bit version whichever you prefer) - * GCC 7.4.0 for mipsel-unknown-elf (download from Lameguy64's website at - http://lameguy64.net?page=psn00bsdk if you rather not build it yourself) -2. Install MSys2, update packages (with pacman -Syu) then install the - following packages: - * git - * make - * mingw-w64-i686-gcc (32-bit) or mingw-w64-x86_64-gcc (64-bit) - You may need to close and reopen MSys2 for the PATH environment in the - shell to update for MinGW. - * mingw-w64-i686-tinyxml2 (32-bit) or mingw-w64-x86_64-tinyxml2 (64-bit) - Used by lzpack and smxlink. -3. Extract GCC 7.4.0 for mipsel-unknown-elf to the root of your C drive. -4. Edit `mipsel-unknown-elf/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x` - and append definitions to the .text definition as explained in - toolchain.txt. -5. Add `export PATH=$PATH:/c/mipsel-unknown-elf/bin` to your `.bash_profile` - file in MSys2. Test if `mipsel-unknown-elf-gcc` can be called from any - directory in the terminal after reloading the MSys2 shell for the change - to take effect. -6. Clone from PSn00bSDK source with - `git clone https://github.com/lameguy64/psn00bsdk` - Clone it in the root of your C drive or in any location you prefer. -7. Enter the tools directory in PSn00bSDK and run `make` to build all tools, - then run `make install` to consolidate all tools to a single bin - directory. Add this directory to your PATH variable by adding - `export=$PATH:<path to SDK>/tools/bin` in your .bash_profile. Reload - the MSys2 shell for the changes to take effect, then enter `elf2x` if - the tools can be executed from any directory. -8. Enter libpsn00b directory and run `make` to build all libpsn00b libraries, - then `make install` to consolidate the libraries to either the parent - directory or the directory specified by ``PSN00BSDK_LIBS``. -6. Compile the example programs by running `make` from the examples - directory to test the SDK. - -If you prefer to do things in the Command Prompt, you can add the paths -c:\msys64\usr\bin, c:\msys64\mingw64\bin (mingw32 for 32-bit), -c:\mipsel-unknown-elf\bin and c:\psn00bsdk\tools\bin (paths may vary -depending on where you've installed/extracted them) to your system's -PATH environment variable. This way, you can invoke make and compile -programs with PSn00bSDK within the Command Prompt. - - -### Linux and Unix-likes: -1. Install gcc, make, texinfo, git and development packages of mpfr, mpc, - gmp, isl and tinyxml2 libraries for your distro. -2. Build and install the GNU GCC toolchain targeting mipsel-unknown-elf - (see toolchain.txt for details). Export a variable named `PSN00BSDK_TC` - containing a path to the installed toolchain's base directory if - you've installed the toolchain in a location other than /usr/local. -3. Clone from PSn00bSDK source with - `git clone https://github.com/lameguy64/psn00bsdk` -4. Enter tools directory and run `make`, then `make install` to consolidate - the tools to the bin directory. Add this directory to your PATH variable - and make sure `elf2x` and other tools are accessible from any directory. -5. Enter the libpsn00b directory and run `make`. Then, run `make install` - to consolidate the libraries to the libpsn00b parent directory, or the - directory specified by ``PSN00BSDK_LIBS``. -6. Compile the example programs by running `make` from the examples - directory to test the SDK. - +Msys2 are being planned however (it is already possible to build installers, +DEB and RPM packages through CPack so it's only a matter of time). ## Examples @@ -207,11 +119,6 @@ for the PlayStation. The tutorials should still apply to PSn00bSDK. * Pad and memory card libraries that don't use the BIOS routines. -* Switching to, or adding support for a build system that's easier to use with - IDEs and/or under Windows, which would also make asset conversion pipelines - easier to manage. CMake might be a good option here but more discussion is - needed. - ## Usage terms PSn00bSDK falls under the terms and conditions of the Mozilla Public diff --git a/doc/cmake_reference.md b/doc/cmake_reference.md new file mode 100644 index 0000000..8810ad4 --- /dev/null +++ b/doc/cmake_reference.md @@ -0,0 +1,203 @@ + +# PSn00bSDK CMake reference + +## Setup + +The only requirement to use the SDK in CMake is to set the +`CMAKE_TOOLCHAIN_FILE` variable to `INSTALL_PATH/lib/libpsn00b/cmake/sdk.cmake` +(where `INSTALL_PATH` is the install prefix PSn00bSDK is installed to). This +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() +``` + +See the [template](../template/CMakeLists.txt) for an example CMake script +showing how to build a simple project. + +## Targets + +These targets are defined when using PSn00bSDK. There is no need to explicitly +link against any of these, as the helper commands (see below) handle linking +behind the scenes. To avoid conflicts, however, no target should be given any +of these names. + +- `c`, `psxgpu`, `psxgte`, `psxspu`, `psxcd`, `psxsio`, `psxetc`, `psxapi`, `lzp` +- `psn00bsdk_common`, `psn00bsdk_object_lib` +- `psn00bsdk_static_exe` +- `psn00bsdk_dynamic_exe` +- `psn00bsdk_static_lib` +- `psn00bsdk_shared_lib`, `psn00bsdk_module_lib` + +## Commands + +- `psn00bsdk_add_executable(<name> <STATIC|DYNAMIC> [EXCLUDE_FROM_ALL] [sources...])` + + A wrapper around `add_executable()` to create PS1 executables. Three files + will be generated for each call to this function: + + - `<name>.elf` (regular ELF executable) + - `<name>.exe` (executable converted to the format expected by the PS1) + - `<name>.map` (symbol map file for dynamic linking/introspection) + + The `.exe` and `.map` extensions can be customized by overriding + `PSN00BSDK_EXECUTABLE_SUFFIX` and `PSN00BSDK_SYMBOL_MAP_SUFFIX` prior to + creating the executable. + + The second argument (mandatory) specifies whether the executable is going to + load DLLs at runtime. If set to `STATIC`, $gp-relative addressing (i.e. + reusing the $gp register normally used for DLL addressing) will be enabled, + slightly reducing executable size and RAM usage but breaking compatibility + with the dynamic linker. + +- `psn00bsdk_add_library(<name> <STATIC|OBJECT|SHARED|MODULE> [EXCLUDE_FROM_ALL] [sources...])` + + Wraps `add_library()` to create static libraries or dynamically-linked + libraries (DLLs). + + The second argument (mandatory, unlike `add_library()`) specifies the type of + library to create. `STATIC` will create a static library named `lib<name>.a`. + `SHARED` and `MODULE` will compile a DLL, producing the following files (note + that there is no `lib` prefix for DLLs): + + - `<name>.so` (regular ELF shared library) + - `<name>.dll` (raw binary with some ELF headers prepended) + + As with executables, the `.dll` extension can be customized by setting + `PSN00BSDK_SHARED_LIBRARY_SUFFIX`. + +- `psn00bsdk_add_cd_image(<name> <image name> <config file> [...])` + + Creates a new target that will build a CD image using `mkpsxiso`. + + The first argument is the name of the target to create; next up is the name + of the generated image file (`<image name>.bin` + `<image name>.cue`). The + third argument is the path to the XML file passed to `mkpsxiso`. + + The XML file is "configured" by CMake, i.e. any `${var}` or `@var@` + expressions are replaced with the values of the respective variables. In + particular `${CD_IMAGE_NAME}` is replaced with the second argument passed to + `psn00bsdk_add_cd_image()`; the file must properly set the output file names + like this: + + ```xml + <?xml version="1.0" encoding="utf-8"?> + <iso_project + image_name="${CD_IMAGE_NAME}.bin" + cue_sheet="${CD_IMAGE_NAME}.cue" + > + ``` + + Any additional argument is passed through to the underlying call to + `add_custom_target()`, so most of the options supported by + `add_custom_target()` are also supported here. + +## Definitions + +When compiling executables and libraries using the above commands the following +preprocessor macros are automatically `#define`'d: + +- `PLAYSTATION` + + Always set to 1. Can be used to implement different options or code paths for + libraries, so they can target both the host and PS1 (as it won't be defined + when compiling outside of the SDK). + +- `DEBUG` + + Defined and set to 1 in a debug configuration, i.e. when the + `CMAKE_BUILD_TYPE` variable is set to `Debug`. This value is used by the + PSn00bSDK libraries, and should be used in executables, to enable additional + debug logging. + + Note that the default CMake configuration is usually debug, so it's + recommended to specify `-DCMAKE_BUILD_TYPE=Release` to get rid of the logging + overhead in release builds and reduce executable size. + +## Cached settings + +These variables are stored in CMake's cache and can be edited by the project's +build script, from the CMake command line when configuring the project +(`-Dname=value`) or using an editor such as the CMake GUI. + +- `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. + + The following GCC target triplets have been confirmed to work with PSn00bSDK: + + - `mipsel-unknown-elf` + - `mipsel-none-elf` + +- `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). + + **IMPORTANT**: if the toolchain's target is not `mipsel-unknown-elf`, + `PSN00BSDK_TARGET` must be set regardless of whether or not `PSN00BSDK_TC` is + also set. + +- `PSN00BSDK_LIBGCC` (`FILEPATH`) + + Path to the `libgcc.a` library bundled with the GCC toolchain. The contents + of this library are merged into `libc` when building the SDK, so this + variable is only actually needed when compiling `libpsn00b`. Setting this + variable manually usually isn't necessary as CMake will locate `libgcc.a` + automatically after finding the toolchain. + +## Internal settings + +These settings are not stored in CMake's cache and can only be set from within +the build script. + +- `PSN00BSDK_LIBRARIES` + + List of libraries to link all created targets against. By default this + includes all PSn00bSDK libraries. + +- `PSN00BSDK_EXECUTABLE_SUFFIX`, `PSN00BSDK_SHARED_LIBRARY_SUFFIX`, + `PSN00BSDK_SYMBOL_MAP_SUFFIX` + + File extensions to use for generated PS1 files. The default values are + `.exe`, `.dll` and `.map` respectively. Note that file names and extensions + can be changed anyway when building a CD image. + +## Read-only variables + +- `PSN00BSDK_TOOLS`, `PSN00BSDK_INCLUDE`, `PSN00BSDK_LDSCRIPTS` + + Lists of paths used internally. Should not be set, manipulated or overridden + by scripts. + +- `TOOLCHAIN_NM` + + Path to the `nm` executable used to generate symbol maps. Although not used + internally by CMake, this program is part of the GCC toolchain. + +- `ELF2X`, `ELF2CPE`, `MKPSXISO`, `LZPACK`, `SMXLINK` + + Paths to the PSn00bSDK tools' executables. As no functions are currently + provided for building assets, `LZPACK` and `SMXLINK` can be used with + `add_custom_command()`/`add_custom_target()` to convert models and generate + LZP archives as part of the build pipeline. + +----------------------------------------- +_Last updated on 2021-09-12 by spicyjpeg_ diff --git a/doc/dev notes.txt b/doc/dev notes.txt index 47aa2df..151a441 100644 --- a/doc/dev notes.txt +++ b/doc/dev notes.txt @@ -92,3 +92,59 @@ power operator, not xor): * If you are overriding any of the memory allocation functions, DO NOT ENABLE LINK-TIME OPTIMIZATION. GCC has a long-standing bug with LTO and weak functions written in assembly, also LTO hasn't been tested at all yet. + +Obscure CMake issues and related stuff: + +* Toolchain files are loaded "early" according to the CMake docs. What this +means in practice is that a lot of commands, such as find_*(), won't work +properly in a toolchain script as they rely on variables initialized by the +project() command. The poorly documented solution to this is to move such +commands to a separate file and set CMAKE_PROJECT_INCLUDE to point to it, so +project() will execute it immediately after initialization. + +* There is no way to use multiple toolchains (PS1 + host) in a single project, +even if you use add_subdirectory() to execute multiple project files (which, +confusingly, adds their targets to the parent project rather than treating them +as separate projects). Thankfully though CMake provides support for automating +the build process of independent CMake projects via the ExternalProject module. +Which brings me to the next issue... + +* If you run CPack on a "superbuild" project (i.e. a project that calls +ExternalProject_Add() to configure, compile and install subprojects at build +time), you'll likely run into a weird issue with CPack bundling folders from +your build directory into DEB and RPM packages. This is caused by the DEB/RPM +generators running "cmake --install" in a chroot/fakeroot to prepare the files +to be packaged, which seems to interfere with absolute paths in the project +cache or something like that (?). The only workaround I know of is to use +CPACK_PRE_BUILD_SCRIPTS to trigger a custom script that deletes anything other +than the actual files to be packaged (see cpack/fakeroot_fix.cmake). + +* Depending on how you find external dependencies (find_package(), vcpkg, +pkg-config...), CMake may end up outputting an executable that relies on a DLL +installed system-wide. To correctly install the DLL alongside the executable +you have to specify a regex as follows: + + install( + TARGETS my_executable + RUNTIME_DEPENDENCIES + PRE_EXCLUDE_REGEXES ".*" + PRE_INCLUDE_REGEXES "tinyxml2" + ) + +CMake will scan the executable at install time and copy all the required DLLs +that match the second regex. If no regex is specified CMake will also copy OS +DLLs like libc or msvcrt, which usually isn't the desired behavior. + +* Using interface targets to set include directories can be finicky. Not only +do you have to use generator expressions to conditionally use different paths +depending on whether the targets are installed, but CMake can get confused on +which options to pass to the compiler. I spent hours trying to get CMake to use +-I rather than -isystem for include directories (for some reason GCC would +ignore -isystem completely). I eventually gave up and just set the include +directories manually for each target, and for some reason CMake actually +started passing -I instead of -isystem to GCC. + +* Not a CMake/CPack bug per se, but NSIS is picky about the banner and header +images shown in generated installers. They must be Windows BMP version 3 files +with no alpha channel, no compression and no metadata. They can either be +24-bit RGB or indexed, though it's common to use indexed colors to save space. diff --git a/psn00bsdk-setup.mk b/psn00bsdk-setup.mk deleted file mode 100644 index 8417358..0000000 --- a/psn00bsdk-setup.mk +++ /dev/null @@ -1,121 +0,0 @@ -# PSn00bSDK project setup file -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions -# -# This file does not depend on any other files (besides paths specified via -# environment variables) and may be copied for use with your projects. See the -# template directory for a makefile template. - -#PREFIX ?= mipsel-none-elf -PREFIX ?= mipsel-unknown-elf - -## Path setup - -# PSn00bSDK library/include path setup -ifndef PSN00BSDK_LIBS - # Default assumes PSn00bSDK is in the same parent dir as this project - LIBDIRS = -L../libpsn00b - INCLUDE = -I../libpsn00b/include -I../libpsn00b/lzp - LDBASE = ../libpsn00b/ldscripts -else - LIBDIRS = -L$(PSN00BSDK_LIBS) - INCLUDE = -I$(PSN00BSDK_LIBS)/include -I$(PSN00BSDK_LIBS)/lzp - LDBASE = ${PSN00BSDK_LIBS}/ldscripts -endif - -# PSn00bSDK toolchain path setup -ifndef PSN00BSDK_TC - # Default assumes GCC toolchain is in root of C drive or /usr/local - ifeq "$(OS)" "Windows_NT" - GCC_BASE ?= /c/$(PREFIX) - GCC_BIN ?= - else - GCC_BASE ?= /usr/local/$(PREFIX) - GCC_BIN ?= - endif -else - GCC_BASE ?= $(PSN00BSDK_TC) - GCC_BIN ?= $(PSN00BSDK_TC)/bin/ -endif - -# Autodetect GCC version by folder name (ugly but it works, lol) -#GCC_VERSION ?= 7.4.0 -GCC_VERSION ?= $(word 1, $(notdir $(wildcard $(GCC_BASE)/lib/gcc/$(PREFIX)/*))) - -# PSn00bSDK tools path setup (TODO) -PSN00BSDK_BIN ?= - -## Commands - -# GCC toolchain -CC = $(GCC_BIN)$(PREFIX)-gcc -CXX = $(GCC_BIN)$(PREFIX)-g++ -AS = $(GCC_BIN)$(PREFIX)-as -AR = $(GCC_BIN)$(PREFIX)-ar -LD = $(GCC_BIN)$(PREFIX)-ld -RANLIB = $(GCC_BIN)$(PREFIX)-ranlib -OBJCOPY = $(GCC_BIN)$(PREFIX)-objcopy -NM = $(GCC_BIN)$(PREFIX)-nm - -# PSn00bSDK tools + mkpsxiso -ELF2X = $(PSN00BSDK_BIN)elf2x -LZPACK = $(PSN00BSDK_BIN)lzpack -SMXLINK = $(PSN00BSDK_BIN)smxlink -MKPSXISO = $(PSN00BSDK_BIN)mkpsxiso - -## Flags - -# SDK libraries (IMPORTANT: don't change the order) -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxcd -lpsxsio -lpsxetc -lpsxapi -lc - -# Common options: -# - Debugging symbols enabled -# - Wrap each symbol in a separate section -# - Optimize for R3000, no FPU, 32-bit ABI -# - Division by zero causes break opcodes to be executed -# - C standard library (including libgcc) disabled -# - C++ features that rely on runtime support disabled -AFLAGS = -g -msoft-float -march=r3000 -mtune=r3000 -mabi=32 -CFLAGS = $(AFLAGS) -mdivide-breaks -O2 -ffreestanding -fno-builtin -nostdlib \ - -fdata-sections -ffunction-sections -fsigned-char -fno-strict-overflow -CPPFLAGS= $(CFLAGS) -fno-exceptions -fno-rtti -fno-unwind-tables \ - -fno-threadsafe-statics -fno-use-cxa-atexit -LDFLAGS = -nostdlib - -# Options for static libraries (and SDK libraries): -# - GP-relative addressing disabled -# - ABI-compatible calls disabled -# - Local stripping enabled -AFLAGS_LIB = $(AFLAGS) -G0 -Wa,--strip-local-absolute -CFLAGS_LIB = $(CFLAGS) -G0 -mno-abicalls -mno-gpopt -CPPFLAGS_LIB = $(CPPFLAGS) -G0 -mno-abicalls -mno-gpopt - -# Options for executables without support for dynamic linking: -# - Position-independent code disabled -# - GP-relative addressing enabled only for local symbols -# - ABI-compatible calls disabled (incompatible with GP-relative addressing) -# - Unused section stripping enabled -AFLAGS_EXE = $(AFLAGS) -G8 -CFLAGS_EXE = $(CFLAGS) -G8 -mno-abicalls -mgpopt -mno-extern-sdata -CPPFLAGS_EXE = $(CPPFLAGS) -G8 -mno-abicalls -mgpopt -mno-extern-sdata -LDFLAGS_EXE = $(LDFLAGS) -G8 -static -T$(LDBASE)/exe.ld -gc-sections - -# Options for executables with support for dynamic linking: -# - Position-independent code disabled -# - GP-relative addressing disabled -# - ABI-compatible calls disabled (must be done manually) -# - Unused section stripping enabled -AFLAGS_EXEDYN = $(AFLAGS) -G0 -CFLAGS_EXEDYN = $(CFLAGS) -G0 -mno-abicalls -mno-gpopt -CPPFLAGS_EXEDYN = $(CPPFLAGS) -G0 -mno-abicalls -mno-gpopt -LDFLAGS_EXEDYN = $(LDFLAGS) -G0 -static -T$(LDBASE)/exe.ld -gc-sections - -# Options for dynamically-loaded libraries: -# - Position-independent code enabled -# - GP-relative addressing disabled (incompatible with ABI calls) -# - ABI-compatible calls enabled -# - Unused section stripping not available -AFLAGS_DLL = $(AFLAGS) -G0 -CFLAGS_DLL = $(CFLAGS) -G0 -mabicalls -mshared -mno-gpopt -fPIC -CPPFLAGS_DLL = $(CPPFLAGS) -G0 -mabicalls -mshared -mno-gpopt -fPIC -LDFLAGS_DLL = $(LDFLAGS) -G0 -shared -T$(LDBASE)/dll.ld diff --git a/toolchain.txt b/toolchain.txt index e67cfe1..d34d54b 100644 --- a/toolchain.txt +++ b/toolchain.txt @@ -20,12 +20,8 @@ the libgcc.a library from it to the Windows build. Make sure the following packages are installed prior to building: * make -* texinfo -* mpfr (development libs, if your distro offers it in a separate package) -* isl (development libs, if your distro offers it in a separate package) -* gmp (development libs, if your distro offers it in a separate package) -* mpc (development libs, if your distro offers it in a separate package) -* build-essential or build-essentials, if you don't have GCC installed yet. +* build-essential or build-essentials, if you don't have GCC installed yet + (a host toolchain is required to build the rest of the SDK anyway). Building binutils: @@ -38,16 +34,17 @@ mipsel-unknown-elf. wish to use with PSn00bSDK. The reference version that PSn00bSDK is tested with most is 2.31. -* Extract the contents of the archive, preferably in a directory named gcc. +* Extract the contents of the archive, preferably in a directory named + "toolchain" (or whatever). -* Create a directory named binutils-build inside the gcc directory. Do not - create it inside the binutils directory with the source files. +* Create a directory named binutils-build inside the toolchain directory. Do + not create it inside the binutils directory with the source files. * Enter the binutils-build directory and configure binutils from there with the following command line: ../binutils-<version>/configure --prefix=/usr/local/mipsel-unknown-elf \ ---target=mipsel-unknown-elf --with-float=soft +--target=mipsel-unknown-elf --disable-docs --disable-nls --with-float=soft Replace <version> with the version of binutils you wish to use. You may also want to change the prefix argument to a path you prefer to have the toolchain @@ -73,17 +70,23 @@ longer so it's going to take a longer while to build this. wish to use with PSn00bSDK. The reference version that PSn00bSDK is tested with most is 7.4.0. -* Extract it to the same gcc directory you extracted binutils in. +* Extract it to the same toolchain directory you extracted binutils in. -* Create a directory named gcc-build inside the gcc directory. +* Enter the extracted "gcc-<version>" folder and run the following command + from there to download the required dependencies: + +./contrib/download_prerequisites + +* Go back and create a directory named gcc-build inside the toolchain + directory. * Enter the gcc-build directory and configure gcc from there with the following command line: -../gcc-<version>/configure --disable-nls --disable-libada --disable-libssp \ ---disable-libquadmath --disable-libstdc++-v3 --target=mipsel-unknown-elf \ ---prefix=/usr/local/mipsel-unknown-elf --with-float=soft \ ---enable-languages=c,c++ --with-gnu-as --with-gnu-ld +../gcc-<version>/configure --prefix=/usr/local/mipsel-unknown-elf \ +--target=mipsel-unknown-elf --disable-docs --disable-nls --disable-libada \ +--disable-libssp --disable-libquadmath --disable-libstdc++-v3 \ +--with-float=soft --enable-languages=c,c++ --with-gnu-as --with-gnu-ld Replace <version> with the version of gcc you downloaded. The prefix path must match to what you've specified for binutils earlier, if you've decided @@ -109,9 +112,10 @@ through System Properties. Note regarding C++ support: -C++ support in PSn00bSDK only goes as far as basic classes, namespaces and -the ability to dynamically create and delete class objects at any point of -the program. The required dependencies are supplied by libc of libpsn00b. +C++ support in PSn00bSDK, besides compile-time features like constexpr, only +goes as far as basic classes, namespaces and the ability to dynamically create +and delete class objects at any point of the program. The required dependencies +are supplied by libc of libpsn00b. Standard C++ libraries are not implemented and likely never going to be implemented due to bloat concerns that it may introduce. Besides, the official |
