forked from cairoD/cairoD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.d
More file actions
254 lines (227 loc) · 8.14 KB
/
Copy pathconfigure.d
File metadata and controls
254 lines (227 loc) · 8.14 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import std.conv, std.file, std.string, std.path, std.process, std.stdio;
struct CairoConfiguration
{
// if true, use minimal default set as defined in cairo.c.config
bool CAIROD_CONFIGURE_FAILED = false;
bool CAIRO_HAS_PS_SURFACE = false;
bool CAIRO_HAS_PDF_SURFACE = false;
bool CAIRO_HAS_SVG_SURFACE = false;
bool CAIRO_HAS_WIN32_SURFACE = false;
bool CAIRO_HAS_WIN32_FONT = false;
bool CAIRO_HAS_FT_FONT = false;
bool CAIRO_HAS_XCB_SURFACE = false;
bool CAIRO_HAS_DIRECTFB_SURFACE = false;
bool CAIRO_HAS_XLIB_SURFACE = false;
bool CAIRO_HAS_PNG_FUNCTIONS = false;
}
void main(string[] args)
{
writeDoubleLine();
writeln("=> Configuring cairoD");
writeln("=> Environment variables:");
writeln(" CC C compiler used to detect cairo features");
writeln(" CAIROD_FEATURES Manually overwrite feature flags");
writeln();
CairoConfiguration conf;
// First check manual configuration
string features = environment.get("CAIROD_FEATURES");
if (features !is null)
{
foreach (entry; features.split(" "))
{
switch (entry)
{
case "CAIRO_HAS_PS_SURFACE":
conf.CAIRO_HAS_PS_SURFACE = true;
break;
case "CAIRO_HAS_PDF_SURFACE":
conf.CAIRO_HAS_PDF_SURFACE = true;
break;
case "CAIRO_HAS_SVG_SURFACE":
conf.CAIRO_HAS_SVG_SURFACE = true;
break;
case "CAIRO_HAS_WIN32_SURFACE":
conf.CAIRO_HAS_WIN32_SURFACE = true;
break;
case "CAIRO_HAS_WIN32_FONT":
conf.CAIRO_HAS_WIN32_FONT = true;
break;
case "CAIRO_HAS_FT_FONT":
conf.CAIRO_HAS_FT_FONT = true;
break;
case "CAIRO_HAS_XCB_SURFACE":
conf.CAIRO_HAS_XCB_SURFACE = true;
break;
case "CAIRO_HAS_DIRECTFB_SURFACE":
conf.CAIRO_HAS_DIRECTFB_SURFACE = true;
break;
case "CAIRO_HAS_XLIB_SURFACE":
conf.CAIRO_HAS_XLIB_SURFACE = true;
break;
case "CAIRO_HAS_PNG_FUNCTIONS":
conf.CAIRO_HAS_PNG_FUNCTIONS = true;
break;
default:
writefln("Error: Unknown feature '%s'!", entry);
return;
}
}
}
else
{
try
conf = detectFeatures();
catch (Exception e)
{
conf.CAIROD_CONFIGURE_FAILED = true;
}
writeln();
}
string pkgDir = ".";
if (args.length > 1)
pkgDir = args[1];
writeConfiguration(conf, pkgDir);
writeln("=> Configuration:");
if (conf.CAIROD_CONFIGURE_FAILED)
{
writeln(" Using minimal native configuration");
}
else
{
string[] surfaces, fonts;
if (conf.CAIRO_HAS_PS_SURFACE)
surfaces ~= "PostScript";
if (conf.CAIRO_HAS_PDF_SURFACE)
surfaces ~= "PDF";
if (conf.CAIRO_HAS_SVG_SURFACE)
surfaces ~= "SVG";
if (conf.CAIRO_HAS_WIN32_SURFACE)
surfaces ~= "Win32";
if (conf.CAIRO_HAS_XCB_SURFACE)
surfaces ~= "XCB";
if (conf.CAIRO_HAS_DIRECTFB_SURFACE)
surfaces ~= "DirectFB";
if (conf.CAIRO_HAS_XLIB_SURFACE)
surfaces ~= "xlib";
if (conf.CAIRO_HAS_WIN32_FONT)
fonts ~= "Win32";
if (conf.CAIRO_HAS_FT_FONT)
fonts ~= "FreeType";
writefln(" PNG support: %s", conf.CAIRO_HAS_PNG_FUNCTIONS);
writefln(" Surfaces: %s", surfaces.join(" "));
writefln(" Font backends: %s", fonts.join(" "));
}
writeDoubleLine();
}
CairoConfiguration detectFeatures()
{
writeln("=> Trying to detect features supported by cairo library");
string compiler = environment.get("CC", "gcc");
writeResult(" Searching for C compiler name...", compiler);
auto cairoOK = compiler.tryCompile("#include <cairo/cairo.h>");
writeResult(" Whether C compiler can compile cairo programs...", to!string(cairoOK));
if (!cairoOK)
{
writeln("=> Can not autodetect features! Using minimal configuration.");
writeln(" Use CAIROD_FEATURES environment variable to specify features manually.");
throw new Exception("error");
}
CairoConfiguration conf;
conf.CAIRO_HAS_PS_SURFACE = compiler.testFeature("CAIRO_HAS_PS_SURFACE");
conf.CAIRO_HAS_PDF_SURFACE = compiler.testFeature("CAIRO_HAS_PDF_SURFACE");
conf.CAIRO_HAS_SVG_SURFACE = compiler.testFeature("CAIRO_HAS_SVG_SURFACE");
conf.CAIRO_HAS_WIN32_SURFACE = compiler.testFeature("CAIRO_HAS_WIN32_SURFACE");
conf.CAIRO_HAS_WIN32_FONT = compiler.testFeature("CAIRO_HAS_WIN32_FONT");
conf.CAIRO_HAS_FT_FONT = compiler.testFeature("CAIRO_HAS_FT_FONT");
conf.CAIRO_HAS_XCB_SURFACE = compiler.testFeature("CAIRO_HAS_XCB_SURFACE");
conf.CAIRO_HAS_DIRECTFB_SURFACE = compiler.testFeature("CAIRO_HAS_DIRECTFB_SURFACE");
conf.CAIRO_HAS_XLIB_SURFACE = compiler.testFeature("CAIRO_HAS_XLIB_SURFACE");
conf.CAIRO_HAS_PNG_FUNCTIONS = compiler.testFeature("CAIRO_HAS_PNG_FUNCTIONS");
return conf;
}
void writeConfiguration(CairoConfiguration conf, string pkgDir)
{
string basePath = pkgDir.buildPath("src", "cairo", "c", "config.d");
auto basePart = File(basePath ~ ".part", "r");
auto outFile = File(basePath, "w");
foreach (line; basePart.byLine())
outFile.writeln(line);
if (conf.CAIROD_CONFIGURE_FAILED)
return;
outFile.writeln("version(D_Ddoc) {}");
outFile.writeln("else");
outFile.writeln("{");
outFile.writefln(" enum bool CAIRO_HAS_PNG_FUNCTIONS = %s;", conf.CAIRO_HAS_PNG_FUNCTIONS);
outFile.writefln(" enum bool CAIRO_HAS_PS_SURFACE = %s;", conf.CAIRO_HAS_PS_SURFACE);
outFile.writefln(" enum bool CAIRO_HAS_PDF_SURFACE = %s;", conf.CAIRO_HAS_PDF_SURFACE);
outFile.writefln(" enum bool CAIRO_HAS_SVG_SURFACE = %s;", conf.CAIRO_HAS_SVG_SURFACE);
outFile.writefln(" enum bool CAIRO_HAS_WIN32_SURFACE = %s;", conf.CAIRO_HAS_WIN32_SURFACE);
outFile.writefln(" enum bool CAIRO_HAS_WIN32_FONT = %s;", conf.CAIRO_HAS_WIN32_FONT);
outFile.writefln(" enum bool CAIRO_HAS_FT_FONT = %s;", conf.CAIRO_HAS_FT_FONT);
outFile.writefln(" enum bool CAIRO_HAS_XCB_SURFACE = %s;", conf.CAIRO_HAS_XCB_SURFACE);
outFile.writefln(" enum bool CAIRO_HAS_DIRECTFB_SURFACE = %s;",
conf.CAIRO_HAS_DIRECTFB_SURFACE);
outFile.writefln(" enum bool CAIRO_HAS_XLIB_SURFACE = %s;", conf.CAIRO_HAS_XLIB_SURFACE);
outFile.writeln(" enum bool CAIROD_IS_CONFIGURED = true;");
outFile.writeln("}");
}
bool tryCompile(string compiler, string program)
{
auto tempPath = tempDir().buildPath("cairod_test.c");
scope (exit)
{
if (tempPath.exists)
remove(tempPath);
}
std.file.write(tempPath, program);
try
{
auto result = execute([compiler, "-c", tempPath]);
return result.status == 0;
}
catch (Exception e)
{
return false;
}
}
bool compileTestFeature(string compiler, string feature)
{
import std.ascii;
string program = "#include <cairo/cairo.h>" ~ newline ~ newline;
program ~= "#ifndef " ~ feature ~ newline;
program ~= " #error \"Feature not available\"" ~ newline;
program ~= "#endif" ~ newline;
return tryCompile(compiler, program);
}
bool testFeature(string compiler, string feature)
{
auto result = compiler.compileTestFeature(feature);
writeResult(" For " ~ feature ~ "...", to!string(result));
return result;
}
/*
* Console output functions
*/
enum lineLength = 80;
enum minResultLength = 10;
/**
* Format one output line
*/
void writeResult(string msg, string result)
{
if (msg.length >= lineLength - minResultLength)
{
writefln("%s %s", msg, result);
}
else
{
auto remaining = lineLength - msg.length - 1; //One space
writefln("%s %*.*s", msg, remaining, remaining, result);
}
}
void writeDoubleLine()
{
for (size_t i = 0; i < lineLength; i++)
write("=");
writeln();
}