Paul Monson | 32119e1 | 2019-03-29 16:30:10 -0700 | [diff] [blame] | 1 | @echo off |
| 2 | goto :Run |
| 3 | |
| 4 | :Usage |
| 5 | echo. |
| 6 | echo Before running prepare_libffi.bat |
| 7 | echo LIBFFI_SOURCE environment variable must be set to the location of |
| 8 | echo of python-source-deps clone of libffi branch |
| 9 | echo VCVARSALL must be set to location of vcvarsall.bat |
| 10 | echo cygwin must be installed (see below) |
| 11 | echo SH environment variable must be set to the location of sh.exe |
| 12 | echo. |
| 13 | echo Tested with cygwin-x86 from https://www.cygwin.com/install.html |
| 14 | echo Select http://mirrors.kernel.org as the download site |
| 15 | echo Include the following cygwin packages in cygwin configuration: |
| 16 | echo make, autoconf, automake, libtool, dejagnu |
| 17 | echo. |
| 18 | echo NOTE: dejagnu is only required for running tests. |
| 19 | echo set LIBFFI_TEST=1 to run tests (optional) |
| 20 | echo. |
| 21 | echo Based on https://github.com/libffi/libffi/blob/master/.appveyor.yml |
| 22 | echo. |
| 23 | echo. |
| 24 | echo.Available flags: |
| 25 | echo. -x64 build for x64 |
| 26 | echo. -x86 build for x86 |
| 27 | echo. -? this help |
| 28 | echo. --install-cygwin install cygwin to c:\cygwin |
| 29 | exit /b 127 |
| 30 | |
| 31 | :Run |
| 32 | |
| 33 | set BUILD_X64= |
| 34 | set BUILD_X86= |
| 35 | set INSTALL_CYGWIN= |
| 36 | |
| 37 | :CheckOpts |
| 38 | if "%1"=="" goto :CheckOptsDone |
| 39 | if /I "%1"=="-x64" (set BUILD_X64=1) & shift & goto :CheckOpts |
| 40 | if /I "%1"=="-x86" (set BUILD_X86=1) & shift & goto :CheckOpts |
| 41 | if /I "%1"=="-?" goto :Usage |
| 42 | if /I "%1"=="--install-cygwin" (set INSTALL_CYGWIN=1) & shift & goto :CheckOpts |
| 43 | goto :Usage |
| 44 | |
| 45 | :CheckOptsDone |
| 46 | |
| 47 | if NOT DEFINED BUILD_X64 if NOT DEFINED BUILD_X86 if NOT DEFINED BUILD_ARM32 ( |
| 48 | set BUILD_X64=1 |
| 49 | set BUILD_X86=1 |
| 50 | ) |
| 51 | |
| 52 | if "%INSTALL_CYGWIN%"=="1" call :InstallCygwin |
| 53 | |
| 54 | setlocal |
| 55 | if NOT DEFINED SH if exist c:\cygwin\bin\sh.exe set SH=c:\cygwin\bin\sh.exe |
| 56 | |
| 57 | if NOT DEFINED VCVARSALL ( |
| 58 | if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ( |
| 59 | set VCVARSALL="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" |
| 60 | ) |
| 61 | ) |
| 62 | if ^%VCVARSALL:~0,1% NEQ ^" SET VCVARSALL="%VCVARSALL%" |
| 63 | |
| 64 | if NOT DEFINED LIBFFI_SOURCE echo.&&echo ERROR LIBFFI_SOURCE environment variable not set && goto :Usage |
| 65 | if NOT DEFINED SH echo ERROR SH environment variable not set && goto :Usage |
| 66 | |
| 67 | if not exist %SH% echo ERROR %SH% does not exist && goto :Usage |
| 68 | if not exist %LIBFFI_SOURCE% echo ERROR %LIBFFI_SOURCE% does not exist && goto :Usage |
| 69 | |
| 70 | set OLDPWD=%LIBFFI_SOURCE% |
| 71 | pushd %LIBFFI_SOURCE% |
| 72 | |
| 73 | %SH% --login -lc "cygcheck -dc cygwin" |
| 74 | set GET_MSVCC=%SH% -lc "cd $OLDPWD; export MSVCC=`/usr/bin/find $PWD -name msvcc.sh`; echo ${MSVCC};" |
| 75 | FOR /F "usebackq delims==" %%i IN (`%GET_MSVCC%`) do @set MSVCC=%%i |
| 76 | |
| 77 | echo. |
| 78 | echo VCVARSALL : %VCVARSALL% |
| 79 | echo SH : %SH% |
| 80 | echo LIBFFI_SOURCE: %LIBFFI_SOURCE% |
| 81 | echo MSVCC : %MSVCC% |
| 82 | echo. |
| 83 | |
| 84 | if not exist Makefile.in (%SH% -lc "(cd $LIBFFI_SOURCE; ./autogen.sh;)") |
| 85 | |
| 86 | call :BuildOne x86 i686-pc-cygwin i686-pc-cygwin |
| 87 | call :BuildOne x64 x86_64-w64-cygwin x86_64-w64-cygwin |
| 88 | |
| 89 | popd |
| 90 | endlocal |
| 91 | exit /b 0 |
| 92 | REM all done |
| 93 | |
| 94 | |
| 95 | REM this subroutine is called once for each architecture |
| 96 | :BuildOne |
| 97 | |
| 98 | setlocal |
| 99 | |
| 100 | REM Initialize variables |
| 101 | set VCVARS_PLATFORM=%1 |
| 102 | set BUILD=%2 |
| 103 | set HOST=%3 |
| 104 | set ASSEMBLER= |
| 105 | set SRC_ARCHITECTURE=x86 |
| 106 | |
| 107 | if NOT DEFINED VCVARS_PLATFORM echo ERROR bad VCVARS_PLATFORM&&exit /b 123 |
| 108 | |
| 109 | if /I "%VCVARS_PLATFORM%" EQU "x64" ( |
| 110 | set ARCH=amd64 |
| 111 | set ARTIFACTS=%LIBFFI_SOURCE%\x86_64-w64-cygwin |
| 112 | set ASSEMBLER=-m64 |
| 113 | set SRC_ARCHITECTURE=x86 |
| 114 | ) |
| 115 | if /I "%VCVARS_PLATFORM%" EQU "x86" ( |
| 116 | set ARCH=win32 |
| 117 | set ARTIFACTS=%LIBFFI_SOURCE%\i686-pc-cygwin |
| 118 | set ASSEMBLER= |
| 119 | set SRC_ARCHITECTURE=x86 |
| 120 | ) |
| 121 | |
| 122 | if NOT DEFINED LIBFFI_OUT set LIBFFI_OUT=%~dp0\..\externals\libffi |
| 123 | set _LIBFFI_OUT=%LIBFFI_OUT%\%ARCH% |
| 124 | |
| 125 | echo get VS build environment |
| 126 | call %VCVARSALL% %VCVARS_PLATFORM% |
| 127 | |
| 128 | echo clean %_LIBFFI_OUT% |
| 129 | if exist %_LIBFFI_OUT% (rd %_LIBFFI_OUT% /s/q) |
| 130 | |
| 131 | echo Configure the build to generate fficonfig.h and ffi.h |
| 132 | %SH% -lc "(cd $OLDPWD; ./configure CC='%MSVCC% %ASSEMBLER%' CXX='%MSVCC% %ASSEMBLER%' LD='link' CPP='cl -nologo -EP' CXXCPP='cl -nologo -EP' CPPFLAGS='-DFFI_BUILDING_DLL' NM='dumpbin -symbols' STRIP=':' --build=$BUILD --host=$HOST;)" |
| 133 | |
| 134 | echo Building libffi |
| 135 | %SH% -lc "(cd $OLDPWD; export PATH=/usr/bin:$PATH; cp src/%SRC_ARCHITECTURE%/ffitarget.h include; make; find .;)" |
| 136 | |
| 137 | REM Tests are not needed to produce artifacts |
| 138 | if "%LIBFFI_TEST%" EQU "1" ( |
| 139 | echo "Running tests..." |
| 140 | %SH% -lc "(cd $OLDPWD; export PATH=/usr/bin:$PATH; cp `find $PWD -name 'libffi-?.dll'` $HOST/testsuite/; make check; cat `find ./ -name libffi.log`)" |
| 141 | ) else ( |
| 142 | echo "Not running tests" |
| 143 | ) |
| 144 | |
| 145 | |
| 146 | echo copying files to %_LIBFFI_OUT% |
| 147 | if not exist %_LIBFFI_OUT%\include (md %_LIBFFI_OUT%\include) |
| 148 | copy %ARTIFACTS%\.libs\libffi-7.dll %_LIBFFI_OUT% |
| 149 | copy %ARTIFACTS%\.libs\libffi-7.lib %_LIBFFI_OUT% |
| 150 | copy %ARTIFACTS%\fficonfig.h %_LIBFFI_OUT%\include |
| 151 | copy %ARTIFACTS%\include\*.h %_LIBFFI_OUT%\include |
| 152 | |
| 153 | endlocal |
| 154 | exit /b |
| 155 | |
| 156 | :InstallCygwin |
| 157 | setlocal |
| 158 | |
| 159 | if NOT DEFINED CYG_ROOT (set CYG_ROOT=c:/cygwin) |
| 160 | if NOT DEFINED CYG_CACHE (set CYG_CACHE=C:/cygwin/var/cache/setup) |
| 161 | if NOT DEFINED CYG_MIRROR (set CYG_MIRROR=http://mirrors.kernel.org/sourceware/cygwin/) |
| 162 | |
| 163 | powershell -c "md $env:CYG_ROOT -ErrorAction SilentlyContinue" |
| 164 | powershell -c "$setup = $env:CYG_ROOT+'/setup.exe'; if (!(Test-Path $setup)){invoke-webrequest https://cygwin.com/setup-x86.exe -outfile $setup} |
| 165 | %CYG_ROOT%/setup.exe -qnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P make -P autoconf -P automake -P libtool -P dejagnu |
| 166 | |
| 167 | endlocal |
| 168 | exit /b |
| 169 | |