Debian Codegraph @

build/package-win32.ps1

raw
1 #######################################################################
2 #
3 # Copyright (C) 2018 Joseph Benden <[email protected]>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc.
18 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #
20 #######################################################################
21 #
22 # Requirements:
23 # - Microsoft Visual Studio 2017 Community is installed.
24 # - Cygwin; both 32-bit and 64-bit.
25 # - All Cygwin dependencies are installed in both 32-bit and in
26 # 64-bit versions.
27 # - Airpcap is extracted in the root of the project.
28 # - The working directory is the root of the project.
29 # - Assumes utilities are installed in AppVeyor-specific
30 # locations. (Mostly default installation locations.)
31 #
32 # Running the script:
33 #
34 # powershell -File package-win32.ps1
35 #
36 #######################################################################
37
38 $env:CHERE_INVOKING = 1
39
40 $env:AIRPCAP = c:\cygwin\bin\bash.exe -e -l -c "/bin/cygpath -u `'$(Get-Location)`'"
41 $env:MSBUILD = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
42
43 $REV = c:\cygwin\bin\bash.exe -e -l -c "./evalrev"
44 $env:DIST = "aircrack-ng-$REV-win"
45
46 Write-Host -ForegroundColor Blue "Creating dist folder: $env:DIST"
47
48 if ((Test-Path -Path "src\.deps")) {
49 Write-Host -ForegroundColor Blue "Running distclean"
50 c:\cygwin\bin\bash.exe -e -l -c "/bin/make distclean"
51 }
52
53 if ((Test-Path -Path "$env:DIST")) {
54 Write-Host -ForegroundColor Blue "Removing existing dist folder."
55 Remove-Item -Recurse -Force $env:DIST
56 }
57
58 Write-Host -ForegroundColor Blue "Creating pristine sources"
59 c:\cygwin\bin\bash.exe -e -l -c "git archive --format=tar --prefix=`"$env:DIST/`" HEAD | /bin/tar xf -"
60 if ($LASTEXITCODE -ne 0) {
61 Write-Host -ForegroundColor Red "Failed to create pristine sources!"
62 Break
63 }
64
65 Write-Host -ForegroundColor Blue "Running autoreconf"
66 c:\cygwin\bin\bash.exe -e -l -c "/bin/autoreconf -vi" | Out-Null
67 if ($LASTEXITCODE -ne 0) {
68 Write-Host -ForegroundColor Red "Failed to run autoreconf!"
69 Break
70 }
71
72 Write-Host -ForegroundColor Blue "Building 32-bit binaries"
73 $b32 = @"
74 #!/bin/bash
75 set -eufx
76 [ -d 32bit ] && rm -fr 32bit
77 mkdir 32bit
78 cd 32bit
79 env CFLAGS="-O3 -mtune=i686 -DNDEBUG" LDFLAGS="-Wl,--enable-auto-image-base" ../configure --host=i686-pc-cygwin --target=i686-pc-cygwin --with-experimental --with-airpcap=$env:AIRPCAP --enable-win32-portable
80 /bin/make V=1
81 "@
82 $b32.Replace("`r`n","`n") | Set-Content -Path 32build.sh -Force
83 c:\cygwin\bin\bash.exe -e -l -c "/bin/chmod +x 32build.sh && ./32build.sh"
84 if ($LASTEXITCODE -ne 0) {
85 Write-Host -ForegroundColor Red "Failed to build 32-bit binaries!"
86 Break
87 }
88
89 Write-Host -ForegroundColor Blue "Building 64-bit binaries"
90 $b64 = @"
91 #!/bin/bash
92 set -eufx
93 [ -d 64bit ] && rm -fr 64bit
94 mkdir 64bit
95 cd 64bit
96 env CFLAGS="-O3 -mtune=opteron -DNDEBUG" LDFLAGS="-Wl,--enable-auto-image-base" ../configure --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --with-experimental --with-airpcap=$env:AIRPCAP --enable-win32-portable
97 /bin/make V=1
98 "@
99 $b64.Replace("`r`n","`n") | Set-Content -Path 64build.sh -Force
100 c:\cygwin64\bin\bash.exe -e -l -c "/bin/chmod +x 64build.sh && ./64build.sh"
101 if ($LASTEXITCODE -ne 0) {
102 Write-Host -ForegroundColor Red "Failed to build 64-bit binaries!"
103 Break
104 }
105
106 Write-Host -ForegroundColor Blue "Cloning GUI tools"
107 if ((Test-Path -Path "gui")) {
108 Write-Host -ForegroundColor Blue "Removing existing gui folder."
109 Remove-Item -Recurse -Force gui
110 }
111 git clone --no-checkout --depth 1 --single-branch --branch Windows https://github.com/aircrack-ng/aircrack-ng.git gui
112 Push-Location gui
113 git reset --hard
114 Pop-Location
115
116 c:\cygwin\bin\bash.exe -e -l -c "/bin/rsync -a gui/ `"$env:DIST/src`" && /bin/rm -fr `"$env:DIST/src/.git`" `"$env:DIST/.gitignore`" `"$env:DIST/appveyor.yml`" `"$env:DIST/.travis.yml`" `"$env:DIST/README.md`" `"$env:DIST/.github`" `"$env:DIST/patches`" `"$env:DIST/apparmor`""
117
118 Push-Location gui/GUI
119 & "$env:MSBUILD" Aircrack-ng.sln /p:Configuration=Release /p:Platform="Any CPU"
120 if ($LASTEXITCODE -ne 0) {
121 Write-Host -ForegroundColor Red "Failed to build GUI!"
122 Pop-Location
123 Break
124 }
125 Pop-Location
126
127 if ((Test-Path -Path "$env:DIST.zip")) {
128 Write-Host -ForegroundColor Blue "Removing existing ZIP file."
129 Remove-Item -Force "$env:DIST.zip"
130 }
131
132 $pkg = @"
133 #!/bin/bash
134 set -eufx
135
136 mkdir "$env:DIST/bin"
137 mkdir "$env:DIST/bin/32bit"
138 mkdir "$env:DIST/bin/64bit"
139
140 cp -pr "gui/GUI/Aircrack-ng/bin/Release/Aircrack-ng GUI.exe" $env:DIST/bin
141
142 find 32bit -path "*/.libs" -print0 | xargs -0I [] -n 1 find [] \( -name "*.exe" -o -name "*.dll" \) -exec cp -p {} "$env:DIST/bin/32bit" ';'
143 find 64bit -path "*/.libs" -print0 | xargs -0I [] -n 1 find [] \( -name "*.exe" -o -name "*.dll" \) -exec cp -p {} "$env:DIST/bin/64bit" ';'
144
145 # AirPcap DLLs
146 cp -p "Airpcap_Devpack/bin/x86/airpcap.dll" "$env:DIST/bin/32bit"
147 cp -p "Airpcap_Devpack/bin/x64/airpcap.dll" "$env:DIST/bin/64bit"
148
149 # Cygwin License
150 cp /usr/share/doc/Cygwin/CYGWIN_LICENSE "$env:DIST/LICENSE.Cygwin"
151
152 # gather dependencies of Cygwin
153 FILES="cygcrypto-1.1.dll cyghwloc-15.dll cyggcc_s-1.dll cyggcc_s-seh-1.dll cygpcre2-8-0.dll cygsqlite3-0.dll cygstdc++-6.dll cygwin1.dll cygz.dll cygxml2-2.dll cyglzma-5.dll cygiconv-2.dll"
154
155 for FILE in `$FILES; do
156 cp -p "/cygdrive/c/cygwin/bin/`$FILE" "$env:DIST/bin/32bit" || :
157 cp -p "/cygdrive/c/cygwin64/bin/`$FILE" "$env:DIST/bin/64bit" || :
158 done
159
160 "$env:DIST/bin/32bit/aircrack-ng" -u
161 rc=`$("$env:DIST/bin/32bit/aircrack-ng" --simd-list | wc -c)
162 if [ `$rc -ne 22 ]; then
163 echo "The expected number of SIMD engines are NOT present in 32-bit binary."
164 exit 1
165 fi
166
167 "$env:DIST/bin/64bit/aircrack-ng" -u
168 rc=`$("$env:DIST/bin/64bit/aircrack-ng" --simd-list | wc -c)
169 if [ `$rc -ne 22 ]; then
170 echo "The expected number of SIMD engines are NOT present in 64-bit binary."
171 exit 1
172 fi
173
174 zip -o -v -9 -r "$env:DIST.zip" "$env:DIST"
175 ( cat README; echo; echo . ) | zip -z "$env:DIST.zip"
176 exit 0
177 #
178 #
179 "@
180 $pkg.Replace("`r`n","`n") | Set-Content -Path pkg.sh -Force
181 c:\cygwin\bin\bash.exe -e -l -c "/bin/chmod +x pkg.sh && ./pkg.sh"
182 if ($LASTEXITCODE -ne 0) {
183 Write-Host -ForegroundColor Red "Failed to package!"
184 Break
185 }
186
187 Write-Host -ForegroundColor Green "Packaging successful!"