@@ -120,53 +120,6 @@ limitations under the License.]])
120
120
string (STRIP header "${header} " )
121
121
string (REPLACE "\n " ";" header_lines "${header} " )
122
122
123
- # Prefix for the Batch script:
124
- set (bat_preamble [[
125
- call :init
126
-
127
- :print
128
- <nul set /p_=%~1
129
- exit /b
130
-
131
- :rmfile
132
- set f=%__prefix%\%~1
133
- call :print "Remove file %f% "
134
- if EXIST "%f%" (
135
- del /Q /F "%f%" || exit /b %errorlevel%
136
- call :print " - ok"
137
- ) else (
138
- call :print " - skipped: not present"
139
- )
140
- echo(
141
- exit /b
142
-
143
- :rmdir
144
- set f=%__prefix%\%~1
145
- call :print "Remove directory: %f% "
146
- if EXIST "%f%" (
147
- rmdir /Q "%f%" 2>nul
148
- if ERRORLEVEL 0 (
149
- call :print "- ok"
150
- ) else (
151
- call :print "- skipped (non-empty?)"
152
- )
153
- ) else (
154
- call :print " - skipped: not present"
155
- )
156
- echo(
157
- exit /b
158
-
159
- :init
160
- setlocal EnableDelayedExpansion
161
- setlocal EnableExtensions
162
- if /i "%~dp0" NEQ "%TEMP%\" (
163
- set tmpfile=%TEMP%\mongoc-%~nx0
164
- copy "%~f0" "!tmpfile!" >nul
165
- call "!tmpfile!" & del "!tmpfile!"
166
- exit /b
167
- )
168
- ]] )
169
-
170
123
# Prefix for the shell script:
171
124
set (sh_preamble [[
172
125
set -eu
@@ -225,15 +178,9 @@ if(UNINSTALL_IS_WIN32)
225
178
""
226
179
"${header_lines} "
227
180
""
228
- "${bat_preamble} "
229
- "if \" %DESTDIR%\" ==\"\" ("
230
- " set __prefix=${install_prefix} "
231
- ") else ("
232
- " set __prefix=!DESTDIR!\\ ${relative_prefix} "
233
- ")"
234
- "" )
235
- set (__rmfile "call :rmfile" )
236
- set (__rmdir "call :rmdir" )
181
+ "if \" %DESTDIR%\" ==\"\" (set __prefix=${install_prefix} ) else (set __prefix=!DESTDIR!\\ ${relative_prefix} )"
182
+ ""
183
+ "(GOTO) 2>nul & (" )
237
184
else ()
238
185
# Comment the header:
239
186
list (TRANSFORM header_lines PREPEND "# " REGEX "^.+$" )
@@ -247,8 +194,6 @@ else()
247
194
"${sh_preamble} "
248
195
"__prefix=\$ {DESTDIR:-}${install_prefix} "
249
196
"" )
250
- set (__rmfile "__rmfile" )
251
- set (__rmdir "__rmdir" )
252
197
endif ()
253
198
254
199
# Add the first lines to the file:
@@ -258,13 +203,37 @@ append_line("${init}")
258
203
# Generate a "remove a file" command
259
204
function (add_rmfile filename )
260
205
file (TO_NATIVE_PATH "${filename} " native )
261
- append_line ("${__rmfile} '${native} '" )
206
+ if (WIN32 )
207
+ set (file "%__prefix%\\ ${native} " )
208
+ set (rmfile_lines
209
+ " <nul set /p \" =Remove file: ${file} \" "
210
+ " if EXIST \" ${file} \" ("
211
+ " del /Q /F \" ${file} \" && echo - ok"
212
+ " ) ELSE echo - skipped: not present"
213
+ ") && (" )
214
+ string (REPLACE ";" "\n " rmfile "${rmfile_lines} " )
215
+ append_line ("${rmfile} " )
216
+ else ()
217
+ append_line ("__rmfile '${native} '" )
218
+ endif ()
262
219
endfunction ()
263
220
264
221
# Generate a "remove a directory" command
265
222
function (add_rmdir dirname )
266
223
file (TO_NATIVE_PATH "${dirname} " native )
267
- append_line ("${__rmdir} '${native} '" )
224
+ if (WIN32 )
225
+ set (dir "%__prefix%\\ ${native} " )
226
+ set (rmdir_lines
227
+ " <nul set /p \" =Remove directory: ${dir} \" "
228
+ " if EXIST \" ${dir} \" ("
229
+ " rmdir /Q \" ${dir} \" 2>nul && echo - ok || echo - skipped ^(non-empty?^)"
230
+ " ) ELSE echo - skipped: not present"
231
+ ") && (" )
232
+ string (REPLACE ";" "\n " rmdir "${rmdir_lines} " )
233
+ append_line ("${rmdir} " )
234
+ else ()
235
+ append_line ("__rmdir '${native} '" )
236
+ endif ()
268
237
endfunction ()
269
238
270
239
set (script_self "${install_prefix} /${UNINSTALL_SCRIPT_SELF} " )
@@ -298,4 +267,10 @@ foreach(dir IN LISTS dirs_to_remove)
298
267
add_rmdir ("${relpath} " )
299
268
endforeach ()
300
269
270
+ # Allow the batch script delete itself without error.
271
+ if (WIN32 )
272
+ append_line (" ver>nul" )
273
+ append_line (")" )
274
+ endif ()
275
+
301
276
message (STATUS "Generated uninstaller: ${UNINSTALL_WRITE_FILE} " )
0 commit comments