diff options
| author | John "Lameguy" Wilbert Villamor <lameguy64@gmail.com> | 2021-10-15 09:22:45 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-15 09:22:45 +0800 |
| commit | dd0f088aaa4c6bf013643be2d1d8621dbffdb000 (patch) | |
| tree | d848d6ce007d8bb9357c8b99d6a0a39ec41d244e /tools | |
| parent | 9e08d1047fa8deeb3ccb3ce9bb11d69e25a52d56 (diff) | |
| parent | eb719a424e6a16fb64209139a32c9f8a7235a929 (diff) | |
| download | psn00bsdk-dd0f088aaa4c6bf013643be2d1d8621dbffdb000.tar.gz | |
Merge pull request #38 from spicyjpeg/cmake
Full CMake support (in place of makefiles)
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/CMakeLists.txt | 76 | ||||
| -rw-r--r-- | tools/lzpack/filelist.h | 7 | ||||
| -rw-r--r-- | tools/lzpack/lzp/makefile | 30 | ||||
| -rw-r--r-- | tools/lzpack/main.cpp | 34 | ||||
| -rw-r--r-- | tools/lzpack/makefile | 46 | ||||
| -rw-r--r-- | tools/makefile | 12 | ||||
| -rw-r--r-- | tools/smxlink/main.cpp | 4 | ||||
| -rw-r--r-- | tools/smxlink/makefile | 45 | ||||
| -rw-r--r-- | tools/smxlink/timreader.cpp | 4 | ||||
| -rw-r--r-- | tools/util/elf2cpe.c | 4 | ||||
| -rw-r--r-- | tools/util/elf2x.c | 9 | ||||
| -rw-r--r-- | tools/util/makefile | 20 |
12 files changed, 120 insertions, 171 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 0000000..dd90109 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,76 @@ +# PSn00bSDK tools build script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +project( + PSn00bSDK-tools + LANGUAGES C CXX + DESCRIPTION "PSn00bSDK command-line tools" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +include(GNUInstallDirs) + +## External dependencies + +# Let CMake attempt to find tinyxml2 on its own first. This avoids invoking +# pkg-config where it might not be installed, and allows usage of package +# managers like vcpkg. The path to tinyxml2 can also be specified manually by +# passing -Dtinyxml2_ROOT. +find_package(tinyxml2 CONFIG) + +if(NOT tinyxml2_FOUND) + find_package(PkgConfig REQUIRED) + pkg_search_module(_tinyxml2 REQUIRED IMPORTED_TARGET tinyxml2) + + add_library(tinyxml2::tinyxml2 ALIAS PkgConfig::_tinyxml2) +endif() + +## Internal dependencies + +# Build liblzp using sources from the libpsn00b tree. Hacky but it works. +set(LIBPSN00B_PATH ${PROJECT_SOURCE_DIR}/../libpsn00b) +file( + GLOB _sources + ${LIBPSN00B_PATH}/lzp/*.c + #${LIBPSN00B_PATH}/lzp/*.cpp +) + +add_library(lzp STATIC ${_sources}) +target_include_directories( + lzp PUBLIC + lzpack/lzp + ${LIBPSN00B_PATH}/include/lzp +) + +## Executables + +# This is required in order to properly link against tinyxml2 under MSVC. +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 11) + +add_executable(elf2x util/elf2x.c) +add_executable(elf2cpe util/elf2cpe.c) +add_executable(smxlink smxlink/main.cpp smxlink/timreader.cpp) +add_executable(lzpack lzpack/main.cpp lzpack/filelist.cpp) +target_link_libraries(smxlink tinyxml2::tinyxml2) +target_link_libraries(lzpack tinyxml2::tinyxml2 lzp) + +## Installation + +# Install the executables alongside the tinyxml2 DLL (if any) and copy the +# Blender SMX export plugin to the data directory (for manual installation). +install( + TARGETS elf2x elf2cpe smxlink lzpack + RUNTIME_DEPENDENCIES + PRE_EXCLUDE_REGEXES ".*" + PRE_INCLUDE_REGEXES "tinyxml2" +) +install( + DIRECTORY plugin + DESTINATION ${CMAKE_INSTALL_DATADIR}/psn00bsdk +) + +include(InstallRequiredSystemLibraries) diff --git a/tools/lzpack/filelist.h b/tools/lzpack/filelist.h index 5351335..f6ad478 100644 --- a/tools/lzpack/filelist.h +++ b/tools/lzpack/filelist.h @@ -4,9 +4,14 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#include <unistd.h> #include <limits.h> +#ifdef WIN32 +#include <windows.h> +#else +#include <unistd.h> +#endif + #ifndef MAX_PATH #define MAX_PATH PATH_MAX #endif diff --git a/tools/lzpack/lzp/makefile b/tools/lzpack/lzp/makefile deleted file mode 100644 index 83da67d..0000000 --- a/tools/lzpack/lzp/makefile +++ /dev/null @@ -1,30 +0,0 @@ -# This LZP library builds off the lzp sources in libpsn00b/lzp. The only -# difference is this is built with compression enabled specified in the -# lzconfig.h file and the library is built for the host platform. - -TARGET = liblzp.a - -CFILES = $(wildcard ../../../libpsn00b/lzp/*.c) -OFILES = $(addprefix build/, $(notdir $(CFILES:.c=.o))) - -INCLUDE = -I../include -I. - -CFLAGS = -g -O2 - -CC = $(PREFIX)gcc -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib - -all: $(TARGET) - -$(TARGET): $(OFILES) - $(AR) cr $(TARGET) $(OFILES) - $(RANLIB) $(TARGET) - -# Dunno if there's a better way to do this but it works at least -build/%.o: ../../../libpsn00b/lzp/%.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -Rf build $(TARGET)
\ No newline at end of file diff --git a/tools/lzpack/main.cpp b/tools/lzpack/main.cpp index 801cdd1..506b76c 100644 --- a/tools/lzpack/main.cpp +++ b/tools/lzpack/main.cpp @@ -1,8 +1,8 @@ #include <stdio.h> #include <tinyxml2.h> -#include "lzp/lzconfig.h" -#include "lzp/lzp.h" +#include "lzconfig.h" +#include "lzp.h" #include "filelist.h" @@ -151,11 +151,10 @@ int main(int argc, const char* argv[]) { int CreateLZPfile(const char* packFile, FileListClass* fileList) { FILE* packp; - LZP_FILE entry[fileList->EntryCount()]; + LZP_FILE* entry=new LZP_FILE[fileList->EntryCount()]; int overallSize=0; int overallPackedSize=0; - packp = fopen(packFile, "wb"); fseek(packp, sizeof(LZP_HEAD)+(sizeof(LZP_FILE)*fileList->EntryCount()), SEEK_SET); @@ -179,6 +178,7 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { printf("ERROR: Entry '%s' has more than 15 characters.\n", name); fclose(packp); unlink(packFile); + delete[] entry; return(0); @@ -199,13 +199,13 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { int fileSize = ftell(fp); fseek(fp, 0, SEEK_SET); - void* fileBuff = malloc(fileSize); + char* fileBuff = new char[fileSize]; fread(fileBuff, fileSize, 1, fp); fclose(fp); - void* compBuff = malloc(fileSize+16384); + char* compBuff = new char[fileSize+16384]; int compSize = lzCompress(compBuff, fileBuff, fileSize, 2); @@ -216,8 +216,8 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { fwrite(compBuff, compSize, 1, packp); - free(compBuff); - free(fileBuff); + delete[] compBuff; + delete[] fileBuff; printf("Ok. (%.02f%%)\n", 100.f*((float)compSize/fileSize)); @@ -238,7 +238,7 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { fwrite(entry, sizeof(LZP_FILE), fileList->EntryCount(), packp); fclose(packp); - + delete[] entry; printf("Packed %d file(s) totaling %d bytes (%.02f%% compression ratio).\n", fileList->EntryCount(), @@ -255,7 +255,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { FILE* packp; QLP_HEAD head; - QLP_FILE fileEntry[fileList->EntryCount()]; + QLP_FILE* fileEntry=new QLP_FILE[fileList->EntryCount()]; strncpy(head.id, "QLP", 3); head.numFiles = fileList->EntryCount(); @@ -285,6 +285,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { printf("ERROR: Entry '%s' has more than 15 characters.\n", name); fclose(packp); unlink(packFile); + delete[] fileEntry; return(0); @@ -315,7 +316,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { FILE* fp = fopen(fileList->Entry(i)->fileName, "rb"); int bytesCopied = 0; - void* copyBuff = malloc(BUFF_SIZE); + char* copyBuff = new char[BUFF_SIZE]; while(!feof(fp)) { @@ -327,7 +328,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { } - free(copyBuff); + delete[] copyBuff; fclose(fp); fileEntry[i].fileSize = bytesCopied; @@ -344,6 +345,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { fwrite(fileEntry, sizeof(QLP_FILE), head.numFiles, packp); fclose(packp); + delete[] fileEntry; return(true); @@ -402,7 +404,7 @@ int CreatePCKfile(const char* packFile, FileListClass* fileList) { } FILE* fp = fopen(fileList->Entry(i)->fileName, "rb"); - void* buff = malloc(BUFF_SIZE); + char* buff = new char[BUFF_SIZE]; int bytesTotal = 0; @@ -415,18 +417,18 @@ int CreatePCKfile(const char* packFile, FileListClass* fileList) { } fclose(fp); - free(buff); + delete[] buff; toc.file[i].size = bytesTotal; if ((2048*((ftell(packp)+2047)/2048)) != ftell(packp)) { int pad = (2048*(((ftell(packp)%2048)+2047)/2048))-(ftell(packp)%2048); - char padding[pad]; + char* padding = new char[pad]; memset(padding, 0x00, pad); fwrite(padding, pad, 1, packp); - + delete[] padding; } printf("Done.\n"); diff --git a/tools/lzpack/makefile b/tools/lzpack/makefile deleted file mode 100644 index e11f5c7..0000000 --- a/tools/lzpack/makefile +++ /dev/null @@ -1,46 +0,0 @@ -TARGET := lzpack - -CPPFILES = main.cpp filelist.cpp -CFLAGS = -O2 -LDFLAGS = -s - -LIBS = -ltinyxml2 -llzp - -CC = gcc -CXX = g++ - -OFILES = $(addprefix build/,$(CPPFILES:.cpp=.o)) - -ifeq "$(OS)" "Windows_NT" - -# Config for Windows -INCLUDE = -I/c/tinyxml2 -LIBDIRS = -L/c/tinyxml2 -TARGET := $(TARGET).exe - -else - -# Config for anything else that isn't Linux - -endif - -INCLUDE += -I../../libpsn00b -LIBDIRS += -Llzp - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -all: $(OFILES) - $(MAKE) -C lzp - $(CXX) $(CFLAGS) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - -install: - mkdir -p ../bin - cp $(TARGET) ../bin/$(TARGET) - -clean: - $(MAKE) -C lzp clean - rm -Rf build $(TARGET) - -cleanall: clean diff --git a/tools/makefile b/tools/makefile deleted file mode 100644 index aec452c..0000000 --- a/tools/makefile +++ /dev/null @@ -1,12 +0,0 @@ -TOPTARGETS = all install clean - -TOOLDIRS = lzpack smxlink util - -$(TOPTARGETS): $(TOOLDIRS) -$(TOOLDIRS): - $(MAKE) -C $@ $(MAKECMDGOALS) - -clean: $(LIBDIRS) - rm -Rf bin - -.PHONY: $(TOPTARGETS) $(TOOLDIRS) diff --git a/tools/smxlink/main.cpp b/tools/smxlink/main.cpp index 8072274..d58f36a 100644 --- a/tools/smxlink/main.cpp +++ b/tools/smxlink/main.cpp @@ -15,6 +15,10 @@ //#include <windef.h> #include "timreader.h" +#ifdef WIN32 +#define strcasecmp _stricmp +#endif + #define VERSION "0.25b" namespace param diff --git a/tools/smxlink/makefile b/tools/smxlink/makefile deleted file mode 100644 index ff759b1..0000000 --- a/tools/smxlink/makefile +++ /dev/null @@ -1,45 +0,0 @@ -TARGET := smxlink - -CPPFILES = main.cpp timreader.cpp -CFLAGS = -O2 -LDFLAGS = -s - -INCLUDE = -LIBDIRS = -LIBS = -ltinyxml2 - -CC = gcc -CXX = g++ - -OFILES = $(addprefix build/,$(CPPFILES:.cpp=.o)) - -ifeq "$(OS)" "Windows_NT" - -# Config for Windows (comment out if in msys2) -INCLUDE = -I/c/tinyxml2 -LIBDIRS = -L/c/tinyxml2 - -TARGET := $(TARGET).exe - -else - -# Config for anything else that isn't Windows -EXE_SUFFIX = - -endif - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CFLAGS) $(INCLUDE) -c $< -o $@ - -all: $(OFILES) - $(CXX) $(CFLAGS) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) - -install: - mkdir -p ../bin - cp $(TARGET) ../bin/$(TARGET) - -clean: - rm -Rf build $(TARGET) - -cleanall: clean diff --git a/tools/smxlink/timreader.cpp b/tools/smxlink/timreader.cpp index a8fba94..5116f52 100644 --- a/tools/smxlink/timreader.cpp +++ b/tools/smxlink/timreader.cpp @@ -2,6 +2,10 @@ #include <string.h> #include "timreader.h" +#ifdef WIN32 +#define strcasecmp _stricmp +#endif + int GetTimCoords(const char* fileName, TIM_COORDS *coords) { FILE* fp = fopen(fileName, "rb"); diff --git a/tools/util/elf2cpe.c b/tools/util/elf2cpe.c index 4379f4a..46b0a37 100644 --- a/tools/util/elf2cpe.c +++ b/tools/util/elf2cpe.c @@ -3,6 +3,10 @@ #include <malloc.h> #include "elf.h" +#ifdef WIN32 +#define strcasecmp _stricmp +#endif + #define MAX_prg_entry_count 128 #ifndef false diff --git a/tools/util/elf2x.c b/tools/util/elf2x.c index 26ec9a3..9a7c126 100644 --- a/tools/util/elf2x.c +++ b/tools/util/elf2x.c @@ -6,6 +6,10 @@ #include <string.h> #include "elf.h" +#ifdef WIN32 +#define strcasecmp _stricmp +#endif + #define MAX_prg_entry_count 128 #define true (1) #define false (0) @@ -233,9 +237,12 @@ int main(int argc, char** argv) { exe.params.t_size = exe_tsize; exe.params.pc0 = head.prg_entry_addr; + // Some later PAL BIOS versions seem to actually verify the license string + // in the executable (despite what the nocash docs claim) and display the + // dreaded "insert PlayStation CD-ROM" screen if it's not valid. strncpy( exe.header, "PS-X EXE", 8 ); strcpy( exe.license, - "Not Licensed or Endorsed by Sony Computer Entertainment Inc." ); + "Sony Computer Entertainment Inc. for Europe area" ); strcpy( exe.pad2, "Built using GCC and PSn00bSDK libraries" ); diff --git a/tools/util/makefile b/tools/util/makefile deleted file mode 100644 index fe7aed5..0000000 --- a/tools/util/makefile +++ /dev/null @@ -1,20 +0,0 @@ -CFLAGS = -O2 -s - -CC = gcc - -ifeq "$(OS)" "Windows_NT" -EXE_SUFFIX = .exe -else -EXE_SUFFIX = -endif - -all: - $(CC) $(CFLAGS) elf2x.c -o elf2x$(EXE_SUFFIX) - $(CC) $(CFLAGS) elf2cpe.c -o elf2cpe$(EXE_SUFFIX) - -install: - mkdir -p ../bin - cp elf2x$(EXE_SUFFIX) ../bin/elf2x$(EXE_SUFFIX) - -clean: - rm -f elf2x$(EXE_SUFFIX) |
