Skip to content

Commit

Permalink
Replace getopt and aspritf implementations
Browse files Browse the repository at this point in the history
The new code is licensed under BSD
  • Loading branch information
rapperskull committed Feb 28, 2024
1 parent 6113b15 commit 2334785
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 314 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "deps/getopt_port"]
path = deps/getopt_port
url = https://github.com/kimgr/getopt_port.git
[submodule "deps/asprintf"]
path = deps/asprintf
url = https://github.com/eiszapfen2000/asprintf.git
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ set(SOURCE_FILES
extract-xiso.c
)

set(DEPS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps)
set(GETOPT_DIR ${DEPS_DIR}/getopt_port)
set(ASPRINTF_DIR ${DEPS_DIR}/asprintf)

if(MSVC)
set(CMAKE_C_FLAGS_RELEASE_INIT "/O2")
add_compile_options(/W4 /utf-8)
Expand All @@ -21,6 +25,7 @@ else()
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
add_compile_options(-Wall -Wextra -Wpedantic -Wno-comment)
endif()

add_executable(extract-xiso ${SOURCE_FILES})
target_compile_definitions(extract-xiso PRIVATE ${TARGET_OS})
if(CMAKE_C_BYTE_ORDER MATCHES "^$")
Expand All @@ -29,4 +34,25 @@ endif()
target_compile_definitions(extract-xiso PRIVATE CMAKE_ENDIANNESS=${CMAKE_C_BYTE_ORDER})
set_property(TARGET extract-xiso PROPERTY C_STANDARD 99)
set_property(TARGET extract-xiso PROPERTY C_EXTENSIONS OFF)

if(WIN32)
add_library(getopt STATIC ${GETOPT_DIR}/getopt.c)
target_sources(getopt PUBLIC ${GETOPT_DIR}/getopt.h)
target_include_directories(getopt PUBLIC ${GETOPT_DIR})
set_property(TARGET getopt PROPERTY C_STANDARD 99)
set_property(TARGET getopt PROPERTY C_EXTENSIONS OFF)

target_link_libraries(extract-xiso getopt)
endif()

if(MSVC)
add_library(asprintf STATIC ${ASPRINTF_DIR}/asprintf.c)
target_sources(asprintf PUBLIC ${ASPRINTF_DIR}/asprintf.h)
target_include_directories(asprintf PUBLIC ${ASPRINTF_DIR})
set_property(TARGET asprintf PROPERTY C_STANDARD 99)
set_property(TARGET asprintf PROPERTY C_EXTENSIONS OFF)

target_link_libraries(extract-xiso asprintf)
endif()

install(TARGETS extract-xiso RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
1 change: 1 addition & 0 deletions deps/asprintf
Submodule asprintf added at 29fe98
1 change: 1 addition & 0 deletions deps/getopt_port
Submodule getopt_port added at 6ad8cc
5 changes: 3 additions & 2 deletions extract-xiso.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,18 @@
#endif

#if defined(_WIN32)
#include <io.h>
#include <direct.h>
#include "win32/dirent.c"
#include "win32/getopt.c"
#include <getopt.h> /* Provided by CMake */
#else
#include <dirent.h>
#include <limits.h>
#include <unistd.h>
#endif

#if defined(_MSC_VER)
#include "win32/asprintf.c"
#include <asprintf.h> /* Provided by CMake */
#include <BaseTsd.h>
#else
#include <strings.h>
Expand Down
79 changes: 0 additions & 79 deletions win32/asprintf.c

This file was deleted.

233 changes: 0 additions & 233 deletions win32/getopt.c

This file was deleted.

0 comments on commit 2334785

Please sign in to comment.