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