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)
|
---|
5 | :: This script performs 2 steps:
|
---|
6 | :: replace all occurrences of "tempfile" in .mak files within httpd-2.2.11 with "tempfile$counter"
|
---|
7 | :: replace all occurrences of "/MD" in .mak files within httpd-2.2.11 with "/MT"
|
---|
8 |
|
---|
9 | :: http://www.theverge.com/2016/3/30/11331014/microsoft-windows-linux-ubuntu-bash
|
---|
10 | :: "Microsoft is adding the Linux command line to Windows 10" Mar 30, 2016
|
---|
11 |
|
---|
12 |
|
---|
13 | @echo off
|
---|
14 |
|
---|
15 | :: pass in the httpd folder to this script, e.g. httpd-2.2.11
|
---|
16 | if [%1]==[] echo ERROR: Extracted httpd folder name not specified. Unable to adjust win .mak files&& goto :eof
|
---|
17 | if not exist "%~dp0%1" echo ERROR: Extracted httpd folder %~dp0%1 doesn't exist. Unable to adjust win .mak files&& goto :eof
|
---|
18 |
|
---|
19 | setlocal enableextensions enabledelayedexpansion
|
---|
20 | set httpdfolder=%1
|
---|
21 |
|
---|
22 | :: http://stackoverflow.com/questions/4419868/what-is-the-current-directory-in-a-batch-file
|
---|
23 | pushd "%CD%"
|
---|
24 | cd /d "%~dp0"
|
---|
25 |
|
---|
26 | :: Use sed to regex search and replace text files
|
---|
27 | :: http://stackoverflow.com/questions/1115508/batch-find-and-edit-lines-in-txt-file
|
---|
28 | :: (Instead of sed can also use FindRepl.bat from http://www.dostips.com/forum/viewtopic.php?t=4697)
|
---|
29 | :: First add SED to PATH:
|
---|
30 | set PATH=..\..\..\bin\windows;%PATH%
|
---|
31 |
|
---|
32 | :: Incrementing http://stackoverflow.com/questions/21697199/how-to-increment-variable-under-dos
|
---|
33 | :: http://stackoverflow.com/questions/2913231/how-do-i-increment-a-dos-variable-in-a-for-f-loop
|
---|
34 | :: http://stackoverflow.com/questions/17605767/create-list-or-arrays-in-windows-batch
|
---|
35 | set counter=0
|
---|
36 |
|
---|
37 | :: http://stackoverflow.com/questions/2951063/windows-bat-file-how-to-recursively-list-all-files-of-type-mp3
|
---|
38 | :: "This batch file demonstrates how to extract elements of a filename from the variable in a for loop.
|
---|
39 | :: Save this as listfiles.bat, then run "listfiles some\folder *.mp3".
|
---|
40 | :: I set up the file finding as a subroutine in the batch file so you can insert it into your own scripts."
|
---|
41 |
|
---|
42 | call :rsr-files %httpdfolder% *.mak
|
---|
43 | ::echo PATHS: %PATHS%
|
---|
44 | ::echo NAMES: %NAMES%
|
---|
45 |
|
---|
46 | popd
|
---|
47 | endlocal
|
---|
48 |
|
---|
49 | goto :eof
|
---|
50 |
|
---|
51 | :: ************************ SUBROUTINES **********************************************
|
---|
52 |
|
---|
53 | :: append counter to tempfile.bat references in the current .mak file of loop
|
---|
54 | :: And change any occurrence of /MD to /MT in each .mak file too
|
---|
55 | :: Digit wildcard doesn't work for me in sed regex here, and although the any char wildcard
|
---|
56 | :: works it may be too greedy. Fortunately, character classes for digits works.
|
---|
57 | :: To check this script has worked, check httpd-2.2.11/modules/ssl/mod_ssl.mak to make sure
|
---|
58 | :: occurrences of "tempfile.bat" have a number suffix before the extension and that there's
|
---|
59 | :: no occurrence of /MD (or /MDd) only of /MT (and /MTd).
|
---|
60 | :: See https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx for /MD, /MDd, /MT, /MTd
|
---|
61 |
|
---|
62 | :rsr-files
|
---|
63 | set PATHS=
|
---|
64 | set NAMES=
|
---|
65 | for /r "%~1" %%P in ("%~2") do (
|
---|
66 | rem set PATHS=!PATHS! "%%~fP"
|
---|
67 | rem set NAMES=!NAMES! "%%~nP%%~xP"
|
---|
68 |
|
---|
69 |
|
---|
70 | set /a "counter +=1"
|
---|
71 | rem echo counter: !counter!
|
---|
72 |
|
---|
73 | set filename=%%~fP
|
---|
74 |
|
---|
75 | echo Writing tempfile!counter! into
|
---|
76 | echo file: !filename!
|
---|
77 |
|
---|
78 |
|
---|
79 | copy "!filename!" "!filename!.tmp"
|
---|
80 | sed "s@tempfile[0-9]*\.bat@tempfile!counter!.bat@g" "!filename!.tmp" > "!filename!"
|
---|
81 | del "!filename!.tmp"
|
---|
82 |
|
---|
83 | copy "!filename!" "!filename!.tmp"
|
---|
84 | sed "s@/MD@/MT@g" "!filename!.tmp" > "!filename!"
|
---|
85 | del "!filename!.tmp"
|
---|
86 |
|
---|
87 | )
|
---|
88 | goto :eof
|
---|
89 |
|
---|
90 | :: copy httpd-2.2.11\libhttpd.mak httpd-2.2.11\libhttpd.mak.tmp
|
---|
91 |
|
---|
92 | :: Use batch cmd 'type' to view files without file locking and for viewing locked files: http://www.robvanderwoude.com/type.php
|
---|
93 | rem type httpd-2.2.11\libhttpd.mak.tmp | sed "s/tempfile/tempfile1/g" > httpd-2.2.11\libhttpd.mak
|
---|
94 | :: Alternatively:
|
---|
95 | rem sed "s/tempfile/tempfile%counter%/g" httpd-2.2.11\libhttpd.mak.tmp > httpd-2.2.11\libhttpd.mak
|
---|
96 |
|
---|
97 | :: del httpd-2.2.11\libhttpd.mak.tmp
|
---|