From d82646157368574dcf29e76eff7e9b7a9b0559ef Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 29 Aug 2025 19:51:13 +1000 Subject: [PATCH] PS4: Bring makefile up to date --- misc/ps4/Makefile | 117 +++++++++++++++++++++++------------ src/UWP/Platform_UWP.cpp | 52 +++------------- src/UWP/Window_UWP.cpp | 19 +++--- src/{ => ps4}/Platform_PS4.c | 71 +++++---------------- src/{ => ps4}/Window_PS4.c | 27 ++++---- 5 files changed, 123 insertions(+), 163 deletions(-) rename src/{ => ps4}/Platform_PS4.c (88%) rename src/{ => ps4}/Window_PS4.c (91%) diff --git a/misc/ps4/Makefile b/misc/ps4/Makefile index bf4983917..9ffbc51ad 100644 --- a/misc/ps4/Makefile +++ b/misc/ps4/Makefile @@ -1,53 +1,76 @@ -# Package metadata. -TITLE := OpenOrbis Hello World Sample +ifeq ($(strip $(OO_PS4_TOOLCHAIN)),) +$(error "Please set OO_PS4_TOOLCHAIN in your environment. export OO_PS4_TOOLCHAIN=") +endif +TOOLCHAIN := $(OO_PS4_TOOLCHAIN) + +.SUFFIXES: + +#--------------------------------------------------------------------------------- +# Configurable options +#--------------------------------------------------------------------------------- +BUILD_DIR = build/ps4 +SOURCE_DIRS = src src/ps4 third_party/bearssl + +TARGET = ClassiCube-PS4 +TITLE := ClassiCube VERSION := 1.00 TITLE_ID := BREW00083 CONTENT_ID := IV0000-BREW00083_00-HELLOWORLD000000 -# Libraries linked into the ELF. +#--------------------------------------------------------------------------------- +# Compilable files +#--------------------------------------------------------------------------------- +CPP_FILES = $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.cpp)) +C_FILES = $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c)) +OBJS = $(addprefix $(BUILD_DIR)/, $(notdir $(C_FILES:%.c=%.o) $(CPP_FILES:%.cpp=%.o))) + +# Dependency tracking +DEPFLAGS = -MT $@ -MMD -MP -MF $(BUILD_DIR)/$*.d +DEPFILES := $(OBJS:%.o=%.d) + +#--------------------------------------------------------------------------------- +# Code generation +#-------------------------------------------------------------------------------- LIBS := -lc -lkernel -lc++ -lSceVideoOut -lSceNet -# Additional compile flags. -#EXTRAFLAGS := - -# Asset and module directories. -LIBMODULES := $(wildcard sce_module/*) - -# You likely won't need to touch anything below this point. - -# Root vars -TOOLCHAIN := $(OO_PS4_TOOLCHAIN) -PROJDIR := src -INTDIR := build-ps4 - -# Define objects to build -CFILES := $(wildcard $(PROJDIR)/*.c) -CPPFILES := $(wildcard $(PROJDIR)/*.cpp) -OBJS := $(patsubst $(PROJDIR)/%.c, $(INTDIR)/%.o, $(CFILES)) $(patsubst $(PROJDIR)/%.cpp, $(INTDIR)/%.o, $(CPPFILES)) - -# Define final C/C++ flags CFLAGS := --target=x86_64-pc-freebsd12-elf -fPIC -funwind-tables -c $(EXTRAFLAGS) -isysroot $(TOOLCHAIN) -isystem $(TOOLCHAIN)/include -isystem $(TOOLCHAIN)/include/orbis -DPLAT_PS4 CXXFLAGS := $(CFLAGS) -isystem $(TOOLCHAIN)/include/c++/v1 LDFLAGS := -m elf_x86_64 -pie --script $(TOOLCHAIN)/link.x --eh-frame-hdr -L$(TOOLCHAIN)/lib $(LIBS) $(TOOLCHAIN)/lib/crt1.o -# Create the intermediate directory incase it doesn't already exist. -_unused := $(shell mkdir -p $(INTDIR)) +#--------------------------------------------------------------------------------- +# Compiler tools +#--------------------------------------------------------------------------------- CC := clang CCX := clang++ LD := ld.lld CDIR := linux -all: $(CONTENT_ID).pkg +#--------------------------------------------------------------------------------- +# Main targets +#--------------------------------------------------------------------------------- +all: $(BUILD_DIR) $(CONTENT_ID).pkg + +clean: + rm -f $(CONTENT_ID).pkg pkg.gp4 pkg/sce_sys/param.sfo eboot.bin \ + $(BUILD_DIR)/$(PROJDIR).elf $(BUILD_DIR)/$(PROJDIR).oelf $(OBJS) + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + + +#--------------------------------------------------------------------------------- +# Executable generation +#--------------------------------------------------------------------------------- $(CONTENT_ID).pkg: pkg.gp4 $(TOOLCHAIN)/bin/$(CDIR)/PkgTool.Core pkg_build $< . -pkg.gp4: eboot.bin - cd misc/ps4 - $(TOOLCHAIN)/bin/$(CDIR)/create-gp4 -out $@ --content-id=$(CONTENT_ID) --files "sce_sys/about/right.sprx sce_sys/param.sfo sce_sys/icon0.png" +pkg.gp4: eboot.bin $(BUILD_DIR)/sce_sys/param.sfo + $(TOOLCHAIN)/bin/$(CDIR)/create-gp4 -out $@ --content-id=$(CONTENT_ID) --files "eboot.bin sce_sys/about/right.sprx sce_sys/param.sfo sce_sys/icon0.png" -misc/ps4/sce_sys/param.sfo: Makefile +$(BUILD_DIR)/sce_sys/param.sfo: + mkdir -p $(BUILD_DIR)/sce_sys $(TOOLCHAIN)/bin/$(CDIR)/PkgTool.Core sfo_new $@ $(TOOLCHAIN)/bin/$(CDIR)/PkgTool.Core sfo_setentry $@ APP_TYPE --type Integer --maxsize 4 --value 1 $(TOOLCHAIN)/bin/$(CDIR)/PkgTool.Core sfo_setentry $@ APP_VER --type Utf8 --maxsize 8 --value '$(VERSION)' @@ -60,16 +83,32 @@ misc/ps4/sce_sys/param.sfo: Makefile $(TOOLCHAIN)/bin/$(CDIR)/PkgTool.Core sfo_setentry $@ TITLE_ID --type Utf8 --maxsize 12 --value '$(TITLE_ID)' $(TOOLCHAIN)/bin/$(CDIR)/PkgTool.Core sfo_setentry $@ VERSION --type Utf8 --maxsize 8 --value '$(VERSION)' -eboot.bin: $(INTDIR) $(OBJS) - $(LD) $(INTDIR)/*.o -o $(INTDIR)/$(PROJDIR).elf $(LDFLAGS) - $(TOOLCHAIN)/bin/$(CDIR)/create-fself -in=$(INTDIR)/$(PROJDIR).elf -out=$(INTDIR)/$(PROJDIR).oelf --eboot "eboot.bin" --paid 0x3800000000000011 +$(BUILD_DIR)/$(TARGET).elf: $(OBJS) + $(LD) $(OBJS) -o $(BUILD_DIR)/$(TARGET).elf $(LDFLAGS) -$(INTDIR)/%.o: $(PROJDIR)/%.c - $(CC) $(CFLAGS) -o $@ $< +eboot.bin: $(BUILD_DIR)/$(TARGET).elf + $(TOOLCHAIN)/bin/$(CDIR)/create-fself -in=$(BUILD_DIR)/$(TARGET).elf -out=$(BUILD_DIR)/$(TARGET).oelf --eboot "eboot.bin" --paid 0x3800000000000011 -$(INTDIR)/%.o: $(PROJDIR)/%.cpp - $(CCX) $(CXXFLAGS) -o $@ $< -clean: - rm -f $(CONTENT_ID).pkg pkg.gp4 pkg/sce_sys/param.sfo eboot.bin \ - $(INTDIR)/$(PROJDIR).elf $(INTDIR)/$(PROJDIR).oelf $(OBJS) +#--------------------------------------------------------------------------------- +# Object generation +#--------------------------------------------------------------------------------- +$(BUILD_DIR)/%.o: src/%.c + $(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@ + +$(BUILD_DIR)/%.o: src/%.cpp + $(CCX) $(CXXFLAGS) $(DEPFLAGS) -c $< -o $@ + +$(BUILD_DIR)/%.o: src/ps4/%.c + $(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@ + +$(BUILD_DIR)/%.o: third_party/bearssl/%.c + $(CC) $(CFLAGS) -c $< -o $@ + + +#--------------------------------------------------------------------------------- +# Dependency tracking +#--------------------------------------------------------------------------------- +$(DEPFILES): + +include $(wildcard $(DEPFILES)) diff --git a/src/UWP/Platform_UWP.cpp b/src/UWP/Platform_UWP.cpp index e109c3a58..30760feb3 100644 --- a/src/UWP/Platform_UWP.cpp +++ b/src/UWP/Platform_UWP.cpp @@ -1,10 +1,9 @@ -#include "../../src/Core.h" -#include "../../src/_PlatformBase.h" -#include "../../src/Stream.h" -#include "../../src/SystemFonts.h" -#include "../../src/Funcs.h" -#include "../../src/Utils.h" -#include "../../src/Errors.h" +#include "../_PlatformBase.h" +#include "../Stream.h" +#include "../SystemFonts.h" +#include "../Funcs.h" +#include "../Utils.h" +#include "../Errors.h" #define WIN32_LEAN_AND_MEAN #define NOSERVICE @@ -14,6 +13,7 @@ #define UNICODE #define _UNICODE #endif + #include #include #include @@ -557,43 +557,7 @@ static cc_result Process_RawGetExePath(cc_winstring* path, int* len) { } cc_result Process_StartGame2(const cc_string* args, int numArgs) { - union STARTUPINFO_union { - STARTUPINFOW wide; - STARTUPINFOA ansi; - } si = { 0 }; // less compiler warnings this way - - cc_winstring path; - cc_string argv; char argvBuffer[NATIVE_STR_LEN]; - PROCESS_INFORMATION pi = { 0 }; - cc_winstring raw; - cc_result res; - int len, i; - - if (Platform_IsSingleProcess()) return SetGameArgs(args, numArgs); - - if ((res = Process_RawGetExePath(&path, &len))) return res; - si.wide.cb = sizeof(STARTUPINFOW); - - String_InitArray(argv, argvBuffer); - /* Game doesn't actually care about argv[0] */ - String_AppendConst(&argv, "cc"); - for (i = 0; i < numArgs; i++) - { - if (String_IndexOf(&args[i], ' ') >= 0) { - String_Format1(&argv, " \"%s\"", &args[i]); - } else { - String_Format1(&argv, " %s", &args[i]); - } - } - Platform_EncodeString(&raw, &argv); - - if (!CreateProcessW(UWP_STRING(&path), UWP_STRING(&raw), NULL, NULL, - false, 0, NULL, NULL, &si.wide, &pi)) return GetLastError(); - - /* Don't leak memory for process return code */ - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - return 0; + return SetGameArgs(args, numArgs); } void Process_Exit(cc_result code) { ExitProcess(code); } diff --git a/src/UWP/Window_UWP.cpp b/src/UWP/Window_UWP.cpp index 7b434ae62..71d942edb 100644 --- a/src/UWP/Window_UWP.cpp +++ b/src/UWP/Window_UWP.cpp @@ -1,4 +1,11 @@ -#include "../../src/Core.h" +#include "../_WindowBase.h" +#include "../String.h" +#include "../Funcs.h" +#include "../Bitmap.h" +#include "../Options.h" +#include "../Errors.h" +#include "../Graphics.h" +#include "../Game.h" #include #include @@ -23,14 +30,6 @@ using namespace Windows::System; using namespace Windows::UI::Core; using namespace Windows::UI::Input; -#include "../../src/_WindowBase.h" -#include "../../src/String.h" -#include "../../src/Funcs.h" -#include "../../src/Bitmap.h" -#include "../../src/Options.h" -#include "../../src/Errors.h" -#include "../../src/Graphics.h" -#include "../../src/Game.h" #define UWP_STRING(str) ((wchar_t*)(str)->uni) @@ -326,4 +325,4 @@ int __stdcall wWinMain(void*, void*, wchar_t** argv, int argc) { auto app = make(); CoreApplication::Run(app); -} \ No newline at end of file +} diff --git a/src/Platform_PS4.c b/src/ps4/Platform_PS4.c similarity index 88% rename from src/Platform_PS4.c rename to src/ps4/Platform_PS4.c index 30aa77ab1..e34734db9 100644 --- a/src/Platform_PS4.c +++ b/src/ps4/Platform_PS4.c @@ -1,16 +1,17 @@ -#include "Core.h" -#if defined CC_BUILD_PS4 - #define CC_XTEA_ENCRYPTION -#include "_PlatformBase.h" -#include "Stream.h" -#include "ExtMath.h" -#include "SystemFonts.h" -#include "Funcs.h" -#include "Window.h" -#include "Utils.h" -#include "Errors.h" -#include "PackedCol.h" +#define CC_NO_UPDATER +#define CC_NO_DYNLIB + +#include "../_PlatformBase.h" +#include "../Stream.h" +#include "../ExtMath.h" +#include "../SystemFonts.h" +#include "../Funcs.h" +#include "../Window.h" +#include "../Utils.h" +#include "../Errors.h" +#include "../PackedCol.h" + #include #include #include @@ -31,7 +32,7 @@ #include #include #include -#include "_PlatformConsole.h" +#include "../_PlatformConsole.h" const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */ const cc_result ReturnCode_FileNotFound = ENOENT; @@ -39,7 +40,6 @@ const cc_result ReturnCode_DirectoryExists = EEXIST; const cc_result ReturnCode_SocketInProgess = EINPROGRESS; const cc_result ReturnCode_SocketWouldBlock = EWOULDBLOCK; const cc_result ReturnCode_SocketDropped = EPIPE; -#define SUPPORTS_GETADDRINFO 1 const char* Platform_AppNameSuffix = " PS4"; cc_bool Platform_ReadonlyFilesystem; @@ -182,25 +182,15 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { } cc_result File_Open(cc_file* file, const cc_filepath* path) { -#if !defined CC_BUILD_OS2 return File_Do(file, path->buffer, O_RDONLY); -#else - return File_Do(file, path->buffer, O_RDONLY | O_BINARY); -#endif } + cc_result File_Create(cc_file* file, const cc_filepath* path) { -#if !defined CC_BUILD_OS2 return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC); -#else - return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC | O_BINARY); -#endif } + cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { -#if !defined CC_BUILD_OS2 return File_Do(file, path->buffer, O_RDWR | O_CREAT); -#else - return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_BINARY); -#endif } cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { @@ -377,12 +367,6 @@ void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) { } -/*########################################################################################################################* -*--------------------------------------------------------Font/Text--------------------------------------------------------* -*#########################################################################################################################*/ -void Platform_LoadSysFonts(void) { } - - /*########################################################################################################################* *---------------------------------------------------------Socket----------------------------------------------------------* *#########################################################################################################################*/ @@ -492,27 +476,6 @@ void Socket_Close(cc_socket s) { close(s); } -#if defined CC_BUILD_DARWIN || defined CC_BUILD_BEOS -/* poll is broken on old OSX apparently https://daniel.haxx.se/docs/poll-vs-select.html */ -/* BeOS lacks support for poll */ -static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) { - fd_set set; - struct timeval time = { 0 }; - int selectCount; - - FD_ZERO(&set); - FD_SET(s, &set); - - if (mode == SOCKET_POLL_READ) { - selectCount = select(s + 1, &set, NULL, NULL, &time); - } else { - selectCount = select(s + 1, NULL, &set, NULL, &time); - } - - if (selectCount == -1) { *success = false; return errno; } - *success = FD_ISSET(s, &set) != 0; return 0; -} -#else #include static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) { struct pollfd pfd; @@ -527,7 +490,6 @@ static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) { *success = (pfd.revents & flags) != 0; return 0; } -#endif cc_result Socket_CheckReadable(cc_socket s, cc_bool* readable) { return Socket_Poll(s, SOCKET_POLL_READ, readable); @@ -589,4 +551,3 @@ static cc_result GetMachineID(cc_uint32* key) { cc_result Platform_GetEntropy(void* data, int len) { return ERR_NOT_SUPPORTED; } -#endif diff --git a/src/Window_PS4.c b/src/ps4/Window_PS4.c similarity index 91% rename from src/Window_PS4.c rename to src/ps4/Window_PS4.c index e11de6415..a19792b1b 100644 --- a/src/Window_PS4.c +++ b/src/ps4/Window_PS4.c @@ -1,17 +1,15 @@ -#include "Core.h" -#if defined CC_BUILD_PS4 -#include "Window.h" -#include "Platform.h" -#include "Input.h" -#include "Event.h" -#include "Graphics.h" -#include "String.h" -#include "Funcs.h" -#include "Bitmap.h" -#include "Errors.h" -#include "ExtMath.h" -#include "Logger.h" -#include "VirtualKeyboard.h" +#include "../Window.h" +#include "../Platform.h" +#include "../Input.h" +#include "../Event.h" +#include "../Graphics.h" +#include "../String.h" +#include "../Funcs.h" +#include "../Bitmap.h" +#include "../Errors.h" +#include "../ExtMath.h" +#include "../Logger.h" +#include "../VirtualKeyboard.h" #include static cc_bool launcherMode; @@ -152,4 +150,3 @@ cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) { cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) { return ERR_NOT_SUPPORTED; } -#endif