diff --git a/.github/workflows/compilation.yml b/.github/workflows/compilation.yml index 29edb9e..3bd139a 100644 --- a/.github/workflows/compilation.yml +++ b/.github/workflows/compilation.yml @@ -11,6 +11,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + submodules: true - name: Get Information Variables id: core diff --git a/CMakeLists.txt b/CMakeLists.txt index 2968a04..77ae432 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,9 @@ -cmake_minimum_required(VERSION 2.6) -project(vita-toolchain) +cmake_minimum_required(VERSION 3.4) +project(vita-toolchain LANGUAGES C) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") -if (NOT TOOLCHAIN_DEPS_DIR) - set(TOOLCHAIN_DEPS_DIR "${CMAKE_SOURCE_DIR}/builds/deps_build") -endif() -set(ENV{PKG_CONFIG_PATH} "${TOOLCHAIN_DEPS_DIR}/lib/pkgconfig:${TOOLCHAIN_DEPS_DIR}/share/pkgconfig") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/") +set(TOOLCHAIN_DEPS_DIR "${CMAKE_SOURCE_DIR}/builds/deps_build" CACHE PATH "Prefix to search for dependencies in.") +list(APPEND CMAKE_PREFIX_PATH "${TOOLCHAIN_DEPS_DIR}") add_subdirectory(src) add_subdirectory(psp2rela) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 910b559..030ba0b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,16 @@ else() set(runtime_destination lib) endif() +# Check if strndup is available, Windows toolchains typically don't provide it +include(CheckCSourceCompiles) +check_c_source_compiles(" +#include +#include +int main() { + free(strndup(\"foo\", 4)); +}" +HAVE_STRNDUP) + add_library(vita-yaml yamltree.c yamltreeutil.c) add_library(vita-export vita-export-parse.c sha256.c) add_library(vita-import vita-import.c vita-import-parse.c) @@ -53,12 +63,16 @@ target_include_directories(vita-import PUBLIC $) add_executable(vita-libs-gen vita-libs-gen.c) -add_executable(vita-elf-create vita-elf-create.c elf-create-argp.c vita-elf.c elf-defs.c sce-elf.c varray.c elf-utils.c yamlemitter.c) +add_executable(vita-elf-create vita-elf-create.c elf-create-argp.c vita-elf.c elf-defs.c sce-elf.c varray.c elf-utils.c yamlemitter.c strndup.c) add_executable(vita-mksfoex vita-mksfoex.c getopt_long.c) add_executable(vita-make-fself vita-make-fself.c) add_executable(vita-pack-vpk vita-pack-vpk.c) add_executable(vita-elf-export vita-elf-export.c yamlemitter.c) +if(HAVE_STRNDUP) + target_compile_definitions(vita-elf-create PRIVATE "HAVE_STRNDUP") +endif() + target_link_libraries(vita-yaml ${libyaml_LIBRARIES}) target_link_libraries(vita-import vita-yaml) target_link_libraries(vita-export vita-yaml) diff --git a/src/elf-create-argp.c b/src/elf-create-argp.c index 2c91834..b796da7 100644 --- a/src/elf-create-argp.c +++ b/src/elf-create-argp.c @@ -5,6 +5,10 @@ #include #include +#ifndef HAVE_STRNDUP +#include "strndup.h" +#endif + int parse_arguments(int argc, char *argv[], elf_create_args *arguments) { int c; diff --git a/src/strndup.c b/src/strndup.c new file mode 100644 index 0000000..5e942e6 --- /dev/null +++ b/src/strndup.c @@ -0,0 +1,17 @@ +#ifndef HAVE_STRNDUP +#include "strndup.h" + +#include +#include + +char *strndup(const char *source, size_t maxlen) { + size_t dest_size = strnlen(source, maxlen); + char *dest = malloc(dest_size + 1); + if (dest == NULL) { + return NULL; + } + memcmp(dest, source, dest_size); + dest[dest_size] = '\0'; + return dest; +} +#endif diff --git a/src/strndup.h b/src/strndup.h new file mode 100644 index 0000000..0e57db2 --- /dev/null +++ b/src/strndup.h @@ -0,0 +1,8 @@ +#ifndef STRNDUP_H +#define STRNDUP_H + +#include + +char *strndup(const char *source, size_t maxlen); + +#endif /* STRNDUP_H */ diff --git a/src/vita-libs-gen.c b/src/vita-libs-gen.c index 8ced47e..36585b4 100644 --- a/src/vita-libs-gen.c +++ b/src/vita-libs-gen.c @@ -494,7 +494,8 @@ int generate_makefile(vita_imports_t **imports, int imports_count) "clean:\n" "\trm -f $(TARGETS) $(TARGETS_WEAK) $(ALL_OBJS)\n\n" "$(TARGETS) $(TARGETS_WEAK):\n" - "\t$(AR) cru $@ $?\n" + "\t@echo \"$?\" > $@-objs\n" + "\t$(AR) cru $@ @$@-objs\n" "\t$(RANLIB) $@\n\n" "%.o: %.S\n" "\t$(AS) --defsym GEN_WEAK_EXPORTS=0 $< -o $@\n\n"