+@echo off\r
+if not exist Nmakefile goto wrong_dir\r
+\r
+if /i %PROCESSOR_ARCHITECTURE%==AMD64 (\r
+ set _target="x86-64"\r
+ set _bootimage="boot.winnt-x86.64.image"\r
+) else (\r
+ set _target="x86-32"\r
+ set _bootimage="boot.winnt-x86.32.image"\r
+)\r
+\r
+if "%1"=="/?" goto usage\r
+\r
+if "%1"=="" (\r
+ set _bootimage_version="latest"\r
+ set _git_branch=master\r
+)\r
+if "%1"=="latest" (\r
+ set _bootimage_version="latest"\r
+ set _git_branch=master\r
+)\r
+if "%1"=="clean" (\r
+ set _bootimage_version="clean"\r
+ set _git_branch=clean-winnt-%_target%\r
+)\r
+\r
+if not defined _bootimage_version goto usage\r
+\r
+echo Updating working copy...\r
+cmd /c "git pull http://factorcode.org/git/factor.git %_git_branch%"\r
+if not errorlevel 0 goto fail\r
+\r
+echo Building vm...\r
+nmake /nologo /f Nmakefile clean\r
+if not errorlevel 0 goto fail\r
+nmake /nologo /f Nmakefile %_target%\r
+if not errorlevel 0 goto fail\r
+\r
+echo Fetching %_bootimage_version% boot image...\r
+cscript /nologo build-support\http-get.vbs http://factorcode.org/images/%_bootimage_version%/%_bootimage% %_bootimage%\r
+if not errorlevel 0 goto fail\r
+\r
+echo Bootstrapping...\r
+.\factor.com -i=%_bootimage%\r
+if not errorlevel 0 goto fail\r
+\r
+echo Build complete.\r
+goto cleanup\r
+\r
+:fail\r
+echo Build failed.\r
+goto cleanup\r
+\r
+:wrong_dir\r
+echo build-support\factor.cmd must be run from the root of the Factor source tree.\r
+goto cleanup\r
+\r
+:usage\r
+echo Usage: build-support\factor.cmd [latest/clean]\r
+echo Updates the working copy, cleans and builds the vm using nmake,\r
+echo fetches a boot image, and bootstraps factor.\r
+echo If latest is specified, then the working copy is updated to the\r
+echo upstream "master" branch and the boot image corresponding to the\r
+echo most recent factor build is downloaded. This is the default.\r
+echo If clean is specified, then the working copy is updated to the\r
+echo upstream "clean-winnt-*" branch corresponding to the current\r
+echo platform and the corresponding boot image is downloaded.\r
+goto cleanup\r
+\r
+:cleanup\r
+set _target=\r
+set _bootimage=\r
+set _bootimage_version=\r
+set _git_branch=\r