Skip to content

Commit

Permalink
Merge pull request #230 from FtZPetruska/mingw-fixes
Browse files Browse the repository at this point in the history
MinGW fixes
  • Loading branch information
d3m3vilurr authored Jun 12, 2023
2 parents a302403 + 51a2142 commit be08722
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Get Information Variables
id: core
Expand Down
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
16 changes: 15 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h>
#include <stdlib.h>
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)
Expand All @@ -53,12 +63,16 @@ target_include_directories(vita-import PUBLIC
$<INSTALL_INTERFACE:include>)

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)
Expand Down
4 changes: 4 additions & 0 deletions src/elf-create-argp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <string.h>
#include <unistd.h>

#ifndef HAVE_STRNDUP
#include "strndup.h"
#endif

int parse_arguments(int argc, char *argv[], elf_create_args *arguments)
{
int c;
Expand Down
17 changes: 17 additions & 0 deletions src/strndup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef HAVE_STRNDUP
#include "strndup.h"

#include <stdlib.h>
#include <string.h>

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
8 changes: 8 additions & 0 deletions src/strndup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef STRNDUP_H
#define STRNDUP_H

#include <stddef.h>

char *strndup(const char *source, size_t maxlen);

#endif /* STRNDUP_H */
3 changes: 2 additions & 1 deletion src/vita-libs-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit be08722

Please sign in to comment.