@@ -5,14 +5,25 @@ setlocal EnableExtensions EnableDelayedExpansion
5
5
REM cls
6
6
7
7
SET ARG = " %* "
8
+ SET SRC_PATH = %~dp0
9
+
10
+
11
+ REM 32/64 bit argument needs to stay on top, before setting LIBCURL path.
12
+ REM presence of '32' or '64': set the Bits/Target ARCHhitecture
13
+ if not _%ARG:32 =% == _%ARG% (
14
+ set TARCH = x86
15
+ set BARCH = 32
16
+ ) else (
17
+ set TARCH = x64
18
+ set BARCH = 64
19
+ )
20
+
21
+
8
22
9
23
REM
10
24
REM List of variables that can be customized
11
25
REM
12
26
13
- if " %SRC_PATH% " == " " (
14
- SET SRC_PATH = %~dp0
15
- )
16
27
if " %BUILD_DIR% " == " " (
17
28
SET BUILD_DIR = %SRC_PATH% \builds
18
29
)
@@ -33,7 +44,7 @@ if "%INSTALL_DIR%" == "" (
33
44
)
34
45
35
46
if " %LIBCURL_PATH_BUILD% " == " " (
36
- SET LIBCURL_PATH_BUILD = %SRC_PATH% \libs\curl\builds\libcurl-vc-x64 -release-dll-ipv6-sspi-winssl
47
+ SET LIBCURL_PATH_BUILD = %SRC_PATH% \libs\curl\builds\libcurl-vc-!TARCH! -release-dll-ipv6-sspi-winssl
37
48
)
38
49
39
50
if " %CMAKE_BIN_PATH% " == " " (
@@ -43,49 +54,173 @@ if "%CMAKE_BIN_PATH%" == "" (
43
54
44
55
45
56
REM
46
- REM Perform the building steps
57
+ REM Perform the building steps
58
+ REM
59
+
60
+ REM presence of 'help'/'?': invoke USAGE "function" and exit
61
+ if /i not _%ARG:help =% == _%ARG% (
62
+ call :USAGE %0
63
+ goto end
64
+ ) else if not _%ARG:? =% == _%ARG% (
65
+ call :USAGE %0
66
+ goto end
67
+ )
68
+
69
+ REM presence of 'proper' or 'clean': invoke respective "functions"
70
+ if /i not _%ARG:proper =% == _%ARG% (
71
+ call :PROPER
72
+ goto end
73
+ ) else if /i not _%ARG:clean =% == _%ARG% (
74
+ call :CLEAN
75
+ )
76
+
77
+ REM presence of 'setup': invoke SETUP "function"
78
+ if /i not _%ARG:setup =% == _%ARG% (
79
+ call :SETUP
80
+ ) else (
81
+ REM Invoked without 'setup': setting up build vars skipped.
82
+
83
+ where cl.exe > nul 2 >& 1
84
+ if ERRORLEVEL 1 (
85
+ echo .
86
+ echo Note: building environment not set. Run with /? to see options.
87
+ echo .
88
+ )
89
+ )
90
+
91
+ REM presence of 'fetch': invoke FETCH "function"
92
+ if /i not _%ARG:fetch =% == _%ARG% (
93
+ call :FETCH
94
+ )
95
+
96
+
97
+ cd %BUILD_DIR%
98
+
99
+ REM absence of nobuild: invoke BUILD "function"
100
+ if /i _%ARG:nobuild =% == _%ARG% (
101
+ call :BUILD
102
+ ) else (
103
+ echo Invoked with 'nobuild', building skipped.
104
+ )
105
+
106
+ REM presence of 'copy': invoke COPY "function"
107
+ if /i not _%ARG:copy =% == _%ARG% (
108
+ call :COPY
109
+ ) else (
110
+ REM Invoked without 'copy': DLLs test installation skipped.
111
+ )
112
+
113
+ REM presence of 'trunclogs': invoke TRUNCLOGS "function"
114
+ if /i not _%ARG:trunclogs =% == _%ARG% (
115
+ call :TRUNCLOGS
116
+ ) else (
117
+ REM Invoked without 'trunclogs', logs not truncated.
118
+ )
119
+
120
+ REM presence of 'regadd': call REGADD "function"
121
+ if /i not _%ARG:regadd =% == _%ARG% (
122
+ call :REGADD
123
+ ) else (
124
+ REM Invoked without 'regadd': registry adding skipped.
125
+ )
126
+
127
+ REM presence of 'regdel': invoke REGDEL "function"
128
+ if /i not _%ARG:regdel =% == _%ARG% (
129
+ call :REGDEL
130
+ ) else (
131
+ REM Invoked without 'regadd': registry adding skipped.
132
+ )
133
+
134
+ :end
135
+ exit /b 0
136
+
137
+
138
+
139
+ REM
140
+ REM "Functions"
47
141
REM
48
142
49
- REM presence of 'help' : output a usage message
50
- if not _ %ARG: help =% == _ %ARG% (
51
- echo Usage: %0 [argument(s^ )]
143
+ REM USAGE function : output a usage message
144
+ : USAGE
145
+ echo Usage: %1 [argument(s^ )]
52
146
echo .
53
147
echo The following arguments are supported:
54
- echo help : output this message and exit.
148
+ echo help^ |*?* : output this message and exit.
149
+ echo 32^ |64 : setup the architecture to 32- or 64-bit (default^ );
150
+ echo useful with 'setup' and 'reg*' arguments only;
151
+ echo x86 and x64 platforms supported only.
152
+ echo setup : invoke MSVC's build environment setup script before
153
+ echo building (requires 2017 version or later^ ).
55
154
echo clean : clean the build dir files.
56
155
echo proper : clean both the build and libs dir and exit.
57
156
echo fetch : fetch, patch and build the dependency libs.
58
- echo nobuild : don't build the project (the default is to build^ ).
59
- echo copy : copy the DLL into the test dir.
60
- echo regadd : register the driver into the registry (run as Administrator^ ).
61
- echo regdel : deregister the driver from the registry (run as Administrator^ ).
62
- echo trunclogs : truncate the logs.
157
+ echo nobuild : skip project building (the default is to build^ ).
158
+ echo copy : copy the DLL into the test dir (%INSTALL_DIR% ^ ).
159
+ echo regadd : register the driver into the registry;
160
+ echo (needs Administrator privileges^ ).
161
+ echo regdel : deregister the driver from the registry;
162
+ echo (needs Administrator privileges^ ).
163
+ echo trunclogs : truncate the logs (in %LOGGING_DIR% ^ ).
63
164
echo .
64
165
echo Multiple arguments can be used concurrently.
65
166
echo Invoked with no arguments, the script will only initiate a build.
167
+ echo Example:^ > %1 setup 32 fetch
66
168
echo .
67
-
68
- goto end
69
- )
169
+ echo List of settable environment variables:
170
+ echo BUILD_DIR : path to folder to hold the build files;
171
+ echo now set to: `%BUILD_DIR% `.
172
+ echo LOGGING_DIR : path to folder holding the logging files;
173
+ echo now set to: `%LOGGING_DIR% `.
174
+ echo INSTALL_DIR : path to folder to hold the built driver;
175
+ echo now set to: `%INSTALL_DIR% `.
176
+ echo LIBCURL_PATH_BUILD : path to libcurl library;
177
+ echo now set to: `%LIBCURL_PATH_BUILD% `.
178
+ echo CMAKE_BIN_PATH : path to cmake executable;
179
+ echo now set to: `%CMAKE_BIN_PATH% `.
180
+ echo .
181
+
182
+ goto :eof
70
183
71
- REM presence of 'proper': clean up the build and libs dir before building
72
- if not _%ARG:proper =% == _%ARG% (
184
+
185
+ REM PROPER function: clean up the build and libs dir before building
186
+ :PROPER
73
187
echo Cleaning all build and libs files.
74
188
del /s /q %BUILD_DIR% \* > nul 2 >& 1
75
189
for /d %%i in (%BUILD_DIR% \*) do rmdir /s /q %%i > nul 2 >& 1
76
190
del /s /q libs\* > nul 2 >& 1
77
191
for /d %%i in (libs\*) do rmdir /s /q %%i > nul 2 >& 1
78
192
79
- goto end
80
- ) else if not _%ARG:clean =% == _%ARG% (
81
- REM presence of 'clean': clean up the build dir before building
193
+ goto :eof
194
+
195
+
196
+ REM CLEAN function: clean up the build dir before building
197
+ :CLEAN
82
198
echo Cleaning all build files.
83
199
del /s /q %BUILD_DIR% \* > nul 2 >& 1
84
200
for /d %%i in (%BUILD_DIR% \*) do rmdir /s /q %%i > nul 2 >& 1
85
- )
86
201
87
- REM presence of 'fetch': fetch, patch, build the external libs
88
- if not _%ARG:fetch =% == _%ARG% (
202
+ goto :eof
203
+
204
+
205
+ REM SETUP function: set-up the build environment
206
+ :SETUP
207
+ set RELEASE = 2017
208
+ set EDITION = Professional
209
+ for %%e in (Enterprise, Professional, Community) do (
210
+ if exist " C:\Program Files (x86)\Microsoft Visual Studio\%RELEASE% \%%e \Common7\Tools\VsDevCmd.bat" (
211
+ if /i " %%e " == " Community" (
212
+ echo WARNING: Community edition is not licensed to build commerical projects.
213
+ )
214
+ call " C:\Program Files (x86)\Microsoft Visual Studio\%RELEASE% \%%e \Common7\Tools\VsDevCmd.bat" -arch=!TARCH!
215
+ break
216
+ )
217
+ )
218
+
219
+ goto :eof
220
+
221
+
222
+ REM FETCH function: fetch, patch, build the external libs
223
+ :FETCH
89
224
echo Fetching external dependencies, patching and building them.
90
225
91
226
rem pushd .
@@ -119,18 +254,17 @@ if not _%ARG:fetch=% == _%ARG% (
119
254
REM build libcurl
120
255
cd curl
121
256
git checkout curl-7_58_0
122
-
257
+
123
258
call buildconf.bat
124
259
REM buildconf.bat will cd
125
260
cd winbuild
126
- call nmake /f Makefile.vc mode=dll MACHINE=x64
127
- )
261
+ call nmake /f Makefile.vc mode=dll MACHINE=!TARCH!
128
262
263
+ goto :eof
129
264
130
- cd %BUILD_DIR%
131
265
132
- REM absence of nobuild: run the build
133
- if _ %ARG: nobuild =% == _ %ARG% (
266
+ REM BUILD function: compile, build the driver
267
+ : BUILD
134
268
echo Building the driver:
135
269
if not exist ALL_BUILD.vcxproj (
136
270
echo Generating the project files.
@@ -139,68 +273,68 @@ if _%ARG:nobuild=% == _%ARG% (
139
273
echo Building the project.
140
274
REM MSBuild ALL_BUILD.vcxproj /t:rebuild
141
275
MSBuild ALL_BUILD.vcxproj
142
- ) else (
143
- echo Invoked with 'nobuild', building skipped.
144
- )
145
276
146
- REM presence of copy: copy DLLs (libcurl, odbc) to the test "install" dir
147
- if not _%ARG:copy =% == _%ARG% (
277
+ goto :eof
278
+
279
+
280
+ REM COPY function: copy DLLs (libcurl, odbc) to the test "install" dir
281
+ :COPY
148
282
echo Copying into test install folder %INSTALL_DIR% .
149
283
rem dumpbin /exports Debug\elasticodbc*.dll
150
284
151
285
copy Debug\elasticodbc*.dll %INSTALL_DIR% \
152
286
copy %LIBCURL_PATH_BUILD% \bin\libcurl.dll %INSTALL_DIR% \
153
- ) else (
154
- REM Invoked without 'copy': DLLs test installation skipped.
155
- )
156
287
157
- REM presence of regadd: add driver into the registry
158
- if not _%ARG:regadd =% == _%ARG% (
288
+ goto :eof
289
+
290
+
291
+ REM TRUNCLOGS function: empty logs files
292
+ :TRUNCLOGS
293
+ echo Truncating logs in %LOGGING_DIR% .
294
+ echo .> %LOGGING_DIR% \mylog.txt
295
+ echo .> %LOGGING_DIR% \SQL32.LOG
296
+ echo .> %LOGGING_DIR% \SQL.LOG
297
+
298
+ goto :eof
299
+
300
+
301
+ REM REGADD function: add driver into the registry
302
+ :REGADD
159
303
echo Adding driver into the registry.
160
304
161
305
REM check if driver exists, otherwise the filename is unknown
162
- if not exist Debug\elasticodbc*.dll (
306
+ if not exist %BUILD_DIR% \ Debug\elasticodbc*.dll (
163
307
echo Error: Driver can only be added into the registry once built.
164
308
goto end
165
309
)
166
- for /f %%i in (" Debug\elasticodbc*.dll" ) do set DRVNAME = %%~nxi
310
+ for /f %%i in (" %BUILD_DIR% \ Debug\elasticodbc*.dll" ) do set DRVNAME = %%~nxi
167
311
168
- echo Registering driver in registry under: %INSTALL_DIR% \!DRVNAME!
312
+ echo Adding ESODBC driver %INSTALL_DIR% \!DRVNAME! to the registry.
169
313
170
314
reg add " HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" ^
171
- /v " Elasticsearch ODBC" /t REG_SZ /d Installed /f /reg:64
315
+ /v " Elasticsearch ODBC" /t REG_SZ /d Installed /f /reg:!BARCH!
172
316
173
- reg add " HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f /reg:64
317
+ reg add " HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f ^
318
+ /reg:!BARCH!
174
319
reg add " HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /v Driver ^
175
- /t REG_SZ /d %INSTALL_DIR% \!DRVNAME! /f /reg:64
320
+ /t REG_SZ /d %INSTALL_DIR% \!DRVNAME! /f /reg:!BARCH!
176
321
reg add " HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /v Setup ^
177
- /t REG_SZ /d %INSTALL_DIR% \!DRVNAME! /f /reg:64
322
+ /t REG_SZ /d %INSTALL_DIR% \!DRVNAME! /f /reg:!BARCH!
178
323
reg add " HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /v UsageCount^
179
- /t REG_DWORD /d 1 /f /reg:64
180
- ) else (
181
- REM Invoked without 'regadd': registry adding skipped.
182
- )
324
+ /t REG_DWORD /d 1 /f /reg:!BARCH!
325
+
326
+ goto :eof
183
327
184
- REM presence of regdel: remove driver from the registry
185
- if not _%ARG:regdel =% == _%ARG% (
186
- echo Removing driver from the registry.
328
+
329
+ REM REGDEL function: remove driver from the registry
330
+ :REGDEL
331
+ echo Removing ESODBC driver from the registry.
187
332
188
333
reg delete " HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" ^
189
- /v " Elasticsearch ODBC" /f /reg:64
190
- reg delete " HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f /reg:64
191
- ) else (
192
- REM Invoked without 'regadd': registry adding skipped.
193
- )
334
+ /v " Elasticsearch ODBC" /f /reg:!BARCH!
335
+ reg delete " HKLM\SOFTWARE\ODBC\ODBCINST.INI\Elasticsearch ODBC" /f ^
336
+ /reg:!BARCH!
194
337
195
- REM presence of keeplogs: empty logs files
196
- if not _%ARG:trunclogs =% == _%ARG% (
197
- echo Truncating logs in %LOGGING_DIR% .
198
- echo .> %LOGGING_DIR% \mylog.txt
199
- echo .> %LOGGING_DIR% \SQL32.LOG
200
- echo .> %LOGGING_DIR% \SQL.LOG
201
- ) else (
202
- REM Invoked without 'trunclogs', logs not truncated.
203
- )
338
+ goto :eof
204
339
205
- :end
206
340
endlocal
0 commit comments