1717set -e
1818
1919if [ $# -lt 1 ]; then
20- echo $0 {vc.zip sdk.zip target\ | target}
20+ echo " $0 {vc.zip sdk.zip target|target}"
2121 exit 0
2222fi
2323
2424if [ $# -eq 3 ]; then
25- VC_ZIP=$( cd $( dirname $1 ) && pwd) /$( basename $1 )
26- SDK_ZIP=$( cd $( dirname $2 ) && pwd) /$( basename $2 )
25+ VC_ZIP=$( cd " $( dirname " $1 " ) " && pwd) /$( basename " $1 " )
26+ SDK_ZIP=$( cd " $( dirname " $2 " ) " && pwd) /$( basename " $2 " )
2727 DEST=$3
2828else
2929 DEST=$1
3030fi
31- ORIG=$( cd $( dirname $0 ) && pwd)
31+ ORIG=$( cd " $( dirname " $0 " ) " && pwd)
3232
33- mkdir -p $DEST
34- cd $DEST
33+ mkdir -p " $DEST "
34+ cd " $DEST "
3535DEST=$( pwd)
3636
3737ln_s () {
@@ -41,9 +41,9 @@ ln_s() {
4141}
4242
4343if [ -n " $VC_ZIP " ]; then
44- unzip $VC_ZIP
44+ unzip " $VC_ZIP "
4545fi
46- ln_s kits " Windows Kits"
46+ ln_s " Windows Kits" kits
4747ln_s VC vc
4848ln_s Tools vc/tools
4949ln_s MSVC vc/tools/msvc
@@ -71,15 +71,24 @@ cd ..
7171# Thus process them to reference the other headers with lowercase names.
7272# Also lowercase these files, as a few of them do have non-lowercase names,
7373# and the call to fixinclude lowercases those references.
74- $ORIG /lowercase -symlink include
75- $ORIG /fixinclude include
74+ " $ORIG " /lowercase -symlink include
75+ " $ORIG " /fixinclude include
76+ if [ -d " atlmfc/include" ]; then
77+ # The ATL headers are lowercased themselves, but they refer to
78+ # WinSDK headers with mixed casing.
79+ " $ORIG " /fixinclude " atlmfc/include"
80+ fi
7681cd bin
7782# vctip.exe is known to cause problems at some times; just remove it.
7883# See https://bugs.chromium.org/p/chromium/issues/detail?id=735226 and
7984# https://github.com/mstorsjo/msvc-wine/issues/23 for references.
8085for i in $( find . -iname vctip.exe) ; do
8186 rm $i
8287done
88+ if [ -d HostX64 ]; then
89+ # 15.x - 16.4
90+ mv HostX64 Hostx64
91+ fi
8392if [ -d HostARM64 ]; then
8493 # 17.2 - 17.3
8594 mv HostARM64 Hostarm64
@@ -99,13 +108,15 @@ if [ -d kits/10 ]; then
99108else
100109 mkdir kits
101110 cd kits
102- unzip $SDK_ZIP
111+ unzip " $SDK_ZIP "
103112 cd 10
104113fi
105114ln_s Lib lib
106115ln_s Include include
107116cd ../..
108- SDKVER=$( basename $( echo kits/10/include/* | awk ' {print $NF}' ) )
117+
118+ SDKVER=$( basename $( echo kits/10/include/10.* | awk ' {print $NF}' ) )
119+ echo Using SDK version $SDKVER
109120
110121# Lowercase the SDK headers and libraries. As long as cl.exe is executed
111122# within wine, this is mostly not necessary.
@@ -123,44 +134,78 @@ SDKVER=$(basename $(echo kits/10/include/* | awk '{print $NF}'))
123134# The original casing of file names is preserved though, by adding lowercase
124135# symlinks instead of doing a plain rename, so files can be referred to with
125136# either the out of the box filename or with the lowercase name.
126- $ORIG /lowercase -map_winsdk -symlink kits/10/include/$SDKVER /um
127- $ORIG /lowercase -map_winsdk -symlink kits/10/include/$SDKVER /shared
128- $ORIG /fixinclude -map_winsdk kits/10/include/$SDKVER /um
129- $ORIG /fixinclude -map_winsdk kits/10/include/$SDKVER /shared
137+ for incdir in um shared winrt km; do
138+ SDK_INCDIR=" kits/10/include/$SDKVER /$incdir "
139+
140+ if [ -d " $SDK_INCDIR " ]; then
141+ " $ORIG " /lowercase -map_winsdk -symlink " $SDK_INCDIR "
142+ " $ORIG " /fixinclude -map_winsdk " $SDK_INCDIR "
143+ fi
144+ done
145+
146+ # The WDF is a part of the Windows Driver Kit.
147+ WDF_INCDIR=" kits/10/include/wdf"
148+ if [ -d " $WDF_INCDIR " ]; then
149+ " $ORIG " /lowercase -map_winsdk -symlink " $WDF_INCDIR "
150+ " $ORIG " /fixinclude -map_winsdk " $WDF_INCDIR "
151+ fi
152+
130153for arch in x86 x64 arm arm64; do
131- if [ ! -d " kits/10/lib/$SDKVER /um/$arch " ]; then
132- continue
154+ SDK_LIBDIR=" kits/10/lib/$SDKVER /um/$arch "
155+ DDK_LIBDIR=" kits/10/lib/$SDKVER /km/$arch "
156+
157+ if [ -d " $SDK_LIBDIR " ]; then
158+ " $ORIG " /lowercase -symlink " $SDK_LIBDIR "
159+ fi
160+ if [ -d " $DDK_LIBDIR " ]; then
161+ " $ORIG " /lowercase -symlink " $DDK_LIBDIR "
133162 fi
134- $ORIG /lowercase -symlink kits/10/lib/$SDKVER /um/$arch
135163done
136164
137165host=x64
166+ # .NET-based tools use different host arch directories
167+ dotnet_host=amd64
138168if [ " $( uname -m) " = " aarch64" ]; then
139169 host=arm64
170+ dotnet_host=arm64
140171fi
141172
142- SDKVER=$( basename $( echo kits/10/include/* | awk ' {print $NF}' ) )
143173MSVCVER=$( basename $( echo vc/tools/msvc/* | awk ' {print $1}' ) )
144- cat $ORIG /wrappers/msvcenv.sh | sed ' s/MSVCVER=.*/MSVCVER=' $MSVCVER / | sed ' s/SDKVER=.*/SDKVER=' $SDKVER / | sed s/x64/$host / > msvcenv.sh
174+ echo Using MSVC version $MSVCVER
175+
176+ # Support `import std` for CMake.
177+ if [ -d " VC/Tools/MSVC/$MSVCVER /modules" ]; then
178+ ln_s VC/Tools/MSVC/$MSVCVER /modules modules
179+ fi
180+
181+ cat " $ORIG " /wrappers/msvcenv.sh \
182+ | sed ' s/MSVCVER=.*/MSVCVER=' $MSVCVER / \
183+ | sed ' s/SDKVER=.*/SDKVER=' $SDKVER / \
184+ | sed s/x64/$host / \
185+ | sed s/amd64/$dotnet_host / \
186+ > msvcenv.sh
187+
145188for arch in x86 x64 arm arm64; do
146- if [ ! -d " vc/tools/msvc/$MSVCVER /bin/Hostx64 /$arch " ]; then
189+ if [ ! -d " vc/tools/msvc/$MSVCVER /bin/Host $host /$arch " ]; then
147190 continue
148191 fi
149192 mkdir -p bin/$arch
150- cp -a $ORIG /wrappers/* bin/$arch
193+ cp -a " $ORIG " /wrappers/* bin/$arch
151194 cat msvcenv.sh | sed ' s/ARCH=.*/ARCH=' $arch / > bin/$arch /msvcenv.sh
152195done
153196rm msvcenv.sh
154197
155- if [ -d " $DEST /bin/$host " ] && [ -x " $( which wine64 2> /dev/null) " ]; then
156- WINEDEBUG=-all wine64 wineboot & > /dev/null
157- echo " Build msvctricks ..."
158- " $DEST /bin/$host /cl" /EHsc /O2 " $ORIG /msvctricks.cpp"
159- if [ $? -eq 0 ]; then
160- mv msvctricks.exe bin/
161- rm msvctricks.obj
162- echo " Build msvctricks done."
163- else
164- echo " Build msvctricks failed."
198+ if [ -d " $DEST /bin/$host " ]; then
199+ if WINE=" $( command -v wine64 || command -v wine) " ; then
200+ WINEDEBUG=-all " ${WINE} " wineboot & > /dev/null
201+ echo " Build msvctricks ..."
202+ " $DEST /bin/$host /cl" /EHsc /O2 " $ORIG /msvctricks.cpp"
203+ if [ $? -eq 0 ]; then
204+ mv msvctricks.exe bin/
205+ rm msvctricks.obj
206+ echo " Build msvctricks done."
207+ else
208+ echo " Build msvctricks failed."
209+ fi
165210 fi
166211fi
0 commit comments