From a2495bd1ac9e5e54074d65616de0efa822a6309e Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 1 Apr 2020 00:13:11 +0200 Subject: Add preliminary VisualStudio support - Mostly workarounds/clutches in compat.h - Change getline return type to int - Replace C99 style flexible array with alloca - Add all the MSVC solution/project crap Signed-off-by: David Oberhollenzer --- Makefile.am | 1 + include/compat.h | 23 ++++- include/win32/config.h | 12 +++ lib/compat/getline.c | 2 +- lib/sqfs/Makemodule.am | 2 + lib/sqfs/comp/compressor.c | 4 +- lib/sqfs/libsqfs.vcxproj | 230 +++++++++++++++++++++++++++++++++++++++++++++ lib/sqfs/write_inode.c | 9 -- squashfs-tools-ng.sln | 31 ++++++ squashfs-tools-ng.vcxproj | 145 ++++++++++++++++++++++++++++ 10 files changed, 445 insertions(+), 14 deletions(-) create mode 100644 include/win32/config.h create mode 100644 lib/sqfs/libsqfs.vcxproj create mode 100644 squashfs-tools-ng.sln create mode 100644 squashfs-tools-ng.vcxproj diff --git a/Makefile.am b/Makefile.am index 7d4f9ba..f55cf18 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,6 +18,7 @@ check_SCRIPTS = pkgconfig_DATA = EXTRA_DIST = autogen.sh README.md CHANGELOG.md COPYING.md mkwinbins.sh licenses +EXTRA_DIST += squashfs-tools-ng.sln squashfs-tools-ng.vcxproj TESTS = include lib/sqfs/Makemodule.am diff --git a/include/compat.h b/include/compat.h index b2bb054..5d7a052 100644 --- a/include/compat.h +++ b/include/compat.h @@ -27,6 +27,10 @@ # define SZ_ADD_OV __builtin_add_overflow # define SZ_MUL_OV __builtin_mul_overflow # endif +#elif defined(_MSC_VER) +# include +# define SZ_ADD_OV SizeTAdd +# define SZ_MUL_OV SizeTMult #else # error I do not know how to trap integer overflows with this compiler #endif @@ -40,7 +44,13 @@ # define PRI_U32 "%" PRIu32 #endif -#if SIZEOF_SIZE_T <= SIZEOF_INT +#ifdef _MSC_VER +# ifdef _WIN64 +# define PRI_SZ PRI_U64 +# else +# define PRI_SZ PRI_U32 +# endif +#elif SIZEOF_SIZE_T <= SIZEOF_INT # define PRI_SZ "%u" #elif SIZEOF_SIZE_T == SIZEOF_LONG # define PRI_SZ "%lu" @@ -73,8 +83,17 @@ #define WIN32_LEAN_AND_MEAN #include + +#include + +#ifdef _MSC_VER +# define alloca _alloca +#endif + +#define strdup _strdup #else #include +#include #endif #if defined(_WIN32) || defined(__WINDOWS__) @@ -167,7 +186,7 @@ int chdir(const char *path); #ifndef HAVE_GETLINE #include -ssize_t getline(char **line, size_t *n, FILE *fp); +int getline(char **line, size_t *n, FILE *fp); #endif #ifndef HAVE_STRNDUP diff --git a/include/win32/config.h b/include/win32/config.h new file mode 100644 index 0000000..00ec3bb --- /dev/null +++ b/include/win32/config.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * config.h - manually created stub for MSVC + * + * Copyright (C) 2019 David Oberhollenzer + */ +#ifndef CONFIG_H +#define CONFIG_H + + + +#endif /* CONFIG_H */ diff --git a/lib/compat/getline.c b/lib/compat/getline.c index e63c50e..d7e456b 100644 --- a/lib/compat/getline.c +++ b/lib/compat/getline.c @@ -11,7 +11,7 @@ #include #ifndef HAVE_GETLINE -ssize_t getline(char **line, size_t *n, FILE *fp) +int getline(char **line, size_t *n, FILE *fp) { size_t new_cap, len = 0, cap = 0; char *buffer = NULL, *new; diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am index 942c37c..6786ee2 100644 --- a/lib/sqfs/Makemodule.am +++ b/lib/sqfs/Makemodule.am @@ -113,3 +113,5 @@ lib_LTLIBRARIES += libsquashfs.la pkgconfig_DATA += lib/sqfs/libsquashfs0.pc EXTRA_DIST += lib/sqfs/comp/lz4/README lib/sqfs/comp/zlib/README +EXTRA_DIST += lib/sqfs/libsqfs.vcxproj +EXTRA_DIST += include/win32/config.h diff --git a/lib/sqfs/comp/compressor.c b/lib/sqfs/comp/compressor.c index 946ee25..2294b98 100644 --- a/lib/sqfs/comp/compressor.c +++ b/lib/sqfs/comp/compressor.c @@ -42,7 +42,7 @@ static const char *names[] = { int sqfs_generic_write_options(sqfs_file_t *file, const void *data, size_t size) { - sqfs_u8 buffer[size + 2]; + sqfs_u8 *buffer = alloca(size + 2); int ret; *((sqfs_u16 *)buffer) = htole16(0x8000 | size); @@ -58,7 +58,7 @@ int sqfs_generic_write_options(sqfs_file_t *file, const void *data, size_t size) int sqfs_generic_read_options(sqfs_file_t *file, void *data, size_t size) { - sqfs_u8 buffer[size + 2]; + sqfs_u8 *buffer = alloca(size + 2); int ret; ret = file->read_at(file, sizeof(sqfs_super_t), diff --git a/lib/sqfs/libsqfs.vcxproj b/lib/sqfs/libsqfs.vcxproj new file mode 100644 index 0000000..176ba20 --- /dev/null +++ b/lib/sqfs/libsqfs.vcxproj @@ -0,0 +1,230 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {7F732A8E-22A5-4DC1-B8DB-7091D37BE502} + libsqfs + 10.0 + squashfs + + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Configuration)\ + + + true + + + false + $(SolutionDir)$(Configuration)\ + + + false + + + + Level3 + true + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;WITH_GZIP;WITH_LZ4;NO_GZIP;%(PreprocessorDefinitions) + true + $(SolutionDir)\include;$(SolutionDir)\include\win32;$(SolutionDir)\lib\sqfs\comp\zlib;$(SolutionDir)\lib\sqfs\comp\lz4;%(AdditionalIncludeDirectories) + CompileAsC + $(IntDir)%(RelativeDir) + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;WITH_GZIP;WITH_LZ4;NO_GZIP;%(PreprocessorDefinitions) + true + $(SolutionDir)\include;$(SolutionDir)\include\win32;$(SolutionDir)\lib\sqfs\comp\zlib;$(SolutionDir)\lib\sqfs\comp\lz4;%(AdditionalIncludeDirectories) + CompileAsC + $(IntDir)%(RelativeDir) + + + Console + true + true + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c index 787c4b5..d27d1b4 100644 --- a/lib/sqfs/write_inode.c +++ b/lib/sqfs/write_inode.c @@ -15,15 +15,6 @@ #include -#if defined(_WIN32) || defined(__WINDOWS__) -# include -# ifdef _MSC_VER -# define alloca _alloca -# endif -#else -# include -#endif - static int write_block_sizes(sqfs_meta_writer_t *ir, const sqfs_inode_generic_t *n) { diff --git a/squashfs-tools-ng.sln b/squashfs-tools-ng.sln new file mode 100644 index 0000000..418bcc5 --- /dev/null +++ b/squashfs-tools-ng.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29926.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsqfs", "lib\sqfs\libsqfs.vcxproj", "{7F732A8E-22A5-4DC1-B8DB-7091D37BE502}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7F732A8E-22A5-4DC1-B8DB-7091D37BE502}.Debug|x64.ActiveCfg = Debug|x64 + {7F732A8E-22A5-4DC1-B8DB-7091D37BE502}.Debug|x64.Build.0 = Debug|x64 + {7F732A8E-22A5-4DC1-B8DB-7091D37BE502}.Debug|x86.ActiveCfg = Debug|Win32 + {7F732A8E-22A5-4DC1-B8DB-7091D37BE502}.Debug|x86.Build.0 = Debug|Win32 + {7F732A8E-22A5-4DC1-B8DB-7091D37BE502}.Release|x64.ActiveCfg = Release|x64 + {7F732A8E-22A5-4DC1-B8DB-7091D37BE502}.Release|x64.Build.0 = Release|x64 + {7F732A8E-22A5-4DC1-B8DB-7091D37BE502}.Release|x86.ActiveCfg = Release|Win32 + {7F732A8E-22A5-4DC1-B8DB-7091D37BE502}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {922C1643-B534-47CC-A7AD-81F7090BF34B} + EndGlobalSection +EndGlobal diff --git a/squashfs-tools-ng.vcxproj b/squashfs-tools-ng.vcxproj new file mode 100644 index 0000000..c4b8ee1 --- /dev/null +++ b/squashfs-tools-ng.vcxproj @@ -0,0 +1,145 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {25DDF12C-B25D-4A92-9633-5315BFDC0D0C} + squashfstoolsng + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + \ No newline at end of file -- cgit v1.2.3