source: main/trunk/greenstone2/runtime-src/packages/apache-httpd/adjust-winmak-files.bat@ 31425

Last change on this file since 31425 was 31425, checked in by ak19, 7 years ago

Fix to commits 31421 and 31422. Adding Dr Bainbridge's new awk file script (with slight modification) now used by adjust-winmakefiles.bat in place of sed. To prevent race conditions when compiling up apache-httpd2 for GS2, tempfile.bat files should be numbered incrementally within each win32.mak in httpd-2.2.11, not incrementally between each win32.mak within httpd-2.2.11.

File size: 5.0 KB
RevLine 
[31421]1:: This file ports the changes Sam made to the release-kit (using ant tasks) for compiling the GS2 release
2:: See changeset http://trac.greenstone.org/changeset/22490
3:: (Also http://trac.greenstone.org/browser/main/trunk/ant-tasks/src/org/greenstone/anttasks/RegexSearchReplace.java
4:: http://trac.greenstone.org/browser/main/trunk/ant-tasks/src/org/greenstone/anttasks/InsertUniqueValue.java)
[31425]5:: This script makes use of mod_winmake_file.awk to perform the following 2 steps
6:: to prevent race conditions to any win32.mak file trying to create/access the same tempfile.bat:
7:: - in each .mak within httpd-2.2.11, make each line that refers to "tempfile.bat" refer to a unique tempfile.bat instead
8:: - replace all occurrences of "/MD" in .mak files within httpd-2.2.11 with "/MT"
[31421]9
10:: http://www.theverge.com/2016/3/30/11331014/microsoft-windows-linux-ubuntu-bash
11:: "Microsoft is adding the Linux command line to Windows 10" Mar 30, 2016
12
13
14@echo off
15
16:: pass in the httpd folder to this script, e.g. httpd-2.2.11
17if [%1]==[] echo ERROR: Extracted httpd folder name not specified. Unable to adjust win .mak files&& goto :eof
18if not exist "%~dp0%1" echo ERROR: Extracted httpd folder %~dp0%1 doesn't exist. Unable to adjust win .mak files&& goto :eof
19
20setlocal enableextensions enabledelayedexpansion
21set httpdfolder=%1
22
23:: http://stackoverflow.com/questions/4419868/what-is-the-current-directory-in-a-batch-file
24pushd "%CD%"
25cd /d "%~dp0"
26
27:: Use sed to regex search and replace text files
28:: http://stackoverflow.com/questions/1115508/batch-find-and-edit-lines-in-txt-file
29:: (Instead of sed can also use FindRepl.bat from http://www.dostips.com/forum/viewtopic.php?t=4697)
30:: First add SED to PATH:
31set PATH=..\..\..\bin\windows;%PATH%
32
33:: Incrementing http://stackoverflow.com/questions/21697199/how-to-increment-variable-under-dos
34:: http://stackoverflow.com/questions/2913231/how-do-i-increment-a-dos-variable-in-a-for-f-loop
35:: http://stackoverflow.com/questions/17605767/create-list-or-arrays-in-windows-batch
[31425]36rem set counter=0
[31421]37
38:: http://stackoverflow.com/questions/2951063/windows-bat-file-how-to-recursively-list-all-files-of-type-mp3
39:: "This batch file demonstrates how to extract elements of a filename from the variable in a for loop.
40:: Save this as listfiles.bat, then run "listfiles some\folder *.mp3".
41:: I set up the file finding as a subroutine in the batch file so you can insert it into your own scripts."
42
43call :rsr-files %httpdfolder% *.mak
44
45popd
46endlocal
[31422]47
[31421]48goto :eof
49
50:: ************************ SUBROUTINES **********************************************
51
[31425]52:: A win mak file may make references to tempfile.bat in various lines of the makefile. The different
53:: references could end up clashing with each other when they're generated on the file system by
54:: that .mak file, leading to race conditions. To avoid this, within each win32.mak file, ensure
55:: unique tempfile .bat files are generated:
56:: For each win32.mak file, change each line of reference to tempfile.bat to a unique tempfile.bat
57:: by renaming the references in that makefile line to tempfile<number>.bat. Note: change each
58:: LINE to refer consistently to a unique tempfile .bat, don't make each reference in a line
59:: refer to a different tempfile.bat.
60:: Further, change any occurrence of /MD to /MT in each .mak file too.
[31421]61:: To check this script has worked, check httpd-2.2.11/modules/ssl/mod_ssl.mak to make sure
62:: occurrences of "tempfile.bat" have a number suffix before the extension and that there's
63:: no occurrence of /MD (or /MDd) only of /MT (and /MTd).
64:: See https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx for /MD, /MDd, /MT, /MTd
65
66:rsr-files
67 set PATHS=
68 set NAMES=
69 for /r "%~1" %%P in ("%~2") do (
70
[31425]71 rem set /a "counter +=1"
[31421]72 rem echo counter: !counter!
73
74 set filename=%%~fP
[31425]75 echo file: Modifying win32.mak file !filename! to refer to unique tempfile .bat files to avoid race conditions.
[31421]76
[31425]77 rem echo Writing tempfile!counter! into
78 rem echo file: !filename!
[31421]79
[31425]80 rem copy "!filename!" "!filename!.tmp"
81 rem sed "s@tempfile[0-9]*\.bat@tempfile!counter!.bat@g" "!filename!.tmp" > "!filename!"
82 rem del "!filename!.tmp"
83
84 rem copy "!filename!" "!filename!.tmp"
85 rem sed "s@/MD@/MT@g" "!filename!.tmp" > "!filename!"
86 rem del "!filename!.tmp"
[31421]87
[31425]88 rem http://stackoverflow.com/questions/4462954/sed-increment-number
89 rem https://www.gnu.org/software/gawk/manual/gawk.html see section An Example with Two Rules
[31421]90 copy "!filename!" "!filename!.tmp"
[31425]91 awk -f mod_winmak_file.awk "!filename!.tmp" > "!filename!"
[31421]92 del "!filename!.tmp"
93
94 )
95goto :eof
96
97:: copy httpd-2.2.11\libhttpd.mak httpd-2.2.11\libhttpd.mak.tmp
98
99:: Use batch cmd 'type' to view files without file locking and for viewing locked files: http://www.robvanderwoude.com/type.php
100rem type httpd-2.2.11\libhttpd.mak.tmp | sed "s/tempfile/tempfile1/g" > httpd-2.2.11\libhttpd.mak
101:: Alternatively:
102rem sed "s/tempfile/tempfile%counter%/g" httpd-2.2.11\libhttpd.mak.tmp > httpd-2.2.11\libhttpd.mak
103
104:: del httpd-2.2.11\libhttpd.mak.tmp
Note: See TracBrowser for help on using the repository browser.