aboutsummaryrefslogtreecommitdiff
path: root/bootstrap-msvc.bat
blob: 56623d4179cbe1f8f8b1888c82f6aa2e2d35bd1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@echo off

rem file      : bootstrap-msvc.bat
rem copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
rem license   : MIT; see accompanying LICENSE file

setlocal EnableDelayedExpansion
goto start

:usage
echo.
echo Usage: %0 [/?] [cl-exe [cl-option...]]
echo.
echo Normally this batch file is executed from one of the Visual Studio
echo command prompts. It assume that the VC compiler can be executed as
echo just cl.exe and that all the relevant environment variables (INCLUDE,
echo LIB) are set.
echo.
echo The batch file expects to find the libbutl\ or libbutl-*\ directory
echo either in the current directory (build2 root) or one level up.
echo.
echo Note that is any cl-option arguments are specified, then they must be
echo preceded by the VC compiler executable (use cl.exe as the default).
echo For example:
echo.
echo %0 cl.exe /nologo
echo.
echo See the INSTALL file for details.
echo.
goto end

rem Clean up .obj files from all the directories passed as arguments.
rem
:clean_obj
  for %%d in (%*) do (
    if exist %%d\*.obj del %%d\*.obj
  )
goto :eof

:start

if "_%1_" == "_/?_" goto usage

rem See if there is libbutl or libbutl-* in the current directory and one
rem directory up. Note that globbing returns paths in alphabetic order.
rem
if exist libbutl\ (
  set "libbutl=libbutl"
) else (
  for /D %%d in (libbutl-*) do set "libbutl=%%d"
)

if "_%libbutl%_" == "__" (
  if exist ..\libbutl\ (
      set "libbutl=..\libbutl"
  ) else (
    for /D %%d in (..\libbutl-*) do set "libbutl=%%d"
  )
)

if "_%libbutl%_" == "__" (
  echo error: unable to find libbutl, run %0 /? for details
  goto error
)

rem All the source directories.
rem
set "src=build2"
set "src=%src% build2\config"
set "src=%src% build2\dist"
set "src=%src% build2\bin"
set "src=%src% build2\c"
set "src=%src% build2\cc"
set "src=%src% build2\cxx"
set "src=%src% build2\cli"
set "src=%src% build2\test"
set "src=%src% build2\install"
set "src=%src% %libbutl%\butl"

rem Get the compiler executable.
rem
if "_%1_" == "__" (
  set "cxx=cl.exe"
) else (
  set "cxx=%1"
)

rem Get the compile options.
rem
set "ops=/EHsc /MT /MP"
:ops_next
shift
if "_%1_" == "__" (
  goto ops_done
) else (
  set "ops=%ops% %1"
  goto ops_next
)
:ops_done

rem First clean up any stale .obj files we might have laying around.
rem
call :clean_obj %src%

rem Compile.
rem
rem VC dumps .obj files in the current directory not caring if the names
rem clash. And boy do they clash.
rem
set "obj="
set "cwd=%CD%"
for %%d in (%src%) do (
  echo.
  echo compiling in %%d\
  echo.
  cd %%d
  echo %cxx% /I%cwd%\%libbutl% /I%cwd% /DBUILD2_HOST_TRIPLET=\"i686-microsoft-win32-msvc\" %ops% /c /TP *.cxx
       %cxx% /I%cwd%\%libbutl% /I%cwd% /DBUILD2_HOST_TRIPLET=\"i686-microsoft-win32-msvc\" %ops% /c /TP *.cxx
  if errorlevel 1 (
    cd %cwd%
    goto error
  )
  cd %cwd%
  set "obj=!obj! %%d\*.obj"
)

rem Link.
rem
echo.
echo %cxx% %ops% /Fe: build2\b-boot.exe %obj% shell32.lib
     %cxx% %ops% /Fe: build2\b-boot.exe %obj% shell32.lib
if errorlevel 1 goto error

rem Clean up .obj.
rem
call :clean_obj %src%
goto end

:error
endlocal
exit /b 1

:end
endlocal