/
patchcmake.c
122 lines (81 loc) · 3.03 KB
/
patchcmake.c
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
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
//==============================================================================
// CMake file patcher for Qt package
//==============================================================================
#include <stdio.h>
#include <string.h>
//==============================================================================
FILE *in;
FILE *out;
char outFileName[FILENAME_MAX];
//==============================================================================
int cleanUp()
{
if (in)
fclose(in);
if (out) {
fclose(out);
remove(outFileName);
}
return 0;
}
//==============================================================================
int error(char *pErrorMessage)
{
// Output the given error message and free/close a few things
fprintf(stderr, "%s", pErrorMessage);
cleanUp();
return 1;
}
//==============================================================================
int main(int pArgC, char *pArgV[])
{
#define LINE_MAX 1024
char line[LINE_MAX];
char oldLine[LINE_MAX];
char newLine[LINE_MAX];
// Make sure that a file name has been provided
if (pArgC != 3) {
printf("Usage: %s <filename> <qtpackagename>\n", pArgV[0]);
return 1;
}
// Open the file
in = fopen(pArgV[1], "r");
out = 0;
if (!in)
return error("The file could not be opened.\n");
// Open a temporary file
sprintf(outFileName, "%s.tmp", pArgV[1]);
out = fopen(outFileName, "w");
if (!out)
return error("The temporary file could not be created.\n");
// Process each line of the file and output it to our temporary file
sprintf(oldLine, "get_filename_component(_qt5%s_install_prefix \"${CMAKE_CURRENT_LIST_DIR}/../../../\" ABSOLUTE)\n", pArgV[2]);
sprintf(newLine, "set(_qt5%s_install_prefix ${CMAKE_SOURCE_DIR}/src/3rdparty/Qt%s/ext)\n", pArgV[2], pArgV[2]);
while (fgets(line, LINE_MAX, in)) {
if (!strcmp(line, oldLine))
fprintf(out, newLine);
else
fprintf(out, "%s", line);
}
fclose(in);
fclose(out);
in = out = 0;
remove(pArgV[1]);
if (rename(outFileName, pArgV[1]) == -1)
return error("The file could not be patched.\n");
// We are all done
return 0;
}