]> gitweb.factorcode.org Git - factor.git/blob - build.cmd
factor: trim some using lists
[factor.git] / build.cmd
1 @echo off
2 setlocal
3
4 : Check which branch we are on, or just assume master if we are not in a git repository
5 for /f %%z in ('git rev-parse --abbrev-ref HEAD') do set GIT_BRANCH=%%z
6 if not defined GIT_BRANCH (
7     set GIT_BRANCH=master
8 )
9
10 if "%1"=="/?" (
11     goto usage
12 ) else if "%1"=="" (
13     set _git_pull=1
14     set _compile_vm=1
15     set _bootimage_type=download
16     set _bootstrap_factor=1
17 ) else if "%1"=="latest" (
18     set _git_pull=1
19     set _compile_vm=1
20     set _bootimage_type=download
21     set _bootstrap_factor=1
22 ) else if "%1"=="update" (
23     set _git_pull=1
24     set _compile_vm=1
25     set _bootimage_type=download
26     set _bootstrap_factor=1
27 ) else if "%1"=="compile" (
28     set _git_pull=0
29     set _compile_vm=1
30     set _bootimage_type=current
31     set _bootstrap_factor=0
32 ) else if "%1"=="self-bootstrap" (
33     set _git_pull=1
34     set _compile_vm=0
35     set _bootimage_type=make
36     set _bootstrap_factor=1
37 ) else if "%1"=="bootstrap" (
38     set _git_pull=0
39     set _compile_vm=0
40     set _bootimage_type=current
41     set _bootstrap_factor=1
42 ) else if "%1"=="net-bootstrap" (
43     set _git_pull=0
44     set _compile_vm=1
45     set _bootimage_type=download
46     set _bootstrap_factor=1
47 ) else goto usage
48
49 if not exist Nmakefile goto wrongdir
50
51 call cl 2>&1 | find "x86" >nul
52 if not errorlevel 1 (
53     echo x86-32 cl.exe detected.
54     set _target=x86-32
55     set _bootimage=boot.windows-x86.32.image
56 ) else (
57     call cl 2>&1 | find "x64" >nul
58     if not errorlevel 1 (
59         echo x86-64 cl.exe detected.
60         set _target=x86-64
61         set _bootimage=boot.windows-x86.64.image
62     ) else goto nocl
63 )
64
65 echo Deleting staging images from temp/...
66 del temp\staging.*.image
67
68 if "%_git_pull%"=="1" (
69     echo Updating working copy from %GIT_BRANCH%...
70     call git pull https://github.com/factor/factor %GIT_BRANCH%
71     if errorlevel 1 goto fail
72 )
73
74 if "%_compile_vm%"=="1" (
75     echo Building vm...
76     nmake /nologo /f Nmakefile clean
77     if errorlevel 1 goto fail
78
79     nmake /nologo /f Nmakefile %_target%
80     if errorlevel 1 goto fail
81 )
82
83 set _bootimage_url=https://downloads.factorcode.org/images/%GIT_BRANCH%/%_bootimage%
84 if "%_bootimage_type%"=="download" (
85     echo Fetching %GIT_BRANCH% boot image...
86     echo URL: %_bootimage_url%
87     cscript /nologo misc\http-get.vbs %_bootimage_url% %_bootimage%
88     if errorlevel 1 goto fail
89 ) else if "%_bootimage_type%"=="make" (
90     echo Making boot image...
91     .\factor.com -run=bootstrap.image %_bootimage%
92     if errorlevel 1 goto fail
93 )
94
95 if "%_bootstrap_factor%"=="1" (
96     echo Bootstrapping...
97     .\factor.com -i=%_bootimage%
98     if errorlevel 1 goto fail
99
100     echo Copying fresh factor.image to factor.image.fresh.
101     copy factor.image factor.image.fresh
102     if errorlevel 1 goto fail
103 )
104
105 echo Build complete.
106 goto :EOF
107
108 :fail
109 echo Build failed.
110 goto :EOF
111
112 :wrongdir
113 echo build.cmd must be run from the root of the Factor source tree.
114 goto :EOF
115
116 :nocl
117 echo Unable to detect cl.exe target platform.
118 echo Make sure you're running within the Visual Studio or Windows SDK environment.
119 goto :EOF
120
121 :usage
122 echo Usage: build.cmd [command]
123 echo     Updates the working copy, cleans and builds the vm using nmake,
124 echo     fetches a boot image, and bootstraps factor.
125 echo:
126 echo     The branch that bootstraps is the one that is checked out locally.
127 echo:
128 echo     compile - recompile vm
129 echo     update - git pull, recompile vm, download a boot image, bootstrap
130 echo     self-bootstrap - git pull, make a boot image, bootstrap
131 echo     bootstrap - existing boot image, bootstrap
132 echo     net-bootstrap - recompile vm, download a boot image, bootstrap
133 goto :EOF