From b7fa2584a0616479540170e0a141d0ef1f57bab0 Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Tue, 24 Jul 2018 15:30:15 -0300 Subject: [PATCH] update to 1.0.4 --- recipe/bld.bat | 20 ++++++---- recipe/build.sh | 49 +++++++++++++++++++++++ recipe/meta.yaml | 77 ++++++++++++++++++++++++++++++------ recipe/unit.c | 101 ----------------------------------------------- 4 files changed, 126 insertions(+), 121 deletions(-) create mode 100644 recipe/build.sh delete mode 100644 recipe/unit.c diff --git a/recipe/bld.bat b/recipe/bld.bat index 6590b4a..3e810a0 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -1,8 +1,14 @@ -copy c99wrap.exe %LIBRARY_BIN%\c99wrap.exe -copy c99conv.exe %LIBRARY_BIN%\c99conv.exe -copy makedef %LIBRARY_BIN%\makedef - -rem Have to run the test here as cl.exe is only -rem available during building. -c99wrap cl /EP /P %RECIPE_DIR%\unit.c +copy "%RECIPE_DIR%\build.sh" . +FOR /F "delims=" %%i IN ('cygpath.exe -u "%LIBRARY_PREFIX%"') DO set "LIBRARY_PREFIX=%%i" +FOR /F "delims=" %%i IN ('cygpath.exe -u "%PREFIX%"') DO set "PREFIX=%%i" +FOR /F "delims=" %%i IN ('cygpath.exe -u "%PYTHON%"') DO set "PYTHON=%%i" +FOR /F "delims=" %%i IN ('cygpath.exe -u "%RECIPE_DIR%"') DO set "RECIPE_DIR=%%i" +FOR /F "delims=" %%i IN ('cygpath.exe -u "%SP_DIR%"') DO set "SP_DIR=%%i" +FOR /F "delims=" %%i IN ('cygpath.exe -u "%SRC_DIR%"') DO set "SRC_DIR=%%i" +FOR /F "delims=" %%i IN ('cygpath.exe -u "%STDLIB_DIR%"') DO set "STDLIB_DIR=%%i" +set MSYSTEM=MINGW%ARCH% +set MSYS2_PATH_TYPE=inherit +set CHERE_INVOKING=1 +bash -lc ./build.sh if errorlevel 1 exit 1 +exit 0 diff --git a/recipe/build.sh b/recipe/build.sh new file mode 100644 index 0000000..1725659 --- /dev/null +++ b/recipe/build.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -x + +# $(dirname $(dirname $(dirname $(which 7z))))/usr/lib/p7zip/7z x -aoa -o$PWD/clang LLVM*${ARCH}.exe || exit 1 +pushd llvm +7z x -aoa -o$PWD/clang LLVM*.exe || exit 1 +popd + +CLANGDIR=${PWD}/clang +# Rename libclang.dll to avoid conflicts. Sorry. No one builds static libclangs on Windows for some reason? +cp ${CLANGDIR}/bin/libclang.dll ${CLANGDIR}/bin/c99-to-c89-libclang.dll + +# Create an import library for c99-to-c89-libclang.dll +gendef ${CLANGDIR}/bin/c99-to-c89-libclang.dll - > c99-to-c89-libclang.dll.def +sed -i 's|LIBRARY "libclang.dll"|LIBRARY "c99-to-c89-libclang.dll"|' c99-to-c89-libclang.dll.def +if [[ ${ARCH} == 32 ]]; then + MS_MACH=X86 +else + MS_MACH=X64 +fi +if [[ ${vc} == 9 ]]; then + SNPRINTF=-Dsnprintf=_snprintf +fi +lib /def:c99-to-c89-libclang.dll.def /out:$(cygpath -m ${CLANGDIR}/lib/c99-to-c89-libclang.lib) /machine:${MS_MACH} + +if ! CFLAGS="${CFLAGS} -I${BUILD_PREFIX}/Library/include ${SNPRINTF}" CLANGDIR=${PWD}/clang make -f Makefile.w32; then + echo "ERROR :: Build failed" + exit 1 +fi +cp c99*.exe ${CLANGDIR}/bin/c99-to-c89-libclang.dll ${PREFIX}/Library/bin + +# This file should be passed to the CMake command-line as: +# -DCMAKE_C_COMPILER="c99-to-c89-cmake-nmake-wrap.bat" +# I have given it a very specific name as I do not know that it will work for any other CMake. +# We set the some debug flags so that we see the contents of the @response files and so that +# temporaries are retained. +pushd ${PREFIX}/Library/bin + echo "@echo off" > c99-to-c89-cmake-nmake-wrap.bat + echo "echo cd %CD%" >> c99-to-c89-cmake-nmake-wrap.bat + echo "setlocal EnableExtensions EnableDelayedExpansion" >> c99-to-c89-cmake-nmake-wrap.bat + echo "if \"%VERBOSE_CM%\"==\"1\" (" >> c99-to-c89-cmake-nmake-wrap.bat + echo " set C99_TO_C89_WRAP_DEBUG_LEVEL=1" >> c99-to-c89-cmake-nmake-wrap.bat + echo " set C99_TO_C89_WRAP_SAVE_TEMPS=1" >> c99-to-c89-cmake-nmake-wrap.bat + echo " set C99_TO_C89_WRAP_NO_LINE_DIRECTIVES=1" >> c99-to-c89-cmake-nmake-wrap.bat + echo " set C99_TO_C89_CONV_DEBUG_LEVEL=1" >> c99-to-c89-cmake-nmake-wrap.bat + echo ")" >> c99-to-c89-cmake-nmake-wrap.bat + echo "%~dp0c99wrap.exe -keep cl %*" >> c99-to-c89-cmake-nmake-wrap.bat +popd diff --git a/recipe/meta.yaml b/recipe/meta.yaml index f097e9d..0919743 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -1,30 +1,81 @@ -{% set version = "1.0.3" %} +{% set version = "1.0.4" %} package: name: c99-to-c89 version: {{ version }} source: - fn: c99-to-c89-{{ version }}.zip # [win] - url: https://github.com/libav/c99-to-c89/releases/download/release-1.0.3/c99-to-c89-{{ version }}.zip # [win] - md5: d58bc9741f258841aa3196a1b4155e51 + - url: https://github.com/AnacondaRecipes/c99-to-c89/archive/release-{{ version }}.tar.gz + sha256: 1df2ec430d34e9034d162969fe1a12cee50fa67cacdcc60d7b57b6c45b576467 + # We need a libclang. No one builds them statically for Windows unfortunately (though the + # libav binaries have been built this way). I rename the libclang.dll in these to avoid + # conflicts with conda-forge's clangdev (which we cannot use at present due to compat). + # LLVM 6 has changed too much and is no longer compatible. It is at the ABI level, but + # not semantically (Assertion failed: n_tokens == 2, file convert.c, line 559). + - url: http://releases.llvm.org/3.9.1/LLVM-3.9.1-win64.exe + sha256: 7ea2b7bc0de6b96a6ce11e6cfece7b84a31fb0c86c977f42ee178cba41517606 + folder: llvm build: number: 0 - skip: True # [unix] - + skip: true # [win and vc!=14] + +requirements: + build: + - {{ compiler('c') }} + - msinttypes # [win and vc==9] + - m2-sed + - m2-base + - m2-make + - m2-filesystem + - m2-p7zip + - m2w64-tools-git + +test: + requires: + - {{ compiler('c') }} test: + source_files: + - c99-to-c89-release/recipe/tests commands: - # Would be good to run this - but can't because there are no version or help - # commands and without the proper input arguments it always returns exit code 1 - - if not exist %PREFIX%\\Library\\bin\\c99wrap.exe exit 1 # [win] - - if not exist %PREFIX%\\Library\\bin\\c99conv.exe exit 1 # [win] + - echo on + - echo cd %CD% + - set C99_TO_C89_CONV_DEBUG_LEVEL=0 + - set C99_TO_C89_WRAP_DEBUG_LEVEL=0 + - set C99_TO_C89_WRAP_SAVE_TEMPS=1 + - set C99_TO_C89_WRAP_NO_LINE_DIRECTIVES=1 + # Simple but large test: + - c99wrap cl /nologo -DDLL_EXPORT -DHAVE_CONFIG_H -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_DEPRECATE -Dlzma_EXPORTS -I%CD%\tests /DWIN32 /D_WINDOWS /Fo%TEMP%\check.c.obj -c %CD%\c99-to-c89-release\recipe\tests\check.c + - echo /nologo -DDLL_EXPORT -DHAVE_CONFIG_H -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_DEPRECATE -Dlzma_EXPORTS -I%CD%\tests /DWIN32 /D_WINDOWS /Fo%TEMP%\check.c.obj -c %CD%\c99-to-c89-release\recipe\tests\check.c > response-file + # Same test but via a response-file: + - c99wrap cl @response-file + # Small tests from now on so can safely enable a lot of debug output: + - set C99_TO_C89_CONV_DEBUG_LEVEL=2 + - set C99_TO_C89_WRAP_DEBUG_LEVEL=2 + # Test fix for broken handling of empty cond-statement in loops when moving the decl out of the init-expression: + # for (int i = 0 ; ; ++i) {} => int i = 0 ; ; for ( ; i++) {} + - c99wrap cl /Folzma_encoder_optimal_normal.c.obj -c %CD%\c99-to-c89-release\recipe\tests\lzma_encoder_optimal_normal.c + # Simple case I broke when attempting to fix cursor position management bug tested below: + - c99wrap cl /Focheck-2.c.obj -c %CD%\c99-to-c89-release\recipe\tests\check-2.c + # The cl pre-processor does not remove line continuations and the cl compiler cannot handle these: + - c99wrap cl /Fotest-macro-line-continuation.o -c %CD%\c99-to-c89-release\recipe\tests\test-macro-line-continuation.c + - c99wrap cl /Fotest-pragma-comment.o -c %CD%\c99-to-c89-release\recipe\tests\test-pragma-comment.c + # Next problem, cursor position management bug. "else if" => "elseif" and all other spaces vanish + # after insertion text to an earlier position on the same line, fixed by maintaining relative spacing. + # .. this test must be the last one due it exiting in both cases (though we could probably make it a + # c99wrap test instead so failure to compile would cause a natural exit). + - c99conv -ms %CD%\c99-to-c89-release\recipe\tests\stream_encoder.c.obj_preprocessed.c stream_encoder.c.converted.c + - findstr elseif stream_encoder.c.converted.c && (exit /b 1) || (exit /b 0) about: - home: https://github.com/libav/c99-to-c89/ - license: Apache v2 - summary: 'Tool to convert C99 code to MSVC-compatible C89' + home: https://github.com/libav/c99-to-c89 + license: Apache 2.0 + license_family: Apache + license_file: LICENSE + summary: 'Tool to convert C99 code to MSVC-compatible C89, with many Anaconda Distribution fixes' + dev_url: https://github.com/libav/c99-to-c89 extra: recipe-maintainers: + - mingwandroid - patricksnape diff --git a/recipe/unit.c b/recipe/unit.c deleted file mode 100644 index 91ec0a8..0000000 --- a/recipe/unit.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Unit test for compound literal C99-to-C89 replacement. - */ - -typedef struct AVRational { int num, den; } AVRational; -struct AVRational2 { int num; int den; char **test[3]; }; -typedef struct AVRational2 AVRational2; -typedef struct AVRational4 AVRational4; -typedef struct { int num, den; struct AVRational test; } AVRational3; - -static AVRational gap_test() { - AVRational gap = { .den = 4 }; - gap.num = 1; - return gap; -} - -static AVRational call_function_2(AVRational x) -{ - AVRational y = (struct AVRational) { x.den, x.num }; - int z = -1; // unused - y = (AVRational) { y.den, y.num }; - if (z == 0) - return (AVRational) { 5, -5 }; - else - return x.num > 0 ? (AVRational) { x.num, x.den } : - x.den > 0 ? (AVRational) { x.den, x.num } : - (AVRational) { 0, 0 }; -} - -static int call_function_3(AVRational x) -{ - return x.num ^ x.den; -} - -static int call_function(AVRational x) -{ - AVRational y = x.num > 0 ? call_function_2((AVRational) { x.num, x.den }) : - x.den > 0 ? call_function_2((AVRational) { x.den, x.num }) : - call_function_2((AVRational) { 0, 0 }); - int res; - - if ((res = call_function_3((AVRational) { 5, -5 }) > 0)) { - return ((AVRational) { -8, 8 }).den; - } else if (1 && (res = call_function_3((AVRational) { 6, -6 }) > 0)) { - return call_function_3((AVRational) { -5, 5 }); - } else - return 0; -} - -#define lut_vals(x) x, x+1, x+2, x+3 -#define lut(x) { lut_vals(x), lut_vals(x+4) } -static const int l[][8] = { - lut(0), - lut(16), - lut(32), - lut(48) -}; - -typedef struct AVCodec { - int (*decode) (AVRational x); - const int *samplefmts; -} AVCodec; - -static AVCodec decoder = { - .samplefmts = (const int[]) { 0, 1 }, - .decode = call_function, -}; - -typedef struct AVFilterPad { - const char *name; -} AVFilterPad; - -typedef struct AVFilter { - const char *name; - const AVFilterPad *inputs; -} AVFilter; - -AVFilter filter = { - .name = "filter", - .inputs = (const AVFilterPad[]) {{.name="pad",},{.name=(void*)0,},}, -}; - -int main(int argc, char *argv[]) -{ - int var; - -#define X 3 - switch (call_function((AVRational){1, 1})) { - case 0: - call_function((AVRational){2, 2}); - break; - default: - call_function((AVRational){3, 3}); - break; - } - var = ((const int[2]){1,2})[argc]; - var = call_function((AVRational){1, 2}); - if (var == 0) return call_function((AVRational){X, 2}); - else return call_function((AVRational){2, X}); -#undef X -} \ No newline at end of file