aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Targets
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Targets')
-rw-r--r--Prebuild/src/Core/Targets/.NAntTarget.cs.swpbin0 -> 49152 bytes
-rw-r--r--Prebuild/src/Core/Targets/.svn/all-wcprops101
-rw-r--r--Prebuild/src/Core/Targets/.svn/dir-prop-base5
-rw-r--r--Prebuild/src/Core/Targets/.svn/entries572
-rw-r--r--Prebuild/src/Core/Targets/.svn/prop-base/DebugTarget.cs.svn-base9
-rw-r--r--Prebuild/src/Core/Targets/.svn/prop-base/MakefileTarget.cs.svn-base9
-rw-r--r--Prebuild/src/Core/Targets/.svn/prop-base/MonoDevelopTarget.cs.svn-base9
-rw-r--r--Prebuild/src/Core/Targets/.svn/prop-base/NAntTarget.cs.svn-base9
-rw-r--r--Prebuild/src/Core/Targets/.svn/prop-base/SharpDevelopTarget.cs.svn-base9
-rw-r--r--Prebuild/src/Core/Targets/.svn/prop-base/VS2002Target.cs.svn-base9
-rw-r--r--Prebuild/src/Core/Targets/.svn/prop-base/VS2003Target.cs.svn-base9
-rw-r--r--Prebuild/src/Core/Targets/.svn/prop-base/VS2005Target.cs.svn-base9
-rw-r--r--Prebuild/src/Core/Targets/.svn/prop-base/XcodeTarget.cs.svn-base9
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/AutotoolsTarget.cs.svn-base1070
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/DebugTarget.cs.svn-base102
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/MakefileTarget.cs.svn-base469
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/MonoDevelopTarget.cs.svn-base515
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/NAntTarget.cs.svn-base776
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/SharpDevelop2Target.cs.svn-base82
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/SharpDevelopTarget.cs.svn-base425
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/ToolInfo.cs.svn-base197
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/VS2002Target.cs.svn-base87
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/VS2003Target.cs.svn-base593
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/VS2005Target.cs.svn-base147
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/VS2008Target.cs.svn-base127
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/VS2010Target.cs.svn-base138
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/VSGenericTarget.cs.svn-base922
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/VSVersion.cs.svn-base54
-rw-r--r--Prebuild/src/Core/Targets/.svn/text-base/XcodeTarget.cs.svn-base594
-rw-r--r--Prebuild/src/Core/Targets/AutotoolsTarget.cs1070
-rw-r--r--Prebuild/src/Core/Targets/DebugTarget.cs102
-rw-r--r--Prebuild/src/Core/Targets/MakefileTarget.cs469
-rw-r--r--Prebuild/src/Core/Targets/MonoDevelopTarget.cs515
-rw-r--r--Prebuild/src/Core/Targets/NAntTarget.cs792
-rw-r--r--Prebuild/src/Core/Targets/SharpDevelop2Target.cs82
-rw-r--r--Prebuild/src/Core/Targets/SharpDevelopTarget.cs425
-rw-r--r--Prebuild/src/Core/Targets/ToolInfo.cs197
-rw-r--r--Prebuild/src/Core/Targets/VS2002Target.cs87
-rw-r--r--Prebuild/src/Core/Targets/VS2003Target.cs593
-rw-r--r--Prebuild/src/Core/Targets/VS2005Target.cs147
-rw-r--r--Prebuild/src/Core/Targets/VS2008Target.cs127
-rw-r--r--Prebuild/src/Core/Targets/VS2010Target.cs138
-rw-r--r--Prebuild/src/Core/Targets/VSGenericTarget.cs922
-rw-r--r--Prebuild/src/Core/Targets/VSVersion.cs54
-rw-r--r--Prebuild/src/Core/Targets/XcodeTarget.cs594
45 files changed, 13371 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Targets/.NAntTarget.cs.swp b/Prebuild/src/Core/Targets/.NAntTarget.cs.swp
new file mode 100644
index 0000000..afec61c
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.NAntTarget.cs.swp
Binary files differ
diff --git a/Prebuild/src/Core/Targets/.svn/all-wcprops b/Prebuild/src/Core/Targets/.svn/all-wcprops
new file mode 100644
index 0000000..91d6694
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/all-wcprops
@@ -0,0 +1,101 @@
1K 25
2svn:wc:ra_dav:version-url
3V 58
4/svnroot/dnpb/!svn/ver/323/trunk/Prebuild/src/Core/Targets
5END
6MakefileTarget.cs
7K 25
8svn:wc:ra_dav:version-url
9V 76
10/svnroot/dnpb/!svn/ver/307/trunk/Prebuild/src/Core/Targets/MakefileTarget.cs
11END
12SharpDevelop2Target.cs
13K 25
14svn:wc:ra_dav:version-url
15V 81
16/svnroot/dnpb/!svn/ver/295/trunk/Prebuild/src/Core/Targets/SharpDevelop2Target.cs
17END
18ToolInfo.cs
19K 25
20svn:wc:ra_dav:version-url
21V 70
22/svnroot/dnpb/!svn/ver/290/trunk/Prebuild/src/Core/Targets/ToolInfo.cs
23END
24VSGenericTarget.cs
25K 25
26svn:wc:ra_dav:version-url
27V 77
28/svnroot/dnpb/!svn/ver/316/trunk/Prebuild/src/Core/Targets/VSGenericTarget.cs
29END
30DebugTarget.cs
31K 25
32svn:wc:ra_dav:version-url
33V 73
34/svnroot/dnpb/!svn/ver/164/trunk/Prebuild/src/Core/Targets/DebugTarget.cs
35END
36VSVersion.cs
37K 25
38svn:wc:ra_dav:version-url
39V 71
40/svnroot/dnpb/!svn/ver/316/trunk/Prebuild/src/Core/Targets/VSVersion.cs
41END
42MonoDevelopTarget.cs
43K 25
44svn:wc:ra_dav:version-url
45V 79
46/svnroot/dnpb/!svn/ver/307/trunk/Prebuild/src/Core/Targets/MonoDevelopTarget.cs
47END
48AutotoolsTarget.cs
49K 25
50svn:wc:ra_dav:version-url
51V 77
52/svnroot/dnpb/!svn/ver/298/trunk/Prebuild/src/Core/Targets/AutotoolsTarget.cs
53END
54VS2010Target.cs
55K 25
56svn:wc:ra_dav:version-url
57V 74
58/svnroot/dnpb/!svn/ver/317/trunk/Prebuild/src/Core/Targets/VS2010Target.cs
59END
60VS2002Target.cs
61K 25
62svn:wc:ra_dav:version-url
63V 74
64/svnroot/dnpb/!svn/ver/295/trunk/Prebuild/src/Core/Targets/VS2002Target.cs
65END
66SharpDevelopTarget.cs
67K 25
68svn:wc:ra_dav:version-url
69V 80
70/svnroot/dnpb/!svn/ver/307/trunk/Prebuild/src/Core/Targets/SharpDevelopTarget.cs
71END
72VS2003Target.cs
73K 25
74svn:wc:ra_dav:version-url
75V 74
76/svnroot/dnpb/!svn/ver/307/trunk/Prebuild/src/Core/Targets/VS2003Target.cs
77END
78VS2005Target.cs
79K 25
80svn:wc:ra_dav:version-url
81V 74
82/svnroot/dnpb/!svn/ver/307/trunk/Prebuild/src/Core/Targets/VS2005Target.cs
83END
84NAntTarget.cs
85K 25
86svn:wc:ra_dav:version-url
87V 72
88/svnroot/dnpb/!svn/ver/323/trunk/Prebuild/src/Core/Targets/NAntTarget.cs
89END
90XcodeTarget.cs
91K 25
92svn:wc:ra_dav:version-url
93V 73
94/svnroot/dnpb/!svn/ver/307/trunk/Prebuild/src/Core/Targets/XcodeTarget.cs
95END
96VS2008Target.cs
97K 25
98svn:wc:ra_dav:version-url
99V 74
100/svnroot/dnpb/!svn/ver/307/trunk/Prebuild/src/Core/Targets/VS2008Target.cs
101END
diff --git a/Prebuild/src/Core/Targets/.svn/dir-prop-base b/Prebuild/src/Core/Targets/.svn/dir-prop-base
new file mode 100644
index 0000000..a1989a0
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/dir-prop-base
@@ -0,0 +1,5 @@
1K 10
2svn:ignore
3V 5
4*.swp
5END
diff --git a/Prebuild/src/Core/Targets/.svn/entries b/Prebuild/src/Core/Targets/.svn/entries
new file mode 100644
index 0000000..c6daa49
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/entries
@@ -0,0 +1,572 @@
110
2
3dir
4323
5https://dnpb.svn.sourceforge.net/svnroot/dnpb/trunk/Prebuild/src/Core/Targets
6https://dnpb.svn.sourceforge.net/svnroot/dnpb
7
8
9
102010-09-10T17:51:36.189738Z
11323
12jhurliman
13has-props
14
15
16
17
18
19
20
21
22
23
24
25
26
273355ff64-970d-0410-bbe8-d0fbd18be4fb
28
29MakefileTarget.cs
30file
31
32
33
34
352010-09-10T22:51:44.000000Z
369f1538adc7e579b57d104dc7f313946b
372009-04-15T01:28:16.827957Z
38307
39kunnis
40has-props
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
6119043
62
63SharpDevelop2Target.cs
64file
65
66
67
68
692010-09-10T22:51:44.000000Z
70f6e8e9d8f335a5a264babb4a8f05a2a5
712009-02-19T06:47:52.218324Z
72295
73kunnis
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
952442
96
97ToolInfo.cs
98file
99
100
101
102
1032010-09-10T22:51:44.000000Z
10420e6cf8e0ad0b0744b6189534bfd049a
1052009-02-18T05:47:43.979044Z
106290
107kunnis
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
1294315
130
131VSGenericTarget.cs
132file
133
134
135
136
1372010-09-10T22:51:44.000000Z
1386956b93fe770e1f5786cc44872c31d06
1392010-05-08T05:43:01.449559Z
140316
141jhurliman
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
16334542
164
165DebugTarget.cs
166file
167
168
169
170
1712010-09-10T22:51:44.000000Z
1727346beba16e30e642f272e7bcf3924bb
1732006-09-20T07:42:51.680045Z
174164
175jendave
176has-props
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
1972703
198
199VSVersion.cs
200file
201
202
203
204
2052010-09-10T22:51:44.000000Z
20678ab7ae5edbe12dfb34c9fbd3dba9c23
2072010-05-08T05:43:01.449559Z
208316
209jhurliman
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
2311950
232
233MonoDevelopTarget.cs
234file
235
236
237
238
2392010-09-10T22:51:44.000000Z
240d8b264553d4c2d66a19f9610be56f4b4
2412009-04-15T01:28:16.827957Z
242307
243kunnis
244has-props
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
26515976
266
267AutotoolsTarget.cs
268file
269
270
271
272
2732010-09-10T22:51:44.000000Z
274bc5383cb56dd751ac946386a51852a77
2752009-02-20T02:15:45.530129Z
276298
277kunnis
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
29941145
300
301VS2010Target.cs
302file
303
304
305
306
3072010-09-10T22:51:44.000000Z
3087d9c7f130f06ead33e747f0920b989c4
3092010-05-09T07:39:45.137959Z
310317
311jhurliman
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
3332745
334
335VS2002Target.cs
336file
337
338
339
340
3412010-09-10T22:51:44.000000Z
342912769a89b935429b3801db96c467de7
3432009-02-19T06:47:52.218324Z
344295
345kunnis
346has-props
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
3672507
368
369SharpDevelopTarget.cs
370file
371
372
373
374
3752010-09-10T22:51:44.000000Z
376f9017c8dd94137dee4b673bee40c8e6e
3772009-04-15T01:28:16.827957Z
378307
379kunnis
380has-props
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
40112773
402
403VS2003Target.cs
404file
405
406
407
408
4092010-09-10T22:51:44.000000Z
410c8e60070e9d7343d50c297d3dff12ac4
4112009-04-15T01:28:16.827957Z
412307
413kunnis
414has-props
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
43518912
436
437VS2005Target.cs
438file
439
440
441
442
4432010-09-10T22:51:44.000000Z
444812092c2b5b068e087806088d80fe635
4452009-04-15T01:28:16.827957Z
446307
447kunnis
448has-props
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
4694291
470
471NAntTarget.cs
472file
473
474
475
476
4772010-09-10T22:51:44.000000Z
478b635fc47efdd3eed660017693b9073c4
4792010-09-10T17:51:36.189738Z
480323
481jhurliman
482has-props
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
50332065
504
505VS2008Target.cs
506file
507
508
509
510
5112010-09-10T22:51:44.000000Z
512154f10d6947ee7bf4d5caf10fad8c43d
5132009-04-15T01:28:16.827957Z
514307
515kunnis
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
5372514
538
539XcodeTarget.cs
540file
541
542
543
544
5452010-09-10T22:51:44.000000Z
5467ec0bbdd62020f03a725d8f99258769d
5472009-04-15T01:28:16.827957Z
548307
549kunnis
550has-props
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
57128408
572
diff --git a/Prebuild/src/Core/Targets/.svn/prop-base/DebugTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/prop-base/DebugTarget.cs.svn-base
new file mode 100644
index 0000000..7b57b30
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/prop-base/DebugTarget.cs.svn-base
@@ -0,0 +1,9 @@
1K 13
2svn:eol-style
3V 6
4native
5K 12
6svn:keywords
7V 23
8Author Date Id Revision
9END
diff --git a/Prebuild/src/Core/Targets/.svn/prop-base/MakefileTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/prop-base/MakefileTarget.cs.svn-base
new file mode 100644
index 0000000..05f6c06
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/prop-base/MakefileTarget.cs.svn-base
@@ -0,0 +1,9 @@
1K 13
2svn:eol-style
3V 6
4native
5K 13
6svn:mime-type
7V 13
8text/x-csharp
9END
diff --git a/Prebuild/src/Core/Targets/.svn/prop-base/MonoDevelopTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/prop-base/MonoDevelopTarget.cs.svn-base
new file mode 100644
index 0000000..7b57b30
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/prop-base/MonoDevelopTarget.cs.svn-base
@@ -0,0 +1,9 @@
1K 13
2svn:eol-style
3V 6
4native
5K 12
6svn:keywords
7V 23
8Author Date Id Revision
9END
diff --git a/Prebuild/src/Core/Targets/.svn/prop-base/NAntTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/prop-base/NAntTarget.cs.svn-base
new file mode 100644
index 0000000..7b57b30
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/prop-base/NAntTarget.cs.svn-base
@@ -0,0 +1,9 @@
1K 13
2svn:eol-style
3V 6
4native
5K 12
6svn:keywords
7V 23
8Author Date Id Revision
9END
diff --git a/Prebuild/src/Core/Targets/.svn/prop-base/SharpDevelopTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/prop-base/SharpDevelopTarget.cs.svn-base
new file mode 100644
index 0000000..7b57b30
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/prop-base/SharpDevelopTarget.cs.svn-base
@@ -0,0 +1,9 @@
1K 13
2svn:eol-style
3V 6
4native
5K 12
6svn:keywords
7V 23
8Author Date Id Revision
9END
diff --git a/Prebuild/src/Core/Targets/.svn/prop-base/VS2002Target.cs.svn-base b/Prebuild/src/Core/Targets/.svn/prop-base/VS2002Target.cs.svn-base
new file mode 100644
index 0000000..7b57b30
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/prop-base/VS2002Target.cs.svn-base
@@ -0,0 +1,9 @@
1K 13
2svn:eol-style
3V 6
4native
5K 12
6svn:keywords
7V 23
8Author Date Id Revision
9END
diff --git a/Prebuild/src/Core/Targets/.svn/prop-base/VS2003Target.cs.svn-base b/Prebuild/src/Core/Targets/.svn/prop-base/VS2003Target.cs.svn-base
new file mode 100644
index 0000000..7b57b30
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/prop-base/VS2003Target.cs.svn-base
@@ -0,0 +1,9 @@
1K 13
2svn:eol-style
3V 6
4native
5K 12
6svn:keywords
7V 23
8Author Date Id Revision
9END
diff --git a/Prebuild/src/Core/Targets/.svn/prop-base/VS2005Target.cs.svn-base b/Prebuild/src/Core/Targets/.svn/prop-base/VS2005Target.cs.svn-base
new file mode 100644
index 0000000..7b57b30
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/prop-base/VS2005Target.cs.svn-base
@@ -0,0 +1,9 @@
1K 13
2svn:eol-style
3V 6
4native
5K 12
6svn:keywords
7V 23
8Author Date Id Revision
9END
diff --git a/Prebuild/src/Core/Targets/.svn/prop-base/XcodeTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/prop-base/XcodeTarget.cs.svn-base
new file mode 100644
index 0000000..05f6c06
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/prop-base/XcodeTarget.cs.svn-base
@@ -0,0 +1,9 @@
1K 13
2svn:eol-style
3V 6
4native
5K 13
6svn:mime-type
7V 13
8text/x-csharp
9END
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/AutotoolsTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/AutotoolsTarget.cs.svn-base
new file mode 100644
index 0000000..e46b5a5
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/AutotoolsTarget.cs.svn-base
@@ -0,0 +1,1070 @@
1#region BSD License
2/*
3
4Copyright (c) 2004 - 2008
5Matthew Holmes (matthew@wildfiregames.com),
6Dan Moorehead (dan05a@gmail.com),
7Dave Hudson (jendave@yahoo.com),
8C.J. Adams-Collier (cjac@colliertech.org),
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are
12met:
13
14* Redistributions of source code must retain the above copyright
15notice, this list of conditions and the following disclaimer.
16
17* Redistributions in binary form must reproduce the above copyright
18notice, this list of conditions and the following disclaimer in the
19documentation and/or other materials provided with the distribution.
20
21* The name of the author may not be used to endorse or promote
22products derived from this software without specific prior written
23permission.
24
25THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
29INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35POSSIBILITY OF SUCH DAMAGE.
36
37*/
38#endregion
39
40#region MIT X11 license
41
42/*
43 Portions of this file authored by Lluis Sanchez Gual
44
45 Copyright (C) 2006 Novell, Inc (http://www.novell.com)
46
47 Permission is hereby granted, free of charge, to any person obtaining
48 a copy of this software and associated documentation files (the
49 "Software"), to deal in the Software without restriction, including
50 without limitation the rights to use, copy, modify, merge, publish,
51 distribute, sublicense, and/or sell copies of the Software, and to
52 permit persons to whom the Software is furnished to do so, subject to
53 the following conditions:
54
55 The above copyright notice and this permission notice shall be
56 included in all copies or substantial portions of the Software.
57
58 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
59 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
61 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
62 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
63 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
64 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65 */
66
67#endregion
68using System;
69using System.Collections.Generic;
70using System.IO;
71using System.Reflection;
72using System.Text;
73using System.Text.RegularExpressions;
74using System.Xml;
75using System.Xml.Xsl;
76using System.Net;
77using System.Diagnostics;
78
79using Prebuild.Core.Attributes;
80using Prebuild.Core.Interfaces;
81using Prebuild.Core.Nodes;
82using Prebuild.Core.Utilities;
83
84namespace Prebuild.Core.Targets
85{
86 public enum ClrVersion
87 {
88 Default,
89 Net_1_1,
90 Net_2_0
91 }
92
93 public class SystemPackage
94 {
95 string name;
96 string version;
97 string description;
98 string[] assemblies;
99 bool isInternal;
100 ClrVersion targetVersion;
101
102 public void Initialize(string name,
103 string version,
104 string description,
105 string[] assemblies,
106 ClrVersion targetVersion,
107 bool isInternal)
108 {
109 this.isInternal = isInternal;
110 this.name = name;
111 this.version = version;
112 this.assemblies = assemblies;
113 this.description = description;
114 this.targetVersion = targetVersion;
115 }
116
117 public string Name
118 {
119 get { return name; }
120 }
121
122 public string Version
123 {
124 get { return version; }
125 }
126
127 public string Description
128 {
129 get { return description; }
130 }
131
132 public ClrVersion TargetVersion
133 {
134 get { return targetVersion; }
135 }
136
137 // The package is part of the mono SDK
138 public bool IsCorePackage
139 {
140 get { return name == "mono"; }
141 }
142
143 // The package has been registered by an add-in, and is not installed
144 // in the system.
145 public bool IsInternalPackage
146 {
147 get { return isInternal; }
148 }
149
150 public string[] Assemblies
151 {
152 get { return assemblies; }
153 }
154
155 }
156
157
158 /// <summary>
159 ///
160 /// </summary>
161 [Target("autotools")]
162 public class AutotoolsTarget : ITarget
163 {
164 #region Fields
165
166 Kernel m_Kernel;
167 XmlDocument autotoolsDoc;
168 XmlUrlResolver xr;
169 System.Security.Policy.Evidence e;
170 readonly Dictionary<string, SystemPackage> assemblyPathToPackage = new Dictionary<string, SystemPackage>();
171 readonly Dictionary<string, string> assemblyFullNameToPath = new Dictionary<string, string>();
172 readonly Dictionary<string, SystemPackage> packagesHash = new Dictionary<string, SystemPackage>();
173 readonly List<SystemPackage> packages = new List<SystemPackage>();
174
175 #endregion
176
177 #region Private Methods
178
179 private static void mkdirDashP(string dirName)
180 {
181 DirectoryInfo di = new DirectoryInfo(dirName);
182 if (di.Exists)
183 return;
184
185 string parentDirName = System.IO.Path.GetDirectoryName(dirName);
186 DirectoryInfo parentDi = new DirectoryInfo(parentDirName);
187 if (!parentDi.Exists)
188 mkdirDashP(parentDirName);
189
190 di.Create();
191 }
192
193 private static void chkMkDir(string dirName)
194 {
195 System.IO.DirectoryInfo di =
196 new System.IO.DirectoryInfo(dirName);
197
198 if (!di.Exists)
199 di.Create();
200 }
201
202 private void transformToFile(string filename, XsltArgumentList argList, string nodeName)
203 {
204 // Create an XslTransform for this file
205 XslTransform templateTransformer =
206 new XslTransform();
207
208 // Load up the template
209 XmlNode templateNode =
210 autotoolsDoc.SelectSingleNode(nodeName + "/*");
211 templateTransformer.Load(templateNode.CreateNavigator(), xr, e);
212
213 // Create a writer for the transformed template
214 XmlTextWriter templateWriter =
215 new XmlTextWriter(filename, null);
216
217 // Perform transformation, writing the file
218 templateTransformer.Transform
219 (m_Kernel.CurrentDoc, argList, templateWriter, xr);
220 }
221
222 static string NormalizeAsmName(string name)
223 {
224 int i = name.IndexOf(", PublicKeyToken=null");
225 if (i != -1)
226 return name.Substring(0, i).Trim();
227 return name;
228 }
229
230 private void AddAssembly(string assemblyfile, SystemPackage package)
231 {
232 if (!File.Exists(assemblyfile))
233 return;
234
235 try
236 {
237 System.Reflection.AssemblyName an = System.Reflection.AssemblyName.GetAssemblyName(assemblyfile);
238 assemblyFullNameToPath[NormalizeAsmName(an.FullName)] = assemblyfile;
239 assemblyPathToPackage[assemblyfile] = package;
240 }
241 catch
242 {
243 }
244 }
245
246 private static List<string> GetAssembliesWithLibInfo(string line, string file)
247 {
248 List<string> references = new List<string>();
249 List<string> libdirs = new List<string>();
250 List<string> retval = new List<string>();
251 foreach (string piece in line.Split(' '))
252 {
253 if (piece.ToLower().Trim().StartsWith("/r:") || piece.ToLower().Trim().StartsWith("-r:"))
254 {
255 references.Add(ProcessPiece(piece.Substring(3).Trim(), file));
256 }
257 else if (piece.ToLower().Trim().StartsWith("/lib:") || piece.ToLower().Trim().StartsWith("-lib:"))
258 {
259 libdirs.Add(ProcessPiece(piece.Substring(5).Trim(), file));
260 }
261 }
262
263 foreach (string refrnc in references)
264 {
265 foreach (string libdir in libdirs)
266 {
267 if (File.Exists(libdir + Path.DirectorySeparatorChar + refrnc))
268 {
269 retval.Add(libdir + Path.DirectorySeparatorChar + refrnc);
270 }
271 }
272 }
273
274 return retval;
275 }
276
277 private static List<string> GetAssembliesWithoutLibInfo(string line, string file)
278 {
279 List<string> references = new List<string>();
280 foreach (string reference in line.Split(' '))
281 {
282 if (reference.ToLower().Trim().StartsWith("/r:") || reference.ToLower().Trim().StartsWith("-r:"))
283 {
284 string final_ref = reference.Substring(3).Trim();
285 references.Add(ProcessPiece(final_ref, file));
286 }
287 }
288 return references;
289 }
290
291 private static string ProcessPiece(string piece, string pcfile)
292 {
293 int start = piece.IndexOf("${");
294 if (start == -1)
295 return piece;
296
297 int end = piece.IndexOf("}");
298 if (end == -1)
299 return piece;
300
301 string variable = piece.Substring(start + 2, end - start - 2);
302 string interp = GetVariableFromPkgConfig(variable, Path.GetFileNameWithoutExtension(pcfile));
303 return ProcessPiece(piece.Replace("${" + variable + "}", interp), pcfile);
304 }
305
306 private static string GetVariableFromPkgConfig(string var, string pcfile)
307 {
308 ProcessStartInfo psi = new ProcessStartInfo("pkg-config");
309 psi.RedirectStandardOutput = true;
310 psi.UseShellExecute = false;
311 psi.Arguments = String.Format("--variable={0} {1}", var, pcfile);
312 Process p = new Process();
313 p.StartInfo = psi;
314 p.Start();
315 string ret = p.StandardOutput.ReadToEnd().Trim();
316 p.WaitForExit();
317 if (String.IsNullOrEmpty(ret))
318 return String.Empty;
319 return ret;
320 }
321
322 private void ParsePCFile(string pcfile)
323 {
324 // Don't register the package twice
325 string pname = Path.GetFileNameWithoutExtension(pcfile);
326 if (packagesHash.ContainsKey(pname))
327 return;
328
329 List<string> fullassemblies = null;
330 string version = "";
331 string desc = "";
332
333 SystemPackage package = new SystemPackage();
334
335 using (StreamReader reader = new StreamReader(pcfile))
336 {
337 string line;
338 while ((line = reader.ReadLine()) != null)
339 {
340 string lowerLine = line.ToLower();
341 if (lowerLine.StartsWith("libs:") && lowerLine.IndexOf(".dll") != -1)
342 {
343 string choppedLine = line.Substring(5).Trim();
344 if (choppedLine.IndexOf("-lib:") != -1 || choppedLine.IndexOf("/lib:") != -1)
345 {
346 fullassemblies = GetAssembliesWithLibInfo(choppedLine, pcfile);
347 }
348 else
349 {
350 fullassemblies = GetAssembliesWithoutLibInfo(choppedLine, pcfile);
351 }
352 }
353 else if (lowerLine.StartsWith("version:"))
354 {
355 // "version:".Length == 8
356 version = line.Substring(8).Trim();
357 }
358 else if (lowerLine.StartsWith("description:"))
359 {
360 // "description:".Length == 12
361 desc = line.Substring(12).Trim();
362 }
363 }
364 }
365
366 if (fullassemblies == null)
367 return;
368
369 foreach (string assembly in fullassemblies)
370 {
371 AddAssembly(assembly, package);
372 }
373
374 package.Initialize(pname,
375 version,
376 desc,
377 fullassemblies.ToArray(),
378 ClrVersion.Default,
379 false);
380 packages.Add(package);
381 packagesHash[pname] = package;
382 }
383
384 void RegisterSystemAssemblies(string prefix, string version, ClrVersion ver)
385 {
386 SystemPackage package = new SystemPackage();
387 List<string> list = new List<string>();
388
389 string dir = Path.Combine(prefix, version);
390 if (!Directory.Exists(dir))
391 {
392 return;
393 }
394
395 foreach (string assembly in Directory.GetFiles(dir, "*.dll"))
396 {
397 AddAssembly(assembly, package);
398 list.Add(assembly);
399 }
400
401 package.Initialize("mono",
402 version,
403 "The Mono runtime",
404 list.ToArray(),
405 ver,
406 false);
407 packages.Add(package);
408 }
409
410 void RunInitialization()
411 {
412 string versionDir;
413
414 if (Environment.Version.Major == 1)
415 {
416 versionDir = "1.0";
417 }
418 else
419 {
420 versionDir = "2.0";
421 }
422
423 //Pull up assemblies from the installed mono system.
424 string prefix = Path.GetDirectoryName(typeof(int).Assembly.Location);
425
426 if (prefix.IndexOf(Path.Combine("mono", versionDir)) == -1)
427 prefix = Path.Combine(prefix, "mono");
428 else
429 prefix = Path.GetDirectoryName(prefix);
430
431 RegisterSystemAssemblies(prefix, "1.0", ClrVersion.Net_1_1);
432 RegisterSystemAssemblies(prefix, "2.0", ClrVersion.Net_2_0);
433
434 string search_dirs = Environment.GetEnvironmentVariable("PKG_CONFIG_PATH");
435 string libpath = Environment.GetEnvironmentVariable("PKG_CONFIG_LIBPATH");
436
437 if (String.IsNullOrEmpty(libpath))
438 {
439 string path_dirs = Environment.GetEnvironmentVariable("PATH");
440 foreach (string pathdir in path_dirs.Split(Path.PathSeparator))
441 {
442 if (pathdir == null)
443 continue;
444 if (File.Exists(pathdir + Path.DirectorySeparatorChar + "pkg-config"))
445 {
446 libpath = Path.Combine(pathdir, "..");
447 libpath = Path.Combine(libpath, "lib");
448 libpath = Path.Combine(libpath, "pkgconfig");
449 break;
450 }
451 }
452 }
453 search_dirs += Path.PathSeparator + libpath;
454 if (!string.IsNullOrEmpty(search_dirs))
455 {
456 List<string> scanDirs = new List<string>();
457 foreach (string potentialDir in search_dirs.Split(Path.PathSeparator))
458 {
459 if (!scanDirs.Contains(potentialDir))
460 scanDirs.Add(potentialDir);
461 }
462 foreach (string pcdir in scanDirs)
463 {
464 if (pcdir == null)
465 continue;
466
467 if (Directory.Exists(pcdir))
468 {
469 foreach (string pcfile in Directory.GetFiles(pcdir, "*.pc"))
470 {
471 ParsePCFile(pcfile);
472 }
473 }
474 }
475 }
476 }
477
478 private void WriteCombine(SolutionNode solution)
479 {
480 #region "Create Solution directory if it doesn't exist"
481 string solutionDir = Path.Combine(solution.FullPath,
482 Path.Combine("autotools",
483 solution.Name));
484 chkMkDir(solutionDir);
485 #endregion
486
487 #region "Write Solution-level files"
488 XsltArgumentList argList = new XsltArgumentList();
489 argList.AddParam("solutionName", "", solution.Name);
490 // $solutionDir is $rootDir/$solutionName/
491 transformToFile(Path.Combine(solutionDir, "configure.ac"),
492 argList, "/Autotools/SolutionConfigureAc");
493 transformToFile(Path.Combine(solutionDir, "Makefile.am"),
494 argList, "/Autotools/SolutionMakefileAm");
495 transformToFile(Path.Combine(solutionDir, "autogen.sh"),
496 argList, "/Autotools/SolutionAutogenSh");
497 #endregion
498
499 foreach (ProjectNode project in solution.ProjectsTableOrder)
500 {
501 m_Kernel.Log.Write(String.Format("Writing project: {0}",
502 project.Name));
503 WriteProject(solution, project);
504 }
505 }
506
507 private static string FindFileReference(string refName,
508 ProjectNode project)
509 {
510 foreach (ReferencePathNode refPath in project.ReferencePaths)
511 {
512 string fullPath =
513 Helper.MakeFilePath(refPath.Path, refName, "dll");
514
515 if (File.Exists(fullPath)) {
516 return fullPath;
517 }
518 }
519
520 return null;
521 }
522
523 /// <summary>
524 /// Gets the XML doc file.
525 /// </summary>
526 /// <param name="project">The project.</param>
527 /// <param name="conf">The conf.</param>
528 /// <returns></returns>
529 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
530 {
531 if (conf == null)
532 {
533 throw new ArgumentNullException("conf");
534 }
535 if (project == null)
536 {
537 throw new ArgumentNullException("project");
538 }
539 string docFile = (string)conf.Options["XmlDocFile"];
540 // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
541 // {
542 // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
543 // }
544 return docFile;
545 }
546
547 /// <summary>
548 /// Normalizes the path.
549 /// </summary>
550 /// <param name="path">The path.</param>
551 /// <returns></returns>
552 public static string NormalizePath(string path)
553 {
554 if (path == null)
555 {
556 return "";
557 }
558
559 StringBuilder tmpPath;
560
561 if (Core.Parse.Preprocessor.GetOS() == "Win32")
562 {
563 tmpPath = new StringBuilder(path.Replace('\\', '/'));
564 tmpPath.Replace("/", @"\\");
565 }
566 else
567 {
568 tmpPath = new StringBuilder(path.Replace('\\', '/'));
569 tmpPath = tmpPath.Replace('/', Path.DirectorySeparatorChar);
570 }
571 return tmpPath.ToString();
572 }
573
574 private void WriteProject(SolutionNode solution, ProjectNode project)
575 {
576 string solutionDir = Path.Combine(solution.FullPath, Path.Combine("autotools", solution.Name));
577 string projectDir = Path.Combine(solutionDir, project.Name);
578 string projectVersion = project.Version;
579 bool hasAssemblyConfig = false;
580 chkMkDir(projectDir);
581
582 List<string>
583 compiledFiles = new List<string>(),
584 contentFiles = new List<string>(),
585 embeddedFiles = new List<string>(),
586
587 binaryLibs = new List<string>(),
588 pkgLibs = new List<string>(),
589 systemLibs = new List<string>(),
590 runtimeLibs = new List<string>(),
591
592 extraDistFiles = new List<string>(),
593 localCopyTargets = new List<string>();
594
595 // If there exists a .config file for this assembly, copy
596 // it to the project folder
597
598 // TODO: Support copying .config.osx files
599 // TODO: support processing the .config file for native library deps
600 string projectAssemblyName = project.Name;
601 if (project.AssemblyName != null)
602 projectAssemblyName = project.AssemblyName;
603
604 if (File.Exists(Path.Combine(project.FullPath, projectAssemblyName) + ".dll.config"))
605 {
606 hasAssemblyConfig = true;
607 System.IO.File.Copy(Path.Combine(project.FullPath, projectAssemblyName + ".dll.config"), Path.Combine(projectDir, projectAssemblyName + ".dll.config"), true);
608 extraDistFiles.Add(project.AssemblyName + ".dll.config");
609 }
610
611 foreach (ConfigurationNode conf in project.Configurations)
612 {
613 if (conf.Options.KeyFile != string.Empty)
614 {
615 // Copy snk file into the project's directory
616 // Use the snk from the project directory directly
617 string source = Path.Combine(project.FullPath, conf.Options.KeyFile);
618 string keyFile = conf.Options.KeyFile;
619 Regex re = new Regex(".*/");
620 keyFile = re.Replace(keyFile, "");
621
622 string dest = Path.Combine(projectDir, keyFile);
623 // Tell the user if there's a problem copying the file
624 try
625 {
626 mkdirDashP(System.IO.Path.GetDirectoryName(dest));
627 System.IO.File.Copy(source, dest, true);
628 }
629 catch (System.IO.IOException e)
630 {
631 Console.WriteLine(e.Message);
632 }
633 }
634 }
635
636 // Copy compiled, embedded and content files into the project's directory
637 foreach (string filename in project.Files)
638 {
639 string source = Path.Combine(project.FullPath, filename);
640 string dest = Path.Combine(projectDir, filename);
641
642 if (filename.Contains("AssemblyInfo.cs"))
643 {
644 // If we've got an AssemblyInfo.cs, pull the version number from it
645 string[] sources = { source };
646 string[] args = { "" };
647 Microsoft.CSharp.CSharpCodeProvider cscp =
648 new Microsoft.CSharp.CSharpCodeProvider();
649
650 string tempAssemblyFile = Path.Combine(Path.GetTempPath(), project.Name + "-temp.dll");
651 System.CodeDom.Compiler.CompilerParameters cparam =
652 new System.CodeDom.Compiler.CompilerParameters(args, tempAssemblyFile);
653
654 System.CodeDom.Compiler.CompilerResults cr =
655 cscp.CompileAssemblyFromFile(cparam, sources);
656
657 foreach (System.CodeDom.Compiler.CompilerError error in cr.Errors)
658 Console.WriteLine("Error! '{0}'", error.ErrorText);
659
660 try {
661 string projectFullName = cr.CompiledAssembly.FullName;
662 Regex verRegex = new Regex("Version=([\\d\\.]+)");
663 Match verMatch = verRegex.Match(projectFullName);
664 if (verMatch.Success)
665 projectVersion = verMatch.Groups[1].Value;
666 }catch{
667 Console.WriteLine("Couldn't compile AssemblyInfo.cs");
668 }
669
670 // Clean up the temp file
671 try
672 {
673 if (File.Exists(tempAssemblyFile))
674 File.Delete(tempAssemblyFile);
675 }
676 catch
677 {
678 Console.WriteLine("Error! '{0}'", e);
679 }
680
681 }
682
683 // Tell the user if there's a problem copying the file
684 try
685 {
686 mkdirDashP(System.IO.Path.GetDirectoryName(dest));
687 System.IO.File.Copy(source, dest, true);
688 }
689 catch (System.IO.IOException e)
690 {
691 Console.WriteLine(e.Message);
692 }
693
694 switch (project.Files.GetBuildAction(filename))
695 {
696 case BuildAction.Compile:
697 compiledFiles.Add(filename);
698 break;
699 case BuildAction.Content:
700 contentFiles.Add(filename);
701 extraDistFiles.Add(filename);
702 break;
703 case BuildAction.EmbeddedResource:
704 embeddedFiles.Add(filename);
705 break;
706 }
707 }
708
709 // Set up references
710 for (int refNum = 0; refNum < project.References.Count; refNum++)
711 {
712 ReferenceNode refr = project.References[refNum];
713 Assembly refAssembly = Assembly.LoadWithPartialName(refr.Name);
714
715 /* Determine which pkg-config (.pc) file refers to
716 this assembly */
717
718 SystemPackage package = null;
719
720 if (packagesHash.ContainsKey(refr.Name))
721 {
722 package = packagesHash[refr.Name];
723
724 }
725 else
726 {
727 string assemblyFullName = string.Empty;
728 if (refAssembly != null)
729 assemblyFullName = refAssembly.FullName;
730
731 string assemblyFileName = string.Empty;
732 if (assemblyFullName != string.Empty &&
733 assemblyFullNameToPath.ContainsKey(assemblyFullName)
734 )
735 assemblyFileName =
736 assemblyFullNameToPath[assemblyFullName];
737
738 if (assemblyFileName != string.Empty &&
739 assemblyPathToPackage.ContainsKey(assemblyFileName)
740 )
741 package = assemblyPathToPackage[assemblyFileName];
742
743 }
744
745 /* If we know the .pc file and it is not "mono"
746 (already in the path), add a -pkg: argument */
747
748 if (package != null &&
749 package.Name != "mono" &&
750 !pkgLibs.Contains(package.Name)
751 )
752 pkgLibs.Add(package.Name);
753
754 string fileRef =
755 FindFileReference(refr.Name, (ProjectNode)refr.Parent);
756
757 if (refr.LocalCopy ||
758 solution.ProjectsTable.ContainsKey(refr.Name) ||
759 fileRef != null ||
760 refr.Path != null
761 )
762 {
763
764 /* Attempt to copy the referenced lib to the
765 project's directory */
766
767 string filename = refr.Name + ".dll";
768 string source = filename;
769 if (refr.Path != null)
770 source = Path.Combine(refr.Path, source);
771 source = Path.Combine(project.FullPath, source);
772 string dest = Path.Combine(projectDir, filename);
773
774 /* Since we depend on this binary dll to build, we
775 * will add a compile- time dependency on the
776 * copied dll, and add the dll to the list of
777 * files distributed with this package
778 */
779
780 binaryLibs.Add(refr.Name + ".dll");
781 extraDistFiles.Add(refr.Name + ".dll");
782
783 // TODO: Support copying .config.osx files
784 // TODO: Support for determining native dependencies
785 if (File.Exists(source + ".config"))
786 {
787 System.IO.File.Copy(source + ".config", Path.GetDirectoryName(dest), true);
788 extraDistFiles.Add(refr.Name + ".dll.config");
789 }
790
791 try
792 {
793 System.IO.File.Copy(source, dest, true);
794 }
795 catch (System.IO.IOException)
796 {
797 if (solution.ProjectsTable.ContainsKey(refr.Name)){
798
799 /* If an assembly is referenced, marked for
800 * local copy, in the list of projects for
801 * this solution, but does not exist, put a
802 * target into the Makefile.am to build the
803 * assembly and copy it to this project's
804 * directory
805 */
806
807 ProjectNode sourcePrj =
808 ((solution.ProjectsTable[refr.Name]));
809
810 string target =
811 String.Format("{0}:\n" +
812 "\t$(MAKE) -C ../{1}\n" +
813 "\tln ../{2}/$@ $@\n",
814 filename,
815 sourcePrj.Name,
816 sourcePrj.Name );
817
818 localCopyTargets.Add(target);
819 }
820 }
821 }
822 else if( !pkgLibs.Contains(refr.Name) )
823 {
824 // Else, let's assume it's in the GAC or the lib path
825 string assemName = string.Empty;
826 int index = refr.Name.IndexOf(",");
827
828 if (index > 0)
829 assemName = refr.Name.Substring(0, index);
830 else
831 assemName = refr.Name;
832
833 m_Kernel.Log.Write(String.Format(
834 "Warning: Couldn't find an appropriate assembly " +
835 "for reference:\n'{0}'", refr.Name
836 ));
837 systemLibs.Add(assemName);
838 }
839 }
840
841 const string lineSep = " \\\n\t";
842 string compiledFilesString = string.Empty;
843 if (compiledFiles.Count > 0)
844 compiledFilesString =
845 lineSep + string.Join(lineSep, compiledFiles.ToArray());
846
847 string embeddedFilesString = "";
848 if (embeddedFiles.Count > 0)
849 embeddedFilesString =
850 lineSep + string.Join(lineSep, embeddedFiles.ToArray());
851
852 string contentFilesString = "";
853 if (contentFiles.Count > 0)
854 contentFilesString =
855 lineSep + string.Join(lineSep, contentFiles.ToArray());
856
857 string extraDistFilesString = "";
858 if (extraDistFiles.Count > 0)
859 extraDistFilesString =
860 lineSep + string.Join(lineSep, extraDistFiles.ToArray());
861
862 string pkgLibsString = "";
863 if (pkgLibs.Count > 0)
864 pkgLibsString =
865 lineSep + string.Join(lineSep, pkgLibs.ToArray());
866
867 string binaryLibsString = "";
868 if (binaryLibs.Count > 0)
869 binaryLibsString =
870 lineSep + string.Join(lineSep, binaryLibs.ToArray());
871
872 string systemLibsString = "";
873 if (systemLibs.Count > 0)
874 systemLibsString =
875 lineSep + string.Join(lineSep, systemLibs.ToArray());
876
877 string localCopyTargetsString = "";
878 if (localCopyTargets.Count > 0)
879 localCopyTargetsString =
880 string.Join("\n", localCopyTargets.ToArray());
881
882 string monoPath = "";
883 foreach (string runtimeLib in runtimeLibs)
884 {
885 monoPath += ":`pkg-config --variable=libdir " + runtimeLib + "`";
886 }
887
888 // Add the project name to the list of transformation
889 // parameters
890 XsltArgumentList argList = new XsltArgumentList();
891 argList.AddParam("projectName", "", project.Name);
892 argList.AddParam("solutionName", "", solution.Name);
893 argList.AddParam("assemblyName", "", projectAssemblyName);
894 argList.AddParam("compiledFiles", "", compiledFilesString);
895 argList.AddParam("embeddedFiles", "", embeddedFilesString);
896 argList.AddParam("contentFiles", "", contentFilesString);
897 argList.AddParam("extraDistFiles", "", extraDistFilesString);
898 argList.AddParam("pkgLibs", "", pkgLibsString);
899 argList.AddParam("binaryLibs", "", binaryLibsString);
900 argList.AddParam("systemLibs", "", systemLibsString);
901 argList.AddParam("monoPath", "", monoPath);
902 argList.AddParam("localCopyTargets", "", localCopyTargetsString);
903 argList.AddParam("projectVersion", "", projectVersion);
904 argList.AddParam("hasAssemblyConfig", "", hasAssemblyConfig ? "true" : "");
905
906 // Transform the templates
907 transformToFile(Path.Combine(projectDir, "configure.ac"), argList, "/Autotools/ProjectConfigureAc");
908 transformToFile(Path.Combine(projectDir, "Makefile.am"), argList, "/Autotools/ProjectMakefileAm");
909 transformToFile(Path.Combine(projectDir, "autogen.sh"), argList, "/Autotools/ProjectAutogenSh");
910
911 if (project.Type == Core.Nodes.ProjectType.Library)
912 transformToFile(Path.Combine(projectDir, project.Name + ".pc.in"), argList, "/Autotools/ProjectPcIn");
913 if (project.Type == Core.Nodes.ProjectType.Exe || project.Type == Core.Nodes.ProjectType.WinExe)
914 transformToFile(Path.Combine(projectDir, project.Name.ToLower() + ".in"), argList, "/Autotools/ProjectWrapperScriptIn");
915 }
916
917 private void CleanProject(ProjectNode project)
918 {
919 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
920 string projectFile = Helper.MakeFilePath(project.FullPath, "Include", "am");
921 Helper.DeleteIfExists(projectFile);
922 }
923
924 private void CleanSolution(SolutionNode solution)
925 {
926 m_Kernel.Log.Write("Cleaning Autotools make files for", solution.Name);
927
928 string slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "am");
929 Helper.DeleteIfExists(slnFile);
930
931 slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "in");
932 Helper.DeleteIfExists(slnFile);
933
934 slnFile = Helper.MakeFilePath(solution.FullPath, "configure", "ac");
935 Helper.DeleteIfExists(slnFile);
936
937 slnFile = Helper.MakeFilePath(solution.FullPath, "configure");
938 Helper.DeleteIfExists(slnFile);
939
940 slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile");
941 Helper.DeleteIfExists(slnFile);
942
943 foreach (ProjectNode project in solution.Projects)
944 {
945 CleanProject(project);
946 }
947
948 m_Kernel.Log.Write("");
949 }
950
951 #endregion
952
953 #region ITarget Members
954
955 /// <summary>
956 /// Writes the specified kern.
957 /// </summary>
958 /// <param name="kern">The kern.</param>
959 public void Write(Kernel kern)
960 {
961 if (kern == null)
962 {
963 throw new ArgumentNullException("kern");
964 }
965 m_Kernel = kern;
966 m_Kernel.Log.Write("Parsing system pkg-config files");
967 RunInitialization();
968
969 const string streamName = "autotools.xml";
970 string fqStreamName = String.Format("Prebuild.data.{0}",
971 streamName
972 );
973
974 // Retrieve stream for the autotools template XML
975 Stream autotoolsStream = Assembly.GetExecutingAssembly()
976 .GetManifestResourceStream(fqStreamName);
977
978 if(autotoolsStream == null) {
979
980 /*
981 * try without the default namespace prepended, in
982 * case prebuild.exe assembly was compiled with
983 * something other than Visual Studio .NET
984 */
985
986 autotoolsStream = Assembly.GetExecutingAssembly()
987 .GetManifestResourceStream(streamName);
988 if(autotoolsStream == null){
989 string errStr =
990 String.Format("Could not find embedded resource file:\n" +
991 "'{0}' or '{1}'",
992 streamName, fqStreamName
993 );
994
995 m_Kernel.Log.Write(errStr);
996
997 throw new System.Reflection.TargetException(errStr);
998 }
999 }
1000
1001 // Create an XML URL Resolver with default credentials
1002 xr = new System.Xml.XmlUrlResolver();
1003 xr.Credentials = CredentialCache.DefaultCredentials;
1004
1005 // Create a default evidence - no need to limit access
1006 e = new System.Security.Policy.Evidence();
1007
1008 // Load the autotools XML
1009 autotoolsDoc = new XmlDocument();
1010 autotoolsDoc.Load(autotoolsStream);
1011
1012 /* rootDir is the filesystem location where the Autotools
1013 * build tree will be created - for now we'll make it
1014 * $PWD/autotools
1015 */
1016
1017 string pwd = Directory.GetCurrentDirectory();
1018 //string pwd = System.Environment.GetEnvironmentVariable("PWD");
1019 //if (pwd.Length != 0)
1020 //{
1021 string rootDir = Path.Combine(pwd, "autotools");
1022 //}
1023 //else
1024 //{
1025 // pwd = Assembly.GetExecutingAssembly()
1026 //}
1027 chkMkDir(rootDir);
1028
1029 foreach (SolutionNode solution in kern.Solutions)
1030 {
1031 m_Kernel.Log.Write(String.Format("Writing solution: {0}",
1032 solution.Name));
1033 WriteCombine(solution);
1034 }
1035 m_Kernel = null;
1036 }
1037
1038 /// <summary>
1039 /// Cleans the specified kern.
1040 /// </summary>
1041 /// <param name="kern">The kern.</param>
1042 public virtual void Clean(Kernel kern)
1043 {
1044 if (kern == null)
1045 {
1046 throw new ArgumentNullException("kern");
1047 }
1048 m_Kernel = kern;
1049 foreach (SolutionNode sol in kern.Solutions)
1050 {
1051 CleanSolution(sol);
1052 }
1053 m_Kernel = null;
1054 }
1055
1056 /// <summary>
1057 /// Gets the name.
1058 /// </summary>
1059 /// <value>The name.</value>
1060 public string Name
1061 {
1062 get
1063 {
1064 return "autotools";
1065 }
1066 }
1067
1068 #endregion
1069 }
1070}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/DebugTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/DebugTarget.cs.svn-base
new file mode 100644
index 0000000..3494c30
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/DebugTarget.cs.svn-base
@@ -0,0 +1,102 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26#region CVS Information
27/*
28 * $Source$
29 * $Author$
30 * $Date$
31 * $Revision$
32 */
33#endregion
34
35using System;
36
37using Prebuild.Core.Attributes;
38using Prebuild.Core.Interfaces;
39using Prebuild.Core.Nodes;
40
41#if (DEBUG && _DEBUG_TARGET)
42namespace Prebuild.Core.Targets
43{
44 [Target("debug")]
45 public class DebugTarget : ITarget
46 {
47#region Fields
48
49 private Kernel m_Kernel = null;
50
51#endregion
52
53#region ITarget Members
54
55 public void Write()
56 {
57 foreach(SolutionNode s in m_Kernel.Solutions)
58 {
59 Console.WriteLine("Solution [ {0}, {1} ]", s.Name, s.Path);
60 foreach(string file in s.Files)
61{
62 Console.WriteLine("\tFile [ {0} ]", file);
63}
64
65 foreach(ProjectNode proj in s.Projects)
66 {
67 Console.WriteLine("\tProject [ {0}, {1}. {2} ]", proj.Name, proj.Path, proj.Language);
68 foreach(string file in proj.Files)
69 Console.WriteLine("\t\tFile [ {0} ]", file);
70 }
71 }
72 }
73
74 public void Clean()
75 {
76 Console.WriteLine("Not implemented");
77 }
78
79 public string Name
80 {
81 get
82 {
83 return "debug";
84 }
85 }
86
87 public Kernel Kernel
88 {
89 get
90 {
91 return m_Kernel;
92 }
93 set
94 {
95 m_Kernel = value;
96 }
97 }
98
99#endregion
100 }
101}
102#endif
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/MakefileTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/MakefileTarget.cs.svn-base
new file mode 100644
index 0000000..54046dd
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/MakefileTarget.cs.svn-base
@@ -0,0 +1,469 @@
1#region BSD License
2/*
3Copyright (c) 2004 Crestez Leonard (cleonard@go.ro)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Text.RegularExpressions;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using Prebuild.Core.Nodes;
33using Prebuild.Core.Utilities;
34
35namespace Prebuild.Core.Targets
36{
37 [Target("makefile")]
38 public class MakefileTarget : ITarget
39 {
40 #region Fields
41
42 private Kernel m_Kernel = null;
43
44 #endregion
45
46 #region Private Methods
47
48 // This converts a path relative to the path of a project to
49 // a path relative to the solution path.
50 private string NicePath(ProjectNode proj, string path)
51 {
52 string res;
53 SolutionNode solution = (SolutionNode)proj.Parent;
54 res = Path.Combine(Helper.NormalizePath(proj.FullPath, '/'), Helper.NormalizePath(path, '/'));
55 res = Helper.NormalizePath(res, '/');
56 res = res.Replace("/./", "/");
57 while (res.IndexOf("/../") >= 0)
58 {
59 int a = res.IndexOf("/../");
60 int b = res.LastIndexOf("/", a - 1);
61 res = res.Remove(b, a - b + 3);
62 }
63 res = Helper.MakePathRelativeTo(solution.FullPath, res);
64 if (res.StartsWith("./"))
65 res = res.Substring(2, res.Length - 2);
66 res = Helper.NormalizePath(res, '/');
67 return res;
68 }
69
70 private void WriteProjectFiles(StreamWriter f, SolutionNode solution, ProjectNode project)
71 {
72 // Write list of source code files
73 f.WriteLine("SOURCES_{0} = \\", project.Name);
74 foreach (string file in project.Files)
75 if (project.Files.GetBuildAction(file) == BuildAction.Compile)
76 f.WriteLine("\t{0} \\", NicePath(project, file));
77 f.WriteLine();
78
79 // Write list of resource files
80 f.WriteLine("RESOURCES_{0} = \\", project.Name);
81 foreach (string file in project.Files)
82 if (project.Files.GetBuildAction(file) == BuildAction.EmbeddedResource)
83 {
84 string path = NicePath(project, file);
85 f.WriteLine("\t-resource:{0},{1} \\", path, Path.GetFileName(path));
86 }
87 f.WriteLine();
88
89 // There's also Content and None in BuildAction.
90 // What am I supposed to do with that?
91 }
92
93 private string FindFileReference(string refName, ProjectNode project)
94 {
95 foreach (ReferencePathNode refPath in project.ReferencePaths)
96 {
97 string fullPath = NicePath(project, Helper.MakeFilePath(refPath.Path, refName, "dll"));
98 if (File.Exists(fullPath))
99 return fullPath;
100 }
101 return null;
102 }
103
104 private void WriteProjectReferences(StreamWriter f, SolutionNode solution, ProjectNode project)
105 {
106 f.WriteLine("REFERENCES_{0} = \\", project.Name);
107 foreach (ReferenceNode refr in project.References)
108 {
109 string path;
110 // Project references change with configurations.
111 if (solution.ProjectsTable.ContainsKey(refr.Name))
112 continue;
113 path = FindFileReference(refr.Name, project);
114 if (path != null)
115 f.WriteLine("\t-r:{0} \\", path);
116 else
117 f.WriteLine("\t-r:{0} \\", refr.Name);
118 }
119 f.WriteLine();
120 }
121
122 private void WriteProjectDependencies(StreamWriter f, SolutionNode solution, ProjectNode project)
123 {
124 f.WriteLine("DEPENDENCIES_{0} = \\", project.Name);
125 f.WriteLine("\t$(SOURCES_{0}) \\", project.Name);
126 foreach (string file in project.Files)
127 if (project.Files.GetBuildAction(file) == BuildAction.EmbeddedResource)
128 f.WriteLine("\t{0} \\", NicePath(project, file));
129 f.WriteLine();
130 }
131
132 private string ProjectTypeToExtension(ProjectType t)
133 {
134 if (t == ProjectType.Exe || t == ProjectType.WinExe)
135 {
136 return "exe";
137 }
138 else if (t == ProjectType.Library)
139 {
140 return "dll";
141 }
142 else
143 {
144 throw new FatalException("Bad ProjectType: {0}", t);
145 }
146 }
147
148 private string ProjectTypeToTarget(ProjectType t)
149 {
150 if (t == ProjectType.Exe)
151 {
152 return "exe";
153 }
154 else if (t == ProjectType.WinExe)
155 {
156 return "winexe";
157 }
158 else if (t == ProjectType.Library)
159 {
160 return "library";
161 }
162 else
163 {
164 throw new FatalException("Bad ProjectType: {0}", t);
165 }
166 }
167
168 private string ProjectOutput(ProjectNode project, ConfigurationNode config)
169 {
170 string filepath;
171 filepath = Helper.MakeFilePath((string)config.Options["OutputPath"],
172 project.AssemblyName, ProjectTypeToExtension(project.Type));
173 return NicePath(project, filepath);
174 }
175
176 // Returns true if two configs in one project have the same output.
177 private bool ProjectClashes(ProjectNode project)
178 {
179 foreach (ConfigurationNode conf1 in project.Configurations)
180 foreach (ConfigurationNode conf2 in project.Configurations)
181 if (ProjectOutput(project, conf1) == ProjectOutput(project, conf2) && conf1 != conf2)
182 {
183 m_Kernel.Log.Write("Warning: Configurations {0} and {1} for project {2} output the same file",
184 conf1.Name, conf2.Name, project.Name);
185 m_Kernel.Log.Write("Warning: I'm going to use some timestamps(extra empty files).");
186 return true;
187 }
188 return false;
189 }
190
191 private void WriteProject(StreamWriter f, SolutionNode solution, ProjectNode project)
192 {
193 f.WriteLine("# This is for project {0}", project.Name);
194 f.WriteLine();
195
196 WriteProjectFiles(f, solution, project);
197 WriteProjectReferences(f, solution, project);
198 WriteProjectDependencies(f, solution, project);
199
200 bool clash = ProjectClashes(project);
201
202 foreach (ConfigurationNode conf in project.Configurations)
203 {
204 string outpath = ProjectOutput(project, conf);
205 string filesToClean = outpath;
206
207 if (clash)
208 {
209 f.WriteLine("{0}-{1}: .{0}-{1}-timestamp", project.Name, conf.Name);
210 f.WriteLine();
211 f.Write(".{0}-{1}-timestamp: $(DEPENDENCIES_{0})", project.Name, conf.Name);
212 }
213 else
214 {
215 f.WriteLine("{0}-{1}: {2}", project.Name, conf.Name, outpath);
216 f.WriteLine();
217 f.Write("{2}: $(DEPENDENCIES_{0})", project.Name, conf.Name, outpath);
218 }
219 // Dependencies on other projects.
220 foreach (ReferenceNode refr in project.References)
221 if (solution.ProjectsTable.ContainsKey(refr.Name))
222 {
223 ProjectNode refProj = (ProjectNode)solution.ProjectsTable[refr.Name];
224 if (ProjectClashes(refProj))
225 f.Write(" .{0}-{1}-timestamp", refProj.Name, conf.Name);
226 else
227 f.Write(" {0}", ProjectOutput(refProj, conf));
228 }
229 f.WriteLine();
230
231 // make directory for output.
232 if (Path.GetDirectoryName(outpath) != "")
233 {
234 f.WriteLine("\tmkdir -p {0}", Path.GetDirectoryName(outpath));
235 }
236 // mcs command line.
237 f.Write("\tgmcs", project.Name);
238 f.Write(" -warn:{0}", conf.Options["WarningLevel"]);
239 if ((bool)conf.Options["DebugInformation"])
240 f.Write(" -debug");
241 if ((bool)conf.Options["AllowUnsafe"])
242 f.Write(" -unsafe");
243 if ((bool)conf.Options["CheckUnderflowOverflow"])
244 f.Write(" -checked");
245 if (project.StartupObject != "")
246 f.Write(" -main:{0}", project.StartupObject);
247 if ((string)conf.Options["CompilerDefines"] != "")
248 {
249 f.Write(" -define:\"{0}\"", conf.Options["CompilerDefines"]);
250 }
251
252 f.Write(" -target:{0} -out:{1}", ProjectTypeToTarget(project.Type), outpath);
253
254 // Build references to other projects. Now that sux.
255 // We have to reference the other project in the same conf.
256 foreach (ReferenceNode refr in project.References)
257 if (solution.ProjectsTable.ContainsKey(refr.Name))
258 {
259 ProjectNode refProj;
260 refProj = (ProjectNode)solution.ProjectsTable[refr.Name];
261 f.Write(" -r:{0}", ProjectOutput(refProj, conf));
262 }
263
264 f.Write(" $(REFERENCES_{0})", project.Name);
265 f.Write(" $(RESOURCES_{0})", project.Name);
266 f.Write(" $(SOURCES_{0})", project.Name);
267 f.WriteLine();
268
269 // Copy references with localcopy.
270 foreach (ReferenceNode refr in project.References)
271 if (refr.LocalCopy)
272 {
273 string outPath, srcPath, destPath;
274 outPath = Helper.NormalizePath((string)conf.Options["OutputPath"]);
275 if (solution.ProjectsTable.ContainsKey(refr.Name))
276 {
277 ProjectNode refProj;
278 refProj = (ProjectNode)solution.ProjectsTable[refr.Name];
279 srcPath = ProjectOutput(refProj, conf);
280 destPath = Path.Combine(outPath, Path.GetFileName(srcPath));
281 destPath = NicePath(project, destPath);
282 if (srcPath != destPath)
283 {
284 f.WriteLine("\tcp -f {0} {1}", srcPath, destPath);
285 filesToClean += " " + destPath;
286 }
287 continue;
288 }
289 srcPath = FindFileReference(refr.Name, project);
290 if (srcPath != null)
291 {
292 destPath = Path.Combine(outPath, Path.GetFileName(srcPath));
293 destPath = NicePath(project, destPath);
294 f.WriteLine("\tcp -f {0} {1}", srcPath, destPath);
295 filesToClean += " " + destPath;
296 }
297 }
298
299 if (clash)
300 {
301 filesToClean += String.Format(" .{0}-{1}-timestamp", project.Name, conf.Name);
302 f.WriteLine("\ttouch .{0}-{1}-timestamp", project.Name, conf.Name);
303 f.Write("\trm -rf");
304 foreach (ConfigurationNode otherConf in project.Configurations)
305 if (otherConf != conf)
306 f.WriteLine(" .{0}-{1}-timestamp", project.Name, otherConf.Name);
307 f.WriteLine();
308 }
309 f.WriteLine();
310 f.WriteLine("{0}-{1}-clean:", project.Name, conf.Name);
311 f.WriteLine("\trm -rf {0}", filesToClean);
312 f.WriteLine();
313 }
314 }
315
316 private void WriteIntro(StreamWriter f, SolutionNode solution)
317 {
318 f.WriteLine("# Makefile for {0} generated by Prebuild ( http://dnpb.sf.net )", solution.Name);
319 f.WriteLine("# Do not edit.");
320 f.WriteLine("#");
321
322 f.Write("# Configurations:");
323 foreach (ConfigurationNode conf in solution.Configurations)
324 f.Write(" {0}", conf.Name);
325 f.WriteLine();
326
327 f.WriteLine("# Projects:");
328 foreach (ProjectNode proj in solution.Projects)
329 f.WriteLine("#\t{0}", proj.Name);
330
331 f.WriteLine("#");
332 f.WriteLine("# Building:");
333 f.WriteLine("#\t\"make\" to build everything under the default(first) configuration");
334 f.WriteLine("#\t\"make CONF\" to build every project under configuration CONF");
335 f.WriteLine("#\t\"make PROJ\" to build project PROJ under the default(first) configuration");
336 f.WriteLine("#\t\"make PROJ-CONF\" to build project PROJ under configuration CONF");
337 f.WriteLine("#");
338 f.WriteLine("# Cleaning (removing results of build):");
339 f.WriteLine("#\t\"make clean\" to clean everything, that's what you probably want");
340 f.WriteLine("#\t\"make CONF\" to clean everything for a configuration");
341 f.WriteLine("#\t\"make PROJ\" to clean everything for a project");
342 f.WriteLine("#\t\"make PROJ-CONF\" to clea project PROJ under configuration CONF");
343 f.WriteLine();
344 }
345
346 private void WritePhony(StreamWriter f, SolutionNode solution)
347 {
348 string defconf = "";
349 foreach (ConfigurationNode conf in solution.Configurations)
350 {
351 defconf = conf.Name;
352 break;
353 }
354
355 f.Write(".PHONY: all");
356 foreach (ProjectNode proj in solution.Projects)
357 f.Write(" {0} {0}-clean", proj.Name);
358 foreach (ConfigurationNode conf in solution.Configurations)
359 f.Write(" {0} {0}-clean", conf.Name);
360 foreach (ProjectNode proj in solution.Projects)
361 foreach (ConfigurationNode conf in solution.Configurations)
362 f.Write(" {0}-{1} {0}-{1}-clean", proj.Name, conf.Name);
363 f.WriteLine();
364 f.WriteLine();
365
366 f.WriteLine("all: {0}", defconf);
367 f.WriteLine();
368
369 f.Write("clean:");
370 foreach (ConfigurationNode conf in solution.Configurations)
371 f.Write(" {0}-clean", conf.Name);
372 f.WriteLine();
373 f.WriteLine();
374
375 foreach (ConfigurationNode conf in solution.Configurations)
376 {
377 f.Write("{0}: ", conf.Name);
378 foreach (ProjectNode proj in solution.Projects)
379 f.Write(" {0}-{1}", proj.Name, conf.Name);
380 f.WriteLine();
381 f.WriteLine();
382
383 f.Write("{0}-clean: ", conf.Name);
384 foreach (ProjectNode proj in solution.Projects)
385 f.Write(" {0}-{1}-clean", proj.Name, conf.Name);
386 f.WriteLine();
387 f.WriteLine();
388 }
389
390 foreach (ProjectNode proj in solution.Projects)
391 {
392 f.WriteLine("{0}: {0}-{1}", proj.Name, defconf);
393 f.WriteLine();
394
395 f.Write("{0}-clean:", proj.Name);
396 foreach (ConfigurationNode conf in proj.Configurations)
397 f.Write(" {0}-{1}-clean", proj.Name, conf.Name);
398 f.WriteLine();
399 f.WriteLine();
400 }
401 }
402
403 private void WriteSolution(SolutionNode solution)
404 {
405 m_Kernel.Log.Write("Creating makefile for {0}", solution.Name);
406 m_Kernel.CurrentWorkingDirectory.Push();
407
408 string file = "Makefile";// Helper.MakeFilePath(solution.FullPath, solution.Name, "make");
409 StreamWriter f = new StreamWriter(file);
410
411 Helper.SetCurrentDir(Path.GetDirectoryName(file));
412
413 using (f)
414 {
415 WriteIntro(f, solution);
416 WritePhony(f, solution);
417
418 foreach (ProjectNode project in solution.Projects)
419 {
420 m_Kernel.Log.Write("...Creating Project: {0}", project.Name);
421 WriteProject(f, solution, project);
422 }
423 }
424
425 m_Kernel.Log.Write("");
426 m_Kernel.CurrentWorkingDirectory.Pop();
427 }
428
429 private void CleanSolution(SolutionNode solution)
430 {
431 m_Kernel.Log.Write("Cleaning makefile for {0}", solution.Name);
432
433 string file = Helper.MakeFilePath(solution.FullPath, solution.Name, "make");
434 Helper.DeleteIfExists(file);
435
436 m_Kernel.Log.Write("");
437 }
438
439 #endregion
440
441 #region ITarget Members
442
443 public void Write(Kernel kern)
444 {
445 m_Kernel = kern;
446 foreach (SolutionNode solution in kern.Solutions)
447 WriteSolution(solution);
448 m_Kernel = null;
449 }
450
451 public virtual void Clean(Kernel kern)
452 {
453 m_Kernel = kern;
454 foreach (SolutionNode sol in kern.Solutions)
455 CleanSolution(sol);
456 m_Kernel = null;
457 }
458
459 public string Name
460 {
461 get
462 {
463 return "makefile";
464 }
465 }
466
467 #endregion
468 }
469}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/MonoDevelopTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/MonoDevelopTarget.cs.svn-base
new file mode 100644
index 0000000..ea6d2c2
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/MonoDevelopTarget.cs.svn-base
@@ -0,0 +1,515 @@
1#region BSD License
2/*
3Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Reflection;
29using System.Text.RegularExpressions;
30
31using Prebuild.Core.Attributes;
32using Prebuild.Core.Interfaces;
33using Prebuild.Core.Nodes;
34using Prebuild.Core.Utilities;
35
36namespace Prebuild.Core.Targets
37{
38 /// <summary>
39 ///
40 /// </summary>
41 [Target("monodev")]
42 public class MonoDevelopTarget : ITarget
43 {
44 #region Fields
45
46 private Kernel m_Kernel;
47
48 #endregion
49
50 #region Private Methods
51
52 private static string PrependPath(string path)
53 {
54 string tmpPath = Helper.NormalizePath(path, '/');
55 Regex regex = new Regex(@"(\w):/(\w+)");
56 Match match = regex.Match(tmpPath);
57 if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
58 {
59 tmpPath = Helper.NormalizePath(tmpPath);
60 }
61 else
62 {
63 tmpPath = Helper.NormalizePath("./" + tmpPath);
64 }
65
66 return tmpPath;
67 }
68
69 private static string BuildReference(SolutionNode solution, ReferenceNode refr)
70 {
71 string ret = "<ProjectReference type=\"";
72 if(solution.ProjectsTable.ContainsKey(refr.Name))
73 {
74 ret += "Project\"";
75 ret += " localcopy=\"" + refr.LocalCopy.ToString() + "\" refto=\"" + refr.Name + "\" />";
76 }
77 else
78 {
79 ProjectNode project = (ProjectNode)refr.Parent;
80 string fileRef = FindFileReference(refr.Name, project);
81
82 if(refr.Path != null || fileRef != null)
83 {
84 ret += "Assembly\" refto=\"";
85
86 string finalPath = (refr.Path != null) ? Helper.MakeFilePath(refr.Path, refr.Name, "dll") : fileRef;
87
88 ret += finalPath;
89 ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />";
90 return ret;
91 }
92
93 ret += "Gac\"";
94 ret += " localcopy=\"" + refr.LocalCopy.ToString() + "\"";
95 ret += " refto=\"";
96 try
97 {
98 /*
99 Day changed to 28 Mar 2007
100 ...
101 08:09 < cj> is there anything that replaces Assembly.LoadFromPartialName() ?
102 08:09 < jonp> no
103 08:10 < jonp> in their infinite wisdom [sic], microsoft decided that the
104 ability to load any assembly version by-name was an inherently
105 bad idea
106 08:11 < cj> I'm thinking of a bunch of four-letter words right now...
107 08:11 < cj> security through making it difficult for the developer!!!
108 08:12 < jonp> just use the Obsolete API
109 08:12 < jonp> it should still work
110 08:12 < cj> alrighty.
111 08:12 < jonp> you just get warnings when using it
112 */
113 Assembly assem = Assembly.LoadWithPartialName(refr.Name);
114 ret += assem.FullName;
115 //ret += refr.Name;
116 }
117 catch (System.NullReferenceException e)
118 {
119 e.ToString();
120 ret += refr.Name;
121 }
122 ret += "\" />";
123 }
124
125 return ret;
126 }
127
128 private static string FindFileReference(string refName, ProjectNode project)
129 {
130 foreach(ReferencePathNode refPath in project.ReferencePaths)
131 {
132 string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
133
134 if(File.Exists(fullPath))
135 {
136 return fullPath;
137 }
138 }
139
140 return null;
141 }
142
143 /// <summary>
144 /// Gets the XML doc file.
145 /// </summary>
146 /// <param name="project">The project.</param>
147 /// <param name="conf">The conf.</param>
148 /// <returns></returns>
149 public static string GenerateXmlDocFile(ProjectNode project, ConfigurationNode conf)
150 {
151 if( conf == null )
152 {
153 throw new ArgumentNullException("conf");
154 }
155 if( project == null )
156 {
157 throw new ArgumentNullException("project");
158 }
159 string docFile = (string)conf.Options["XmlDocFile"];
160 if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
161 {
162 return "False";
163 }
164 return "True";
165 }
166
167 private void WriteProject(SolutionNode solution, ProjectNode project)
168 {
169 string csComp = "Mcs";
170 string netRuntime = "Mono";
171 if(project.Runtime == ClrRuntime.Microsoft)
172 {
173 csComp = "Csc";
174 netRuntime = "MsNet";
175 }
176
177 string projFile = Helper.MakeFilePath(project.FullPath, project.Name, "mdp");
178 StreamWriter ss = new StreamWriter(projFile);
179
180 m_Kernel.CurrentWorkingDirectory.Push();
181 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
182
183 using(ss)
184 {
185 ss.WriteLine(
186 "<Project name=\"{0}\" description=\"\" standardNamespace=\"{1}\" newfilesearch=\"None\" enableviewstate=\"True\" fileversion=\"2.0\" language=\"C#\" clr-version=\"Net_2_0\" ctype=\"DotNetProject\">",
187 project.Name,
188 project.RootNamespace
189 );
190
191 int count = 0;
192
193 ss.WriteLine(" <Configurations active=\"{0}\">", solution.ActiveConfig);
194
195 foreach(ConfigurationNode conf in project.Configurations)
196 {
197 ss.WriteLine(" <Configuration name=\"{0}\" ctype=\"DotNetProjectConfiguration\">", conf.Name);
198 ss.Write(" <Output");
199 ss.Write(" directory=\"{0}\"", Helper.EndPath(Helper.NormalizePath(".\\" + conf.Options["OutputPath"].ToString())));
200 ss.Write(" assembly=\"{0}\"", project.AssemblyName);
201 ss.Write(" executeScript=\"{0}\"", conf.Options["RunScript"]);
202 //ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]);
203 //ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]);
204 if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0)
205 {
206 ss.Write(" executeBeforeBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString()));
207 }
208 else
209 {
210 ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]);
211 }
212 if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0)
213 {
214 ss.Write(" executeAfterBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString()));
215 }
216 else
217 {
218 ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]);
219 }
220 ss.Write(" executeBeforeBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]);
221 ss.Write(" executeAfterBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]);
222 ss.WriteLine(" />");
223
224 ss.Write(" <Build");
225 ss.Write(" debugmode=\"True\"");
226 if (project.Type == ProjectType.WinExe)
227 {
228 ss.Write(" target=\"{0}\"", ProjectType.Exe.ToString());
229 }
230 else
231 {
232 ss.Write(" target=\"{0}\"", project.Type);
233 }
234 ss.WriteLine(" />");
235
236 ss.Write(" <Execution");
237 ss.Write(" runwithwarnings=\"{0}\"", !conf.Options.WarningsAsErrors);
238 ss.Write(" consolepause=\"True\"");
239 ss.Write(" runtime=\"{0}\"", netRuntime);
240 ss.Write(" clr-version=\"Net_2_0\"");
241 ss.WriteLine(" />");
242
243 ss.Write(" <CodeGeneration");
244 ss.Write(" compiler=\"{0}\"", csComp);
245 ss.Write(" warninglevel=\"{0}\"", conf.Options["WarningLevel"]);
246 ss.Write(" nowarn=\"{0}\"", conf.Options["SuppressWarnings"]);
247 ss.Write(" includedebuginformation=\"{0}\"", conf.Options["DebugInformation"]);
248 ss.Write(" optimize=\"{0}\"", conf.Options["OptimizeCode"]);
249 ss.Write(" unsafecodeallowed=\"{0}\"", conf.Options["AllowUnsafe"]);
250 ss.Write(" generateoverflowchecks=\"{0}\"", conf.Options["CheckUnderflowOverflow"]);
251 ss.Write(" mainclass=\"{0}\"", project.StartupObject);
252 ss.Write(" target=\"{0}\"", project.Type);
253 ss.Write(" definesymbols=\"{0}\"", conf.Options["CompilerDefines"]);
254 ss.Write(" generatexmldocumentation=\"{0}\"", GenerateXmlDocFile(project, conf));
255 ss.Write(" win32Icon=\"{0}\"", project.AppIcon);
256 ss.Write(" ctype=\"CSharpCompilerParameters\"");
257 ss.WriteLine(" />");
258 ss.WriteLine(" </Configuration>");
259
260 count++;
261 }
262 ss.WriteLine(" </Configurations>");
263
264 ss.Write(" <DeploymentInformation");
265 ss.Write(" target=\"\"");
266 ss.Write(" script=\"\"");
267 ss.Write(" strategy=\"File\"");
268 ss.WriteLine(">");
269 ss.WriteLine(" <excludeFiles />");
270 ss.WriteLine(" </DeploymentInformation>");
271
272 ss.WriteLine(" <Contents>");
273 foreach(string file in project.Files)
274 {
275 string buildAction;
276 string dependson = "";
277 string resource_id = "";
278 string copyToOutput = "";
279
280 switch(project.Files.GetBuildAction(file))
281 {
282 case BuildAction.None:
283 buildAction = "Nothing";
284 break;
285
286 case BuildAction.Content:
287 buildAction = "Exclude";
288 break;
289
290 case BuildAction.EmbeddedResource:
291 buildAction = "EmbedAsResource";
292 break;
293
294 default:
295 buildAction = "Compile";
296 break;
297 }
298
299 if (project.Files.GetCopyToOutput(file) != CopyToOutput.Never)
300 buildAction = "FileCopy";
301
302 // Sort of a hack, we try and resolve the path and make it relative, if we can.
303 string extension = Path.GetExtension(file);
304 string designer_format = string.Format(".Designer{0}", extension);
305
306 if (file.EndsWith(designer_format))
307 {
308 string basename = file.Substring(0, file.LastIndexOf(designer_format));
309 string[] extensions = new string[] { ".cs", ".resx", ".settings" };
310
311 foreach(string ext in extensions)
312 {
313 if (project.Files.Contains(basename + ext))
314 {
315 dependson = string.Format(" dependson=\"{0}{1}\"", basename, ext);
316 break;
317 }
318 }
319 }
320 if (extension == ".resx")
321 {
322 buildAction = "EmbedAsResource";
323 string basename = file.Substring(0, file.LastIndexOf(".resx"));
324
325 // Visual Studio type resx + form dependency
326 if (project.Files.Contains(basename + ".cs"))
327 {
328 dependson = string.Format(" dependson=\"{0}{1}\"", basename, ".cs");
329 }
330
331 // We need to specify a resources file name to avoid MissingManifestResourceExceptions
332 // in libraries that are built.
333 resource_id = string.Format(" resource_id=\"{0}.{1}.resources\"",
334 project.AssemblyName, basename.Replace("/", "."));
335 }
336
337 switch(project.Files.GetCopyToOutput(file))
338 {
339 case CopyToOutput.Always:
340 copyToOutput = string.Format(" copyToOutputDirectory=\"Always\"");
341 break;
342 case CopyToOutput.PreserveNewest:
343 copyToOutput = string.Format(" copyToOutputDirectory=\"PreserveNewest\"");
344 break;
345 }
346
347 // Sort of a hack, we try and resolve the path and make it relative, if we can.
348 string filePath = PrependPath(file);
349 ss.WriteLine(" <File name=\"{0}\" subtype=\"Code\" buildaction=\"{1}\"{2}{3}{4} />",
350 filePath, buildAction, dependson, resource_id, copyToOutput);
351 }
352 ss.WriteLine(" </Contents>");
353
354 ss.WriteLine(" <References>");
355 foreach(ReferenceNode refr in project.References)
356 {
357 ss.WriteLine(" {0}", BuildReference(solution, refr));
358 }
359 ss.WriteLine(" </References>");
360
361
362 ss.WriteLine("</Project>");
363 }
364
365 m_Kernel.CurrentWorkingDirectory.Pop();
366 }
367
368 private void WriteCombine(SolutionNode solution)
369 {
370 m_Kernel.Log.Write("Creating MonoDevelop combine and project files");
371 foreach(ProjectNode project in solution.Projects)
372 {
373 if(m_Kernel.AllowProject(project.FilterGroups))
374 {
375 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
376 WriteProject(solution, project);
377 }
378 }
379
380 m_Kernel.Log.Write("");
381 string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "mds");
382 StreamWriter ss = new StreamWriter(combFile);
383
384 m_Kernel.CurrentWorkingDirectory.Push();
385 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
386
387 int count = 0;
388
389 using(ss)
390 {
391 ss.WriteLine("<Combine name=\"{0}\" fileversion=\"2.0\" description=\"\">", solution.Name);
392
393 count = 0;
394 foreach(ConfigurationNode conf in solution.Configurations)
395 {
396 if(count == 0)
397 {
398 ss.WriteLine(" <Configurations active=\"{0}\">", conf.Name);
399 }
400
401 ss.WriteLine(" <Configuration name=\"{0}\" ctype=\"CombineConfiguration\">", conf.Name);
402 foreach(ProjectNode project in solution.Projects)
403 {
404 ss.WriteLine(" <Entry configuration=\"{1}\" build=\"True\" name=\"{0}\" />", project.Name, conf.Name);
405 }
406 ss.WriteLine(" </Configuration>");
407
408 count++;
409 }
410 ss.WriteLine(" </Configurations>");
411
412 count = 0;
413
414 foreach(ProjectNode project in solution.Projects)
415 {
416 if(count == 0)
417 ss.WriteLine(" <StartMode startupentry=\"{0}\" single=\"True\">", project.Name);
418
419 ss.WriteLine(" <Execute type=\"None\" entry=\"{0}\" />", project.Name);
420 count++;
421 }
422 ss.WriteLine(" </StartMode>");
423
424 ss.WriteLine(" <Entries>");
425 foreach(ProjectNode project in solution.Projects)
426 {
427 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
428 ss.WriteLine(" <Entry filename=\"{0}\" />",
429 Helper.MakeFilePath(path, project.Name, "mdp"));
430 }
431 ss.WriteLine(" </Entries>");
432
433 ss.WriteLine("</Combine>");
434 }
435
436 m_Kernel.CurrentWorkingDirectory.Pop();
437 }
438
439 private void CleanProject(ProjectNode project)
440 {
441 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
442 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "mdp");
443 Helper.DeleteIfExists(projectFile);
444 }
445
446 private void CleanSolution(SolutionNode solution)
447 {
448 m_Kernel.Log.Write("Cleaning MonoDevelop combine and project files for", solution.Name);
449
450 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "mds");
451 Helper.DeleteIfExists(slnFile);
452
453 foreach(ProjectNode project in solution.Projects)
454 {
455 CleanProject(project);
456 }
457
458 m_Kernel.Log.Write("");
459 }
460
461 #endregion
462
463 #region ITarget Members
464
465 /// <summary>
466 /// Writes the specified kern.
467 /// </summary>
468 /// <param name="kern">The kern.</param>
469 public void Write(Kernel kern)
470 {
471 if( kern == null )
472 {
473 throw new ArgumentNullException("kern");
474 }
475 m_Kernel = kern;
476 foreach(SolutionNode solution in kern.Solutions)
477 {
478 WriteCombine(solution);
479 }
480 m_Kernel = null;
481 }
482
483 /// <summary>
484 /// Cleans the specified kern.
485 /// </summary>
486 /// <param name="kern">The kern.</param>
487 public virtual void Clean(Kernel kern)
488 {
489 if( kern == null )
490 {
491 throw new ArgumentNullException("kern");
492 }
493 m_Kernel = kern;
494 foreach(SolutionNode sol in kern.Solutions)
495 {
496 CleanSolution(sol);
497 }
498 m_Kernel = null;
499 }
500
501 /// <summary>
502 /// Gets the name.
503 /// </summary>
504 /// <value>The name.</value>
505 public string Name
506 {
507 get
508 {
509 return "sharpdev";
510 }
511 }
512
513 #endregion
514 }
515}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/NAntTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/NAntTarget.cs.svn-base
new file mode 100644
index 0000000..1efc16d
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/NAntTarget.cs.svn-base
@@ -0,0 +1,776 @@
1#region BSD License
2/*
3Copyright (c) 2004 - 2008
4Matthew Holmes (matthew@wildfiregames.com),
5Dan Moorehead (dan05a@gmail.com),
6C.J. Adams-Collier (cjac@colliertech.org),
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are
10met:
11
12* Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15* Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18
19* The name of the author may not be used to endorse or promote
20 products derived from this software without specific prior written
21 permission.
22
23THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#endregion
37
38using System;
39using System.Collections.Generic;
40using System.IO;
41using System.Text.RegularExpressions;
42
43using Prebuild.Core.Attributes;
44using Prebuild.Core.Interfaces;
45using Prebuild.Core.Nodes;
46using Prebuild.Core.Utilities;
47
48namespace Prebuild.Core.Targets
49{
50 /// <summary>
51 ///
52 /// </summary>
53 [Target("nant")]
54 public class NAntTarget : ITarget
55 {
56 #region Fields
57
58 private Kernel m_Kernel;
59
60 #endregion
61
62 #region Private Methods
63
64 private static string PrependPath(string path)
65 {
66 string tmpPath = Helper.NormalizePath(path, '/');
67 Regex regex = new Regex(@"(\w):/(\w+)");
68 Match match = regex.Match(tmpPath);
69 //if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
70 //{
71 tmpPath = Helper.NormalizePath(tmpPath);
72 //}
73 // else
74 // {
75 // tmpPath = Helper.NormalizePath("./" + tmpPath);
76 // }
77
78 return tmpPath;
79 }
80
81 private static string BuildReference(SolutionNode solution, ProjectNode currentProject, ReferenceNode refr)
82 {
83
84 if (!String.IsNullOrEmpty(refr.Path))
85 {
86 return refr.Path;
87 }
88
89 if (solution.ProjectsTable.ContainsKey(refr.Name))
90 {
91 ProjectNode projectRef = (ProjectNode) solution.ProjectsTable[refr.Name];
92 string finalPath =
93 Helper.NormalizePath(refr.Name + GetProjectExtension(projectRef), '/');
94 return finalPath;
95 }
96
97 ProjectNode project = (ProjectNode) refr.Parent;
98
99 // Do we have an explicit file reference?
100 string fileRef = FindFileReference(refr.Name, project);
101 if (fileRef != null)
102 {
103 return fileRef;
104 }
105
106 // Is there an explicit path in the project ref?
107 if (refr.Path != null)
108 {
109 return Helper.NormalizePath(refr.Path + "/" + refr.Name + GetProjectExtension(project), '/');
110 }
111
112 // No, it's an extensionless GAC ref, but nant needs the .dll extension anyway
113 return refr.Name + ".dll";
114 }
115
116 public static string GetRefFileName(string refName)
117 {
118 if (ExtensionSpecified(refName))
119 {
120 return refName;
121 }
122 else
123 {
124 return refName + ".dll";
125 }
126 }
127
128 private static bool ExtensionSpecified(string refName)
129 {
130 return refName.EndsWith(".dll") || refName.EndsWith(".exe");
131 }
132
133 private static string GetProjectExtension(ProjectNode project)
134 {
135 string extension = ".dll";
136 if (project.Type == ProjectType.Exe || project.Type == ProjectType.WinExe)
137 {
138 extension = ".exe";
139 }
140 return extension;
141 }
142
143 private static string FindFileReference(string refName, ProjectNode project)
144 {
145 foreach (ReferencePathNode refPath in project.ReferencePaths)
146 {
147 string fullPath = Helper.MakeFilePath(refPath.Path, refName);
148
149 if (File.Exists(fullPath))
150 {
151 return fullPath;
152 }
153
154 fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
155
156 if (File.Exists(fullPath))
157 {
158 return fullPath;
159 }
160
161 fullPath = Helper.MakeFilePath(refPath.Path, refName, "exe");
162
163 if (File.Exists(fullPath))
164 {
165 return fullPath;
166 }
167 }
168
169 return null;
170 }
171
172 /// <summary>
173 /// Gets the XML doc file.
174 /// </summary>
175 /// <param name="project">The project.</param>
176 /// <param name="conf">The conf.</param>
177 /// <returns></returns>
178 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
179 {
180 if (conf == null)
181 {
182 throw new ArgumentNullException("conf");
183 }
184 if (project == null)
185 {
186 throw new ArgumentNullException("project");
187 }
188 string docFile = (string)conf.Options["XmlDocFile"];
189 // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
190 // {
191 // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
192 // }
193 return docFile;
194 }
195
196 private void WriteProject(SolutionNode solution, ProjectNode project)
197 {
198 string projFile = Helper.MakeFilePath(project.FullPath, project.Name + GetProjectExtension(project), "build");
199 StreamWriter ss = new StreamWriter(projFile);
200
201 m_Kernel.CurrentWorkingDirectory.Push();
202 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
203 bool hasDoc = false;
204
205 using (ss)
206 {
207 ss.WriteLine("<?xml version=\"1.0\" ?>");
208 ss.WriteLine("<project name=\"{0}\" default=\"build\">", project.Name);
209 ss.WriteLine(" <target name=\"{0}\">", "build");
210 ss.WriteLine(" <echo message=\"Build Directory is ${project::get-base-directory()}/${build.dir}\" />");
211 ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/${build.dir}\" />");
212 ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/${build.dir}\" flatten=\"true\">");
213 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
214 foreach (ReferenceNode refr in project.References)
215 {
216 if (refr.LocalCopy)
217 {
218 ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)) + "\" />", '/'));
219 }
220 }
221
222 ss.WriteLine(" </fileset>");
223 ss.WriteLine(" </copy>");
224 if (project.ConfigFile != null && project.ConfigFile.Length!=0)
225 {
226 ss.Write(" <copy file=\"" + project.ConfigFile + "\" tofile=\"${project::get-base-directory()}/${build.dir}/${project::get-name()}");
227
228 if (project.Type == ProjectType.Library)
229 {
230 ss.Write(".dll.config\"");
231 }
232 else
233 {
234 ss.Write(".exe.config\"");
235 }
236 ss.WriteLine(" />");
237 }
238
239 // Add the content files to just be copied
240 ss.WriteLine(" {0}", "<copy todir=\"${project::get-base-directory()}/${build.dir}\">");
241 ss.WriteLine(" {0}", "<fileset basedir=\".\">");
242
243 foreach (string file in project.Files)
244 {
245 // Ignore if we aren't content
246 if (project.Files.GetBuildAction(file) != BuildAction.Content)
247 continue;
248
249 // Create a include tag
250 ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
251 }
252
253 ss.WriteLine(" {0}", "</fileset>");
254 ss.WriteLine(" {0}", "</copy>");
255
256 ss.Write(" <csc ");
257 ss.Write(" target=\"{0}\"", project.Type.ToString().ToLower());
258 ss.Write(" debug=\"{0}\"", "${build.debug}");
259 ss.Write(" platform=\"${build.platform}\"");
260
261
262 foreach (ConfigurationNode conf in project.Configurations)
263 {
264 if (conf.Options.KeyFile != "")
265 {
266 ss.Write(" keyfile=\"{0}\"", conf.Options.KeyFile);
267 break;
268 }
269 }
270 foreach (ConfigurationNode conf in project.Configurations)
271 {
272 ss.Write(" unsafe=\"{0}\"", conf.Options.AllowUnsafe);
273 break;
274 }
275 foreach (ConfigurationNode conf in project.Configurations)
276 {
277 ss.Write(" warnaserror=\"{0}\"", conf.Options.WarningsAsErrors);
278 break;
279 }
280 foreach (ConfigurationNode conf in project.Configurations)
281 {
282 ss.Write(" define=\"{0}\"", conf.Options.CompilerDefines);
283 break;
284 }
285 foreach (ConfigurationNode conf in project.Configurations)
286 {
287 ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]);
288 break;
289 }
290
291 ss.Write(" main=\"{0}\"", project.StartupObject);
292
293 foreach (ConfigurationNode conf in project.Configurations)
294 {
295 if (GetXmlDocFile(project, conf) != "")
296 {
297 ss.Write(" doc=\"{0}\"", "${project::get-base-directory()}/${build.dir}/" + GetXmlDocFile(project, conf));
298 hasDoc = true;
299 }
300 break;
301 }
302 ss.Write(" output=\"{0}", "${project::get-base-directory()}/${build.dir}/${project::get-name()}");
303 if (project.Type == ProjectType.Library)
304 {
305 ss.Write(".dll\"");
306 }
307 else
308 {
309 ss.Write(".exe\"");
310 }
311 if (project.AppIcon != null && project.AppIcon.Length != 0)
312 {
313 ss.Write(" win32icon=\"{0}\"", Helper.NormalizePath(project.AppIcon, '/'));
314 }
315 // This disables a very different behavior between VS and NAnt. With Nant,
316 // If you have using System.Xml; it will ensure System.Xml.dll is referenced,
317 // but not in VS. This will force the behaviors to match, so when it works
318 // in nant, it will work in VS.
319 ss.Write(" noconfig=\"true\"");
320 ss.WriteLine(">");
321 ss.WriteLine(" <resources prefix=\"{0}\" dynamicprefix=\"true\" >", project.RootNamespace);
322 foreach (string file in project.Files)
323 {
324 switch (project.Files.GetBuildAction(file))
325 {
326 case BuildAction.EmbeddedResource:
327 ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
328 break;
329 default:
330 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
331 {
332 ss.WriteLine(" <include name=\"{0}\" />", file.Substring(0, file.LastIndexOf('.')) + ".resx");
333 }
334 break;
335 }
336 }
337 //if (project.Files.GetSubType(file).ToString() != "Code")
338 //{
339 // ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
340
341 ss.WriteLine(" </resources>");
342 ss.WriteLine(" <sources failonempty=\"true\">");
343 foreach (string file in project.Files)
344 {
345 switch (project.Files.GetBuildAction(file))
346 {
347 case BuildAction.Compile:
348 ss.WriteLine(" <include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
349 break;
350 default:
351 break;
352 }
353 }
354 ss.WriteLine(" </sources>");
355 ss.WriteLine(" <references basedir=\"${project::get-base-directory()}\">");
356 ss.WriteLine(" <lib>");
357 ss.WriteLine(" <include name=\"${project::get-base-directory()}\" />");
358 foreach(ReferencePathNode refPath in project.ReferencePaths)
359 {
360 ss.WriteLine(" <include name=\"${project::get-base-directory()}/" + refPath.Path.TrimEnd('/', '\\') + "\" />");
361 }
362 ss.WriteLine(" </lib>");
363 foreach (ReferenceNode refr in project.References)
364 {
365 string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)), '/');
366 if (refr.Path != null) {
367 if (ExtensionSpecified(refr.Name))
368 {
369 ss.WriteLine (" <include name=\"" + path + refr.Name + "\"/>");
370 }
371 else
372 {
373 ss.WriteLine (" <include name=\"" + path + refr.Name + ".dll\"/>");
374 }
375 }
376 else
377 {
378 ss.WriteLine (" <include name=\"" + path + "\" />");
379 }
380 }
381 ss.WriteLine(" </references>");
382
383 ss.WriteLine(" </csc>");
384
385 foreach (ConfigurationNode conf in project.Configurations)
386 {
387 if (!String.IsNullOrEmpty(conf.Options.OutputPath))
388 {
389 string targetDir = Helper.NormalizePath(conf.Options.OutputPath, '/');
390
391 ss.WriteLine(" <echo message=\"Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/" + targetDir + "\" />");
392
393 ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/" + targetDir + "\"/>");
394
395 ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/" + targetDir + "\">");
396 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}/${build.dir}/\" >");
397 ss.WriteLine(" <include name=\"*.dll\"/>");
398 ss.WriteLine(" <include name=\"*.exe\"/>");
399 ss.WriteLine(" <include name=\"*.mdb\" if='${build.debug}'/>");
400 ss.WriteLine(" <include name=\"*.pdb\" if='${build.debug}'/>");
401 ss.WriteLine(" </fileset>");
402 ss.WriteLine(" </copy>");
403 break;
404 }
405 }
406
407 ss.WriteLine(" </target>");
408
409 ss.WriteLine(" <target name=\"clean\">");
410 ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />");
411 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
412 ss.WriteLine(" </target>");
413
414 ss.WriteLine(" <target name=\"doc\" description=\"Creates documentation.\">");
415 if (hasDoc)
416 {
417 ss.WriteLine(" <property name=\"doc.target\" value=\"\" />");
418 ss.WriteLine(" <if test=\"${platform::is-unix()}\">");
419 ss.WriteLine(" <property name=\"doc.target\" value=\"Web\" />");
420 ss.WriteLine(" </if>");
421 ss.WriteLine(" <ndoc failonerror=\"false\" verbose=\"true\">");
422 ss.WriteLine(" <assemblies basedir=\"${project::get-base-directory()}\">");
423 ss.Write(" <include name=\"${build.dir}/${project::get-name()}");
424 if (project.Type == ProjectType.Library)
425 {
426 ss.WriteLine(".dll\" />");
427 }
428 else
429 {
430 ss.WriteLine(".exe\" />");
431 }
432
433 ss.WriteLine(" </assemblies>");
434 ss.WriteLine(" <summaries basedir=\"${project::get-base-directory()}\">");
435 ss.WriteLine(" <include name=\"${build.dir}/${project::get-name()}.xml\"/>");
436 ss.WriteLine(" </summaries>");
437 ss.WriteLine(" <referencepaths basedir=\"${project::get-base-directory()}\">");
438 ss.WriteLine(" <include name=\"${build.dir}\" />");
439 // foreach(ReferenceNode refr in project.References)
440 // {
441 // string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReferencePath(solution, refr)), '/');
442 // if (path != "")
443 // {
444 // ss.WriteLine(" <include name=\"{0}\" />", path);
445 // }
446 // }
447 ss.WriteLine(" </referencepaths>");
448 ss.WriteLine(" <documenters>");
449 ss.WriteLine(" <documenter name=\"MSDN\">");
450 ss.WriteLine(" <property name=\"OutputDirectory\" value=\"${project::get-base-directory()}/${build.dir}/doc/${project::get-name()}\" />");
451 ss.WriteLine(" <property name=\"OutputTarget\" value=\"${doc.target}\" />");
452 ss.WriteLine(" <property name=\"HtmlHelpName\" value=\"${project::get-name()}\" />");
453 ss.WriteLine(" <property name=\"IncludeFavorites\" value=\"False\" />");
454 ss.WriteLine(" <property name=\"Title\" value=\"${project::get-name()} SDK Documentation\" />");
455 ss.WriteLine(" <property name=\"SplitTOCs\" value=\"False\" />");
456 ss.WriteLine(" <property name=\"DefaulTOC\" value=\"\" />");
457 ss.WriteLine(" <property name=\"ShowVisualBasic\" value=\"True\" />");
458 ss.WriteLine(" <property name=\"AutoDocumentConstructors\" value=\"True\" />");
459 ss.WriteLine(" <property name=\"ShowMissingSummaries\" value=\"${build.debug}\" />");
460 ss.WriteLine(" <property name=\"ShowMissingRemarks\" value=\"${build.debug}\" />");
461 ss.WriteLine(" <property name=\"ShowMissingParams\" value=\"${build.debug}\" />");
462 ss.WriteLine(" <property name=\"ShowMissingReturns\" value=\"${build.debug}\" />");
463 ss.WriteLine(" <property name=\"ShowMissingValues\" value=\"${build.debug}\" />");
464 ss.WriteLine(" <property name=\"DocumentInternals\" value=\"False\" />");
465 ss.WriteLine(" <property name=\"DocumentPrivates\" value=\"False\" />");
466 ss.WriteLine(" <property name=\"DocumentProtected\" value=\"True\" />");
467 ss.WriteLine(" <property name=\"DocumentEmptyNamespaces\" value=\"${build.debug}\" />");
468 ss.WriteLine(" <property name=\"IncludeAssemblyVersion\" value=\"True\" />");
469 ss.WriteLine(" </documenter>");
470 ss.WriteLine(" </documenters>");
471 ss.WriteLine(" </ndoc>");
472 }
473 ss.WriteLine(" </target>");
474 ss.WriteLine("</project>");
475 }
476 m_Kernel.CurrentWorkingDirectory.Pop();
477 }
478
479 private void WriteCombine(SolutionNode solution)
480 {
481 m_Kernel.Log.Write("Creating NAnt build files");
482 foreach (ProjectNode project in solution.Projects)
483 {
484 if (m_Kernel.AllowProject(project.FilterGroups))
485 {
486 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
487 WriteProject(solution, project);
488 }
489 }
490
491 m_Kernel.Log.Write("");
492 string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
493 StreamWriter ss = new StreamWriter(combFile);
494
495 m_Kernel.CurrentWorkingDirectory.Push();
496 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
497
498 using (ss)
499 {
500 ss.WriteLine("<?xml version=\"1.0\" ?>");
501 ss.WriteLine("<project name=\"{0}\" default=\"build\">", solution.Name);
502 ss.WriteLine(" <echo message=\"Using '${nant.settings.currentframework}' Framework\"/>");
503 ss.WriteLine();
504
505 //ss.WriteLine(" <property name=\"dist.dir\" value=\"dist\" />");
506 //ss.WriteLine(" <property name=\"source.dir\" value=\"source\" />");
507 ss.WriteLine(" <property name=\"bin.dir\" value=\"bin\" />");
508 ss.WriteLine(" <property name=\"obj.dir\" value=\"obj\" />");
509 ss.WriteLine(" <property name=\"doc.dir\" value=\"doc\" />");
510 ss.WriteLine(" <property name=\"project.main.dir\" value=\"${project::get-base-directory()}\" />");
511
512 // Use the active configuration, which is the first configuration name in the prebuild file.
513 Dictionary<string,string> emittedConfigurations = new Dictionary<string, string>();
514
515 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", solution.ActiveConfig);
516 ss.WriteLine();
517
518 foreach (ConfigurationNode conf in solution.Configurations)
519 {
520 // If the name isn't in the emitted configurations, we give a high level target to the
521 // platform specific on. This lets "Debug" point to "Debug-AnyCPU".
522 if (!emittedConfigurations.ContainsKey(conf.Name))
523 {
524 // Add it to the dictionary so we only emit one.
525 emittedConfigurations.Add(conf.Name, conf.Platform);
526
527 // Write out the target block.
528 ss.WriteLine(" <target name=\"{0}\" description=\"{0}|{1}\" depends=\"{0}-{1}\">", conf.Name, conf.Platform);
529 ss.WriteLine(" </target>");
530 ss.WriteLine();
531 }
532
533 // Write out the target for the configuration.
534 ss.WriteLine(" <target name=\"{0}-{1}\" description=\"{0}|{1}\">", conf.Name, conf.Platform);
535 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name);
536 ss.WriteLine(" <property name=\"build.debug\" value=\"{0}\" />", conf.Options["DebugInformation"].ToString().ToLower());
537 ss.WriteLine("\t\t <property name=\"build.platform\" value=\"{0}\" />", conf.Platform);
538 ss.WriteLine(" </target>");
539 ss.WriteLine();
540 }
541
542 ss.WriteLine(" <target name=\"net-1.1\" description=\"Sets framework to .NET 1.1\">");
543 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-1.1\" />");
544 ss.WriteLine(" </target>");
545 ss.WriteLine();
546
547 ss.WriteLine(" <target name=\"net-2.0\" description=\"Sets framework to .NET 2.0\">");
548 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-2.0\" />");
549 ss.WriteLine(" </target>");
550 ss.WriteLine();
551
552 ss.WriteLine(" <target name=\"net-3.5\" description=\"Sets framework to .NET 3.5\">");
553 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-3.5\" />");
554 ss.WriteLine(" </target>");
555 ss.WriteLine();
556
557 ss.WriteLine(" <target name=\"mono-1.0\" description=\"Sets framework to mono 1.0\">");
558 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-1.0\" />");
559 ss.WriteLine(" </target>");
560 ss.WriteLine();
561
562 ss.WriteLine(" <target name=\"mono-2.0\" description=\"Sets framework to mono 2.0\">");
563 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-2.0\" />");
564 ss.WriteLine(" </target>");
565 ss.WriteLine();
566
567 ss.WriteLine(" <target name=\"mono-3.5\" description=\"Sets framework to mono 3.5\">");
568 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-3.5\" />");
569 ss.WriteLine(" </target>");
570 ss.WriteLine();
571
572 ss.WriteLine(" <target name=\"init\" description=\"\">");
573 ss.WriteLine(" <call target=\"${project.config}\" />");
574 ss.WriteLine(" <property name=\"sys.os.platform\"");
575 ss.WriteLine(" value=\"${platform::get-name()}\"");
576 ss.WriteLine(" />");
577 ss.WriteLine(" <echo message=\"Platform ${sys.os.platform}\" />");
578 ss.WriteLine(" <property name=\"build.dir\" value=\"${bin.dir}/${project.config}\" />");
579 ss.WriteLine(" </target>");
580 ss.WriteLine();
581
582
583 // sdague - ok, this is an ugly hack, but what it lets
584 // us do is native include of files into the nant
585 // created files from all .nant/*include files. This
586 // lets us keep using prebuild, but allows for
587 // extended nant targets to do build and the like.
588
589 try
590 {
591 Regex re = new Regex(".include$");
592 DirectoryInfo nantdir = new DirectoryInfo(".nant");
593 foreach (FileSystemInfo item in nantdir.GetFileSystemInfos())
594 {
595 if (item is DirectoryInfo) { }
596 else if (item is FileInfo)
597 {
598 if (re.Match(item.FullName) !=
599 System.Text.RegularExpressions.Match.Empty)
600 {
601 Console.WriteLine("Including file: " + item.FullName);
602
603 using (FileStream fs = new FileStream(item.FullName,
604 FileMode.Open,
605 FileAccess.Read,
606 FileShare.None))
607 {
608 using (StreamReader sr = new StreamReader(fs))
609 {
610 ss.WriteLine("<!-- included from {0} -->", (item).FullName);
611 while (sr.Peek() != -1)
612 {
613 ss.WriteLine(sr.ReadLine());
614 }
615 ss.WriteLine();
616 }
617 }
618 }
619 }
620 }
621 }
622 catch { }
623 // ss.WriteLine(" <include buildfile=\".nant/local.include\" />");
624 // ss.WriteLine(" <target name=\"zip\" description=\"\">");
625 // ss.WriteLine(" <zip zipfile=\"{0}-{1}.zip\">", solution.Name, solution.Version);
626 // ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
627
628 // ss.WriteLine(" <include name=\"${project::get-base-directory()}/**/*.cs\" />");
629 // // ss.WriteLine(" <include name=\"${project.main.dir}/**/*\" />");
630 // ss.WriteLine(" </fileset>");
631 // ss.WriteLine(" </zip>");
632 // ss.WriteLine(" <echo message=\"Building zip target\" />");
633 // ss.WriteLine(" </target>");
634 ss.WriteLine();
635
636
637 ss.WriteLine(" <target name=\"clean\" description=\"\">");
638 ss.WriteLine(" <echo message=\"Deleting all builds from all configurations\" />");
639 //ss.WriteLine(" <delete dir=\"${dist.dir}\" failonerror=\"false\" />");
640 if (solution.Cleanup != null && solution.Cleanup.CleanFiles.Count > 0)
641 {
642 foreach (CleanFilesNode cleanFile in solution.Cleanup.CleanFiles)
643 {
644 ss.WriteLine(" <delete failonerror=\"false\">");
645 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
646 ss.WriteLine(" <include name=\"{0}/*\"/>", cleanFile.Pattern);
647 ss.WriteLine(" <include name=\"{0}\"/>", cleanFile.Pattern);
648 ss.WriteLine(" </fileset>");
649 ss.WriteLine(" </delete>");
650 }
651 }
652 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
653 foreach (ProjectNode project in solution.Projects)
654 {
655 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
656 ss.Write(" <nant buildfile=\"{0}\"",
657 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
658 ss.WriteLine(" target=\"clean\" />");
659 }
660 ss.WriteLine(" </target>");
661 ss.WriteLine();
662
663 ss.WriteLine(" <target name=\"build\" depends=\"init\" description=\"\">");
664
665 foreach (ProjectNode project in solution.ProjectsTableOrder)
666 {
667 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
668 ss.Write(" <nant buildfile=\"{0}\"",
669 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
670 ss.WriteLine(" target=\"build\" />");
671 }
672 ss.WriteLine(" </target>");
673 ss.WriteLine();
674
675 ss.WriteLine(" <target name=\"build-release\" depends=\"Release, init, build\" description=\"Builds in Release mode\" />");
676 ss.WriteLine();
677 ss.WriteLine(" <target name=\"build-debug\" depends=\"Debug, init, build\" description=\"Builds in Debug mode\" />");
678 ss.WriteLine();
679 //ss.WriteLine(" <target name=\"package\" depends=\"clean, doc, copyfiles, zip\" description=\"Builds in Release mode\" />");
680 ss.WriteLine(" <target name=\"package\" depends=\"clean, doc\" description=\"Builds all\" />");
681 ss.WriteLine();
682
683 ss.WriteLine(" <target name=\"doc\" depends=\"build-release\">");
684 ss.WriteLine(" <echo message=\"Generating all documentation from all builds\" />");
685 foreach (ProjectNode project in solution.Projects)
686 {
687 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
688 ss.Write(" <nant buildfile=\"{0}\"",
689 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
690 ss.WriteLine(" target=\"doc\" />");
691 }
692 ss.WriteLine(" </target>");
693 ss.WriteLine();
694 ss.WriteLine("</project>");
695 }
696
697 m_Kernel.CurrentWorkingDirectory.Pop();
698 }
699
700 private void CleanProject(ProjectNode project)
701 {
702 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
703 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name + GetProjectExtension(project), "build");
704 Helper.DeleteIfExists(projectFile);
705 }
706
707 private void CleanSolution(SolutionNode solution)
708 {
709 m_Kernel.Log.Write("Cleaning NAnt build files for", solution.Name);
710
711 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
712 Helper.DeleteIfExists(slnFile);
713
714 foreach (ProjectNode project in solution.Projects)
715 {
716 CleanProject(project);
717 }
718
719 m_Kernel.Log.Write("");
720 }
721
722 #endregion
723
724 #region ITarget Members
725
726 /// <summary>
727 /// Writes the specified kern.
728 /// </summary>
729 /// <param name="kern">The kern.</param>
730 public void Write(Kernel kern)
731 {
732 if (kern == null)
733 {
734 throw new ArgumentNullException("kern");
735 }
736 m_Kernel = kern;
737 foreach (SolutionNode solution in kern.Solutions)
738 {
739 WriteCombine(solution);
740 }
741 m_Kernel = null;
742 }
743
744 /// <summary>
745 /// Cleans the specified kern.
746 /// </summary>
747 /// <param name="kern">The kern.</param>
748 public virtual void Clean(Kernel kern)
749 {
750 if (kern == null)
751 {
752 throw new ArgumentNullException("kern");
753 }
754 m_Kernel = kern;
755 foreach (SolutionNode sol in kern.Solutions)
756 {
757 CleanSolution(sol);
758 }
759 m_Kernel = null;
760 }
761
762 /// <summary>
763 /// Gets the name.
764 /// </summary>
765 /// <value>The name.</value>
766 public string Name
767 {
768 get
769 {
770 return "nant";
771 }
772 }
773
774 #endregion
775 }
776}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/SharpDevelop2Target.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/SharpDevelop2Target.cs.svn-base
new file mode 100644
index 0000000..66dd1bc
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/SharpDevelop2Target.cs.svn-base
@@ -0,0 +1,82 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27
28using Prebuild.Core.Attributes;
29
30namespace Prebuild.Core.Targets
31{
32 /// <summary>
33 ///
34 /// </summary>
35 [Target("sharpdev2")]
36 public class SharpDevelop2Target : VS2005Target
37 {
38 #region Properties
39 public override string VersionName
40 {
41 get
42 {
43 return "SharpDevelop2";
44 }
45 }
46 #endregion
47
48 #region Public Methods
49
50 /// <summary>
51 /// Writes the specified kern.
52 /// </summary>
53 /// <param name="kern">The kern.</param>
54 public override void Write(Kernel kern)
55 {
56 base.Write(kern);
57 }
58
59 /// <summary>
60 /// Cleans the specified kern.
61 /// </summary>
62 /// <param name="kern">The kern.</param>
63 public override void Clean(Kernel kern)
64 {
65 base.Clean(kern);
66 }
67
68 /// <summary>
69 /// Gets the name.
70 /// </summary>
71 /// <value>The name.</value>
72 public override string Name
73 {
74 get
75 {
76 return "sharpdev2";
77 }
78 }
79
80 #endregion
81 }
82}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/SharpDevelopTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/SharpDevelopTarget.cs.svn-base
new file mode 100644
index 0000000..8e32050
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/SharpDevelopTarget.cs.svn-base
@@ -0,0 +1,425 @@
1#region BSD License
2/*
3Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Text.RegularExpressions;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using Prebuild.Core.Nodes;
33using Prebuild.Core.Utilities;
34
35namespace Prebuild.Core.Targets
36{
37 /// <summary>
38 ///
39 /// </summary>
40 [Target("sharpdev")]
41 public class SharpDevelopTarget : ITarget
42 {
43 #region Fields
44
45 private Kernel m_Kernel;
46
47 #endregion
48
49 #region Private Methods
50
51 private static string PrependPath(string path)
52 {
53 string tmpPath = Helper.NormalizePath(path, '/');
54 Regex regex = new Regex(@"(\w):/(\w+)");
55 Match match = regex.Match(tmpPath);
56 if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
57 {
58 tmpPath = Helper.NormalizePath(tmpPath);
59 }
60 else
61 {
62 tmpPath = Helper.NormalizePath("./" + tmpPath);
63 }
64
65 return tmpPath;
66 }
67
68 private static string BuildReference(SolutionNode solution, ReferenceNode refr)
69 {
70 string ret = "<Reference type=\"";
71 if(solution.ProjectsTable.ContainsKey(refr.Name))
72 {
73 ret += "Project\" refto=\"" + refr.Name;
74 ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />";
75 }
76 else
77 {
78 ProjectNode project = (ProjectNode)refr.Parent;
79 string fileRef = FindFileReference(refr.Name, project);
80
81 if(refr.Path != null || fileRef != null)
82 {
83 ret += "Assembly\" refto=\"";
84
85 string finalPath = (refr.Path != null) ? Helper.MakeFilePath(refr.Path, refr.Name, "dll") : fileRef;
86
87 ret += finalPath;
88 ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />";
89 return ret;
90 }
91
92 ret += "Gac\" refto=\"";
93 try
94 {
95 //Assembly assem = Assembly.Load(refr.Name);
96 ret += refr.Name;// assem.FullName;
97 }
98 catch (System.NullReferenceException e)
99 {
100 e.ToString();
101 ret += refr.Name;
102 }
103 ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />";
104 }
105
106 return ret;
107 }
108
109 private static string FindFileReference(string refName, ProjectNode project)
110 {
111 foreach(ReferencePathNode refPath in project.ReferencePaths)
112 {
113 string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
114
115 if(File.Exists(fullPath))
116 {
117 return fullPath;
118 }
119 }
120
121 return null;
122 }
123
124 /// <summary>
125 /// Gets the XML doc file.
126 /// </summary>
127 /// <param name="project">The project.</param>
128 /// <param name="conf">The conf.</param>
129 /// <returns></returns>
130 public static string GenerateXmlDocFile(ProjectNode project, ConfigurationNode conf)
131 {
132 if( conf == null )
133 {
134 throw new ArgumentNullException("conf");
135 }
136 if( project == null )
137 {
138 throw new ArgumentNullException("project");
139 }
140 string docFile = (string)conf.Options["XmlDocFile"];
141 if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
142 {
143 return "False";
144 }
145 return "True";
146 }
147
148 private void WriteProject(SolutionNode solution, ProjectNode project)
149 {
150 string csComp = "Csc";
151 string netRuntime = "MsNet";
152 if(project.Runtime == ClrRuntime.Mono)
153 {
154 csComp = "Mcs";
155 netRuntime = "Mono";
156 }
157
158 string projFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx");
159 StreamWriter ss = new StreamWriter(projFile);
160
161 m_Kernel.CurrentWorkingDirectory.Push();
162 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
163
164 using(ss)
165 {
166 ss.WriteLine(
167 "<Project name=\"{0}\" standardNamespace=\"{1}\" description=\"\" newfilesearch=\"None\" enableviewstate=\"True\" version=\"1.1\" projecttype=\"C#\">",
168 project.Name,
169 project.RootNamespace
170 );
171
172 ss.WriteLine(" <Contents>");
173 foreach(string file in project.Files)
174 {
175 string buildAction = "Compile";
176 switch(project.Files.GetBuildAction(file))
177 {
178 case BuildAction.None:
179 buildAction = "Nothing";
180 break;
181
182 case BuildAction.Content:
183 buildAction = "Exclude";
184 break;
185
186 case BuildAction.EmbeddedResource:
187 buildAction = "EmbedAsResource";
188 break;
189
190 default:
191 buildAction = "Compile";
192 break;
193 }
194
195 // Sort of a hack, we try and resolve the path and make it relative, if we can.
196 string filePath = PrependPath(file);
197 ss.WriteLine(" <File name=\"{0}\" subtype=\"Code\" buildaction=\"{1}\" dependson=\"\" data=\"\" />", filePath, buildAction);
198 }
199 ss.WriteLine(" </Contents>");
200
201 ss.WriteLine(" <References>");
202 foreach(ReferenceNode refr in project.References)
203 {
204 ss.WriteLine(" {0}", BuildReference(solution, refr));
205 }
206 ss.WriteLine(" </References>");
207
208 ss.Write(" <DeploymentInformation");
209 ss.Write(" target=\"\"");
210 ss.Write(" script=\"\"");
211 ss.Write(" strategy=\"File\"");
212 ss.WriteLine(" />");
213
214 int count = 0;
215
216 ss.WriteLine(" <Configurations active=\"{0}\">", solution.ActiveConfig);
217
218 foreach(ConfigurationNode conf in project.Configurations)
219 {
220 ss.Write(" <Configuration");
221 ss.Write(" runwithwarnings=\"True\"");
222 ss.Write(" name=\"{0}\"", conf.Name);
223 ss.WriteLine(">");
224 ss.Write(" <CodeGeneration");
225 ss.Write(" runtime=\"{0}\"", netRuntime);
226 ss.Write(" compiler=\"{0}\"", csComp);
227 ss.Write(" compilerversion=\"\"");
228 ss.Write(" warninglevel=\"{0}\"", conf.Options["WarningLevel"]);
229 ss.Write(" nowarn=\"{0}\"", conf.Options["SuppressWarnings"]);
230 ss.Write(" includedebuginformation=\"{0}\"", conf.Options["DebugInformation"]);
231 ss.Write(" optimize=\"{0}\"", conf.Options["OptimizeCode"]);
232 ss.Write(" unsafecodeallowed=\"{0}\"", conf.Options["AllowUnsafe"]);
233 ss.Write(" generateoverflowchecks=\"{0}\"", conf.Options["CheckUnderflowOverflow"]);
234 ss.Write(" mainclass=\"{0}\"", project.StartupObject);
235 ss.Write(" target=\"{0}\"", project.Type);
236 ss.Write(" definesymbols=\"{0}\"", conf.Options["CompilerDefines"]);
237 ss.Write(" generatexmldocumentation=\"{0}\"", GenerateXmlDocFile(project, conf));
238 ss.Write(" win32Icon=\"{0}\"", Helper.NormalizePath(".\\" + project.AppIcon));
239 ss.Write(" noconfig=\"{0}\"", "False");
240 ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]);
241 ss.WriteLine(" />");
242
243 ss.Write(" <Execution");
244 ss.Write(" commandlineparameters=\"\"");
245 ss.Write(" consolepause=\"True\"");
246 ss.WriteLine(" />");
247
248 ss.Write(" <Output");
249 ss.Write(" directory=\".\\{0}\"", Helper.NormalizePath(conf.Options["OutputPath"].ToString()));
250 ss.Write(" assembly=\"{0}\"", project.AssemblyName);
251 ss.Write(" executeScript=\"{0}\"", conf.Options["RunScript"]);
252 if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0)
253 {
254 ss.Write(" executeBeforeBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString()));
255 }
256 else
257 {
258 ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]);
259 }
260 if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0)
261 {
262 ss.Write(" executeAfterBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString()));
263 }
264 else
265 {
266 ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]);
267 }
268 ss.Write(" executeBeforeBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]);
269 ss.Write(" executeAfterBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]);
270 ss.WriteLine(" />");
271 ss.WriteLine(" </Configuration>");
272
273 count++;
274 }
275 ss.WriteLine(" </Configurations>");
276 ss.WriteLine("</Project>");
277 }
278
279 m_Kernel.CurrentWorkingDirectory.Pop();
280 }
281
282 private void WriteCombine(SolutionNode solution)
283 {
284 m_Kernel.Log.Write("Creating SharpDevelop combine and project files");
285 foreach(ProjectNode project in solution.Projects)
286 {
287 if(m_Kernel.AllowProject(project.FilterGroups))
288 {
289 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
290 WriteProject(solution, project);
291 }
292 }
293
294 m_Kernel.Log.Write("");
295 string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx");
296 StreamWriter ss = new StreamWriter(combFile);
297
298 m_Kernel.CurrentWorkingDirectory.Push();
299 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
300
301 using(ss)
302 {
303 ss.WriteLine("<Combine fileversion=\"1.0\" name=\"{0}\" description=\"\">", solution.Name);
304
305 int count = 0;
306 foreach(ProjectNode project in solution.Projects)
307 {
308 if(count == 0)
309 ss.WriteLine(" <StartMode startupentry=\"{0}\" single=\"True\">", project.Name);
310
311 ss.WriteLine(" <Execute entry=\"{0}\" type=\"None\" />", project.Name);
312 count++;
313 }
314 ss.WriteLine(" </StartMode>");
315
316 ss.WriteLine(" <Entries>");
317 foreach(ProjectNode project in solution.Projects)
318 {
319 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
320 ss.WriteLine(" <Entry filename=\"{0}\" />",
321 Helper.MakeFilePath(path, project.Name, "prjx"));
322 }
323 ss.WriteLine(" </Entries>");
324
325 count = 0;
326 foreach(ConfigurationNode conf in solution.Configurations)
327 {
328 if(count == 0)
329 {
330 ss.WriteLine(" <Configurations active=\"{0}\">", conf.Name);
331 }
332
333 ss.WriteLine(" <Configuration name=\"{0}\">", conf.Name);
334 foreach(ProjectNode project in solution.Projects)
335 {
336 ss.WriteLine(" <Entry name=\"{0}\" configurationname=\"{1}\" build=\"True\" />", project.Name, conf.Name);
337 }
338 ss.WriteLine(" </Configuration>");
339
340 count++;
341 }
342 ss.WriteLine(" </Configurations>");
343 ss.WriteLine("</Combine>");
344 }
345
346 m_Kernel.CurrentWorkingDirectory.Pop();
347 }
348
349 private void CleanProject(ProjectNode project)
350 {
351 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
352 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx");
353 Helper.DeleteIfExists(projectFile);
354 }
355
356 private void CleanSolution(SolutionNode solution)
357 {
358 m_Kernel.Log.Write("Cleaning SharpDevelop combine and project files for", solution.Name);
359
360 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx");
361 Helper.DeleteIfExists(slnFile);
362
363 foreach(ProjectNode project in solution.Projects)
364 {
365 CleanProject(project);
366 }
367
368 m_Kernel.Log.Write("");
369 }
370
371 #endregion
372
373 #region ITarget Members
374
375 /// <summary>
376 /// Writes the specified kern.
377 /// </summary>
378 /// <param name="kern">The kern.</param>
379 public void Write(Kernel kern)
380 {
381 if( kern == null )
382 {
383 throw new ArgumentNullException("kern");
384 }
385 m_Kernel = kern;
386 foreach(SolutionNode solution in kern.Solutions)
387 {
388 WriteCombine(solution);
389 }
390 m_Kernel = null;
391 }
392
393 /// <summary>
394 /// Cleans the specified kern.
395 /// </summary>
396 /// <param name="kern">The kern.</param>
397 public virtual void Clean(Kernel kern)
398 {
399 if( kern == null )
400 {
401 throw new ArgumentNullException("kern");
402 }
403 m_Kernel = kern;
404 foreach(SolutionNode sol in kern.Solutions)
405 {
406 CleanSolution(sol);
407 }
408 m_Kernel = null;
409 }
410
411 /// <summary>
412 /// Gets the name.
413 /// </summary>
414 /// <value>The name.</value>
415 public string Name
416 {
417 get
418 {
419 return "sharpdev";
420 }
421 }
422
423 #endregion
424 }
425}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/ToolInfo.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/ToolInfo.cs.svn-base
new file mode 100644
index 0000000..935c674
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/ToolInfo.cs.svn-base
@@ -0,0 +1,197 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Prebuild.Core.Targets
6{
7 /// <summary>
8 ///
9 /// </summary>
10 public struct ToolInfo
11 {
12 string name;
13 string guid;
14 string fileExtension;
15 string xmlTag;
16 string importProject;
17
18 /// <summary>
19 /// Gets or sets the name.
20 /// </summary>
21 /// <value>The name.</value>
22 public string Name
23 {
24 get
25 {
26 return name;
27 }
28 set
29 {
30 name = value;
31 }
32 }
33
34 /// <summary>
35 /// Gets or sets the GUID.
36 /// </summary>
37 /// <value>The GUID.</value>
38 public string Guid
39 {
40 get
41 {
42 return guid;
43 }
44 set
45 {
46 guid = value;
47 }
48 }
49
50 /// <summary>
51 /// Gets or sets the file extension.
52 /// </summary>
53 /// <value>The file extension.</value>
54 public string FileExtension
55 {
56 get
57 {
58 return fileExtension;
59 }
60 set
61 {
62 fileExtension = value;
63 }
64 }
65 public string LanguageExtension
66 {
67 get
68 {
69 switch (this.Name)
70 {
71 case "C#":
72 return ".cs";
73 case "VisualBasic":
74 return ".vb";
75 case "Boo":
76 return ".boo";
77 default:
78 return ".cs";
79 }
80 }
81 }
82 /// <summary>
83 /// Gets or sets the XML tag.
84 /// </summary>
85 /// <value>The XML tag.</value>
86 public string XmlTag
87 {
88 get
89 {
90 return xmlTag;
91 }
92 set
93 {
94 xmlTag = value;
95 }
96 }
97
98 /// <summary>
99 /// Gets or sets the import project property.
100 /// </summary>
101 /// <value>The ImportProject tag.</value>
102 public string ImportProject
103 {
104 get
105 {
106 return importProject;
107 }
108 set
109 {
110 importProject = value;
111 }
112 }
113
114 /// <summary>
115 /// Initializes a new instance of the <see cref="ToolInfo"/> class.
116 /// </summary>
117 /// <param name="name">The name.</param>
118 /// <param name="guid">The GUID.</param>
119 /// <param name="fileExtension">The file extension.</param>
120 /// <param name="xml">The XML.</param>
121 /// <param name="importProject">The import project.</param>
122 public ToolInfo(string name, string guid, string fileExtension, string xml, string importProject)
123 {
124 this.name = name;
125 this.guid = guid;
126 this.fileExtension = fileExtension;
127 this.xmlTag = xml;
128 this.importProject = importProject;
129 }
130
131 /// <summary>
132 /// Initializes a new instance of the <see cref="ToolInfo"/> class.
133 /// </summary>
134 /// <param name="name">The name.</param>
135 /// <param name="guid">The GUID.</param>
136 /// <param name="fileExtension">The file extension.</param>
137 /// <param name="xml">The XML.</param>
138 public ToolInfo(string name, string guid, string fileExtension, string xml)
139 {
140 this.name = name;
141 this.guid = guid;
142 this.fileExtension = fileExtension;
143 this.xmlTag = xml;
144 this.importProject = "$(MSBuildBinPath)\\Microsoft." + xml + ".Targets";
145 }
146
147 /// <summary>
148 /// Equals operator
149 /// </summary>
150 /// <param name="obj">ToolInfo to compare</param>
151 /// <returns>true if toolInfos are equal</returns>
152 public override bool Equals(object obj)
153 {
154 if (obj == null)
155 {
156 throw new ArgumentNullException("obj");
157 }
158 if (obj.GetType() != typeof(ToolInfo))
159 return false;
160
161 ToolInfo c = (ToolInfo)obj;
162 return ((this.name == c.name) && (this.guid == c.guid) && (this.fileExtension == c.fileExtension) && (this.importProject == c.importProject));
163 }
164
165 /// <summary>
166 /// Equals operator
167 /// </summary>
168 /// <param name="c1">ToolInfo to compare</param>
169 /// <param name="c2">ToolInfo to compare</param>
170 /// <returns>True if toolInfos are equal</returns>
171 public static bool operator ==(ToolInfo c1, ToolInfo c2)
172 {
173 return ((c1.name == c2.name) && (c1.guid == c2.guid) && (c1.fileExtension == c2.fileExtension) && (c1.importProject == c2.importProject) && (c1.xmlTag == c2.xmlTag));
174 }
175
176 /// <summary>
177 /// Not equals operator
178 /// </summary>
179 /// <param name="c1">ToolInfo to compare</param>
180 /// <param name="c2">ToolInfo to compare</param>
181 /// <returns>True if toolInfos are not equal</returns>
182 public static bool operator !=(ToolInfo c1, ToolInfo c2)
183 {
184 return !(c1 == c2);
185 }
186
187 /// <summary>
188 /// Hash Code
189 /// </summary>
190 /// <returns>Hash code</returns>
191 public override int GetHashCode()
192 {
193 return name.GetHashCode() ^ guid.GetHashCode() ^ this.fileExtension.GetHashCode() ^ this.importProject.GetHashCode() ^ this.xmlTag.GetHashCode();
194
195 }
196 }
197}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/VS2002Target.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/VS2002Target.cs.svn-base
new file mode 100644
index 0000000..2292624
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/VS2002Target.cs.svn-base
@@ -0,0 +1,87 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27
28using Prebuild.Core.Attributes;
29
30namespace Prebuild.Core.Targets
31{
32 /// <summary>
33 ///
34 /// </summary>
35 [Target("vs2002")]
36 public class VS2002Target : VS2003Target
37 {
38 #region Private Methods
39
40 private void SetVS2002()
41 {
42 this.SolutionVersion = "7.00";
43 this.ProductVersion = "7.0.9254";
44 this.SchemaVersion = "1.0";
45 this.VersionName = "2002";
46 this.Version = VSVersion.VS70;
47 }
48
49 #endregion
50
51 #region Public Methods
52
53 /// <summary>
54 /// Writes the specified kern.
55 /// </summary>
56 /// <param name="kern">The kern.</param>
57 public override void Write(Kernel kern)
58 {
59 SetVS2002();
60 base.Write(kern);
61 }
62
63 /// <summary>
64 /// Cleans the specified kern.
65 /// </summary>
66 /// <param name="kern">The kern.</param>
67 public override void Clean(Kernel kern)
68 {
69 SetVS2002();
70 base.Clean(kern);
71 }
72
73 /// <summary>
74 /// Gets the name.
75 /// </summary>
76 /// <value>The name.</value>
77 public override string Name
78 {
79 get
80 {
81 return "vs2002";
82 }
83 }
84
85 #endregion
86 }
87}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/VS2003Target.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/VS2003Target.cs.svn-base
new file mode 100644
index 0000000..10e2dc4
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/VS2003Target.cs.svn-base
@@ -0,0 +1,593 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.Collections.Generic;
28using System.IO;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using Prebuild.Core.Nodes;
33using Prebuild.Core.Utilities;
34
35namespace Prebuild.Core.Targets
36{
37 [Target("vs2003")]
38 public class VS2003Target : ITarget
39 {
40
41 #region Fields
42
43 string solutionVersion = "8.00";
44 string productVersion = "7.10.3077";
45 string schemaVersion = "2.0";
46 string versionName = "2003";
47 VSVersion version = VSVersion.VS71;
48
49 readonly Dictionary<string, ToolInfo> m_Tools = new Dictionary<string, ToolInfo>();
50 Kernel m_Kernel;
51
52 /// <summary>
53 /// Gets or sets the solution version.
54 /// </summary>
55 /// <value>The solution version.</value>
56 protected string SolutionVersion
57 {
58 get
59 {
60 return solutionVersion;
61 }
62 set
63 {
64 solutionVersion = value;
65 }
66 }
67 /// <summary>
68 /// Gets or sets the product version.
69 /// </summary>
70 /// <value>The product version.</value>
71 protected string ProductVersion
72 {
73 get
74 {
75 return productVersion;
76 }
77 set
78 {
79 productVersion = value;
80 }
81 }
82 /// <summary>
83 /// Gets or sets the schema version.
84 /// </summary>
85 /// <value>The schema version.</value>
86 protected string SchemaVersion
87 {
88 get
89 {
90 return schemaVersion;
91 }
92 set
93 {
94 schemaVersion = value;
95 }
96 }
97 /// <summary>
98 /// Gets or sets the name of the version.
99 /// </summary>
100 /// <value>The name of the version.</value>
101 protected string VersionName
102 {
103 get
104 {
105 return versionName;
106 }
107 set
108 {
109 versionName = value;
110 }
111 }
112 /// <summary>
113 /// Gets or sets the version.
114 /// </summary>
115 /// <value>The version.</value>
116 protected VSVersion Version
117 {
118 get
119 {
120 return version;
121 }
122 set
123 {
124 version = value;
125 }
126 }
127
128 #endregion
129
130 #region Constructors
131
132 /// <summary>
133 /// Initializes a new instance of the <see cref="VS2003Target"/> class.
134 /// </summary>
135 public VS2003Target()
136 {
137 m_Tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP");
138 m_Tools["VB.NET"] = new ToolInfo("VB.NET", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic");
139 }
140
141 #endregion
142
143 #region Private Methods
144
145 private string MakeRefPath(ProjectNode project)
146 {
147 string ret = "";
148 foreach(ReferencePathNode node in project.ReferencePaths)
149 {
150 try
151 {
152 string fullPath = Helper.ResolvePath(node.Path);
153 if(ret.Length < 1)
154 {
155 ret = fullPath;
156 }
157 else
158 {
159 ret += ";" + fullPath;
160 }
161 }
162 catch(ArgumentException)
163 {
164 m_Kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path);
165 }
166 }
167
168 return ret;
169 }
170
171 private void WriteProject(SolutionNode solution, ProjectNode project)
172 {
173 if(!m_Tools.ContainsKey(project.Language))
174 {
175 throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
176 }
177
178 ToolInfo toolInfo = m_Tools[project.Language];
179 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
180 StreamWriter ps = new StreamWriter(projectFile);
181
182 m_Kernel.CurrentWorkingDirectory.Push();
183 Helper.SetCurrentDir(Path.GetDirectoryName(projectFile));
184
185 using(ps)
186 {
187 ps.WriteLine("<VisualStudioProject>");
188 ps.WriteLine(" <{0}", toolInfo.XmlTag);
189 ps.WriteLine("\t\t\t\tProjectType = \"Local\"");
190 ps.WriteLine("\t\t\t\tProductVersion = \"{0}\"", ProductVersion);
191 ps.WriteLine("\t\t\t\tSchemaVersion = \"{0}\"", SchemaVersion);
192 ps.WriteLine("\t\t\t\tProjectGuid = \"{{{0}}}\"", project.Guid.ToString().ToUpper());
193 ps.WriteLine("\t\t>");
194
195 ps.WriteLine("\t\t\t\t<Build>");
196 ps.WriteLine(" <Settings");
197 ps.WriteLine("\t\t\t\t ApplicationIcon = \"{0}\"",project.AppIcon);
198 ps.WriteLine("\t\t\t\t AssemblyKeyContainerName = \"\"");
199 ps.WriteLine("\t\t\t\t AssemblyName = \"{0}\"", project.AssemblyName);
200 ps.WriteLine("\t\t\t\t AssemblyOriginatorKeyFile = \"\"");
201 ps.WriteLine("\t\t\t\t DefaultClientScript = \"JScript\"");
202 ps.WriteLine("\t\t\t\t DefaultHTMLPageLayout = \"Grid\"");
203 ps.WriteLine("\t\t\t\t DefaultTargetSchema = \"IE50\"");
204 ps.WriteLine("\t\t\t\t DelaySign = \"false\"");
205
206 if(Version == VSVersion.VS70)
207 {
208 ps.WriteLine("\t\t\t\t NoStandardLibraries = \"false\"");
209 }
210
211 ps.WriteLine("\t\t\t\t OutputType = \"{0}\"", project.Type);
212
213 foreach(ConfigurationNode conf in project.Configurations)
214 {
215 if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0)
216 {
217 ps.WriteLine("\t\t\t\t PreBuildEvent = \"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString()));
218 }
219 else
220 {
221 ps.WriteLine("\t\t\t\t PreBuildEvent = \"{0}\"", conf.Options["PreBuildEvent"]);
222 }
223 if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0)
224 {
225 ps.WriteLine("\t\t\t\t PostBuildEvent = \"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString()));
226 }
227 else
228 {
229 ps.WriteLine("\t\t\t\t PostBuildEvent = \"{0}\"", conf.Options["PostBuildEvent"]);
230 }
231 if (conf.Options["RunPostBuildEvent"] == null)
232 {
233 ps.WriteLine("\t\t\t\t RunPostBuildEvent = \"{0}\"", "OnBuildSuccess");
234 }
235 else
236 {
237 ps.WriteLine("\t\t\t\t RunPostBuildEvent = \"{0}\"", conf.Options["RunPostBuildEvent"]);
238 }
239 break;
240 }
241
242 ps.WriteLine("\t\t\t\t RootNamespace = \"{0}\"", project.RootNamespace);
243 ps.WriteLine("\t\t\t\t StartupObject = \"{0}\"", project.StartupObject);
244 ps.WriteLine("\t\t >");
245
246 foreach(ConfigurationNode conf in project.Configurations)
247 {
248 ps.WriteLine("\t\t\t\t <Config");
249 ps.WriteLine("\t\t\t\t Name = \"{0}\"", conf.Name);
250 ps.WriteLine("\t\t\t\t AllowUnsafeBlocks = \"{0}\"", conf.Options["AllowUnsafe"].ToString().ToLower());
251 ps.WriteLine("\t\t\t\t BaseAddress = \"{0}\"", conf.Options["BaseAddress"]);
252 ps.WriteLine("\t\t\t\t CheckForOverflowUnderflow = \"{0}\"", conf.Options["CheckUnderflowOverflow"].ToString().ToLower());
253 ps.WriteLine("\t\t\t\t ConfigurationOverrideFile = \"\"");
254 ps.WriteLine("\t\t\t\t DefineConstants = \"{0}\"", conf.Options["CompilerDefines"]);
255 ps.WriteLine("\t\t\t\t DocumentationFile = \"{0}\"", GetXmlDocFile(project, conf));//default to the assembly name
256 ps.WriteLine("\t\t\t\t DebugSymbols = \"{0}\"", conf.Options["DebugInformation"].ToString().ToLower());
257 ps.WriteLine("\t\t\t\t FileAlignment = \"{0}\"", conf.Options["FileAlignment"]);
258 ps.WriteLine("\t\t\t\t IncrementalBuild = \"{0}\"", conf.Options["IncrementalBuild"].ToString().ToLower());
259
260 if(Version == VSVersion.VS71)
261 {
262 ps.WriteLine("\t\t\t\t NoStdLib = \"{0}\"", conf.Options["NoStdLib"].ToString().ToLower());
263 ps.WriteLine("\t\t\t\t NoWarn = \"{0}\"", conf.Options["SuppressWarnings"].ToString().ToLower());
264 }
265
266 ps.WriteLine("\t\t\t\t Optimize = \"{0}\"", conf.Options["OptimizeCode"].ToString().ToLower());
267 ps.WriteLine(" OutputPath = \"{0}\"",
268 Helper.EndPath(Helper.NormalizePath(conf.Options["OutputPath"].ToString())));
269 ps.WriteLine(" RegisterForComInterop = \"{0}\"", conf.Options["RegisterComInterop"].ToString().ToLower());
270 ps.WriteLine(" RemoveIntegerChecks = \"{0}\"", conf.Options["RemoveIntegerChecks"].ToString().ToLower());
271 ps.WriteLine(" TreatWarningsAsErrors = \"{0}\"", conf.Options["WarningsAsErrors"].ToString().ToLower());
272 ps.WriteLine(" WarningLevel = \"{0}\"", conf.Options["WarningLevel"]);
273 ps.WriteLine(" />");
274 }
275
276 ps.WriteLine(" </Settings>");
277
278 ps.WriteLine(" <References>");
279 foreach(ReferenceNode refr in project.References)
280 {
281 ps.WriteLine(" <Reference");
282 ps.WriteLine(" Name = \"{0}\"", refr.Name);
283 ps.WriteLine(" AssemblyName = \"{0}\"", refr.Name);
284
285 if(solution.ProjectsTable.ContainsKey(refr.Name))
286 {
287 ProjectNode refProject = solution.ProjectsTable[refr.Name];
288 ps.WriteLine(" Project = \"{{{0}}}\"", refProject.Guid.ToString().ToUpper());
289 ps.WriteLine(" Package = \"{0}\"", toolInfo.Guid.ToUpper());
290 }
291 else
292 {
293 if(refr.Path != null)
294 {
295 ps.WriteLine(" HintPath = \"{0}\"", Helper.MakeFilePath(refr.Path, refr.Name, "dll"));
296 }
297
298 }
299
300 if(refr.LocalCopySpecified)
301 {
302 ps.WriteLine(" Private = \"{0}\"",refr.LocalCopy);
303 }
304
305 ps.WriteLine(" />");
306 }
307 ps.WriteLine(" </References>");
308
309 ps.WriteLine(" </Build>");
310 ps.WriteLine(" <Files>");
311
312 ps.WriteLine(" <Include>");
313
314 foreach(string file in project.Files)
315 {
316 string fileName = file.Replace(".\\", "");
317 ps.WriteLine(" <File");
318 ps.WriteLine(" RelPath = \"{0}\"", fileName);
319 ps.WriteLine(" SubType = \"{0}\"", project.Files.GetSubType(file));
320 ps.WriteLine(" BuildAction = \"{0}\"", project.Files.GetBuildAction(file));
321 ps.WriteLine(" />");
322
323 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
324 {
325 ps.WriteLine(" <File");
326 ps.WriteLine(" RelPath = \"{0}\"", fileName.Substring(0, fileName.LastIndexOf('.')) + ".resx");
327 int slash = fileName.LastIndexOf('\\');
328 if (slash == -1)
329 {
330 ps.WriteLine(" DependentUpon = \"{0}\"", fileName);
331 }
332 else
333 {
334 ps.WriteLine(" DependentUpon = \"{0}\"", fileName.Substring(slash + 1, fileName.Length - slash - 1));
335 }
336 ps.WriteLine(" BuildAction = \"{0}\"", "EmbeddedResource");
337 ps.WriteLine(" />");
338
339 }
340 }
341 ps.WriteLine(" </Include>");
342
343 ps.WriteLine(" </Files>");
344 ps.WriteLine(" </{0}>", toolInfo.XmlTag);
345 ps.WriteLine("</VisualStudioProject>");
346 }
347
348 ps = new StreamWriter(projectFile + ".user");
349 using(ps)
350 {
351 ps.WriteLine("<VisualStudioProject>");
352 ps.WriteLine(" <{0}>", toolInfo.XmlTag);
353 ps.WriteLine(" <Build>");
354
355 ps.WriteLine(" <Settings ReferencePath=\"{0}\">", MakeRefPath(project));
356 foreach(ConfigurationNode conf in project.Configurations)
357 {
358 ps.WriteLine(" <Config");
359 ps.WriteLine(" Name = \"{0}\"", conf.Name);
360 ps.WriteLine(" />");
361 }
362 ps.WriteLine(" </Settings>");
363
364 ps.WriteLine(" </Build>");
365 ps.WriteLine(" </{0}>", toolInfo.XmlTag);
366 ps.WriteLine("</VisualStudioProject>");
367 }
368
369 m_Kernel.CurrentWorkingDirectory.Pop();
370 }
371
372 /// <summary>
373 /// Gets the XML doc file.
374 /// </summary>
375 /// <param name="project">The project.</param>
376 /// <param name="conf">The conf.</param>
377 /// <returns></returns>
378 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
379 {
380 if( conf == null )
381 {
382 throw new ArgumentNullException("conf");
383 }
384 if( project == null )
385 {
386 throw new ArgumentNullException("project");
387 }
388 // if(!(bool)conf.Options["GenerateXmlDocFile"]) //default to none, if the generate option is false
389 // {
390 // return string.Empty;
391 // }
392
393 //default to "AssemblyName.xml"
394 //string defaultValue = Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
395 //return (string)conf.Options["XmlDocFile", defaultValue];
396
397 //default to no XmlDocFile file
398 return (string)conf.Options["XmlDocFile", ""];
399 }
400
401 private void WriteSolution(SolutionNode solution)
402 {
403 m_Kernel.Log.Write("Creating Visual Studio {0} solution and project files", VersionName);
404
405 foreach(ProjectNode project in solution.Projects)
406 {
407 if(m_Kernel.AllowProject(project.FilterGroups))
408 {
409 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
410 WriteProject(solution, project);
411 }
412 }
413
414 m_Kernel.Log.Write("");
415 string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
416 StreamWriter ss = new StreamWriter(solutionFile);
417
418 m_Kernel.CurrentWorkingDirectory.Push();
419 Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile));
420
421 using(ss)
422 {
423 ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", SolutionVersion);
424 foreach(ProjectNode project in solution.Projects)
425 {
426 if(!m_Tools.ContainsKey(project.Language))
427 {
428 throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
429 }
430
431 ToolInfo toolInfo = m_Tools[project.Language];
432
433 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
434 ss.WriteLine("Project(\"{0}\") = \"{1}\", \"{2}\", \"{{{3}}}\"",
435 toolInfo.Guid, project.Name, Helper.MakeFilePath(path, project.Name,
436 toolInfo.FileExtension), project.Guid.ToString().ToUpper());
437
438 ss.WriteLine("\tProjectSection(ProjectDependencies) = postProject");
439 ss.WriteLine("\tEndProjectSection");
440
441 ss.WriteLine("EndProject");
442 }
443
444 ss.WriteLine("Global");
445
446 ss.WriteLine("\tGlobalSection(SolutionConfiguration) = preSolution");
447 foreach(ConfigurationNode conf in solution.Configurations)
448 {
449 ss.WriteLine("\t\t{0} = {0}", conf.Name);
450 }
451 ss.WriteLine("\tEndGlobalSection");
452
453 ss.WriteLine("\tGlobalSection(ProjectDependencies) = postSolution");
454 foreach(ProjectNode project in solution.Projects)
455 {
456 for(int i = 0; i < project.References.Count; i++)
457 {
458 ReferenceNode refr = project.References[i];
459 if(solution.ProjectsTable.ContainsKey(refr.Name))
460 {
461 ProjectNode refProject = solution.ProjectsTable[refr.Name];
462 ss.WriteLine("\t\t({{{0}}}).{1} = ({{{2}}})",
463 project.Guid.ToString().ToUpper()
464 , i,
465 refProject.Guid.ToString().ToUpper()
466 );
467 }
468 }
469 }
470 ss.WriteLine("\tEndGlobalSection");
471
472 ss.WriteLine("\tGlobalSection(ProjectConfiguration) = postSolution");
473 foreach(ProjectNode project in solution.Projects)
474 {
475 foreach(ConfigurationNode conf in solution.Configurations)
476 {
477 ss.WriteLine("\t\t{{{0}}}.{1}.ActiveCfg = {1}|.NET",
478 project.Guid.ToString().ToUpper(),
479 conf.Name);
480
481 ss.WriteLine("\t\t{{{0}}}.{1}.Build.0 = {1}|.NET",
482 project.Guid.ToString().ToUpper(),
483 conf.Name);
484 }
485 }
486 ss.WriteLine("\tEndGlobalSection");
487
488 if(solution.Files != null)
489 {
490 ss.WriteLine("\tGlobalSection(SolutionItems) = postSolution");
491 foreach(string file in solution.Files)
492 {
493 ss.WriteLine("\t\t{0} = {0}", file);
494 }
495 ss.WriteLine("\tEndGlobalSection");
496 }
497
498 ss.WriteLine("\tGlobalSection(ExtensibilityGlobals) = postSolution");
499 ss.WriteLine("\tEndGlobalSection");
500 ss.WriteLine("\tGlobalSection(ExtensibilityAddIns) = postSolution");
501 ss.WriteLine("\tEndGlobalSection");
502
503 ss.WriteLine("EndGlobal");
504 }
505
506 m_Kernel.CurrentWorkingDirectory.Pop();
507 }
508
509 private void CleanProject(ProjectNode project)
510 {
511 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
512
513 ToolInfo toolInfo = m_Tools[project.Language];
514 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
515 string userFile = projectFile + ".user";
516
517 Helper.DeleteIfExists(projectFile);
518 Helper.DeleteIfExists(userFile);
519 }
520
521 private void CleanSolution(SolutionNode solution)
522 {
523 m_Kernel.Log.Write("Cleaning Visual Studio {0} solution and project files", VersionName, solution.Name);
524
525 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
526 string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo");
527
528 Helper.DeleteIfExists(slnFile);
529 Helper.DeleteIfExists(suoFile);
530
531 foreach(ProjectNode project in solution.Projects)
532 {
533 CleanProject(project);
534 }
535
536 m_Kernel.Log.Write("");
537 }
538
539 #endregion
540
541 #region ITarget Members
542
543 /// <summary>
544 /// Writes the specified kern.
545 /// </summary>
546 /// <param name="kern">The kern.</param>
547 public virtual void Write(Kernel kern)
548 {
549 if( kern == null )
550 {
551 throw new ArgumentNullException("kern");
552 }
553 m_Kernel = kern;
554 foreach(SolutionNode sol in m_Kernel.Solutions)
555 {
556 WriteSolution(sol);
557 }
558 m_Kernel = null;
559 }
560
561 /// <summary>
562 /// Cleans the specified kern.
563 /// </summary>
564 /// <param name="kern">The kern.</param>
565 public virtual void Clean(Kernel kern)
566 {
567 if( kern == null )
568 {
569 throw new ArgumentNullException("kern");
570 }
571 m_Kernel = kern;
572 foreach(SolutionNode sol in m_Kernel.Solutions)
573 {
574 CleanSolution(sol);
575 }
576 m_Kernel = null;
577 }
578
579 /// <summary>
580 /// Gets the name.
581 /// </summary>
582 /// <value>The name.</value>
583 public virtual string Name
584 {
585 get
586 {
587 return "vs2003";
588 }
589 }
590
591 #endregion
592 }
593}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/VS2005Target.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/VS2005Target.cs.svn-base
new file mode 100644
index 0000000..9c70e26
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/VS2005Target.cs.svn-base
@@ -0,0 +1,147 @@
1#region BSD License
2/*
3Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Text;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using Prebuild.Core.Nodes;
33using Prebuild.Core.Utilities;
34
35namespace Prebuild.Core.Targets
36{
37 /// <summary>
38 ///
39 /// </summary>
40 [Target("vs2005")]
41 public class VS2005Target : VSGenericTarget
42 {
43 #region Inner Classes
44
45 #endregion
46
47 #region Fields
48
49 string solutionVersion = "9.00";
50 string productVersion = "8.0.50727";
51 string schemaVersion = "2.0";
52 string versionName = "Visual C# 2005";
53 string name = "vs2005";
54
55 VSVersion version = VSVersion.VS80;
56
57 public override string SolutionTag
58 {
59 get { return "# Visual Studio 2005"; }
60 }
61
62 protected override string GetToolsVersionXml(FrameworkVersion frameworkVersion)
63 {
64 return string.Empty;
65 }
66 /// <summary>
67 /// Gets or sets the solution version.
68 /// </summary>
69 /// <value>The solution version.</value>
70 public override string SolutionVersion
71 {
72 get
73 {
74 return solutionVersion;
75 }
76 }
77 /// <summary>
78 /// Gets or sets the product version.
79 /// </summary>
80 /// <value>The product version.</value>
81 public override string ProductVersion
82 {
83 get
84 {
85 return productVersion;
86 }
87 }
88 /// <summary>
89 /// Gets or sets the schema version.
90 /// </summary>
91 /// <value>The schema version.</value>
92 public override string SchemaVersion
93 {
94 get
95 {
96 return schemaVersion;
97 }
98 }
99 /// <summary>
100 /// Gets or sets the name of the version.
101 /// </summary>
102 /// <value>The name of the version.</value>
103 public override string VersionName
104 {
105 get
106 {
107 return versionName;
108 }
109 }
110 /// <summary>
111 /// Gets or sets the version.
112 /// </summary>
113 /// <value>The version.</value>
114 public override VSVersion Version
115 {
116 get
117 {
118 return version;
119 }
120 }
121 /// <summary>
122 /// Gets the name.
123 /// </summary>
124 /// <value>The name.</value>
125 public override string Name
126 {
127 get
128 {
129 return name;
130 }
131 }
132
133 #endregion
134
135 #region Constructors
136
137 /// <summary>
138 /// Initializes a new instance of the <see cref="VS2005Target"/> class.
139 /// </summary>
140 public VS2005Target()
141 : base()
142 {
143 }
144
145 #endregion
146 }
147}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/VS2008Target.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/VS2008Target.cs.svn-base
new file mode 100644
index 0000000..fee4f7f
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/VS2008Target.cs.svn-base
@@ -0,0 +1,127 @@
1using System;
2using System.IO;
3using System.Text;
4
5using Prebuild.Core.Attributes;
6using Prebuild.Core.Interfaces;
7using Prebuild.Core.Nodes;
8using Prebuild.Core.Utilities;
9using System.CodeDom.Compiler;
10
11namespace Prebuild.Core.Targets
12{
13
14 /// <summary>
15 ///
16 /// </summary>
17 [Target("vs2008")]
18 public class VS2008Target : VSGenericTarget
19 {
20 #region Fields
21 string solutionVersion = "10.00";
22 string productVersion = "9.0.21022";
23 string schemaVersion = "2.0";
24 string versionName = "Visual Studio 2008";
25 string name = "vs2008";
26 VSVersion version = VSVersion.VS90;
27
28 /// <summary>
29 /// Gets or sets the solution version.
30 /// </summary>
31 /// <value>The solution version.</value>
32 public override string SolutionVersion
33 {
34 get
35 {
36 return solutionVersion;
37 }
38 }
39 /// <summary>
40 /// Gets or sets the product version.
41 /// </summary>
42 /// <value>The product version.</value>
43 public override string ProductVersion
44 {
45 get
46 {
47 return productVersion;
48 }
49 }
50 /// <summary>
51 /// Gets or sets the schema version.
52 /// </summary>
53 /// <value>The schema version.</value>
54 public override string SchemaVersion
55 {
56 get
57 {
58 return schemaVersion;
59 }
60 }
61 /// <summary>
62 /// Gets or sets the name of the version.
63 /// </summary>
64 /// <value>The name of the version.</value>
65 public override string VersionName
66 {
67 get
68 {
69 return versionName;
70 }
71 }
72 /// <summary>
73 /// Gets or sets the version.
74 /// </summary>
75 /// <value>The version.</value>
76 public override VSVersion Version
77 {
78 get
79 {
80 return version;
81 }
82 }
83 /// <summary>
84 /// Gets the name.
85 /// </summary>
86 /// <value>The name.</value>
87 public override string Name
88 {
89 get
90 {
91 return name;
92 }
93 }
94
95 protected override string GetToolsVersionXml(FrameworkVersion frameworkVersion)
96 {
97 switch (frameworkVersion)
98 {
99 case FrameworkVersion.v3_5:
100 return "ToolsVersion=\"3.5\"";
101 case FrameworkVersion.v3_0:
102 return "ToolsVersion=\"3.0\"";
103 default:
104 return "ToolsVersion=\"2.0\"";
105 }
106 }
107
108 public override string SolutionTag
109 {
110 get { return "# Visual Studio 2008"; }
111 }
112
113 #endregion
114
115 #region Constructors
116
117 /// <summary>
118 /// Initializes a new instance of the <see cref="VS2005Target"/> class.
119 /// </summary>
120 public VS2008Target()
121 : base()
122 {
123 }
124
125 #endregion
126 }
127}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/VS2010Target.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/VS2010Target.cs.svn-base
new file mode 100644
index 0000000..ea9f736
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/VS2010Target.cs.svn-base
@@ -0,0 +1,138 @@
1using System;
2using System.IO;
3using System.Text;
4
5using Prebuild.Core.Attributes;
6using Prebuild.Core.Interfaces;
7using Prebuild.Core.Nodes;
8using Prebuild.Core.Utilities;
9using System.CodeDom.Compiler;
10
11namespace Prebuild.Core.Targets
12{
13
14 /// <summary>
15 ///
16 /// </summary>
17 [Target("vs2010")]
18 public class VS2010Target : VSGenericTarget
19 {
20 #region Fields
21
22 string solutionVersion = "11.00";
23 string productVersion = "9.0.30729";
24 string schemaVersion = "2.0";
25 string versionName = "Visual Studio 2010";
26 string name = "vs2010";
27 VSVersion version = VSVersion.VS10;
28
29 #endregion
30
31 #region Properties
32
33 /// <summary>
34 /// Gets or sets the solution version.
35 /// </summary>
36 /// <value>The solution version.</value>
37 public override string SolutionVersion
38 {
39 get
40 {
41 return solutionVersion;
42 }
43 }
44
45 /// <summary>
46 /// Gets or sets the product version.
47 /// </summary>
48 /// <value>The product version.</value>
49 public override string ProductVersion
50 {
51 get
52 {
53 return productVersion;
54 }
55 }
56
57 /// <summary>
58 /// Gets or sets the schema version.
59 /// </summary>
60 /// <value>The schema version.</value>
61 public override string SchemaVersion
62 {
63 get
64 {
65 return schemaVersion;
66 }
67 }
68
69 /// <summary>
70 /// Gets or sets the name of the version.
71 /// </summary>
72 /// <value>The name of the version.</value>
73 public override string VersionName
74 {
75 get
76 {
77 return versionName;
78 }
79 }
80
81 /// <summary>
82 /// Gets or sets the version.
83 /// </summary>
84 /// <value>The version.</value>
85 public override VSVersion Version
86 {
87 get
88 {
89 return version;
90 }
91 }
92
93 /// <summary>
94 /// Gets the name.
95 /// </summary>
96 /// <value>The name.</value>
97 public override string Name
98 {
99 get
100 {
101 return name;
102 }
103 }
104
105 protected override string GetToolsVersionXml(FrameworkVersion frameworkVersion)
106 {
107 switch (frameworkVersion)
108 {
109 case FrameworkVersion.v4_0:
110 case FrameworkVersion.v3_5:
111 return "ToolsVersion=\"4.0\"";
112 case FrameworkVersion.v3_0:
113 return "ToolsVersion=\"3.0\"";
114 default:
115 return "ToolsVersion=\"2.0\"";
116 }
117 }
118
119 public override string SolutionTag
120 {
121 get { return "# Visual Studio 2010"; }
122 }
123
124 #endregion
125
126 #region Constructors
127
128 /// <summary>
129 /// Initializes a new instance of the <see cref="VS2005Target"/> class.
130 /// </summary>
131 public VS2010Target()
132 : base()
133 {
134 }
135
136 #endregion
137 }
138}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/VSGenericTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/VSGenericTarget.cs.svn-base
new file mode 100644
index 0000000..6969dd7
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/VSGenericTarget.cs.svn-base
@@ -0,0 +1,922 @@
1#region BSD License
2/*
3Copyright (c) 2008 Matthew Holmes (matthew@wildfiregames.com), John Anderson (sontek@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13 * The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24#endregion
25
26using System;
27using System.Collections.Generic;
28using System.IO;
29using Prebuild.Core.Interfaces;
30using Prebuild.Core.Nodes;
31using Prebuild.Core.Utilities;
32using System.CodeDom.Compiler;
33
34namespace Prebuild.Core.Targets
35{
36
37 /// <summary>
38 ///
39 /// </summary>
40 public abstract class VSGenericTarget : ITarget
41 {
42 #region Fields
43
44 readonly Dictionary<string, ToolInfo> tools = new Dictionary<string, ToolInfo>();
45 Kernel kernel;
46 #endregion
47
48 #region Properties
49 /// <summary>
50 /// Gets or sets the solution version.
51 /// </summary>
52 /// <value>The solution version.</value>
53 public abstract string SolutionVersion { get; }
54 /// <summary>
55 /// Gets or sets the product version.
56 /// </summary>
57 /// <value>The product version.</value>
58 public abstract string ProductVersion { get; }
59 /// <summary>
60 /// Gets or sets the schema version.
61 /// </summary>
62 /// <value>The schema version.</value>
63 public abstract string SchemaVersion { get; }
64 /// <summary>
65 /// Gets or sets the name of the version.
66 /// </summary>
67 /// <value>The name of the version.</value>
68 public abstract string VersionName { get; }
69 /// <summary>
70 /// Gets or sets the version.
71 /// </summary>
72 /// <value>The version.</value>
73 public abstract VSVersion Version { get; }
74 /// <summary>
75 /// Gets the name.
76 /// </summary>
77 /// <value>The name.</value>
78 public abstract string Name { get; }
79
80 protected abstract string GetToolsVersionXml(FrameworkVersion version);
81 public abstract string SolutionTag { get; }
82
83 #endregion
84
85 #region Constructors
86
87 /// <summary>
88 /// Initializes a new instance of the <see cref="VSGenericTarget"/> class.
89 /// </summary>
90 protected VSGenericTarget()
91 {
92 tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP", "$(MSBuildBinPath)\\Microsoft.CSHARP.Targets");
93 tools["Database"] = new ToolInfo("Database", "{4F174C21-8C12-11D0-8340-0000F80270F8}", "dbp", "UNKNOWN");
94 tools["Boo"] = new ToolInfo("Boo", "{45CEA7DC-C2ED-48A6-ACE0-E16144C02365}", "booproj", "Boo", "$(BooBinPath)\\Boo.Microsoft.Build.targets");
95 tools["VisualBasic"] = new ToolInfo("VisualBasic", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic", "$(MSBuildBinPath)\\Microsoft.VisualBasic.Targets");
96 tools["Folder"] = new ToolInfo("Folder", "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", null, null);
97 }
98
99 #endregion
100
101 #region Private Methods
102
103 private string MakeRefPath(ProjectNode project)
104 {
105 string ret = "";
106 foreach (ReferencePathNode node in project.ReferencePaths)
107 {
108 try
109 {
110 string fullPath = Helper.ResolvePath(node.Path);
111 if (ret.Length < 1)
112 {
113 ret = fullPath;
114 }
115 else
116 {
117 ret += ";" + fullPath;
118 }
119 }
120 catch (ArgumentException)
121 {
122 kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path);
123 }
124 }
125
126 return ret;
127 }
128
129 private static ProjectNode FindProjectInSolution(string name, SolutionNode solution)
130 {
131 SolutionNode node = solution;
132
133 while (node.Parent is SolutionNode)
134 node = node.Parent as SolutionNode;
135
136 return FindProjectInSolutionRecursively(name, node);
137 }
138
139 private static ProjectNode FindProjectInSolutionRecursively(string name, SolutionNode solution)
140 {
141 if (solution.ProjectsTable.ContainsKey(name))
142 return solution.ProjectsTable[name];
143
144 foreach (SolutionNode child in solution.Solutions)
145 {
146 ProjectNode node = FindProjectInSolutionRecursively(name, child);
147 if (node != null)
148 return node;
149 }
150
151 return null;
152 }
153
154 private void WriteProject(SolutionNode solution, ProjectNode project)
155 {
156 if (!tools.ContainsKey(project.Language))
157 {
158 throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
159 }
160
161 ToolInfo toolInfo = tools[project.Language];
162 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
163 StreamWriter ps = new StreamWriter(projectFile);
164
165 kernel.CurrentWorkingDirectory.Push();
166 Helper.SetCurrentDir(Path.GetDirectoryName(projectFile));
167
168 #region Project File
169 using (ps)
170 {
171 ps.WriteLine("<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" {0}>", GetToolsVersionXml(project.FrameworkVersion));
172 ps.WriteLine(" <PropertyGroup>");
173 ps.WriteLine(" <ProjectType>Local</ProjectType>");
174 ps.WriteLine(" <ProductVersion>{0}</ProductVersion>", ProductVersion);
175 ps.WriteLine(" <SchemaVersion>{0}</SchemaVersion>", SchemaVersion);
176 ps.WriteLine(" <ProjectGuid>{{{0}}}</ProjectGuid>", project.Guid.ToString().ToUpper());
177
178 // Visual Studio has a hard coded guid for the project type
179 if (project.Type == ProjectType.Web)
180 ps.WriteLine(" <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>");
181 ps.WriteLine(" <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>");
182 ps.WriteLine(" <ApplicationIcon>{0}</ApplicationIcon>", project.AppIcon);
183 ps.WriteLine(" <AssemblyKeyContainerName>");
184 ps.WriteLine(" </AssemblyKeyContainerName>");
185 ps.WriteLine(" <AssemblyName>{0}</AssemblyName>", project.AssemblyName);
186 foreach (ConfigurationNode conf in project.Configurations)
187 {
188 if (conf.Options.KeyFile != "")
189 {
190 ps.WriteLine(" <AssemblyOriginatorKeyFile>{0}</AssemblyOriginatorKeyFile>", conf.Options.KeyFile);
191 ps.WriteLine(" <SignAssembly>true</SignAssembly>");
192 break;
193 }
194 }
195 ps.WriteLine(" <DefaultClientScript>JScript</DefaultClientScript>");
196 ps.WriteLine(" <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>");
197 ps.WriteLine(" <DefaultTargetSchema>IE50</DefaultTargetSchema>");
198 ps.WriteLine(" <DelaySign>false</DelaySign>");
199 ps.WriteLine(" <TargetFrameworkVersion>{0}</TargetFrameworkVersion>", project.FrameworkVersion.ToString().Replace("_", "."));
200
201 ps.WriteLine(" <OutputType>{0}</OutputType>", project.Type == ProjectType.Web ? ProjectType.Library.ToString() : project.Type.ToString());
202 ps.WriteLine(" <AppDesignerFolder>{0}</AppDesignerFolder>", project.DesignerFolder);
203 ps.WriteLine(" <RootNamespace>{0}</RootNamespace>", project.RootNamespace);
204 ps.WriteLine(" <StartupObject>{0}</StartupObject>", project.StartupObject);
205 if (string.IsNullOrEmpty(project.DebugStartParameters))
206 {
207 ps.WriteLine(" <StartArguments>{0}</StartArguments>", project.DebugStartParameters);
208 }
209 ps.WriteLine(" <FileUpgradeFlags>");
210 ps.WriteLine(" </FileUpgradeFlags>");
211
212 ps.WriteLine(" </PropertyGroup>");
213
214 foreach (ConfigurationNode conf in project.Configurations)
215 {
216 ps.Write(" <PropertyGroup ");
217 ps.WriteLine("Condition=\" '$(Configuration)|$(Platform)' == '{0}|{1}' \">", conf.Name, conf.Platform);
218 ps.WriteLine(" <AllowUnsafeBlocks>{0}</AllowUnsafeBlocks>", conf.Options["AllowUnsafe"]);
219 ps.WriteLine(" <BaseAddress>{0}</BaseAddress>", conf.Options["BaseAddress"]);
220 ps.WriteLine(" <CheckForOverflowUnderflow>{0}</CheckForOverflowUnderflow>", conf.Options["CheckUnderflowOverflow"]);
221 ps.WriteLine(" <ConfigurationOverrideFile>");
222 ps.WriteLine(" </ConfigurationOverrideFile>");
223 ps.WriteLine(" <DefineConstants>{0}</DefineConstants>", conf.Options["CompilerDefines"]);
224 ps.WriteLine(" <DocumentationFile>{0}</DocumentationFile>", Helper.NormalizePath(conf.Options["XmlDocFile"].ToString()));
225 ps.WriteLine(" <DebugSymbols>{0}</DebugSymbols>", conf.Options["DebugInformation"]);
226 ps.WriteLine(" <FileAlignment>{0}</FileAlignment>", conf.Options["FileAlignment"]);
227 ps.WriteLine(" <Optimize>{0}</Optimize>", conf.Options["OptimizeCode"]);
228 if (project.Type != ProjectType.Web)
229 ps.WriteLine(" <OutputPath>{0}</OutputPath>",
230 Helper.EndPath(Helper.NormalizePath(conf.Options["OutputPath"].ToString())));
231 else
232 ps.WriteLine(" <OutputPath>{0}</OutputPath>",
233 Helper.EndPath(Helper.NormalizePath("bin\\")));
234
235 ps.WriteLine(" <RegisterForComInterop>{0}</RegisterForComInterop>", conf.Options["RegisterComInterop"]);
236 ps.WriteLine(" <RemoveIntegerChecks>{0}</RemoveIntegerChecks>", conf.Options["RemoveIntegerChecks"]);
237 ps.WriteLine(" <TreatWarningsAsErrors>{0}</TreatWarningsAsErrors>", conf.Options["WarningsAsErrors"]);
238 ps.WriteLine(" <WarningLevel>{0}</WarningLevel>", conf.Options["WarningLevel"]);
239 ps.WriteLine(" <NoStdLib>{0}</NoStdLib>", conf.Options["NoStdLib"]);
240 ps.WriteLine(" <NoWarn>{0}</NoWarn>", conf.Options["SuppressWarnings"]);
241 ps.WriteLine(" <PlatformTarget>{0}</PlatformTarget>", conf.Platform);
242 ps.WriteLine(" </PropertyGroup>");
243 }
244
245 //ps.WriteLine(" </Settings>");
246
247 Dictionary<ReferenceNode, ProjectNode> projectReferences = new Dictionary<ReferenceNode, ProjectNode>();
248 List<ReferenceNode> otherReferences = new List<ReferenceNode>();
249
250 foreach (ReferenceNode refr in project.References)
251 {
252 ProjectNode projectNode = FindProjectInSolution(refr.Name, solution);
253
254 if (projectNode == null)
255 otherReferences.Add(refr);
256 else
257 projectReferences.Add(refr, projectNode);
258 }
259 // Assembly References
260 ps.WriteLine(" <ItemGroup>");
261
262 foreach (ReferenceNode refr in otherReferences)
263 {
264 ps.Write(" <Reference");
265 ps.Write(" Include=\"");
266 ps.Write(refr.Name);
267 ps.WriteLine("\" >");
268 ps.Write(" <Name>");
269 ps.Write(refr.Name);
270 ps.WriteLine("</Name>");
271
272 if(!String.IsNullOrEmpty(refr.Path))
273 {
274 // Use absolute path to assembly (for determining assembly type)
275 string absolutePath = Path.Combine(project.FullPath, refr.Path);
276 if(File.Exists(Helper.MakeFilePath(absolutePath, refr.Name, "exe"))) {
277 // Assembly is an executable (exe)
278 ps.WriteLine(" <HintPath>{0}</HintPath>", Helper.MakeFilePath(refr.Path, refr.Name, "exe"));
279 } else if(File.Exists(Helper.MakeFilePath(absolutePath, refr.Name, "dll"))) {
280 // Assembly is an library (dll)
281 ps.WriteLine(" <HintPath>{0}</HintPath>", Helper.MakeFilePath(refr.Path, refr.Name, "dll"));
282 } else {
283 string referencePath = Helper.MakeFilePath(refr.Path, refr.Name, "dll");
284 kernel.Log.Write(LogType.Warning, "Reference \"{0}\": The specified file doesn't exist.", referencePath);
285 ps.WriteLine(" <HintPath>{0}</HintPath>", Helper.MakeFilePath(refr.Path, refr.Name, "dll"));
286 }
287 }
288
289 ps.WriteLine(" <Private>{0}</Private>", refr.LocalCopy);
290 ps.WriteLine(" </Reference>");
291 }
292 ps.WriteLine(" </ItemGroup>");
293
294 //Project References
295 ps.WriteLine(" <ItemGroup>");
296 foreach (KeyValuePair<ReferenceNode, ProjectNode> pair in projectReferences)
297 {
298 ToolInfo tool = tools[pair.Value.Language];
299 if (tools == null)
300 throw new UnknownLanguageException();
301
302 string path =
303 Helper.MakePathRelativeTo(project.FullPath,
304 Helper.MakeFilePath(pair.Value.FullPath, pair.Value.Name, tool.FileExtension));
305 ps.WriteLine(" <ProjectReference Include=\"{0}\">", path);
306
307 // TODO: Allow reference to visual basic projects
308 ps.WriteLine(" <Name>{0}</Name>", pair.Value.Name);
309 ps.WriteLine(" <Project>{0}</Project>", pair.Value.Guid.ToString("B").ToUpper());
310 ps.WriteLine(" <Package>{0}</Package>", tool.Guid.ToUpper());
311
312 //This is the Copy Local flag in VS
313 ps.WriteLine(" <Private>{0}</Private>", pair.Key.LocalCopy);
314
315 ps.WriteLine(" </ProjectReference>");
316 }
317 ps.WriteLine(" </ItemGroup>");
318
319 // ps.WriteLine(" </Build>");
320 ps.WriteLine(" <ItemGroup>");
321
322 // ps.WriteLine(" <Include>");
323 List<string> list = new List<string>();
324
325 foreach (string path in project.Files)
326 {
327 string lower = path.ToLower();
328 if (lower.EndsWith(".resx"))
329 {
330 string codebehind = String.Format("{0}.Designer{1}", path.Substring(0, path.LastIndexOf('.')), toolInfo.LanguageExtension);
331 if (!list.Contains(codebehind))
332 list.Add(codebehind);
333 }
334
335 }
336
337 foreach (string filePath in project.Files)
338 {
339 // if (file == "Properties\\Bind.Designer.cs")
340 // {
341 // Console.WriteLine("Wait a minute!");
342 // Console.WriteLine(project.Files.GetSubType(file).ToString());
343 // }
344 SubType subType = project.Files.GetSubType(filePath);
345
346 // Visual Studio chokes on file names if forward slash is used as a path separator
347 // instead of backslash. So we must make sure that all file paths written to the
348 // project file use \ as a path separator.
349 string file = filePath.Replace(@"/", @"\");
350
351 if (subType != SubType.Code && subType != SubType.Settings && subType != SubType.Designer
352 && subType != SubType.CodeBehind)
353 {
354 ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
355 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(file));
356 ps.WriteLine(" <SubType>Designer</SubType>");
357 ps.WriteLine(" </EmbeddedResource>");
358 //
359 }
360
361 if (subType == SubType.Designer)
362 {
363 ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file);
364
365 string autogen_name = file.Substring(0, file.LastIndexOf('.')) + ".Designer.cs";
366 string dependent_name = filePath.Substring(0, file.LastIndexOf('.')) + ".cs";
367
368 // Check for a parent .cs file with the same name as this designer file
369 if (File.Exists(Helper.NormalizePath(dependent_name)))
370 {
371 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(dependent_name));
372 }
373 else
374 {
375 ps.WriteLine(" <Generator>ResXFileCodeGenerator</Generator>");
376 ps.WriteLine(" <LastGenOutput>{0}</LastGenOutput>", Path.GetFileName(autogen_name));
377 ps.WriteLine(" <SubType>" + subType + "</SubType>");
378 }
379
380 ps.WriteLine(" </EmbeddedResource>");
381 if (File.Exists(Helper.NormalizePath(autogen_name)))
382 {
383 ps.WriteLine(" <Compile Include=\"{0}\">", autogen_name);
384 //ps.WriteLine(" <DesignTime>True</DesignTime>");
385
386 // If a parent .cs file exists, link this autogen file to it. Otherwise link
387 // to the designer file
388 if (File.Exists(dependent_name))
389 {
390 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(dependent_name));
391 }
392 else
393 {
394 ps.WriteLine(" <AutoGen>True</AutoGen>");
395 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(filePath));
396 }
397
398 ps.WriteLine(" </Compile>");
399 }
400 list.Add(autogen_name);
401 }
402 if (subType == SubType.Settings)
403 {
404 ps.Write(" <{0} ", project.Files.GetBuildAction(filePath));
405 ps.WriteLine("Include=\"{0}\">", file);
406 string fileName = Path.GetFileName(filePath);
407 if (project.Files.GetBuildAction(filePath) == BuildAction.None)
408 {
409 ps.WriteLine(" <Generator>SettingsSingleFileGenerator</Generator>");
410 ps.WriteLine(" <LastGenOutput>{0}</LastGenOutput>", fileName.Substring(0, fileName.LastIndexOf('.')) + ".Designer.cs");
411 }
412 else
413 {
414 ps.WriteLine(" <SubType>Code</SubType>");
415 ps.WriteLine(" <AutoGen>True</AutoGen>");
416 ps.WriteLine(" <DesignTimeSharedInput>True</DesignTimeSharedInput>");
417 string fileNameShort = fileName.Substring(0, fileName.LastIndexOf('.'));
418 string fileNameShorter = fileNameShort.Substring(0, fileNameShort.LastIndexOf('.'));
419 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(fileNameShorter + ".settings"));
420 }
421 ps.WriteLine(" </{0}>", project.Files.GetBuildAction(filePath));
422 }
423 else if (subType != SubType.Designer)
424 {
425 string path = Helper.NormalizePath(file);
426 string path_lower = path.ToLower();
427
428 if (!list.Contains(filePath))
429 {
430 ps.Write(" <{0} ", project.Files.GetBuildAction(filePath));
431
432 int startPos = 0;
433 if (project.Files.GetPreservePath(filePath))
434 {
435 while ((@"./\").IndexOf(file.Substring(startPos, 1)) != -1)
436 startPos++;
437
438 }
439 else
440 {
441 startPos = file.LastIndexOf(Path.GetFileName(path));
442 }
443
444 // be sure to write out the path with backslashes so VS recognizes
445 // the file properly.
446 ps.WriteLine("Include=\"{0}\">", file);
447
448 int last_period_index = file.LastIndexOf('.');
449 string short_file_name = file.Substring(0, last_period_index);
450 string extension = Path.GetExtension(path);
451 // make this upper case, so that when File.Exists tests for the
452 // existence of a designer file on a case-sensitive platform,
453 // it is correctly identified.
454 string designer_format = string.Format(".Designer{0}", extension);
455
456 if (path_lower.EndsWith(designer_format.ToLowerInvariant()))
457 {
458 int designer_index = path.IndexOf(designer_format);
459 string file_name = path.Substring(0, designer_index);
460
461 // There are two corrections to the next lines:
462 // 1. Fix the connection between a designer file and a form
463 // or usercontrol that don't have an associated resx file.
464 // 2. Connect settings files to associated designer files.
465 if (File.Exists(file_name + extension))
466 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(file_name + extension));
467 else if (File.Exists(file_name + ".resx"))
468 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(file_name + ".resx"));
469 else if (File.Exists(file_name + ".settings"))
470 {
471 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(file_name + ".settings"));
472 ps.WriteLine(" <AutoGen>True</AutoGen>");
473 ps.WriteLine(" <DesignTimeSharedInput>True</DesignTimeSharedInput>");
474 }
475 }
476 else if (subType == SubType.CodeBehind)
477 {
478 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(short_file_name));
479 }
480 if (project.Files.GetIsLink(filePath))
481 {
482 string alias = project.Files.GetLinkPath(filePath);
483 alias += file.Substring(startPos);
484 alias = Helper.NormalizePath(alias);
485 ps.WriteLine(" <Link>{0}</Link>", alias);
486 }
487 else if (project.Files.GetBuildAction(filePath) != BuildAction.None)
488 {
489 if (project.Files.GetBuildAction(filePath) != BuildAction.EmbeddedResource)
490 {
491 ps.WriteLine(" <SubType>{0}</SubType>", subType);
492 }
493 }
494
495 if (project.Files.GetCopyToOutput(filePath) != CopyToOutput.Never)
496 {
497 ps.WriteLine(" <CopyToOutputDirectory>{0}</CopyToOutputDirectory>", project.Files.GetCopyToOutput(filePath));
498 }
499
500 ps.WriteLine(" </{0}>", project.Files.GetBuildAction(filePath));
501 }
502 }
503 }
504
505 ps.WriteLine(" </ItemGroup>");
506 ps.WriteLine(" <Import Project=\"" + toolInfo.ImportProject + "\" />");
507 ps.WriteLine(" <PropertyGroup>");
508 ps.WriteLine(" <PreBuildEvent>");
509 ps.WriteLine(" </PreBuildEvent>");
510 ps.WriteLine(" <PostBuildEvent>");
511 ps.WriteLine(" </PostBuildEvent>");
512 ps.WriteLine(" </PropertyGroup>");
513 ps.WriteLine("</Project>");
514 }
515 #endregion
516
517 #region User File
518
519 ps = new StreamWriter(projectFile + ".user");
520 using (ps)
521 {
522 // Get the first configuration from the project.
523 ConfigurationNode firstConfiguration = null;
524
525 if (project.Configurations.Count > 0)
526 {
527 firstConfiguration = project.Configurations[0];
528 }
529
530 ps.WriteLine("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">");
531 //ps.WriteLine( "<VisualStudioProject>" );
532 //ps.WriteLine(" <{0}>", toolInfo.XMLTag);
533 //ps.WriteLine(" <Build>");
534 ps.WriteLine(" <PropertyGroup>");
535 //ps.WriteLine(" <Settings ReferencePath=\"{0}\">", MakeRefPath(project));
536
537 if (firstConfiguration != null)
538 {
539 ps.WriteLine(" <Configuration Condition=\" '$(Configuration)' == '' \">{0}</Configuration>", firstConfiguration.Name);
540 ps.WriteLine(" <Platform Condition=\" '$(Platform)' == '' \">{0}</Platform>", firstConfiguration.Platform);
541 }
542
543 ps.WriteLine(" <ReferencePath>{0}</ReferencePath>", MakeRefPath(project));
544 ps.WriteLine(" <LastOpenVersion>{0}</LastOpenVersion>", ProductVersion);
545 ps.WriteLine(" <ProjectView>ProjectFiles</ProjectView>");
546 ps.WriteLine(" <ProjectTrust>0</ProjectTrust>");
547 ps.WriteLine(" </PropertyGroup>");
548 foreach (ConfigurationNode conf in project.Configurations)
549 {
550 ps.Write(" <PropertyGroup");
551 ps.Write(" Condition = \" '$(Configuration)|$(Platform)' == '{0}|{1}' \"", conf.Name, conf.Platform);
552 ps.WriteLine(" />");
553 }
554 ps.WriteLine("</Project>");
555 }
556 #endregion
557
558 kernel.CurrentWorkingDirectory.Pop();
559 }
560
561 private void WriteSolution(SolutionNode solution, bool writeSolutionToDisk)
562 {
563 kernel.Log.Write("Creating {0} solution and project files", VersionName);
564
565 foreach (SolutionNode child in solution.Solutions)
566 {
567 kernel.Log.Write("...Creating folder: {0}", child.Name);
568 WriteSolution(child, false);
569 }
570
571 foreach (ProjectNode project in solution.Projects)
572 {
573 kernel.Log.Write("...Creating project: {0}", project.Name);
574 WriteProject(solution, project);
575 }
576
577 foreach (DatabaseProjectNode project in solution.DatabaseProjects)
578 {
579 kernel.Log.Write("...Creating database project: {0}", project.Name);
580 WriteDatabaseProject(solution, project);
581 }
582
583 if (writeSolutionToDisk) // only write main solution
584 {
585 kernel.Log.Write("");
586 string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
587
588 using (StreamWriter ss = new StreamWriter(solutionFile))
589 {
590 kernel.CurrentWorkingDirectory.Push();
591 Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile));
592
593 ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", SolutionVersion);
594 ss.WriteLine(SolutionTag);
595
596 WriteProjectDeclarations(ss, solution, solution);
597
598 ss.WriteLine("Global");
599
600 ss.WriteLine("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution");
601 foreach (ConfigurationNode conf in solution.Configurations)
602 {
603 ss.WriteLine("\t\t{0} = {0}", conf.NameAndPlatform);
604 }
605 ss.WriteLine("\tEndGlobalSection");
606
607 ss.WriteLine("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution");
608 WriteConfigurationLines(solution.Configurations, solution, ss);
609 ss.WriteLine("\tEndGlobalSection");
610
611 if (solution.Solutions.Count > 0)
612 {
613 ss.WriteLine("\tGlobalSection(NestedProjects) = preSolution");
614 foreach (SolutionNode embeddedSolution in solution.Solutions)
615 {
616 WriteNestedProjectMap(ss, embeddedSolution);
617 }
618 ss.WriteLine("\tEndGlobalSection");
619 }
620
621 ss.WriteLine("EndGlobal");
622 }
623
624 kernel.CurrentWorkingDirectory.Pop();
625 }
626 }
627
628 private void WriteProjectDeclarations(TextWriter writer, SolutionNode actualSolution, SolutionNode embeddedSolution)
629 {
630 foreach (SolutionNode childSolution in embeddedSolution.Solutions)
631 {
632 WriteEmbeddedSolution(writer, childSolution);
633 WriteProjectDeclarations(writer, actualSolution, childSolution);
634 }
635
636 foreach (ProjectNode project in embeddedSolution.Projects)
637 {
638 WriteProject(actualSolution, writer, project);
639 }
640
641 foreach (DatabaseProjectNode dbProject in embeddedSolution.DatabaseProjects)
642 {
643 WriteProject(actualSolution, writer, dbProject);
644 }
645
646 if (actualSolution.Guid == embeddedSolution.Guid)
647 {
648 WriteSolutionFiles(actualSolution, writer);
649 }
650 }
651
652 private static void WriteNestedProjectMap(TextWriter writer, SolutionNode embeddedSolution)
653 {
654 foreach (ProjectNode project in embeddedSolution.Projects)
655 {
656 WriteNestedProject(writer, embeddedSolution, project.Guid);
657 }
658
659 foreach (DatabaseProjectNode dbProject in embeddedSolution.DatabaseProjects)
660 {
661 WriteNestedProject(writer, embeddedSolution, dbProject.Guid);
662 }
663
664 foreach (SolutionNode child in embeddedSolution.Solutions)
665 {
666 WriteNestedProject(writer, embeddedSolution, child.Guid);
667 WriteNestedProjectMap(writer, child);
668 }
669 }
670
671 private static void WriteNestedProject(TextWriter writer, SolutionNode solution, Guid projectGuid)
672 {
673 WriteNestedFolder(writer, solution.Guid, projectGuid);
674 }
675
676 private static void WriteNestedFolder(TextWriter writer, Guid parentGuid, Guid childGuid)
677 {
678 writer.WriteLine("\t\t{0} = {1}",
679 childGuid.ToString("B").ToUpper(),
680 parentGuid.ToString("B").ToUpper());
681 }
682
683 private static void WriteConfigurationLines(IEnumerable<ConfigurationNode> configurations, SolutionNode solution, TextWriter ss)
684 {
685 foreach (ProjectNode project in solution.Projects)
686 {
687 foreach (ConfigurationNode conf in configurations)
688 {
689 ss.WriteLine("\t\t{0}.{1}.ActiveCfg = {1}",
690 project.Guid.ToString("B").ToUpper(),
691 conf.NameAndPlatform);
692
693 ss.WriteLine("\t\t{0}.{1}.Build.0 = {1}",
694 project.Guid.ToString("B").ToUpper(),
695 conf.NameAndPlatform);
696 }
697 }
698
699 foreach (SolutionNode child in solution.Solutions)
700 {
701 WriteConfigurationLines(configurations, child, ss);
702 }
703 }
704
705 private void WriteSolutionFiles(SolutionNode solution, TextWriter ss)
706 {
707 if(solution.Files != null && solution.Files.Count > 0)
708 WriteProject(ss, "Folder", solution.Guid, "Solution Files", "Solution Files", solution.Files);
709 }
710
711 private void WriteEmbeddedSolution(TextWriter writer, SolutionNode embeddedSolution)
712 {
713 WriteProject(writer, "Folder", embeddedSolution.Guid, embeddedSolution.Name, embeddedSolution.Name, embeddedSolution.Files);
714 }
715
716 private void WriteProject(SolutionNode solution, TextWriter ss, ProjectNode project)
717 {
718 WriteProject(ss, solution, project.Language, project.Guid, project.Name, project.FullPath);
719 }
720
721 private void WriteProject(SolutionNode solution, TextWriter ss, DatabaseProjectNode dbProject)
722 {
723 if (solution.Files != null && solution.Files.Count > 0)
724 WriteProject(ss, solution, "Database", dbProject.Guid, dbProject.Name, dbProject.FullPath);
725 }
726
727 const string ProjectDeclarationBeginFormat = "Project(\"{0}\") = \"{1}\", \"{2}\", \"{3}\"";
728 const string ProjectDeclarationEndFormat = "EndProject";
729
730 private void WriteProject(TextWriter ss, SolutionNode solution, string language, Guid guid, string name, string projectFullPath)
731 {
732 if (!tools.ContainsKey(language))
733 throw new UnknownLanguageException("Unknown .NET language: " + language);
734
735 ToolInfo toolInfo = tools[language];
736
737 string path = Helper.MakePathRelativeTo(solution.FullPath, projectFullPath);
738
739 path = Helper.MakeFilePath(path, name, toolInfo.FileExtension);
740
741 WriteProject(ss, language, guid, name, path);
742 }
743
744 private void WriteProject(TextWriter writer, string language, Guid projectGuid, string name, string location)
745 {
746 WriteProject(writer, language, projectGuid, name, location, null);
747 }
748
749 private void WriteProject(TextWriter writer, string language, Guid projectGuid, string name, string location, FilesNode files)
750 {
751 if (!tools.ContainsKey(language))
752 throw new UnknownLanguageException("Unknown .NET language: " + language);
753
754 ToolInfo toolInfo = tools[language];
755
756 writer.WriteLine(ProjectDeclarationBeginFormat,
757 toolInfo.Guid,
758 name,
759 location,
760 projectGuid.ToString("B").ToUpper());
761
762 if (files != null)
763 {
764 writer.WriteLine("\tProjectSection(SolutionItems) = preProject");
765
766 foreach (string file in files)
767 writer.WriteLine("\t\t{0} = {0}", file);
768
769 writer.WriteLine("\tEndProjectSection");
770 }
771
772 writer.WriteLine(ProjectDeclarationEndFormat);
773 }
774
775 private void WriteDatabaseProject(SolutionNode solution, DatabaseProjectNode project)
776 {
777 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "dbp");
778 IndentedTextWriter ps = new IndentedTextWriter(new StreamWriter(projectFile), " ");
779
780 kernel.CurrentWorkingDirectory.Push();
781
782 Helper.SetCurrentDir(Path.GetDirectoryName(projectFile));
783
784 using (ps)
785 {
786 ps.WriteLine("# Microsoft Developer Studio Project File - Database Project");
787 ps.WriteLine("Begin DataProject = \"{0}\"", project.Name);
788 ps.Indent++;
789 ps.WriteLine("MSDTVersion = \"80\"");
790 // TODO: Use the project.Files property
791 if (ContainsSqlFiles(Path.GetDirectoryName(projectFile)))
792 WriteDatabaseFoldersAndFiles(ps, Path.GetDirectoryName(projectFile));
793
794 ps.WriteLine("Begin DBRefFolder = \"Database References\"");
795 ps.Indent++;
796 foreach (DatabaseReferenceNode reference in project.References)
797 {
798 ps.WriteLine("Begin DBRefNode = \"{0}\"", reference.Name);
799 ps.Indent++;
800 ps.WriteLine("ConnectStr = \"{0}\"", reference.ConnectionString);
801 ps.WriteLine("Provider = \"{0}\"", reference.ProviderId.ToString("B").ToUpper());
802 //ps.WriteLine("Colorizer = 5");
803 ps.Indent--;
804 ps.WriteLine("End");
805 }
806 ps.Indent--;
807 ps.WriteLine("End");
808 ps.Indent--;
809 ps.WriteLine("End");
810
811 ps.Flush();
812 }
813
814 kernel.CurrentWorkingDirectory.Pop();
815 }
816
817 private static bool ContainsSqlFiles(string folder)
818 {
819 if(Directory.GetFiles(folder, "*.sql").Length > 0)
820 return true; // if the folder contains 1 .sql file, that's good enough
821
822 foreach (string child in Directory.GetDirectories(folder))
823 {
824 if (ContainsSqlFiles(child))
825 return true; // if 1 child folder contains a .sql file, still good enough
826 }
827
828 return false;
829 }
830
831 private static void WriteDatabaseFoldersAndFiles(IndentedTextWriter writer, string folder)
832 {
833 foreach (string child in Directory.GetDirectories(folder))
834 {
835 if (ContainsSqlFiles(child))
836 {
837 writer.WriteLine("Begin Folder = \"{0}\"", Path.GetFileName(child));
838 writer.Indent++;
839 WriteDatabaseFoldersAndFiles(writer, child);
840 writer.Indent--;
841 writer.WriteLine("End");
842 }
843 }
844 foreach (string file in Directory.GetFiles(folder, "*.sql"))
845 {
846 writer.WriteLine("Script = \"{0}\"", Path.GetFileName(file));
847 }
848 }
849
850 private void CleanProject(ProjectNode project)
851 {
852 kernel.Log.Write("...Cleaning project: {0}", project.Name);
853
854 ToolInfo toolInfo = tools[project.Language];
855 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
856 string userFile = projectFile + ".user";
857
858 Helper.DeleteIfExists(projectFile);
859 Helper.DeleteIfExists(userFile);
860 }
861
862 private void CleanSolution(SolutionNode solution)
863 {
864 kernel.Log.Write("Cleaning {0} solution and project files", VersionName, solution.Name);
865
866 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
867 string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo");
868
869 Helper.DeleteIfExists(slnFile);
870 Helper.DeleteIfExists(suoFile);
871
872 foreach (ProjectNode project in solution.Projects)
873 {
874 CleanProject(project);
875 }
876
877 kernel.Log.Write("");
878 }
879
880 #endregion
881
882 #region ITarget Members
883
884 /// <summary>
885 /// Writes the specified kern.
886 /// </summary>
887 /// <param name="kern">The kern.</param>
888 public virtual void Write(Kernel kern)
889 {
890 if (kern == null)
891 {
892 throw new ArgumentNullException("kern");
893 }
894 kernel = kern;
895 foreach (SolutionNode sol in kernel.Solutions)
896 {
897 WriteSolution(sol, true);
898 }
899 kernel = null;
900 }
901
902 /// <summary>
903 /// Cleans the specified kern.
904 /// </summary>
905 /// <param name="kern">The kern.</param>
906 public virtual void Clean(Kernel kern)
907 {
908 if (kern == null)
909 {
910 throw new ArgumentNullException("kern");
911 }
912 kernel = kern;
913 foreach (SolutionNode sol in kernel.Solutions)
914 {
915 CleanSolution(sol);
916 }
917 kernel = null;
918 }
919
920 #endregion
921 }
922}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/VSVersion.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/VSVersion.cs.svn-base
new file mode 100644
index 0000000..699b5ca
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/VSVersion.cs.svn-base
@@ -0,0 +1,54 @@
1#region BSD License
2/*
3Copyright (c) 2008-2009 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com), John Anderson (sontek@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26namespace Prebuild.Core.Targets
27{
28 /// <summary>
29 ///
30 /// </summary>
31 public enum VSVersion
32 {
33 /// <summary>
34 /// Visual Studio 2002
35 /// </summary>
36 VS70,
37 /// <summary>
38 /// Visual Studio 2003
39 /// </summary>
40 VS71,
41 /// <summary>
42 /// Visual Studio 2005
43 /// </summary>
44 VS80,
45 /// <summary>
46 /// Visual Studio 2008
47 /// </summary>
48 VS90,
49 /// <summary>
50 /// Visual Studio 2010
51 /// </summary>
52 VS10
53 }
54}
diff --git a/Prebuild/src/Core/Targets/.svn/text-base/XcodeTarget.cs.svn-base b/Prebuild/src/Core/Targets/.svn/text-base/XcodeTarget.cs.svn-base
new file mode 100644
index 0000000..5393cec
--- /dev/null
+++ b/Prebuild/src/Core/Targets/.svn/text-base/XcodeTarget.cs.svn-base
@@ -0,0 +1,594 @@
1#region BSD License
2/*
3Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Reflection;
29using System.Text.RegularExpressions;
30
31using Prebuild.Core.Attributes;
32using Prebuild.Core.Interfaces;
33using Prebuild.Core.Nodes;
34using Prebuild.Core.Utilities;
35
36namespace Prebuild.Core.Targets
37{
38 /// <summary>
39 ///
40 /// </summary>
41 [Target("xcode")]
42 public class XcodeTarget : ITarget
43 {
44 #region Fields
45
46 private Kernel m_Kernel;
47
48 #endregion
49
50 #region Private Methods
51
52 private static string PrependPath(string path)
53 {
54 string tmpPath = Helper.NormalizePath(path, '/');
55 Regex regex = new Regex(@"(\w):/(\w+)");
56 Match match = regex.Match(tmpPath);
57 //if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
58 //{
59 tmpPath = Helper.NormalizePath(tmpPath);
60 //}
61 // else
62 // {
63 // tmpPath = Helper.NormalizePath("./" + tmpPath);
64 // }
65
66 return tmpPath;
67 }
68
69 private static string BuildReference(SolutionNode solution, ReferenceNode refr)
70 {
71 string ret = "";
72 if (solution.ProjectsTable.ContainsKey(refr.Name))
73 {
74 ProjectNode project = (ProjectNode)solution.ProjectsTable[refr.Name];
75 string fileRef = FindFileReference(refr.Name, project);
76 string finalPath = Helper.NormalizePath(Helper.MakeFilePath(project.FullPath + "/${build.dir}/", refr.Name, "dll"), '/');
77 ret += finalPath;
78 return ret;
79 }
80 else
81 {
82 ProjectNode project = (ProjectNode)refr.Parent;
83 string fileRef = FindFileReference(refr.Name, project);
84
85 if (refr.Path != null || fileRef != null)
86 {
87 string finalPath = (refr.Path != null) ? Helper.NormalizePath(refr.Path + "/" + refr.Name + ".dll", '/') : fileRef;
88 ret += finalPath;
89 return ret;
90 }
91
92 try
93 {
94 //Assembly assem = Assembly.Load(refr.Name);
95 //if (assem != null)
96 //{
97 //ret += (refr.Name + ".dll");
98 //}
99 //else
100 //{
101 ret += (refr.Name + ".dll");
102 //}
103 }
104 catch (System.NullReferenceException e)
105 {
106 e.ToString();
107 ret += refr.Name + ".dll";
108 }
109 }
110 return ret;
111 }
112
113 private static string BuildReferencePath(SolutionNode solution, ReferenceNode refr)
114 {
115 string ret = "";
116 if (solution.ProjectsTable.ContainsKey(refr.Name))
117 {
118 ProjectNode project = (ProjectNode)solution.ProjectsTable[refr.Name];
119 string fileRef = FindFileReference(refr.Name, project);
120 string finalPath = Helper.NormalizePath(Helper.MakeReferencePath(project.FullPath + "/${build.dir}/"), '/');
121 ret += finalPath;
122 return ret;
123 }
124 else
125 {
126 ProjectNode project = (ProjectNode)refr.Parent;
127 string fileRef = FindFileReference(refr.Name, project);
128
129 if (refr.Path != null || fileRef != null)
130 {
131 string finalPath = (refr.Path != null) ? Helper.NormalizePath(refr.Path, '/') : fileRef;
132 ret += finalPath;
133 return ret;
134 }
135
136 try
137 {
138 Assembly assem = Assembly.Load(refr.Name);
139 if (assem != null)
140 {
141 ret += "";
142 }
143 else
144 {
145 ret += "";
146 }
147 }
148 catch (System.NullReferenceException e)
149 {
150 e.ToString();
151 ret += "";
152 }
153 }
154 return ret;
155 }
156
157 private static string FindFileReference(string refName, ProjectNode project)
158 {
159 foreach (ReferencePathNode refPath in project.ReferencePaths)
160 {
161 string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
162
163 if (File.Exists(fullPath))
164 {
165 return fullPath;
166 }
167 }
168
169 return null;
170 }
171
172 /// <summary>
173 /// Gets the XML doc file.
174 /// </summary>
175 /// <param name="project">The project.</param>
176 /// <param name="conf">The conf.</param>
177 /// <returns></returns>
178 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
179 {
180 if (conf == null)
181 {
182 throw new ArgumentNullException("conf");
183 }
184 if (project == null)
185 {
186 throw new ArgumentNullException("project");
187 }
188 string docFile = (string)conf.Options["XmlDocFile"];
189 // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
190 // {
191 // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
192 // }
193 return docFile;
194 }
195
196 private void WriteProject(SolutionNode solution, ProjectNode project)
197 {
198 string projFile = Helper.MakeFilePath(project.FullPath, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build");
199 StreamWriter ss = new StreamWriter(projFile);
200
201 m_Kernel.CurrentWorkingDirectory.Push();
202 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
203 bool hasDoc = false;
204
205 using (ss)
206 {
207 ss.WriteLine("<?xml version=\"1.0\" ?>");
208 ss.WriteLine("<project name=\"{0}\" default=\"build\">", project.Name);
209 ss.WriteLine(" <target name=\"{0}\">", "build");
210 ss.WriteLine(" <echo message=\"Build Directory is ${project::get-base-directory()}/${build.dir}\" />");
211 ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/${build.dir}\" />");
212 ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/${build.dir}\">");
213 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
214 foreach (ReferenceNode refr in project.References)
215 {
216 if (refr.LocalCopy)
217 {
218 ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, refr)) + "\" />", '/'));
219 }
220 }
221 ss.WriteLine(" </fileset>");
222 ss.WriteLine(" </copy>");
223 ss.Write(" <csc");
224 ss.Write(" target=\"{0}\"", project.Type.ToString().ToLower());
225 ss.Write(" debug=\"{0}\"", "${build.debug}");
226 foreach (ConfigurationNode conf in project.Configurations)
227 {
228 if (conf.Options.KeyFile != "")
229 {
230 ss.Write(" keyfile=\"{0}\"", conf.Options.KeyFile);
231 break;
232 }
233 }
234 foreach (ConfigurationNode conf in project.Configurations)
235 {
236 ss.Write(" unsafe=\"{0}\"", conf.Options.AllowUnsafe);
237 break;
238 }
239 foreach (ConfigurationNode conf in project.Configurations)
240 {
241 ss.Write(" define=\"{0}\"", conf.Options.CompilerDefines);
242 break;
243 }
244 foreach (ConfigurationNode conf in project.Configurations)
245 {
246 if (GetXmlDocFile(project, conf) != "")
247 {
248 ss.Write(" doc=\"{0}\"", "${project::get-base-directory()}/${build.dir}/" + GetXmlDocFile(project, conf));
249 hasDoc = true;
250 }
251 break;
252 }
253 ss.Write(" output=\"{0}", "${project::get-base-directory()}/${build.dir}/${project::get-name()}");
254 if (project.Type == ProjectType.Library)
255 {
256 ss.Write(".dll\"");
257 }
258 else
259 {
260 ss.Write(".exe\"");
261 }
262 if (project.AppIcon != null && project.AppIcon.Length != 0)
263 {
264 ss.Write(" win32icon=\"{0}\"", Helper.NormalizePath(project.AppIcon, '/'));
265 }
266 ss.WriteLine(">");
267 ss.WriteLine(" <resources prefix=\"{0}\" dynamicprefix=\"true\" >", project.RootNamespace);
268 foreach (string file in project.Files)
269 {
270 switch (project.Files.GetBuildAction(file))
271 {
272 case BuildAction.EmbeddedResource:
273 ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
274 break;
275 default:
276 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
277 {
278 ss.WriteLine(" <include name=\"{0}\" />", file.Substring(0, file.LastIndexOf('.')) + ".resx");
279 }
280 break;
281 }
282 }
283 //if (project.Files.GetSubType(file).ToString() != "Code")
284 //{
285 // ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
286
287 ss.WriteLine(" </resources>");
288 ss.WriteLine(" <sources failonempty=\"true\">");
289 foreach (string file in project.Files)
290 {
291 switch (project.Files.GetBuildAction(file))
292 {
293 case BuildAction.Compile:
294 ss.WriteLine(" <include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
295 break;
296 default:
297 break;
298 }
299 }
300 ss.WriteLine(" </sources>");
301 ss.WriteLine(" <references basedir=\"${project::get-base-directory()}\">");
302 ss.WriteLine(" <lib>");
303 ss.WriteLine(" <include name=\"${project::get-base-directory()}\" />");
304 ss.WriteLine(" <include name=\"${project::get-base-directory()}/${build.dir}\" />");
305 ss.WriteLine(" </lib>");
306 foreach (ReferenceNode refr in project.References)
307 {
308 ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, refr)) + "\" />", '/'));
309 }
310 ss.WriteLine(" </references>");
311
312 ss.WriteLine(" </csc>");
313 ss.WriteLine(" </target>");
314
315 ss.WriteLine(" <target name=\"clean\">");
316 ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />");
317 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
318 ss.WriteLine(" </target>");
319
320 ss.WriteLine(" <target name=\"doc\" description=\"Creates documentation.\">");
321 if (hasDoc)
322 {
323 ss.WriteLine(" <property name=\"doc.target\" value=\"\" />");
324 ss.WriteLine(" <if test=\"${platform::is-unix()}\">");
325 ss.WriteLine(" <property name=\"doc.target\" value=\"Web\" />");
326 ss.WriteLine(" </if>");
327 ss.WriteLine(" <ndoc failonerror=\"false\" verbose=\"true\">");
328 ss.WriteLine(" <assemblies basedir=\"${project::get-base-directory()}\">");
329 ss.Write(" <include name=\"${build.dir}/${project::get-name()}");
330 if (project.Type == ProjectType.Library)
331 {
332 ss.WriteLine(".dll\" />");
333 }
334 else
335 {
336 ss.WriteLine(".exe\" />");
337 }
338
339 ss.WriteLine(" </assemblies>");
340 ss.WriteLine(" <summaries basedir=\"${project::get-base-directory()}\">");
341 ss.WriteLine(" <include name=\"${build.dir}/${project::get-name()}.xml\"/>");
342 ss.WriteLine(" </summaries>");
343 ss.WriteLine(" <referencepaths basedir=\"${project::get-base-directory()}\">");
344 ss.WriteLine(" <include name=\"${build.dir}\" />");
345 // foreach(ReferenceNode refr in project.References)
346 // {
347 // string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReferencePath(solution, refr)), '/');
348 // if (path != "")
349 // {
350 // ss.WriteLine(" <include name=\"{0}\" />", path);
351 // }
352 // }
353 ss.WriteLine(" </referencepaths>");
354 ss.WriteLine(" <documenters>");
355 ss.WriteLine(" <documenter name=\"MSDN\">");
356 ss.WriteLine(" <property name=\"OutputDirectory\" value=\"${project::get-base-directory()}/${build.dir}/doc/${project::get-name()}\" />");
357 ss.WriteLine(" <property name=\"OutputTarget\" value=\"${doc.target}\" />");
358 ss.WriteLine(" <property name=\"HtmlHelpName\" value=\"${project::get-name()}\" />");
359 ss.WriteLine(" <property name=\"IncludeFavorites\" value=\"False\" />");
360 ss.WriteLine(" <property name=\"Title\" value=\"${project::get-name()} SDK Documentation\" />");
361 ss.WriteLine(" <property name=\"SplitTOCs\" value=\"False\" />");
362 ss.WriteLine(" <property name=\"DefaulTOC\" value=\"\" />");
363 ss.WriteLine(" <property name=\"ShowVisualBasic\" value=\"True\" />");
364 ss.WriteLine(" <property name=\"AutoDocumentConstructors\" value=\"True\" />");
365 ss.WriteLine(" <property name=\"ShowMissingSummaries\" value=\"${build.debug}\" />");
366 ss.WriteLine(" <property name=\"ShowMissingRemarks\" value=\"${build.debug}\" />");
367 ss.WriteLine(" <property name=\"ShowMissingParams\" value=\"${build.debug}\" />");
368 ss.WriteLine(" <property name=\"ShowMissingReturns\" value=\"${build.debug}\" />");
369 ss.WriteLine(" <property name=\"ShowMissingValues\" value=\"${build.debug}\" />");
370 ss.WriteLine(" <property name=\"DocumentInternals\" value=\"False\" />");
371 ss.WriteLine(" <property name=\"DocumentPrivates\" value=\"False\" />");
372 ss.WriteLine(" <property name=\"DocumentProtected\" value=\"True\" />");
373 ss.WriteLine(" <property name=\"DocumentEmptyNamespaces\" value=\"${build.debug}\" />");
374 ss.WriteLine(" <property name=\"IncludeAssemblyVersion\" value=\"True\" />");
375 ss.WriteLine(" </documenter>");
376 ss.WriteLine(" </documenters>");
377 ss.WriteLine(" </ndoc>");
378 }
379 ss.WriteLine(" </target>");
380 ss.WriteLine("</project>");
381 }
382 m_Kernel.CurrentWorkingDirectory.Pop();
383 }
384
385 private void WriteCombine(SolutionNode solution)
386 {
387 m_Kernel.Log.Write("Creating Xcode build files");
388 foreach (ProjectNode project in solution.Projects)
389 {
390 if (m_Kernel.AllowProject(project.FilterGroups))
391 {
392 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
393 WriteProject(solution, project);
394 }
395 }
396
397 m_Kernel.Log.Write("");
398 DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(solution.FullPath, solution.Name + ".xcodeproj"));
399 if (!directoryInfo.Exists)
400 {
401 directoryInfo.Create();
402 }
403 string combFile = Helper.MakeFilePath(Path.Combine(solution.FullPath, solution.Name + ".xcodeproj"), "project", "pbxproj");
404 StreamWriter ss = new StreamWriter(combFile);
405
406 m_Kernel.CurrentWorkingDirectory.Push();
407 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
408
409 using (ss)
410 {
411 ss.WriteLine("<?xml version=\"1.0\" ?>");
412 ss.WriteLine("<project name=\"{0}\" default=\"build\">", solution.Name);
413 ss.WriteLine(" <echo message=\"Using '${nant.settings.currentframework}' Framework\"/>");
414 ss.WriteLine();
415
416 //ss.WriteLine(" <property name=\"dist.dir\" value=\"dist\" />");
417 //ss.WriteLine(" <property name=\"source.dir\" value=\"source\" />");
418 ss.WriteLine(" <property name=\"bin.dir\" value=\"bin\" />");
419 ss.WriteLine(" <property name=\"obj.dir\" value=\"obj\" />");
420 ss.WriteLine(" <property name=\"doc.dir\" value=\"doc\" />");
421 ss.WriteLine(" <property name=\"project.main.dir\" value=\"${project::get-base-directory()}\" />");
422
423 foreach (ConfigurationNode conf in solution.Configurations)
424 {
425 // Set the project.config to a non-debug configuration
426 if (conf.Options["DebugInformation"].ToString().ToLower() != "true")
427 {
428 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name);
429 }
430 ss.WriteLine();
431 ss.WriteLine(" <target name=\"{0}\" description=\"\">", conf.Name);
432 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name);
433 ss.WriteLine(" <property name=\"build.debug\" value=\"{0}\" />", conf.Options["DebugInformation"].ToString().ToLower());
434 ss.WriteLine(" </target>");
435 ss.WriteLine();
436 }
437
438 ss.WriteLine(" <target name=\"net-1.1\" description=\"Sets framework to .NET 1.1\">");
439 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-1.1\" />");
440 ss.WriteLine(" </target>");
441 ss.WriteLine();
442
443 ss.WriteLine(" <target name=\"net-2.0\" description=\"Sets framework to .NET 2.0\">");
444 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-2.0\" />");
445 ss.WriteLine(" </target>");
446 ss.WriteLine();
447
448 ss.WriteLine(" <target name=\"mono-2.0\" description=\"Sets framework to mono 2.0\">");
449 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-2.0\" />");
450 ss.WriteLine(" </target>");
451 ss.WriteLine();
452
453 ss.WriteLine(" <target name=\"mono-1.0\" description=\"Sets framework to mono 1.0\">");
454 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-1.0\" />");
455 ss.WriteLine(" </target>");
456 ss.WriteLine();
457
458 ss.WriteLine(" <target name=\"init\" description=\"\">");
459 ss.WriteLine(" <call target=\"${project.config}\" />");
460 ss.WriteLine(" <sysinfo />");
461 ss.WriteLine(" <echo message=\"Platform ${sys.os.platform}\" />");
462 ss.WriteLine(" <property name=\"build.dir\" value=\"${bin.dir}/${project.config}\" />");
463 ss.WriteLine(" </target>");
464 ss.WriteLine();
465
466 ss.WriteLine(" <target name=\"clean\" description=\"\">");
467 ss.WriteLine(" <echo message=\"Deleting all builds from all configurations\" />");
468 //ss.WriteLine(" <delete dir=\"${dist.dir}\" failonerror=\"false\" />");
469 ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />");
470 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
471 //foreach(ProjectNode project in solution.Projects)
472 //{
473 // string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
474 // ss.Write(" <nant buildfile=\"{0}\"",
475 // Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"),'/'));
476 // ss.WriteLine(" target=\"clean\" />");
477 //}
478 ss.WriteLine(" </target>");
479 ss.WriteLine();
480
481 ss.WriteLine(" <target name=\"build\" depends=\"init\" description=\"\">");
482
483 foreach (ProjectNode project in solution.ProjectsTableOrder)
484 {
485 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
486 ss.Write(" <nant buildfile=\"{0}\"",
487 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"), '/'));
488 ss.WriteLine(" target=\"build\" />");
489 }
490 ss.WriteLine(" </target>");
491 ss.WriteLine();
492
493 ss.WriteLine(" <target name=\"build-release\" depends=\"Release, init, build\" description=\"Builds in Release mode\" />");
494 ss.WriteLine();
495 ss.WriteLine(" <target name=\"build-debug\" depends=\"Debug, init, build\" description=\"Builds in Debug mode\" />");
496 ss.WriteLine();
497 //ss.WriteLine(" <target name=\"package\" depends=\"clean, doc, copyfiles, zip\" description=\"Builds in Release mode\" />");
498 ss.WriteLine(" <target name=\"package\" depends=\"clean, doc\" description=\"Builds all\" />");
499 ss.WriteLine();
500
501 ss.WriteLine(" <target name=\"doc\" depends=\"build-release\">");
502 ss.WriteLine(" <echo message=\"Generating all documentation from all builds\" />");
503 foreach (ProjectNode project in solution.Projects)
504 {
505 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
506 ss.Write(" <nant buildfile=\"{0}\"",
507 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"), '/'));
508 ss.WriteLine(" target=\"doc\" />");
509 }
510 ss.WriteLine(" </target>");
511 ss.WriteLine();
512 ss.WriteLine("</project>");
513 }
514
515 m_Kernel.CurrentWorkingDirectory.Pop();
516 }
517
518 private void CleanProject(ProjectNode project)
519 {
520 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
521 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build");
522 Helper.DeleteIfExists(projectFile);
523 }
524
525 private void CleanSolution(SolutionNode solution)
526 {
527 m_Kernel.Log.Write("Cleaning Xcode build files for", solution.Name);
528
529 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
530 Helper.DeleteIfExists(slnFile);
531
532 foreach (ProjectNode project in solution.Projects)
533 {
534 CleanProject(project);
535 }
536
537 m_Kernel.Log.Write("");
538 }
539
540 #endregion
541
542 #region ITarget Members
543
544 /// <summary>
545 /// Writes the specified kern.
546 /// </summary>
547 /// <param name="kern">The kern.</param>
548 public void Write(Kernel kern)
549 {
550 if (kern == null)
551 {
552 throw new ArgumentNullException("kern");
553 }
554 m_Kernel = kern;
555 foreach (SolutionNode solution in kern.Solutions)
556 {
557 WriteCombine(solution);
558 }
559 m_Kernel = null;
560 }
561
562 /// <summary>
563 /// Cleans the specified kern.
564 /// </summary>
565 /// <param name="kern">The kern.</param>
566 public virtual void Clean(Kernel kern)
567 {
568 if (kern == null)
569 {
570 throw new ArgumentNullException("kern");
571 }
572 m_Kernel = kern;
573 foreach (SolutionNode sol in kern.Solutions)
574 {
575 CleanSolution(sol);
576 }
577 m_Kernel = null;
578 }
579
580 /// <summary>
581 /// Gets the name.
582 /// </summary>
583 /// <value>The name.</value>
584 public string Name
585 {
586 get
587 {
588 return "xcode";
589 }
590 }
591
592 #endregion
593 }
594}
diff --git a/Prebuild/src/Core/Targets/AutotoolsTarget.cs b/Prebuild/src/Core/Targets/AutotoolsTarget.cs
new file mode 100644
index 0000000..e46b5a5
--- /dev/null
+++ b/Prebuild/src/Core/Targets/AutotoolsTarget.cs
@@ -0,0 +1,1070 @@
1#region BSD License
2/*
3
4Copyright (c) 2004 - 2008
5Matthew Holmes (matthew@wildfiregames.com),
6Dan Moorehead (dan05a@gmail.com),
7Dave Hudson (jendave@yahoo.com),
8C.J. Adams-Collier (cjac@colliertech.org),
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are
12met:
13
14* Redistributions of source code must retain the above copyright
15notice, this list of conditions and the following disclaimer.
16
17* Redistributions in binary form must reproduce the above copyright
18notice, this list of conditions and the following disclaimer in the
19documentation and/or other materials provided with the distribution.
20
21* The name of the author may not be used to endorse or promote
22products derived from this software without specific prior written
23permission.
24
25THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
29INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35POSSIBILITY OF SUCH DAMAGE.
36
37*/
38#endregion
39
40#region MIT X11 license
41
42/*
43 Portions of this file authored by Lluis Sanchez Gual
44
45 Copyright (C) 2006 Novell, Inc (http://www.novell.com)
46
47 Permission is hereby granted, free of charge, to any person obtaining
48 a copy of this software and associated documentation files (the
49 "Software"), to deal in the Software without restriction, including
50 without limitation the rights to use, copy, modify, merge, publish,
51 distribute, sublicense, and/or sell copies of the Software, and to
52 permit persons to whom the Software is furnished to do so, subject to
53 the following conditions:
54
55 The above copyright notice and this permission notice shall be
56 included in all copies or substantial portions of the Software.
57
58 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
59 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
61 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
62 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
63 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
64 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65 */
66
67#endregion
68using System;
69using System.Collections.Generic;
70using System.IO;
71using System.Reflection;
72using System.Text;
73using System.Text.RegularExpressions;
74using System.Xml;
75using System.Xml.Xsl;
76using System.Net;
77using System.Diagnostics;
78
79using Prebuild.Core.Attributes;
80using Prebuild.Core.Interfaces;
81using Prebuild.Core.Nodes;
82using Prebuild.Core.Utilities;
83
84namespace Prebuild.Core.Targets
85{
86 public enum ClrVersion
87 {
88 Default,
89 Net_1_1,
90 Net_2_0
91 }
92
93 public class SystemPackage
94 {
95 string name;
96 string version;
97 string description;
98 string[] assemblies;
99 bool isInternal;
100 ClrVersion targetVersion;
101
102 public void Initialize(string name,
103 string version,
104 string description,
105 string[] assemblies,
106 ClrVersion targetVersion,
107 bool isInternal)
108 {
109 this.isInternal = isInternal;
110 this.name = name;
111 this.version = version;
112 this.assemblies = assemblies;
113 this.description = description;
114 this.targetVersion = targetVersion;
115 }
116
117 public string Name
118 {
119 get { return name; }
120 }
121
122 public string Version
123 {
124 get { return version; }
125 }
126
127 public string Description
128 {
129 get { return description; }
130 }
131
132 public ClrVersion TargetVersion
133 {
134 get { return targetVersion; }
135 }
136
137 // The package is part of the mono SDK
138 public bool IsCorePackage
139 {
140 get { return name == "mono"; }
141 }
142
143 // The package has been registered by an add-in, and is not installed
144 // in the system.
145 public bool IsInternalPackage
146 {
147 get { return isInternal; }
148 }
149
150 public string[] Assemblies
151 {
152 get { return assemblies; }
153 }
154
155 }
156
157
158 /// <summary>
159 ///
160 /// </summary>
161 [Target("autotools")]
162 public class AutotoolsTarget : ITarget
163 {
164 #region Fields
165
166 Kernel m_Kernel;
167 XmlDocument autotoolsDoc;
168 XmlUrlResolver xr;
169 System.Security.Policy.Evidence e;
170 readonly Dictionary<string, SystemPackage> assemblyPathToPackage = new Dictionary<string, SystemPackage>();
171 readonly Dictionary<string, string> assemblyFullNameToPath = new Dictionary<string, string>();
172 readonly Dictionary<string, SystemPackage> packagesHash = new Dictionary<string, SystemPackage>();
173 readonly List<SystemPackage> packages = new List<SystemPackage>();
174
175 #endregion
176
177 #region Private Methods
178
179 private static void mkdirDashP(string dirName)
180 {
181 DirectoryInfo di = new DirectoryInfo(dirName);
182 if (di.Exists)
183 return;
184
185 string parentDirName = System.IO.Path.GetDirectoryName(dirName);
186 DirectoryInfo parentDi = new DirectoryInfo(parentDirName);
187 if (!parentDi.Exists)
188 mkdirDashP(parentDirName);
189
190 di.Create();
191 }
192
193 private static void chkMkDir(string dirName)
194 {
195 System.IO.DirectoryInfo di =
196 new System.IO.DirectoryInfo(dirName);
197
198 if (!di.Exists)
199 di.Create();
200 }
201
202 private void transformToFile(string filename, XsltArgumentList argList, string nodeName)
203 {
204 // Create an XslTransform for this file
205 XslTransform templateTransformer =
206 new XslTransform();
207
208 // Load up the template
209 XmlNode templateNode =
210 autotoolsDoc.SelectSingleNode(nodeName + "/*");
211 templateTransformer.Load(templateNode.CreateNavigator(), xr, e);
212
213 // Create a writer for the transformed template
214 XmlTextWriter templateWriter =
215 new XmlTextWriter(filename, null);
216
217 // Perform transformation, writing the file
218 templateTransformer.Transform
219 (m_Kernel.CurrentDoc, argList, templateWriter, xr);
220 }
221
222 static string NormalizeAsmName(string name)
223 {
224 int i = name.IndexOf(", PublicKeyToken=null");
225 if (i != -1)
226 return name.Substring(0, i).Trim();
227 return name;
228 }
229
230 private void AddAssembly(string assemblyfile, SystemPackage package)
231 {
232 if (!File.Exists(assemblyfile))
233 return;
234
235 try
236 {
237 System.Reflection.AssemblyName an = System.Reflection.AssemblyName.GetAssemblyName(assemblyfile);
238 assemblyFullNameToPath[NormalizeAsmName(an.FullName)] = assemblyfile;
239 assemblyPathToPackage[assemblyfile] = package;
240 }
241 catch
242 {
243 }
244 }
245
246 private static List<string> GetAssembliesWithLibInfo(string line, string file)
247 {
248 List<string> references = new List<string>();
249 List<string> libdirs = new List<string>();
250 List<string> retval = new List<string>();
251 foreach (string piece in line.Split(' '))
252 {
253 if (piece.ToLower().Trim().StartsWith("/r:") || piece.ToLower().Trim().StartsWith("-r:"))
254 {
255 references.Add(ProcessPiece(piece.Substring(3).Trim(), file));
256 }
257 else if (piece.ToLower().Trim().StartsWith("/lib:") || piece.ToLower().Trim().StartsWith("-lib:"))
258 {
259 libdirs.Add(ProcessPiece(piece.Substring(5).Trim(), file));
260 }
261 }
262
263 foreach (string refrnc in references)
264 {
265 foreach (string libdir in libdirs)
266 {
267 if (File.Exists(libdir + Path.DirectorySeparatorChar + refrnc))
268 {
269 retval.Add(libdir + Path.DirectorySeparatorChar + refrnc);
270 }
271 }
272 }
273
274 return retval;
275 }
276
277 private static List<string> GetAssembliesWithoutLibInfo(string line, string file)
278 {
279 List<string> references = new List<string>();
280 foreach (string reference in line.Split(' '))
281 {
282 if (reference.ToLower().Trim().StartsWith("/r:") || reference.ToLower().Trim().StartsWith("-r:"))
283 {
284 string final_ref = reference.Substring(3).Trim();
285 references.Add(ProcessPiece(final_ref, file));
286 }
287 }
288 return references;
289 }
290
291 private static string ProcessPiece(string piece, string pcfile)
292 {
293 int start = piece.IndexOf("${");
294 if (start == -1)
295 return piece;
296
297 int end = piece.IndexOf("}");
298 if (end == -1)
299 return piece;
300
301 string variable = piece.Substring(start + 2, end - start - 2);
302 string interp = GetVariableFromPkgConfig(variable, Path.GetFileNameWithoutExtension(pcfile));
303 return ProcessPiece(piece.Replace("${" + variable + "}", interp), pcfile);
304 }
305
306 private static string GetVariableFromPkgConfig(string var, string pcfile)
307 {
308 ProcessStartInfo psi = new ProcessStartInfo("pkg-config");
309 psi.RedirectStandardOutput = true;
310 psi.UseShellExecute = false;
311 psi.Arguments = String.Format("--variable={0} {1}", var, pcfile);
312 Process p = new Process();
313 p.StartInfo = psi;
314 p.Start();
315 string ret = p.StandardOutput.ReadToEnd().Trim();
316 p.WaitForExit();
317 if (String.IsNullOrEmpty(ret))
318 return String.Empty;
319 return ret;
320 }
321
322 private void ParsePCFile(string pcfile)
323 {
324 // Don't register the package twice
325 string pname = Path.GetFileNameWithoutExtension(pcfile);
326 if (packagesHash.ContainsKey(pname))
327 return;
328
329 List<string> fullassemblies = null;
330 string version = "";
331 string desc = "";
332
333 SystemPackage package = new SystemPackage();
334
335 using (StreamReader reader = new StreamReader(pcfile))
336 {
337 string line;
338 while ((line = reader.ReadLine()) != null)
339 {
340 string lowerLine = line.ToLower();
341 if (lowerLine.StartsWith("libs:") && lowerLine.IndexOf(".dll") != -1)
342 {
343 string choppedLine = line.Substring(5).Trim();
344 if (choppedLine.IndexOf("-lib:") != -1 || choppedLine.IndexOf("/lib:") != -1)
345 {
346 fullassemblies = GetAssembliesWithLibInfo(choppedLine, pcfile);
347 }
348 else
349 {
350 fullassemblies = GetAssembliesWithoutLibInfo(choppedLine, pcfile);
351 }
352 }
353 else if (lowerLine.StartsWith("version:"))
354 {
355 // "version:".Length == 8
356 version = line.Substring(8).Trim();
357 }
358 else if (lowerLine.StartsWith("description:"))
359 {
360 // "description:".Length == 12
361 desc = line.Substring(12).Trim();
362 }
363 }
364 }
365
366 if (fullassemblies == null)
367 return;
368
369 foreach (string assembly in fullassemblies)
370 {
371 AddAssembly(assembly, package);
372 }
373
374 package.Initialize(pname,
375 version,
376 desc,
377 fullassemblies.ToArray(),
378 ClrVersion.Default,
379 false);
380 packages.Add(package);
381 packagesHash[pname] = package;
382 }
383
384 void RegisterSystemAssemblies(string prefix, string version, ClrVersion ver)
385 {
386 SystemPackage package = new SystemPackage();
387 List<string> list = new List<string>();
388
389 string dir = Path.Combine(prefix, version);
390 if (!Directory.Exists(dir))
391 {
392 return;
393 }
394
395 foreach (string assembly in Directory.GetFiles(dir, "*.dll"))
396 {
397 AddAssembly(assembly, package);
398 list.Add(assembly);
399 }
400
401 package.Initialize("mono",
402 version,
403 "The Mono runtime",
404 list.ToArray(),
405 ver,
406 false);
407 packages.Add(package);
408 }
409
410 void RunInitialization()
411 {
412 string versionDir;
413
414 if (Environment.Version.Major == 1)
415 {
416 versionDir = "1.0";
417 }
418 else
419 {
420 versionDir = "2.0";
421 }
422
423 //Pull up assemblies from the installed mono system.
424 string prefix = Path.GetDirectoryName(typeof(int).Assembly.Location);
425
426 if (prefix.IndexOf(Path.Combine("mono", versionDir)) == -1)
427 prefix = Path.Combine(prefix, "mono");
428 else
429 prefix = Path.GetDirectoryName(prefix);
430
431 RegisterSystemAssemblies(prefix, "1.0", ClrVersion.Net_1_1);
432 RegisterSystemAssemblies(prefix, "2.0", ClrVersion.Net_2_0);
433
434 string search_dirs = Environment.GetEnvironmentVariable("PKG_CONFIG_PATH");
435 string libpath = Environment.GetEnvironmentVariable("PKG_CONFIG_LIBPATH");
436
437 if (String.IsNullOrEmpty(libpath))
438 {
439 string path_dirs = Environment.GetEnvironmentVariable("PATH");
440 foreach (string pathdir in path_dirs.Split(Path.PathSeparator))
441 {
442 if (pathdir == null)
443 continue;
444 if (File.Exists(pathdir + Path.DirectorySeparatorChar + "pkg-config"))
445 {
446 libpath = Path.Combine(pathdir, "..");
447 libpath = Path.Combine(libpath, "lib");
448 libpath = Path.Combine(libpath, "pkgconfig");
449 break;
450 }
451 }
452 }
453 search_dirs += Path.PathSeparator + libpath;
454 if (!string.IsNullOrEmpty(search_dirs))
455 {
456 List<string> scanDirs = new List<string>();
457 foreach (string potentialDir in search_dirs.Split(Path.PathSeparator))
458 {
459 if (!scanDirs.Contains(potentialDir))
460 scanDirs.Add(potentialDir);
461 }
462 foreach (string pcdir in scanDirs)
463 {
464 if (pcdir == null)
465 continue;
466
467 if (Directory.Exists(pcdir))
468 {
469 foreach (string pcfile in Directory.GetFiles(pcdir, "*.pc"))
470 {
471 ParsePCFile(pcfile);
472 }
473 }
474 }
475 }
476 }
477
478 private void WriteCombine(SolutionNode solution)
479 {
480 #region "Create Solution directory if it doesn't exist"
481 string solutionDir = Path.Combine(solution.FullPath,
482 Path.Combine("autotools",
483 solution.Name));
484 chkMkDir(solutionDir);
485 #endregion
486
487 #region "Write Solution-level files"
488 XsltArgumentList argList = new XsltArgumentList();
489 argList.AddParam("solutionName", "", solution.Name);
490 // $solutionDir is $rootDir/$solutionName/
491 transformToFile(Path.Combine(solutionDir, "configure.ac"),
492 argList, "/Autotools/SolutionConfigureAc");
493 transformToFile(Path.Combine(solutionDir, "Makefile.am"),
494 argList, "/Autotools/SolutionMakefileAm");
495 transformToFile(Path.Combine(solutionDir, "autogen.sh"),
496 argList, "/Autotools/SolutionAutogenSh");
497 #endregion
498
499 foreach (ProjectNode project in solution.ProjectsTableOrder)
500 {
501 m_Kernel.Log.Write(String.Format("Writing project: {0}",
502 project.Name));
503 WriteProject(solution, project);
504 }
505 }
506
507 private static string FindFileReference(string refName,
508 ProjectNode project)
509 {
510 foreach (ReferencePathNode refPath in project.ReferencePaths)
511 {
512 string fullPath =
513 Helper.MakeFilePath(refPath.Path, refName, "dll");
514
515 if (File.Exists(fullPath)) {
516 return fullPath;
517 }
518 }
519
520 return null;
521 }
522
523 /// <summary>
524 /// Gets the XML doc file.
525 /// </summary>
526 /// <param name="project">The project.</param>
527 /// <param name="conf">The conf.</param>
528 /// <returns></returns>
529 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
530 {
531 if (conf == null)
532 {
533 throw new ArgumentNullException("conf");
534 }
535 if (project == null)
536 {
537 throw new ArgumentNullException("project");
538 }
539 string docFile = (string)conf.Options["XmlDocFile"];
540 // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
541 // {
542 // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
543 // }
544 return docFile;
545 }
546
547 /// <summary>
548 /// Normalizes the path.
549 /// </summary>
550 /// <param name="path">The path.</param>
551 /// <returns></returns>
552 public static string NormalizePath(string path)
553 {
554 if (path == null)
555 {
556 return "";
557 }
558
559 StringBuilder tmpPath;
560
561 if (Core.Parse.Preprocessor.GetOS() == "Win32")
562 {
563 tmpPath = new StringBuilder(path.Replace('\\', '/'));
564 tmpPath.Replace("/", @"\\");
565 }
566 else
567 {
568 tmpPath = new StringBuilder(path.Replace('\\', '/'));
569 tmpPath = tmpPath.Replace('/', Path.DirectorySeparatorChar);
570 }
571 return tmpPath.ToString();
572 }
573
574 private void WriteProject(SolutionNode solution, ProjectNode project)
575 {
576 string solutionDir = Path.Combine(solution.FullPath, Path.Combine("autotools", solution.Name));
577 string projectDir = Path.Combine(solutionDir, project.Name);
578 string projectVersion = project.Version;
579 bool hasAssemblyConfig = false;
580 chkMkDir(projectDir);
581
582 List<string>
583 compiledFiles = new List<string>(),
584 contentFiles = new List<string>(),
585 embeddedFiles = new List<string>(),
586
587 binaryLibs = new List<string>(),
588 pkgLibs = new List<string>(),
589 systemLibs = new List<string>(),
590 runtimeLibs = new List<string>(),
591
592 extraDistFiles = new List<string>(),
593 localCopyTargets = new List<string>();
594
595 // If there exists a .config file for this assembly, copy
596 // it to the project folder
597
598 // TODO: Support copying .config.osx files
599 // TODO: support processing the .config file for native library deps
600 string projectAssemblyName = project.Name;
601 if (project.AssemblyName != null)
602 projectAssemblyName = project.AssemblyName;
603
604 if (File.Exists(Path.Combine(project.FullPath, projectAssemblyName) + ".dll.config"))
605 {
606 hasAssemblyConfig = true;
607 System.IO.File.Copy(Path.Combine(project.FullPath, projectAssemblyName + ".dll.config"), Path.Combine(projectDir, projectAssemblyName + ".dll.config"), true);
608 extraDistFiles.Add(project.AssemblyName + ".dll.config");
609 }
610
611 foreach (ConfigurationNode conf in project.Configurations)
612 {
613 if (conf.Options.KeyFile != string.Empty)
614 {
615 // Copy snk file into the project's directory
616 // Use the snk from the project directory directly
617 string source = Path.Combine(project.FullPath, conf.Options.KeyFile);
618 string keyFile = conf.Options.KeyFile;
619 Regex re = new Regex(".*/");
620 keyFile = re.Replace(keyFile, "");
621
622 string dest = Path.Combine(projectDir, keyFile);
623 // Tell the user if there's a problem copying the file
624 try
625 {
626 mkdirDashP(System.IO.Path.GetDirectoryName(dest));
627 System.IO.File.Copy(source, dest, true);
628 }
629 catch (System.IO.IOException e)
630 {
631 Console.WriteLine(e.Message);
632 }
633 }
634 }
635
636 // Copy compiled, embedded and content files into the project's directory
637 foreach (string filename in project.Files)
638 {
639 string source = Path.Combine(project.FullPath, filename);
640 string dest = Path.Combine(projectDir, filename);
641
642 if (filename.Contains("AssemblyInfo.cs"))
643 {
644 // If we've got an AssemblyInfo.cs, pull the version number from it
645 string[] sources = { source };
646 string[] args = { "" };
647 Microsoft.CSharp.CSharpCodeProvider cscp =
648 new Microsoft.CSharp.CSharpCodeProvider();
649
650 string tempAssemblyFile = Path.Combine(Path.GetTempPath(), project.Name + "-temp.dll");
651 System.CodeDom.Compiler.CompilerParameters cparam =
652 new System.CodeDom.Compiler.CompilerParameters(args, tempAssemblyFile);
653
654 System.CodeDom.Compiler.CompilerResults cr =
655 cscp.CompileAssemblyFromFile(cparam, sources);
656
657 foreach (System.CodeDom.Compiler.CompilerError error in cr.Errors)
658 Console.WriteLine("Error! '{0}'", error.ErrorText);
659
660 try {
661 string projectFullName = cr.CompiledAssembly.FullName;
662 Regex verRegex = new Regex("Version=([\\d\\.]+)");
663 Match verMatch = verRegex.Match(projectFullName);
664 if (verMatch.Success)
665 projectVersion = verMatch.Groups[1].Value;
666 }catch{
667 Console.WriteLine("Couldn't compile AssemblyInfo.cs");
668 }
669
670 // Clean up the temp file
671 try
672 {
673 if (File.Exists(tempAssemblyFile))
674 File.Delete(tempAssemblyFile);
675 }
676 catch
677 {
678 Console.WriteLine("Error! '{0}'", e);
679 }
680
681 }
682
683 // Tell the user if there's a problem copying the file
684 try
685 {
686 mkdirDashP(System.IO.Path.GetDirectoryName(dest));
687 System.IO.File.Copy(source, dest, true);
688 }
689 catch (System.IO.IOException e)
690 {
691 Console.WriteLine(e.Message);
692 }
693
694 switch (project.Files.GetBuildAction(filename))
695 {
696 case BuildAction.Compile:
697 compiledFiles.Add(filename);
698 break;
699 case BuildAction.Content:
700 contentFiles.Add(filename);
701 extraDistFiles.Add(filename);
702 break;
703 case BuildAction.EmbeddedResource:
704 embeddedFiles.Add(filename);
705 break;
706 }
707 }
708
709 // Set up references
710 for (int refNum = 0; refNum < project.References.Count; refNum++)
711 {
712 ReferenceNode refr = project.References[refNum];
713 Assembly refAssembly = Assembly.LoadWithPartialName(refr.Name);
714
715 /* Determine which pkg-config (.pc) file refers to
716 this assembly */
717
718 SystemPackage package = null;
719
720 if (packagesHash.ContainsKey(refr.Name))
721 {
722 package = packagesHash[refr.Name];
723
724 }
725 else
726 {
727 string assemblyFullName = string.Empty;
728 if (refAssembly != null)
729 assemblyFullName = refAssembly.FullName;
730
731 string assemblyFileName = string.Empty;
732 if (assemblyFullName != string.Empty &&
733 assemblyFullNameToPath.ContainsKey(assemblyFullName)
734 )
735 assemblyFileName =
736 assemblyFullNameToPath[assemblyFullName];
737
738 if (assemblyFileName != string.Empty &&
739 assemblyPathToPackage.ContainsKey(assemblyFileName)
740 )
741 package = assemblyPathToPackage[assemblyFileName];
742
743 }
744
745 /* If we know the .pc file and it is not "mono"
746 (already in the path), add a -pkg: argument */
747
748 if (package != null &&
749 package.Name != "mono" &&
750 !pkgLibs.Contains(package.Name)
751 )
752 pkgLibs.Add(package.Name);
753
754 string fileRef =
755 FindFileReference(refr.Name, (ProjectNode)refr.Parent);
756
757 if (refr.LocalCopy ||
758 solution.ProjectsTable.ContainsKey(refr.Name) ||
759 fileRef != null ||
760 refr.Path != null
761 )
762 {
763
764 /* Attempt to copy the referenced lib to the
765 project's directory */
766
767 string filename = refr.Name + ".dll";
768 string source = filename;
769 if (refr.Path != null)
770 source = Path.Combine(refr.Path, source);
771 source = Path.Combine(project.FullPath, source);
772 string dest = Path.Combine(projectDir, filename);
773
774 /* Since we depend on this binary dll to build, we
775 * will add a compile- time dependency on the
776 * copied dll, and add the dll to the list of
777 * files distributed with this package
778 */
779
780 binaryLibs.Add(refr.Name + ".dll");
781 extraDistFiles.Add(refr.Name + ".dll");
782
783 // TODO: Support copying .config.osx files
784 // TODO: Support for determining native dependencies
785 if (File.Exists(source + ".config"))
786 {
787 System.IO.File.Copy(source + ".config", Path.GetDirectoryName(dest), true);
788 extraDistFiles.Add(refr.Name + ".dll.config");
789 }
790
791 try
792 {
793 System.IO.File.Copy(source, dest, true);
794 }
795 catch (System.IO.IOException)
796 {
797 if (solution.ProjectsTable.ContainsKey(refr.Name)){
798
799 /* If an assembly is referenced, marked for
800 * local copy, in the list of projects for
801 * this solution, but does not exist, put a
802 * target into the Makefile.am to build the
803 * assembly and copy it to this project's
804 * directory
805 */
806
807 ProjectNode sourcePrj =
808 ((solution.ProjectsTable[refr.Name]));
809
810 string target =
811 String.Format("{0}:\n" +
812 "\t$(MAKE) -C ../{1}\n" +
813 "\tln ../{2}/$@ $@\n",
814 filename,
815 sourcePrj.Name,
816 sourcePrj.Name );
817
818 localCopyTargets.Add(target);
819 }
820 }
821 }
822 else if( !pkgLibs.Contains(refr.Name) )
823 {
824 // Else, let's assume it's in the GAC or the lib path
825 string assemName = string.Empty;
826 int index = refr.Name.IndexOf(",");
827
828 if (index > 0)
829 assemName = refr.Name.Substring(0, index);
830 else
831 assemName = refr.Name;
832
833 m_Kernel.Log.Write(String.Format(
834 "Warning: Couldn't find an appropriate assembly " +
835 "for reference:\n'{0}'", refr.Name
836 ));
837 systemLibs.Add(assemName);
838 }
839 }
840
841 const string lineSep = " \\\n\t";
842 string compiledFilesString = string.Empty;
843 if (compiledFiles.Count > 0)
844 compiledFilesString =
845 lineSep + string.Join(lineSep, compiledFiles.ToArray());
846
847 string embeddedFilesString = "";
848 if (embeddedFiles.Count > 0)
849 embeddedFilesString =
850 lineSep + string.Join(lineSep, embeddedFiles.ToArray());
851
852 string contentFilesString = "";
853 if (contentFiles.Count > 0)
854 contentFilesString =
855 lineSep + string.Join(lineSep, contentFiles.ToArray());
856
857 string extraDistFilesString = "";
858 if (extraDistFiles.Count > 0)
859 extraDistFilesString =
860 lineSep + string.Join(lineSep, extraDistFiles.ToArray());
861
862 string pkgLibsString = "";
863 if (pkgLibs.Count > 0)
864 pkgLibsString =
865 lineSep + string.Join(lineSep, pkgLibs.ToArray());
866
867 string binaryLibsString = "";
868 if (binaryLibs.Count > 0)
869 binaryLibsString =
870 lineSep + string.Join(lineSep, binaryLibs.ToArray());
871
872 string systemLibsString = "";
873 if (systemLibs.Count > 0)
874 systemLibsString =
875 lineSep + string.Join(lineSep, systemLibs.ToArray());
876
877 string localCopyTargetsString = "";
878 if (localCopyTargets.Count > 0)
879 localCopyTargetsString =
880 string.Join("\n", localCopyTargets.ToArray());
881
882 string monoPath = "";
883 foreach (string runtimeLib in runtimeLibs)
884 {
885 monoPath += ":`pkg-config --variable=libdir " + runtimeLib + "`";
886 }
887
888 // Add the project name to the list of transformation
889 // parameters
890 XsltArgumentList argList = new XsltArgumentList();
891 argList.AddParam("projectName", "", project.Name);
892 argList.AddParam("solutionName", "", solution.Name);
893 argList.AddParam("assemblyName", "", projectAssemblyName);
894 argList.AddParam("compiledFiles", "", compiledFilesString);
895 argList.AddParam("embeddedFiles", "", embeddedFilesString);
896 argList.AddParam("contentFiles", "", contentFilesString);
897 argList.AddParam("extraDistFiles", "", extraDistFilesString);
898 argList.AddParam("pkgLibs", "", pkgLibsString);
899 argList.AddParam("binaryLibs", "", binaryLibsString);
900 argList.AddParam("systemLibs", "", systemLibsString);
901 argList.AddParam("monoPath", "", monoPath);
902 argList.AddParam("localCopyTargets", "", localCopyTargetsString);
903 argList.AddParam("projectVersion", "", projectVersion);
904 argList.AddParam("hasAssemblyConfig", "", hasAssemblyConfig ? "true" : "");
905
906 // Transform the templates
907 transformToFile(Path.Combine(projectDir, "configure.ac"), argList, "/Autotools/ProjectConfigureAc");
908 transformToFile(Path.Combine(projectDir, "Makefile.am"), argList, "/Autotools/ProjectMakefileAm");
909 transformToFile(Path.Combine(projectDir, "autogen.sh"), argList, "/Autotools/ProjectAutogenSh");
910
911 if (project.Type == Core.Nodes.ProjectType.Library)
912 transformToFile(Path.Combine(projectDir, project.Name + ".pc.in"), argList, "/Autotools/ProjectPcIn");
913 if (project.Type == Core.Nodes.ProjectType.Exe || project.Type == Core.Nodes.ProjectType.WinExe)
914 transformToFile(Path.Combine(projectDir, project.Name.ToLower() + ".in"), argList, "/Autotools/ProjectWrapperScriptIn");
915 }
916
917 private void CleanProject(ProjectNode project)
918 {
919 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
920 string projectFile = Helper.MakeFilePath(project.FullPath, "Include", "am");
921 Helper.DeleteIfExists(projectFile);
922 }
923
924 private void CleanSolution(SolutionNode solution)
925 {
926 m_Kernel.Log.Write("Cleaning Autotools make files for", solution.Name);
927
928 string slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "am");
929 Helper.DeleteIfExists(slnFile);
930
931 slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile", "in");
932 Helper.DeleteIfExists(slnFile);
933
934 slnFile = Helper.MakeFilePath(solution.FullPath, "configure", "ac");
935 Helper.DeleteIfExists(slnFile);
936
937 slnFile = Helper.MakeFilePath(solution.FullPath, "configure");
938 Helper.DeleteIfExists(slnFile);
939
940 slnFile = Helper.MakeFilePath(solution.FullPath, "Makefile");
941 Helper.DeleteIfExists(slnFile);
942
943 foreach (ProjectNode project in solution.Projects)
944 {
945 CleanProject(project);
946 }
947
948 m_Kernel.Log.Write("");
949 }
950
951 #endregion
952
953 #region ITarget Members
954
955 /// <summary>
956 /// Writes the specified kern.
957 /// </summary>
958 /// <param name="kern">The kern.</param>
959 public void Write(Kernel kern)
960 {
961 if (kern == null)
962 {
963 throw new ArgumentNullException("kern");
964 }
965 m_Kernel = kern;
966 m_Kernel.Log.Write("Parsing system pkg-config files");
967 RunInitialization();
968
969 const string streamName = "autotools.xml";
970 string fqStreamName = String.Format("Prebuild.data.{0}",
971 streamName
972 );
973
974 // Retrieve stream for the autotools template XML
975 Stream autotoolsStream = Assembly.GetExecutingAssembly()
976 .GetManifestResourceStream(fqStreamName);
977
978 if(autotoolsStream == null) {
979
980 /*
981 * try without the default namespace prepended, in
982 * case prebuild.exe assembly was compiled with
983 * something other than Visual Studio .NET
984 */
985
986 autotoolsStream = Assembly.GetExecutingAssembly()
987 .GetManifestResourceStream(streamName);
988 if(autotoolsStream == null){
989 string errStr =
990 String.Format("Could not find embedded resource file:\n" +
991 "'{0}' or '{1}'",
992 streamName, fqStreamName
993 );
994
995 m_Kernel.Log.Write(errStr);
996
997 throw new System.Reflection.TargetException(errStr);
998 }
999 }
1000
1001 // Create an XML URL Resolver with default credentials
1002 xr = new System.Xml.XmlUrlResolver();
1003 xr.Credentials = CredentialCache.DefaultCredentials;
1004
1005 // Create a default evidence - no need to limit access
1006 e = new System.Security.Policy.Evidence();
1007
1008 // Load the autotools XML
1009 autotoolsDoc = new XmlDocument();
1010 autotoolsDoc.Load(autotoolsStream);
1011
1012 /* rootDir is the filesystem location where the Autotools
1013 * build tree will be created - for now we'll make it
1014 * $PWD/autotools
1015 */
1016
1017 string pwd = Directory.GetCurrentDirectory();
1018 //string pwd = System.Environment.GetEnvironmentVariable("PWD");
1019 //if (pwd.Length != 0)
1020 //{
1021 string rootDir = Path.Combine(pwd, "autotools");
1022 //}
1023 //else
1024 //{
1025 // pwd = Assembly.GetExecutingAssembly()
1026 //}
1027 chkMkDir(rootDir);
1028
1029 foreach (SolutionNode solution in kern.Solutions)
1030 {
1031 m_Kernel.Log.Write(String.Format("Writing solution: {0}",
1032 solution.Name));
1033 WriteCombine(solution);
1034 }
1035 m_Kernel = null;
1036 }
1037
1038 /// <summary>
1039 /// Cleans the specified kern.
1040 /// </summary>
1041 /// <param name="kern">The kern.</param>
1042 public virtual void Clean(Kernel kern)
1043 {
1044 if (kern == null)
1045 {
1046 throw new ArgumentNullException("kern");
1047 }
1048 m_Kernel = kern;
1049 foreach (SolutionNode sol in kern.Solutions)
1050 {
1051 CleanSolution(sol);
1052 }
1053 m_Kernel = null;
1054 }
1055
1056 /// <summary>
1057 /// Gets the name.
1058 /// </summary>
1059 /// <value>The name.</value>
1060 public string Name
1061 {
1062 get
1063 {
1064 return "autotools";
1065 }
1066 }
1067
1068 #endregion
1069 }
1070}
diff --git a/Prebuild/src/Core/Targets/DebugTarget.cs b/Prebuild/src/Core/Targets/DebugTarget.cs
new file mode 100644
index 0000000..650007e
--- /dev/null
+++ b/Prebuild/src/Core/Targets/DebugTarget.cs
@@ -0,0 +1,102 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26#region CVS Information
27/*
28 * $Source$
29 * $Author: jendave $
30 * $Date: 2006-09-20 08:42:51 +0100 (Wed, 20 Sep 2006) $
31 * $Revision: 164 $
32 */
33#endregion
34
35using System;
36
37using Prebuild.Core.Attributes;
38using Prebuild.Core.Interfaces;
39using Prebuild.Core.Nodes;
40
41#if (DEBUG && _DEBUG_TARGET)
42namespace Prebuild.Core.Targets
43{
44 [Target("debug")]
45 public class DebugTarget : ITarget
46 {
47#region Fields
48
49 private Kernel m_Kernel = null;
50
51#endregion
52
53#region ITarget Members
54
55 public void Write()
56 {
57 foreach(SolutionNode s in m_Kernel.Solutions)
58 {
59 Console.WriteLine("Solution [ {0}, {1} ]", s.Name, s.Path);
60 foreach(string file in s.Files)
61{
62 Console.WriteLine("\tFile [ {0} ]", file);
63}
64
65 foreach(ProjectNode proj in s.Projects)
66 {
67 Console.WriteLine("\tProject [ {0}, {1}. {2} ]", proj.Name, proj.Path, proj.Language);
68 foreach(string file in proj.Files)
69 Console.WriteLine("\t\tFile [ {0} ]", file);
70 }
71 }
72 }
73
74 public void Clean()
75 {
76 Console.WriteLine("Not implemented");
77 }
78
79 public string Name
80 {
81 get
82 {
83 return "debug";
84 }
85 }
86
87 public Kernel Kernel
88 {
89 get
90 {
91 return m_Kernel;
92 }
93 set
94 {
95 m_Kernel = value;
96 }
97 }
98
99#endregion
100 }
101}
102#endif
diff --git a/Prebuild/src/Core/Targets/MakefileTarget.cs b/Prebuild/src/Core/Targets/MakefileTarget.cs
new file mode 100644
index 0000000..54046dd
--- /dev/null
+++ b/Prebuild/src/Core/Targets/MakefileTarget.cs
@@ -0,0 +1,469 @@
1#region BSD License
2/*
3Copyright (c) 2004 Crestez Leonard (cleonard@go.ro)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Text.RegularExpressions;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using Prebuild.Core.Nodes;
33using Prebuild.Core.Utilities;
34
35namespace Prebuild.Core.Targets
36{
37 [Target("makefile")]
38 public class MakefileTarget : ITarget
39 {
40 #region Fields
41
42 private Kernel m_Kernel = null;
43
44 #endregion
45
46 #region Private Methods
47
48 // This converts a path relative to the path of a project to
49 // a path relative to the solution path.
50 private string NicePath(ProjectNode proj, string path)
51 {
52 string res;
53 SolutionNode solution = (SolutionNode)proj.Parent;
54 res = Path.Combine(Helper.NormalizePath(proj.FullPath, '/'), Helper.NormalizePath(path, '/'));
55 res = Helper.NormalizePath(res, '/');
56 res = res.Replace("/./", "/");
57 while (res.IndexOf("/../") >= 0)
58 {
59 int a = res.IndexOf("/../");
60 int b = res.LastIndexOf("/", a - 1);
61 res = res.Remove(b, a - b + 3);
62 }
63 res = Helper.MakePathRelativeTo(solution.FullPath, res);
64 if (res.StartsWith("./"))
65 res = res.Substring(2, res.Length - 2);
66 res = Helper.NormalizePath(res, '/');
67 return res;
68 }
69
70 private void WriteProjectFiles(StreamWriter f, SolutionNode solution, ProjectNode project)
71 {
72 // Write list of source code files
73 f.WriteLine("SOURCES_{0} = \\", project.Name);
74 foreach (string file in project.Files)
75 if (project.Files.GetBuildAction(file) == BuildAction.Compile)
76 f.WriteLine("\t{0} \\", NicePath(project, file));
77 f.WriteLine();
78
79 // Write list of resource files
80 f.WriteLine("RESOURCES_{0} = \\", project.Name);
81 foreach (string file in project.Files)
82 if (project.Files.GetBuildAction(file) == BuildAction.EmbeddedResource)
83 {
84 string path = NicePath(project, file);
85 f.WriteLine("\t-resource:{0},{1} \\", path, Path.GetFileName(path));
86 }
87 f.WriteLine();
88
89 // There's also Content and None in BuildAction.
90 // What am I supposed to do with that?
91 }
92
93 private string FindFileReference(string refName, ProjectNode project)
94 {
95 foreach (ReferencePathNode refPath in project.ReferencePaths)
96 {
97 string fullPath = NicePath(project, Helper.MakeFilePath(refPath.Path, refName, "dll"));
98 if (File.Exists(fullPath))
99 return fullPath;
100 }
101 return null;
102 }
103
104 private void WriteProjectReferences(StreamWriter f, SolutionNode solution, ProjectNode project)
105 {
106 f.WriteLine("REFERENCES_{0} = \\", project.Name);
107 foreach (ReferenceNode refr in project.References)
108 {
109 string path;
110 // Project references change with configurations.
111 if (solution.ProjectsTable.ContainsKey(refr.Name))
112 continue;
113 path = FindFileReference(refr.Name, project);
114 if (path != null)
115 f.WriteLine("\t-r:{0} \\", path);
116 else
117 f.WriteLine("\t-r:{0} \\", refr.Name);
118 }
119 f.WriteLine();
120 }
121
122 private void WriteProjectDependencies(StreamWriter f, SolutionNode solution, ProjectNode project)
123 {
124 f.WriteLine("DEPENDENCIES_{0} = \\", project.Name);
125 f.WriteLine("\t$(SOURCES_{0}) \\", project.Name);
126 foreach (string file in project.Files)
127 if (project.Files.GetBuildAction(file) == BuildAction.EmbeddedResource)
128 f.WriteLine("\t{0} \\", NicePath(project, file));
129 f.WriteLine();
130 }
131
132 private string ProjectTypeToExtension(ProjectType t)
133 {
134 if (t == ProjectType.Exe || t == ProjectType.WinExe)
135 {
136 return "exe";
137 }
138 else if (t == ProjectType.Library)
139 {
140 return "dll";
141 }
142 else
143 {
144 throw new FatalException("Bad ProjectType: {0}", t);
145 }
146 }
147
148 private string ProjectTypeToTarget(ProjectType t)
149 {
150 if (t == ProjectType.Exe)
151 {
152 return "exe";
153 }
154 else if (t == ProjectType.WinExe)
155 {
156 return "winexe";
157 }
158 else if (t == ProjectType.Library)
159 {
160 return "library";
161 }
162 else
163 {
164 throw new FatalException("Bad ProjectType: {0}", t);
165 }
166 }
167
168 private string ProjectOutput(ProjectNode project, ConfigurationNode config)
169 {
170 string filepath;
171 filepath = Helper.MakeFilePath((string)config.Options["OutputPath"],
172 project.AssemblyName, ProjectTypeToExtension(project.Type));
173 return NicePath(project, filepath);
174 }
175
176 // Returns true if two configs in one project have the same output.
177 private bool ProjectClashes(ProjectNode project)
178 {
179 foreach (ConfigurationNode conf1 in project.Configurations)
180 foreach (ConfigurationNode conf2 in project.Configurations)
181 if (ProjectOutput(project, conf1) == ProjectOutput(project, conf2) && conf1 != conf2)
182 {
183 m_Kernel.Log.Write("Warning: Configurations {0} and {1} for project {2} output the same file",
184 conf1.Name, conf2.Name, project.Name);
185 m_Kernel.Log.Write("Warning: I'm going to use some timestamps(extra empty files).");
186 return true;
187 }
188 return false;
189 }
190
191 private void WriteProject(StreamWriter f, SolutionNode solution, ProjectNode project)
192 {
193 f.WriteLine("# This is for project {0}", project.Name);
194 f.WriteLine();
195
196 WriteProjectFiles(f, solution, project);
197 WriteProjectReferences(f, solution, project);
198 WriteProjectDependencies(f, solution, project);
199
200 bool clash = ProjectClashes(project);
201
202 foreach (ConfigurationNode conf in project.Configurations)
203 {
204 string outpath = ProjectOutput(project, conf);
205 string filesToClean = outpath;
206
207 if (clash)
208 {
209 f.WriteLine("{0}-{1}: .{0}-{1}-timestamp", project.Name, conf.Name);
210 f.WriteLine();
211 f.Write(".{0}-{1}-timestamp: $(DEPENDENCIES_{0})", project.Name, conf.Name);
212 }
213 else
214 {
215 f.WriteLine("{0}-{1}: {2}", project.Name, conf.Name, outpath);
216 f.WriteLine();
217 f.Write("{2}: $(DEPENDENCIES_{0})", project.Name, conf.Name, outpath);
218 }
219 // Dependencies on other projects.
220 foreach (ReferenceNode refr in project.References)
221 if (solution.ProjectsTable.ContainsKey(refr.Name))
222 {
223 ProjectNode refProj = (ProjectNode)solution.ProjectsTable[refr.Name];
224 if (ProjectClashes(refProj))
225 f.Write(" .{0}-{1}-timestamp", refProj.Name, conf.Name);
226 else
227 f.Write(" {0}", ProjectOutput(refProj, conf));
228 }
229 f.WriteLine();
230
231 // make directory for output.
232 if (Path.GetDirectoryName(outpath) != "")
233 {
234 f.WriteLine("\tmkdir -p {0}", Path.GetDirectoryName(outpath));
235 }
236 // mcs command line.
237 f.Write("\tgmcs", project.Name);
238 f.Write(" -warn:{0}", conf.Options["WarningLevel"]);
239 if ((bool)conf.Options["DebugInformation"])
240 f.Write(" -debug");
241 if ((bool)conf.Options["AllowUnsafe"])
242 f.Write(" -unsafe");
243 if ((bool)conf.Options["CheckUnderflowOverflow"])
244 f.Write(" -checked");
245 if (project.StartupObject != "")
246 f.Write(" -main:{0}", project.StartupObject);
247 if ((string)conf.Options["CompilerDefines"] != "")
248 {
249 f.Write(" -define:\"{0}\"", conf.Options["CompilerDefines"]);
250 }
251
252 f.Write(" -target:{0} -out:{1}", ProjectTypeToTarget(project.Type), outpath);
253
254 // Build references to other projects. Now that sux.
255 // We have to reference the other project in the same conf.
256 foreach (ReferenceNode refr in project.References)
257 if (solution.ProjectsTable.ContainsKey(refr.Name))
258 {
259 ProjectNode refProj;
260 refProj = (ProjectNode)solution.ProjectsTable[refr.Name];
261 f.Write(" -r:{0}", ProjectOutput(refProj, conf));
262 }
263
264 f.Write(" $(REFERENCES_{0})", project.Name);
265 f.Write(" $(RESOURCES_{0})", project.Name);
266 f.Write(" $(SOURCES_{0})", project.Name);
267 f.WriteLine();
268
269 // Copy references with localcopy.
270 foreach (ReferenceNode refr in project.References)
271 if (refr.LocalCopy)
272 {
273 string outPath, srcPath, destPath;
274 outPath = Helper.NormalizePath((string)conf.Options["OutputPath"]);
275 if (solution.ProjectsTable.ContainsKey(refr.Name))
276 {
277 ProjectNode refProj;
278 refProj = (ProjectNode)solution.ProjectsTable[refr.Name];
279 srcPath = ProjectOutput(refProj, conf);
280 destPath = Path.Combine(outPath, Path.GetFileName(srcPath));
281 destPath = NicePath(project, destPath);
282 if (srcPath != destPath)
283 {
284 f.WriteLine("\tcp -f {0} {1}", srcPath, destPath);
285 filesToClean += " " + destPath;
286 }
287 continue;
288 }
289 srcPath = FindFileReference(refr.Name, project);
290 if (srcPath != null)
291 {
292 destPath = Path.Combine(outPath, Path.GetFileName(srcPath));
293 destPath = NicePath(project, destPath);
294 f.WriteLine("\tcp -f {0} {1}", srcPath, destPath);
295 filesToClean += " " + destPath;
296 }
297 }
298
299 if (clash)
300 {
301 filesToClean += String.Format(" .{0}-{1}-timestamp", project.Name, conf.Name);
302 f.WriteLine("\ttouch .{0}-{1}-timestamp", project.Name, conf.Name);
303 f.Write("\trm -rf");
304 foreach (ConfigurationNode otherConf in project.Configurations)
305 if (otherConf != conf)
306 f.WriteLine(" .{0}-{1}-timestamp", project.Name, otherConf.Name);
307 f.WriteLine();
308 }
309 f.WriteLine();
310 f.WriteLine("{0}-{1}-clean:", project.Name, conf.Name);
311 f.WriteLine("\trm -rf {0}", filesToClean);
312 f.WriteLine();
313 }
314 }
315
316 private void WriteIntro(StreamWriter f, SolutionNode solution)
317 {
318 f.WriteLine("# Makefile for {0} generated by Prebuild ( http://dnpb.sf.net )", solution.Name);
319 f.WriteLine("# Do not edit.");
320 f.WriteLine("#");
321
322 f.Write("# Configurations:");
323 foreach (ConfigurationNode conf in solution.Configurations)
324 f.Write(" {0}", conf.Name);
325 f.WriteLine();
326
327 f.WriteLine("# Projects:");
328 foreach (ProjectNode proj in solution.Projects)
329 f.WriteLine("#\t{0}", proj.Name);
330
331 f.WriteLine("#");
332 f.WriteLine("# Building:");
333 f.WriteLine("#\t\"make\" to build everything under the default(first) configuration");
334 f.WriteLine("#\t\"make CONF\" to build every project under configuration CONF");
335 f.WriteLine("#\t\"make PROJ\" to build project PROJ under the default(first) configuration");
336 f.WriteLine("#\t\"make PROJ-CONF\" to build project PROJ under configuration CONF");
337 f.WriteLine("#");
338 f.WriteLine("# Cleaning (removing results of build):");
339 f.WriteLine("#\t\"make clean\" to clean everything, that's what you probably want");
340 f.WriteLine("#\t\"make CONF\" to clean everything for a configuration");
341 f.WriteLine("#\t\"make PROJ\" to clean everything for a project");
342 f.WriteLine("#\t\"make PROJ-CONF\" to clea project PROJ under configuration CONF");
343 f.WriteLine();
344 }
345
346 private void WritePhony(StreamWriter f, SolutionNode solution)
347 {
348 string defconf = "";
349 foreach (ConfigurationNode conf in solution.Configurations)
350 {
351 defconf = conf.Name;
352 break;
353 }
354
355 f.Write(".PHONY: all");
356 foreach (ProjectNode proj in solution.Projects)
357 f.Write(" {0} {0}-clean", proj.Name);
358 foreach (ConfigurationNode conf in solution.Configurations)
359 f.Write(" {0} {0}-clean", conf.Name);
360 foreach (ProjectNode proj in solution.Projects)
361 foreach (ConfigurationNode conf in solution.Configurations)
362 f.Write(" {0}-{1} {0}-{1}-clean", proj.Name, conf.Name);
363 f.WriteLine();
364 f.WriteLine();
365
366 f.WriteLine("all: {0}", defconf);
367 f.WriteLine();
368
369 f.Write("clean:");
370 foreach (ConfigurationNode conf in solution.Configurations)
371 f.Write(" {0}-clean", conf.Name);
372 f.WriteLine();
373 f.WriteLine();
374
375 foreach (ConfigurationNode conf in solution.Configurations)
376 {
377 f.Write("{0}: ", conf.Name);
378 foreach (ProjectNode proj in solution.Projects)
379 f.Write(" {0}-{1}", proj.Name, conf.Name);
380 f.WriteLine();
381 f.WriteLine();
382
383 f.Write("{0}-clean: ", conf.Name);
384 foreach (ProjectNode proj in solution.Projects)
385 f.Write(" {0}-{1}-clean", proj.Name, conf.Name);
386 f.WriteLine();
387 f.WriteLine();
388 }
389
390 foreach (ProjectNode proj in solution.Projects)
391 {
392 f.WriteLine("{0}: {0}-{1}", proj.Name, defconf);
393 f.WriteLine();
394
395 f.Write("{0}-clean:", proj.Name);
396 foreach (ConfigurationNode conf in proj.Configurations)
397 f.Write(" {0}-{1}-clean", proj.Name, conf.Name);
398 f.WriteLine();
399 f.WriteLine();
400 }
401 }
402
403 private void WriteSolution(SolutionNode solution)
404 {
405 m_Kernel.Log.Write("Creating makefile for {0}", solution.Name);
406 m_Kernel.CurrentWorkingDirectory.Push();
407
408 string file = "Makefile";// Helper.MakeFilePath(solution.FullPath, solution.Name, "make");
409 StreamWriter f = new StreamWriter(file);
410
411 Helper.SetCurrentDir(Path.GetDirectoryName(file));
412
413 using (f)
414 {
415 WriteIntro(f, solution);
416 WritePhony(f, solution);
417
418 foreach (ProjectNode project in solution.Projects)
419 {
420 m_Kernel.Log.Write("...Creating Project: {0}", project.Name);
421 WriteProject(f, solution, project);
422 }
423 }
424
425 m_Kernel.Log.Write("");
426 m_Kernel.CurrentWorkingDirectory.Pop();
427 }
428
429 private void CleanSolution(SolutionNode solution)
430 {
431 m_Kernel.Log.Write("Cleaning makefile for {0}", solution.Name);
432
433 string file = Helper.MakeFilePath(solution.FullPath, solution.Name, "make");
434 Helper.DeleteIfExists(file);
435
436 m_Kernel.Log.Write("");
437 }
438
439 #endregion
440
441 #region ITarget Members
442
443 public void Write(Kernel kern)
444 {
445 m_Kernel = kern;
446 foreach (SolutionNode solution in kern.Solutions)
447 WriteSolution(solution);
448 m_Kernel = null;
449 }
450
451 public virtual void Clean(Kernel kern)
452 {
453 m_Kernel = kern;
454 foreach (SolutionNode sol in kern.Solutions)
455 CleanSolution(sol);
456 m_Kernel = null;
457 }
458
459 public string Name
460 {
461 get
462 {
463 return "makefile";
464 }
465 }
466
467 #endregion
468 }
469}
diff --git a/Prebuild/src/Core/Targets/MonoDevelopTarget.cs b/Prebuild/src/Core/Targets/MonoDevelopTarget.cs
new file mode 100644
index 0000000..ea6d2c2
--- /dev/null
+++ b/Prebuild/src/Core/Targets/MonoDevelopTarget.cs
@@ -0,0 +1,515 @@
1#region BSD License
2/*
3Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Reflection;
29using System.Text.RegularExpressions;
30
31using Prebuild.Core.Attributes;
32using Prebuild.Core.Interfaces;
33using Prebuild.Core.Nodes;
34using Prebuild.Core.Utilities;
35
36namespace Prebuild.Core.Targets
37{
38 /// <summary>
39 ///
40 /// </summary>
41 [Target("monodev")]
42 public class MonoDevelopTarget : ITarget
43 {
44 #region Fields
45
46 private Kernel m_Kernel;
47
48 #endregion
49
50 #region Private Methods
51
52 private static string PrependPath(string path)
53 {
54 string tmpPath = Helper.NormalizePath(path, '/');
55 Regex regex = new Regex(@"(\w):/(\w+)");
56 Match match = regex.Match(tmpPath);
57 if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
58 {
59 tmpPath = Helper.NormalizePath(tmpPath);
60 }
61 else
62 {
63 tmpPath = Helper.NormalizePath("./" + tmpPath);
64 }
65
66 return tmpPath;
67 }
68
69 private static string BuildReference(SolutionNode solution, ReferenceNode refr)
70 {
71 string ret = "<ProjectReference type=\"";
72 if(solution.ProjectsTable.ContainsKey(refr.Name))
73 {
74 ret += "Project\"";
75 ret += " localcopy=\"" + refr.LocalCopy.ToString() + "\" refto=\"" + refr.Name + "\" />";
76 }
77 else
78 {
79 ProjectNode project = (ProjectNode)refr.Parent;
80 string fileRef = FindFileReference(refr.Name, project);
81
82 if(refr.Path != null || fileRef != null)
83 {
84 ret += "Assembly\" refto=\"";
85
86 string finalPath = (refr.Path != null) ? Helper.MakeFilePath(refr.Path, refr.Name, "dll") : fileRef;
87
88 ret += finalPath;
89 ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />";
90 return ret;
91 }
92
93 ret += "Gac\"";
94 ret += " localcopy=\"" + refr.LocalCopy.ToString() + "\"";
95 ret += " refto=\"";
96 try
97 {
98 /*
99 Day changed to 28 Mar 2007
100 ...
101 08:09 < cj> is there anything that replaces Assembly.LoadFromPartialName() ?
102 08:09 < jonp> no
103 08:10 < jonp> in their infinite wisdom [sic], microsoft decided that the
104 ability to load any assembly version by-name was an inherently
105 bad idea
106 08:11 < cj> I'm thinking of a bunch of four-letter words right now...
107 08:11 < cj> security through making it difficult for the developer!!!
108 08:12 < jonp> just use the Obsolete API
109 08:12 < jonp> it should still work
110 08:12 < cj> alrighty.
111 08:12 < jonp> you just get warnings when using it
112 */
113 Assembly assem = Assembly.LoadWithPartialName(refr.Name);
114 ret += assem.FullName;
115 //ret += refr.Name;
116 }
117 catch (System.NullReferenceException e)
118 {
119 e.ToString();
120 ret += refr.Name;
121 }
122 ret += "\" />";
123 }
124
125 return ret;
126 }
127
128 private static string FindFileReference(string refName, ProjectNode project)
129 {
130 foreach(ReferencePathNode refPath in project.ReferencePaths)
131 {
132 string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
133
134 if(File.Exists(fullPath))
135 {
136 return fullPath;
137 }
138 }
139
140 return null;
141 }
142
143 /// <summary>
144 /// Gets the XML doc file.
145 /// </summary>
146 /// <param name="project">The project.</param>
147 /// <param name="conf">The conf.</param>
148 /// <returns></returns>
149 public static string GenerateXmlDocFile(ProjectNode project, ConfigurationNode conf)
150 {
151 if( conf == null )
152 {
153 throw new ArgumentNullException("conf");
154 }
155 if( project == null )
156 {
157 throw new ArgumentNullException("project");
158 }
159 string docFile = (string)conf.Options["XmlDocFile"];
160 if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
161 {
162 return "False";
163 }
164 return "True";
165 }
166
167 private void WriteProject(SolutionNode solution, ProjectNode project)
168 {
169 string csComp = "Mcs";
170 string netRuntime = "Mono";
171 if(project.Runtime == ClrRuntime.Microsoft)
172 {
173 csComp = "Csc";
174 netRuntime = "MsNet";
175 }
176
177 string projFile = Helper.MakeFilePath(project.FullPath, project.Name, "mdp");
178 StreamWriter ss = new StreamWriter(projFile);
179
180 m_Kernel.CurrentWorkingDirectory.Push();
181 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
182
183 using(ss)
184 {
185 ss.WriteLine(
186 "<Project name=\"{0}\" description=\"\" standardNamespace=\"{1}\" newfilesearch=\"None\" enableviewstate=\"True\" fileversion=\"2.0\" language=\"C#\" clr-version=\"Net_2_0\" ctype=\"DotNetProject\">",
187 project.Name,
188 project.RootNamespace
189 );
190
191 int count = 0;
192
193 ss.WriteLine(" <Configurations active=\"{0}\">", solution.ActiveConfig);
194
195 foreach(ConfigurationNode conf in project.Configurations)
196 {
197 ss.WriteLine(" <Configuration name=\"{0}\" ctype=\"DotNetProjectConfiguration\">", conf.Name);
198 ss.Write(" <Output");
199 ss.Write(" directory=\"{0}\"", Helper.EndPath(Helper.NormalizePath(".\\" + conf.Options["OutputPath"].ToString())));
200 ss.Write(" assembly=\"{0}\"", project.AssemblyName);
201 ss.Write(" executeScript=\"{0}\"", conf.Options["RunScript"]);
202 //ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]);
203 //ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]);
204 if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0)
205 {
206 ss.Write(" executeBeforeBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString()));
207 }
208 else
209 {
210 ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]);
211 }
212 if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0)
213 {
214 ss.Write(" executeAfterBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString()));
215 }
216 else
217 {
218 ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]);
219 }
220 ss.Write(" executeBeforeBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]);
221 ss.Write(" executeAfterBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]);
222 ss.WriteLine(" />");
223
224 ss.Write(" <Build");
225 ss.Write(" debugmode=\"True\"");
226 if (project.Type == ProjectType.WinExe)
227 {
228 ss.Write(" target=\"{0}\"", ProjectType.Exe.ToString());
229 }
230 else
231 {
232 ss.Write(" target=\"{0}\"", project.Type);
233 }
234 ss.WriteLine(" />");
235
236 ss.Write(" <Execution");
237 ss.Write(" runwithwarnings=\"{0}\"", !conf.Options.WarningsAsErrors);
238 ss.Write(" consolepause=\"True\"");
239 ss.Write(" runtime=\"{0}\"", netRuntime);
240 ss.Write(" clr-version=\"Net_2_0\"");
241 ss.WriteLine(" />");
242
243 ss.Write(" <CodeGeneration");
244 ss.Write(" compiler=\"{0}\"", csComp);
245 ss.Write(" warninglevel=\"{0}\"", conf.Options["WarningLevel"]);
246 ss.Write(" nowarn=\"{0}\"", conf.Options["SuppressWarnings"]);
247 ss.Write(" includedebuginformation=\"{0}\"", conf.Options["DebugInformation"]);
248 ss.Write(" optimize=\"{0}\"", conf.Options["OptimizeCode"]);
249 ss.Write(" unsafecodeallowed=\"{0}\"", conf.Options["AllowUnsafe"]);
250 ss.Write(" generateoverflowchecks=\"{0}\"", conf.Options["CheckUnderflowOverflow"]);
251 ss.Write(" mainclass=\"{0}\"", project.StartupObject);
252 ss.Write(" target=\"{0}\"", project.Type);
253 ss.Write(" definesymbols=\"{0}\"", conf.Options["CompilerDefines"]);
254 ss.Write(" generatexmldocumentation=\"{0}\"", GenerateXmlDocFile(project, conf));
255 ss.Write(" win32Icon=\"{0}\"", project.AppIcon);
256 ss.Write(" ctype=\"CSharpCompilerParameters\"");
257 ss.WriteLine(" />");
258 ss.WriteLine(" </Configuration>");
259
260 count++;
261 }
262 ss.WriteLine(" </Configurations>");
263
264 ss.Write(" <DeploymentInformation");
265 ss.Write(" target=\"\"");
266 ss.Write(" script=\"\"");
267 ss.Write(" strategy=\"File\"");
268 ss.WriteLine(">");
269 ss.WriteLine(" <excludeFiles />");
270 ss.WriteLine(" </DeploymentInformation>");
271
272 ss.WriteLine(" <Contents>");
273 foreach(string file in project.Files)
274 {
275 string buildAction;
276 string dependson = "";
277 string resource_id = "";
278 string copyToOutput = "";
279
280 switch(project.Files.GetBuildAction(file))
281 {
282 case BuildAction.None:
283 buildAction = "Nothing";
284 break;
285
286 case BuildAction.Content:
287 buildAction = "Exclude";
288 break;
289
290 case BuildAction.EmbeddedResource:
291 buildAction = "EmbedAsResource";
292 break;
293
294 default:
295 buildAction = "Compile";
296 break;
297 }
298
299 if (project.Files.GetCopyToOutput(file) != CopyToOutput.Never)
300 buildAction = "FileCopy";
301
302 // Sort of a hack, we try and resolve the path and make it relative, if we can.
303 string extension = Path.GetExtension(file);
304 string designer_format = string.Format(".Designer{0}", extension);
305
306 if (file.EndsWith(designer_format))
307 {
308 string basename = file.Substring(0, file.LastIndexOf(designer_format));
309 string[] extensions = new string[] { ".cs", ".resx", ".settings" };
310
311 foreach(string ext in extensions)
312 {
313 if (project.Files.Contains(basename + ext))
314 {
315 dependson = string.Format(" dependson=\"{0}{1}\"", basename, ext);
316 break;
317 }
318 }
319 }
320 if (extension == ".resx")
321 {
322 buildAction = "EmbedAsResource";
323 string basename = file.Substring(0, file.LastIndexOf(".resx"));
324
325 // Visual Studio type resx + form dependency
326 if (project.Files.Contains(basename + ".cs"))
327 {
328 dependson = string.Format(" dependson=\"{0}{1}\"", basename, ".cs");
329 }
330
331 // We need to specify a resources file name to avoid MissingManifestResourceExceptions
332 // in libraries that are built.
333 resource_id = string.Format(" resource_id=\"{0}.{1}.resources\"",
334 project.AssemblyName, basename.Replace("/", "."));
335 }
336
337 switch(project.Files.GetCopyToOutput(file))
338 {
339 case CopyToOutput.Always:
340 copyToOutput = string.Format(" copyToOutputDirectory=\"Always\"");
341 break;
342 case CopyToOutput.PreserveNewest:
343 copyToOutput = string.Format(" copyToOutputDirectory=\"PreserveNewest\"");
344 break;
345 }
346
347 // Sort of a hack, we try and resolve the path and make it relative, if we can.
348 string filePath = PrependPath(file);
349 ss.WriteLine(" <File name=\"{0}\" subtype=\"Code\" buildaction=\"{1}\"{2}{3}{4} />",
350 filePath, buildAction, dependson, resource_id, copyToOutput);
351 }
352 ss.WriteLine(" </Contents>");
353
354 ss.WriteLine(" <References>");
355 foreach(ReferenceNode refr in project.References)
356 {
357 ss.WriteLine(" {0}", BuildReference(solution, refr));
358 }
359 ss.WriteLine(" </References>");
360
361
362 ss.WriteLine("</Project>");
363 }
364
365 m_Kernel.CurrentWorkingDirectory.Pop();
366 }
367
368 private void WriteCombine(SolutionNode solution)
369 {
370 m_Kernel.Log.Write("Creating MonoDevelop combine and project files");
371 foreach(ProjectNode project in solution.Projects)
372 {
373 if(m_Kernel.AllowProject(project.FilterGroups))
374 {
375 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
376 WriteProject(solution, project);
377 }
378 }
379
380 m_Kernel.Log.Write("");
381 string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "mds");
382 StreamWriter ss = new StreamWriter(combFile);
383
384 m_Kernel.CurrentWorkingDirectory.Push();
385 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
386
387 int count = 0;
388
389 using(ss)
390 {
391 ss.WriteLine("<Combine name=\"{0}\" fileversion=\"2.0\" description=\"\">", solution.Name);
392
393 count = 0;
394 foreach(ConfigurationNode conf in solution.Configurations)
395 {
396 if(count == 0)
397 {
398 ss.WriteLine(" <Configurations active=\"{0}\">", conf.Name);
399 }
400
401 ss.WriteLine(" <Configuration name=\"{0}\" ctype=\"CombineConfiguration\">", conf.Name);
402 foreach(ProjectNode project in solution.Projects)
403 {
404 ss.WriteLine(" <Entry configuration=\"{1}\" build=\"True\" name=\"{0}\" />", project.Name, conf.Name);
405 }
406 ss.WriteLine(" </Configuration>");
407
408 count++;
409 }
410 ss.WriteLine(" </Configurations>");
411
412 count = 0;
413
414 foreach(ProjectNode project in solution.Projects)
415 {
416 if(count == 0)
417 ss.WriteLine(" <StartMode startupentry=\"{0}\" single=\"True\">", project.Name);
418
419 ss.WriteLine(" <Execute type=\"None\" entry=\"{0}\" />", project.Name);
420 count++;
421 }
422 ss.WriteLine(" </StartMode>");
423
424 ss.WriteLine(" <Entries>");
425 foreach(ProjectNode project in solution.Projects)
426 {
427 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
428 ss.WriteLine(" <Entry filename=\"{0}\" />",
429 Helper.MakeFilePath(path, project.Name, "mdp"));
430 }
431 ss.WriteLine(" </Entries>");
432
433 ss.WriteLine("</Combine>");
434 }
435
436 m_Kernel.CurrentWorkingDirectory.Pop();
437 }
438
439 private void CleanProject(ProjectNode project)
440 {
441 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
442 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "mdp");
443 Helper.DeleteIfExists(projectFile);
444 }
445
446 private void CleanSolution(SolutionNode solution)
447 {
448 m_Kernel.Log.Write("Cleaning MonoDevelop combine and project files for", solution.Name);
449
450 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "mds");
451 Helper.DeleteIfExists(slnFile);
452
453 foreach(ProjectNode project in solution.Projects)
454 {
455 CleanProject(project);
456 }
457
458 m_Kernel.Log.Write("");
459 }
460
461 #endregion
462
463 #region ITarget Members
464
465 /// <summary>
466 /// Writes the specified kern.
467 /// </summary>
468 /// <param name="kern">The kern.</param>
469 public void Write(Kernel kern)
470 {
471 if( kern == null )
472 {
473 throw new ArgumentNullException("kern");
474 }
475 m_Kernel = kern;
476 foreach(SolutionNode solution in kern.Solutions)
477 {
478 WriteCombine(solution);
479 }
480 m_Kernel = null;
481 }
482
483 /// <summary>
484 /// Cleans the specified kern.
485 /// </summary>
486 /// <param name="kern">The kern.</param>
487 public virtual void Clean(Kernel kern)
488 {
489 if( kern == null )
490 {
491 throw new ArgumentNullException("kern");
492 }
493 m_Kernel = kern;
494 foreach(SolutionNode sol in kern.Solutions)
495 {
496 CleanSolution(sol);
497 }
498 m_Kernel = null;
499 }
500
501 /// <summary>
502 /// Gets the name.
503 /// </summary>
504 /// <value>The name.</value>
505 public string Name
506 {
507 get
508 {
509 return "sharpdev";
510 }
511 }
512
513 #endregion
514 }
515}
diff --git a/Prebuild/src/Core/Targets/NAntTarget.cs b/Prebuild/src/Core/Targets/NAntTarget.cs
new file mode 100644
index 0000000..d4a33f8
--- /dev/null
+++ b/Prebuild/src/Core/Targets/NAntTarget.cs
@@ -0,0 +1,792 @@
1#region BSD License
2/*
3Copyright (c) 2004 - 2008
4Matthew Holmes (matthew@wildfiregames.com),
5Dan Moorehead (dan05a@gmail.com),
6C.J. Adams-Collier (cjac@colliertech.org),
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are
10met:
11
12* Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15* Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18
19* The name of the author may not be used to endorse or promote
20 products derived from this software without specific prior written
21 permission.
22
23THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#endregion
37
38using System;
39using System.Collections.Generic;
40using System.IO;
41using System.Text.RegularExpressions;
42
43using Prebuild.Core.Attributes;
44using Prebuild.Core.Interfaces;
45using Prebuild.Core.Nodes;
46using Prebuild.Core.Utilities;
47
48namespace Prebuild.Core.Targets
49{
50 /// <summary>
51 ///
52 /// </summary>
53 [Target("nant")]
54 public class NAntTarget : ITarget
55 {
56 #region Fields
57
58 private Kernel m_Kernel;
59
60 #endregion
61
62 #region Private Methods
63
64 private static string PrependPath(string path)
65 {
66 string tmpPath = Helper.NormalizePath(path, '/');
67 Regex regex = new Regex(@"(\w):/(\w+)");
68 Match match = regex.Match(tmpPath);
69 //if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
70 //{
71 tmpPath = Helper.NormalizePath(tmpPath);
72 //}
73 // else
74 // {
75 // tmpPath = Helper.NormalizePath("./" + tmpPath);
76 // }
77
78 return tmpPath;
79 }
80
81 private static string BuildReference(SolutionNode solution, ProjectNode currentProject, ReferenceNode refr)
82 {
83
84 if (!String.IsNullOrEmpty(refr.Path))
85 {
86 return refr.Path;
87 }
88
89 if (solution.ProjectsTable.ContainsKey(refr.Name))
90 {
91 ProjectNode projectRef = (ProjectNode) solution.ProjectsTable[refr.Name];
92 string finalPath =
93 Helper.NormalizePath(refr.Name + GetProjectExtension(projectRef), '/');
94 return finalPath;
95 }
96
97 ProjectNode project = (ProjectNode) refr.Parent;
98
99 // Do we have an explicit file reference?
100 string fileRef = FindFileReference(refr.Name, project);
101 if (fileRef != null)
102 {
103 return fileRef;
104 }
105
106 // Is there an explicit path in the project ref?
107 if (refr.Path != null)
108 {
109 return Helper.NormalizePath(refr.Path + "/" + refr.Name + GetProjectExtension(project), '/');
110 }
111
112 // No, it's an extensionless GAC ref, but nant needs the .dll extension anyway
113 return refr.Name + ".dll";
114 }
115
116 public static string GetRefFileName(string refName)
117 {
118 if (ExtensionSpecified(refName))
119 {
120 return refName;
121 }
122 else
123 {
124 return refName + ".dll";
125 }
126 }
127
128 private static bool ExtensionSpecified(string refName)
129 {
130 return refName.EndsWith(".dll") || refName.EndsWith(".exe");
131 }
132
133 private static string GetProjectExtension(ProjectNode project)
134 {
135 string extension = ".dll";
136 if (project.Type == ProjectType.Exe || project.Type == ProjectType.WinExe)
137 {
138 extension = ".exe";
139 }
140 return extension;
141 }
142
143 private static string FindFileReference(string refName, ProjectNode project)
144 {
145 foreach (ReferencePathNode refPath in project.ReferencePaths)
146 {
147 string fullPath = Helper.MakeFilePath(refPath.Path, refName);
148
149 if (File.Exists(fullPath))
150 {
151 return fullPath;
152 }
153
154 fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
155
156 if (File.Exists(fullPath))
157 {
158 return fullPath;
159 }
160
161 fullPath = Helper.MakeFilePath(refPath.Path, refName, "exe");
162
163 if (File.Exists(fullPath))
164 {
165 return fullPath;
166 }
167 }
168
169 return null;
170 }
171
172 /// <summary>
173 /// Gets the XML doc file.
174 /// </summary>
175 /// <param name="project">The project.</param>
176 /// <param name="conf">The conf.</param>
177 /// <returns></returns>
178 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
179 {
180 if (conf == null)
181 {
182 throw new ArgumentNullException("conf");
183 }
184 if (project == null)
185 {
186 throw new ArgumentNullException("project");
187 }
188 string docFile = (string)conf.Options["XmlDocFile"];
189 // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
190 // {
191 // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
192 // }
193 return docFile;
194 }
195
196 private void WriteProject(SolutionNode solution, ProjectNode project)
197 {
198 string projFile = Helper.MakeFilePath(project.FullPath, project.Name + GetProjectExtension(project), "build");
199 StreamWriter ss = new StreamWriter(projFile);
200
201 m_Kernel.CurrentWorkingDirectory.Push();
202 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
203 bool hasDoc = false;
204
205 using (ss)
206 {
207 ss.WriteLine("<?xml version=\"1.0\" ?>");
208 ss.WriteLine("<project name=\"{0}\" default=\"build\">", project.Name);
209 ss.WriteLine(" <target name=\"{0}\">", "build");
210 ss.WriteLine(" <echo message=\"Build Directory is ${project::get-base-directory()}/${build.dir}\" />");
211 ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/${build.dir}\" />");
212 ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/${build.dir}\" flatten=\"true\">");
213 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
214 foreach (ReferenceNode refr in project.References)
215 {
216 if (refr.LocalCopy)
217 {
218 ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)) + "\" />", '/'));
219 }
220 }
221
222 ss.WriteLine(" </fileset>");
223 ss.WriteLine(" </copy>");
224 if (project.ConfigFile != null && project.ConfigFile.Length!=0)
225 {
226 ss.Write(" <copy file=\"" + project.ConfigFile + "\" tofile=\"${project::get-base-directory()}/${build.dir}/${project::get-name()}");
227
228 if (project.Type == ProjectType.Library)
229 {
230 ss.Write(".dll.config\"");
231 }
232 else
233 {
234 ss.Write(".exe.config\"");
235 }
236 ss.WriteLine(" />");
237 }
238
239 // Add the content files to just be copied
240 ss.WriteLine(" {0}", "<copy todir=\"${project::get-base-directory()}/${build.dir}\">");
241 ss.WriteLine(" {0}", "<fileset basedir=\".\">");
242
243 foreach (string file in project.Files)
244 {
245 // Ignore if we aren't content
246 if (project.Files.GetBuildAction(file) != BuildAction.Content)
247 continue;
248
249 // Create a include tag
250 ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
251 }
252
253 ss.WriteLine(" {0}", "</fileset>");
254 ss.WriteLine(" {0}", "</copy>");
255
256 ss.Write(" <csc ");
257 ss.Write(" target=\"{0}\"", project.Type.ToString().ToLower());
258 ss.Write(" debug=\"{0}\"", "${build.debug}");
259 ss.Write(" platform=\"${build.platform}\"");
260
261
262 foreach (ConfigurationNode conf in project.Configurations)
263 {
264 if (conf.Options.KeyFile != "")
265 {
266 ss.Write(" keyfile=\"{0}\"", conf.Options.KeyFile);
267 break;
268 }
269 }
270 foreach (ConfigurationNode conf in project.Configurations)
271 {
272 ss.Write(" unsafe=\"{0}\"", conf.Options.AllowUnsafe);
273 break;
274 }
275 foreach (ConfigurationNode conf in project.Configurations)
276 {
277 ss.Write(" warnaserror=\"{0}\"", conf.Options.WarningsAsErrors);
278 break;
279 }
280 foreach (ConfigurationNode conf in project.Configurations)
281 {
282 ss.Write(" define=\"{0}\"", conf.Options.CompilerDefines);
283 break;
284 }
285 foreach (ConfigurationNode conf in project.Configurations)
286 {
287 ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]);
288 break;
289 }
290
291 ss.Write(" main=\"{0}\"", project.StartupObject);
292
293 foreach (ConfigurationNode conf in project.Configurations)
294 {
295 if (GetXmlDocFile(project, conf) != "")
296 {
297 ss.Write(" doc=\"{0}\"", "${project::get-base-directory()}/${build.dir}/" + GetXmlDocFile(project, conf));
298 hasDoc = true;
299 }
300 break;
301 }
302 ss.Write(" output=\"{0}", "${project::get-base-directory()}/${build.dir}/${project::get-name()}");
303 if (project.Type == ProjectType.Library)
304 {
305 ss.Write(".dll\"");
306 }
307 else
308 {
309 ss.Write(".exe\"");
310 }
311 if (project.AppIcon != null && project.AppIcon.Length != 0)
312 {
313 ss.Write(" win32icon=\"{0}\"", Helper.NormalizePath(project.AppIcon, '/'));
314 }
315 // This disables a very different behavior between VS and NAnt. With Nant,
316 // If you have using System.Xml; it will ensure System.Xml.dll is referenced,
317 // but not in VS. This will force the behaviors to match, so when it works
318 // in nant, it will work in VS.
319 ss.Write(" noconfig=\"true\"");
320 ss.WriteLine(">");
321 ss.WriteLine(" <resources prefix=\"{0}\" dynamicprefix=\"true\" >", project.RootNamespace);
322 foreach (string file in project.Files)
323 {
324 switch (project.Files.GetBuildAction(file))
325 {
326 case BuildAction.EmbeddedResource:
327 ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
328 break;
329 default:
330 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
331 {
332 ss.WriteLine(" <include name=\"{0}\" />", file.Substring(0, file.LastIndexOf('.')) + ".resx");
333 }
334 break;
335 }
336 }
337 //if (project.Files.GetSubType(file).ToString() != "Code")
338 //{
339 // ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
340
341 ss.WriteLine(" </resources>");
342 ss.WriteLine(" <sources failonempty=\"true\">");
343 foreach (string file in project.Files)
344 {
345 switch (project.Files.GetBuildAction(file))
346 {
347 case BuildAction.Compile:
348 ss.WriteLine(" <include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
349 break;
350 default:
351 break;
352 }
353 }
354 ss.WriteLine(" </sources>");
355 ss.WriteLine(" <references basedir=\"${project::get-base-directory()}\">");
356 ss.WriteLine(" <lib>");
357 ss.WriteLine(" <include name=\"${project::get-base-directory()}\" />");
358 foreach(ReferencePathNode refPath in project.ReferencePaths)
359 {
360 ss.WriteLine(" <include name=\"${project::get-base-directory()}/" + refPath.Path.TrimEnd('/', '\\') + "\" />");
361 }
362 ss.WriteLine(" </lib>");
363 foreach (ReferenceNode refr in project.References)
364 {
365 string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, project, refr)), '/');
366 if (refr.Path != null) {
367 if (ExtensionSpecified(refr.Name))
368 {
369 ss.WriteLine (" <include name=\"" + path + refr.Name + "\"/>");
370 }
371 else
372 {
373 ss.WriteLine (" <include name=\"" + path + refr.Name + ".dll\"/>");
374 }
375 }
376 else
377 {
378 ss.WriteLine (" <include name=\"" + path + "\" />");
379 }
380 }
381 ss.WriteLine(" </references>");
382
383 ss.WriteLine(" </csc>");
384
385 foreach (ConfigurationNode conf in project.Configurations)
386 {
387 if (!String.IsNullOrEmpty(conf.Options.OutputPath))
388 {
389 string targetDir = Helper.NormalizePath(conf.Options.OutputPath, '/');
390
391 ss.WriteLine(" <echo message=\"Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/" + targetDir + "\" />");
392
393 ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/" + targetDir + "\"/>");
394
395 ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/" + targetDir + "\">");
396 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}/${build.dir}/\" >");
397 ss.WriteLine(" <include name=\"*.dll\"/>");
398 ss.WriteLine(" <include name=\"*.exe\"/>");
399 ss.WriteLine(" <include name=\"*.mdb\" if='${build.debug}'/>");
400 ss.WriteLine(" <include name=\"*.pdb\" if='${build.debug}'/>");
401 ss.WriteLine(" </fileset>");
402 ss.WriteLine(" </copy>");
403 break;
404 }
405 }
406
407 ss.WriteLine(" </target>");
408
409 ss.WriteLine(" <target name=\"clean\">");
410 ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />");
411 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
412 ss.WriteLine(" </target>");
413
414 ss.WriteLine(" <target name=\"doc\" description=\"Creates documentation.\">");
415 if (hasDoc)
416 {
417 ss.WriteLine(" <property name=\"doc.target\" value=\"\" />");
418 ss.WriteLine(" <if test=\"${platform::is-unix()}\">");
419 ss.WriteLine(" <property name=\"doc.target\" value=\"Web\" />");
420 ss.WriteLine(" </if>");
421 ss.WriteLine(" <ndoc failonerror=\"false\" verbose=\"true\">");
422 ss.WriteLine(" <assemblies basedir=\"${project::get-base-directory()}\">");
423 ss.Write(" <include name=\"${build.dir}/${project::get-name()}");
424 if (project.Type == ProjectType.Library)
425 {
426 ss.WriteLine(".dll\" />");
427 }
428 else
429 {
430 ss.WriteLine(".exe\" />");
431 }
432
433 ss.WriteLine(" </assemblies>");
434 ss.WriteLine(" <summaries basedir=\"${project::get-base-directory()}\">");
435 ss.WriteLine(" <include name=\"${build.dir}/${project::get-name()}.xml\"/>");
436 ss.WriteLine(" </summaries>");
437 ss.WriteLine(" <referencepaths basedir=\"${project::get-base-directory()}\">");
438 ss.WriteLine(" <include name=\"${build.dir}\" />");
439 // foreach(ReferenceNode refr in project.References)
440 // {
441 // string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReferencePath(solution, refr)), '/');
442 // if (path != "")
443 // {
444 // ss.WriteLine(" <include name=\"{0}\" />", path);
445 // }
446 // }
447 ss.WriteLine(" </referencepaths>");
448 ss.WriteLine(" <documenters>");
449 ss.WriteLine(" <documenter name=\"MSDN\">");
450 ss.WriteLine(" <property name=\"OutputDirectory\" value=\"${project::get-base-directory()}/${build.dir}/doc/${project::get-name()}\" />");
451 ss.WriteLine(" <property name=\"OutputTarget\" value=\"${doc.target}\" />");
452 ss.WriteLine(" <property name=\"HtmlHelpName\" value=\"${project::get-name()}\" />");
453 ss.WriteLine(" <property name=\"IncludeFavorites\" value=\"False\" />");
454 ss.WriteLine(" <property name=\"Title\" value=\"${project::get-name()} SDK Documentation\" />");
455 ss.WriteLine(" <property name=\"SplitTOCs\" value=\"False\" />");
456 ss.WriteLine(" <property name=\"DefaulTOC\" value=\"\" />");
457 ss.WriteLine(" <property name=\"ShowVisualBasic\" value=\"True\" />");
458 ss.WriteLine(" <property name=\"AutoDocumentConstructors\" value=\"True\" />");
459 ss.WriteLine(" <property name=\"ShowMissingSummaries\" value=\"${build.debug}\" />");
460 ss.WriteLine(" <property name=\"ShowMissingRemarks\" value=\"${build.debug}\" />");
461 ss.WriteLine(" <property name=\"ShowMissingParams\" value=\"${build.debug}\" />");
462 ss.WriteLine(" <property name=\"ShowMissingReturns\" value=\"${build.debug}\" />");
463 ss.WriteLine(" <property name=\"ShowMissingValues\" value=\"${build.debug}\" />");
464 ss.WriteLine(" <property name=\"DocumentInternals\" value=\"False\" />");
465 ss.WriteLine(" <property name=\"DocumentPrivates\" value=\"False\" />");
466 ss.WriteLine(" <property name=\"DocumentProtected\" value=\"True\" />");
467 ss.WriteLine(" <property name=\"DocumentEmptyNamespaces\" value=\"${build.debug}\" />");
468 ss.WriteLine(" <property name=\"IncludeAssemblyVersion\" value=\"True\" />");
469 ss.WriteLine(" </documenter>");
470 ss.WriteLine(" </documenters>");
471 ss.WriteLine(" </ndoc>");
472 }
473 ss.WriteLine(" </target>");
474 ss.WriteLine("</project>");
475 }
476 m_Kernel.CurrentWorkingDirectory.Pop();
477 }
478
479 private void WriteCombine(SolutionNode solution)
480 {
481 m_Kernel.Log.Write("Creating NAnt build files");
482 foreach (ProjectNode project in solution.Projects)
483 {
484 if (m_Kernel.AllowProject(project.FilterGroups))
485 {
486 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
487 WriteProject(solution, project);
488 }
489 }
490
491 m_Kernel.Log.Write("");
492 string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
493 StreamWriter ss = new StreamWriter(combFile);
494
495 m_Kernel.CurrentWorkingDirectory.Push();
496 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
497
498 using (ss)
499 {
500 ss.WriteLine("<?xml version=\"1.0\" ?>");
501 ss.WriteLine("<project name=\"{0}\" default=\"build\">", solution.Name);
502 ss.WriteLine(" <echo message=\"Using '${nant.settings.currentframework}' Framework\"/>");
503 ss.WriteLine();
504
505 //ss.WriteLine(" <property name=\"dist.dir\" value=\"dist\" />");
506 //ss.WriteLine(" <property name=\"source.dir\" value=\"source\" />");
507 ss.WriteLine(" <property name=\"bin.dir\" value=\"bin\" />");
508 ss.WriteLine(" <property name=\"obj.dir\" value=\"obj\" />");
509 ss.WriteLine(" <property name=\"doc.dir\" value=\"doc\" />");
510 ss.WriteLine(" <property name=\"project.main.dir\" value=\"${project::get-base-directory()}\" />");
511
512 // Use the active configuration, which is the first configuration name in the prebuild file.
513 Dictionary<string,string> emittedConfigurations = new Dictionary<string, string>();
514
515 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", solution.ActiveConfig);
516 ss.WriteLine();
517
518 foreach (ConfigurationNode conf in solution.Configurations)
519 {
520 // If the name isn't in the emitted configurations, we give a high level target to the
521 // platform specific on. This lets "Debug" point to "Debug-AnyCPU".
522 if (!emittedConfigurations.ContainsKey(conf.Name))
523 {
524 // Add it to the dictionary so we only emit one.
525 emittedConfigurations.Add(conf.Name, conf.Platform);
526
527 // Write out the target block.
528 ss.WriteLine(" <target name=\"{0}\" description=\"{0}|{1}\" depends=\"{0}-{1}\">", conf.Name, conf.Platform);
529 ss.WriteLine(" </target>");
530 ss.WriteLine();
531 }
532
533 // Write out the target for the configuration.
534 ss.WriteLine(" <target name=\"{0}-{1}\" description=\"{0}|{1}\">", conf.Name, conf.Platform);
535 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name);
536 ss.WriteLine(" <property name=\"build.debug\" value=\"{0}\" />", conf.Options["DebugInformation"].ToString().ToLower());
537 ss.WriteLine("\t\t <property name=\"build.platform\" value=\"{0}\" />", conf.Platform);
538 ss.WriteLine(" </target>");
539 ss.WriteLine();
540 }
541
542 ss.WriteLine(" <target name=\"net-1.1\" description=\"Sets framework to .NET 1.1\">");
543 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-1.1\" />");
544 ss.WriteLine(" </target>");
545 ss.WriteLine();
546
547 ss.WriteLine(" <target name=\"net-2.0\" description=\"Sets framework to .NET 2.0\">");
548 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-2.0\" />");
549 ss.WriteLine(" </target>");
550 ss.WriteLine();
551
552 ss.WriteLine(" <target name=\"net-3.5\" description=\"Sets framework to .NET 3.5\">");
553 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-3.5\" />");
554 ss.WriteLine(" </target>");
555 ss.WriteLine();
556
557 ss.WriteLine(" <target name=\"mono-1.0\" description=\"Sets framework to mono 1.0\">");
558 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-1.0\" />");
559 ss.WriteLine(" </target>");
560 ss.WriteLine();
561
562 ss.WriteLine(" <target name=\"mono-2.0\" description=\"Sets framework to mono 2.0\">");
563 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-2.0\" />");
564 ss.WriteLine(" </target>");
565 ss.WriteLine();
566
567 ss.WriteLine(" <target name=\"mono-3.5\" description=\"Sets framework to mono 3.5\">");
568 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-3.5\" />");
569 ss.WriteLine(" </target>");
570 ss.WriteLine();
571
572 ss.WriteLine(" <target name=\"init\" description=\"\">");
573 ss.WriteLine(" <call target=\"${project.config}\" />");
574 ss.WriteLine(" <property name=\"sys.os.platform\"");
575 ss.WriteLine(" value=\"${platform::get-name()}\"");
576 ss.WriteLine(" />");
577 ss.WriteLine(" <echo message=\"Platform ${sys.os.platform}\" />");
578 ss.WriteLine(" <property name=\"build.dir\" value=\"${bin.dir}/${project.config}\" />");
579 ss.WriteLine(" </target>");
580 ss.WriteLine();
581
582
583 // sdague - ok, this is an ugly hack, but what it lets
584 // us do is native include of files into the nant
585 // created files from all .nant/*include files. This
586 // lets us keep using prebuild, but allows for
587 // extended nant targets to do build and the like.
588
589 try
590 {
591 Regex re = new Regex(".include$");
592 DirectoryInfo nantdir = new DirectoryInfo(".nant");
593 foreach (FileSystemInfo item in nantdir.GetFileSystemInfos())
594 {
595 if (item is DirectoryInfo) { }
596 else if (item is FileInfo)
597 {
598 if (re.Match(item.FullName) !=
599 System.Text.RegularExpressions.Match.Empty)
600 {
601 Console.WriteLine("Including file: " + item.FullName);
602
603 using (FileStream fs = new FileStream(item.FullName,
604 FileMode.Open,
605 FileAccess.Read,
606 FileShare.None))
607 {
608 using (StreamReader sr = new StreamReader(fs))
609 {
610 ss.WriteLine("<!-- included from {0} -->", (item).FullName);
611 while (sr.Peek() != -1)
612 {
613 ss.WriteLine(sr.ReadLine());
614 }
615 ss.WriteLine();
616 }
617 }
618 }
619 }
620 }
621 }
622 catch { }
623 // ss.WriteLine(" <include buildfile=\".nant/local.include\" />");
624 // ss.WriteLine(" <target name=\"zip\" description=\"\">");
625 // ss.WriteLine(" <zip zipfile=\"{0}-{1}.zip\">", solution.Name, solution.Version);
626 // ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
627
628 // ss.WriteLine(" <include name=\"${project::get-base-directory()}/**/*.cs\" />");
629 // // ss.WriteLine(" <include name=\"${project.main.dir}/**/*\" />");
630 // ss.WriteLine(" </fileset>");
631 // ss.WriteLine(" </zip>");
632 // ss.WriteLine(" <echo message=\"Building zip target\" />");
633 // ss.WriteLine(" </target>");
634 ss.WriteLine();
635
636
637 ss.WriteLine(" <target name=\"clean\" description=\"\">");
638 ss.WriteLine(" <echo message=\"Deleting all builds from all configurations\" />");
639 //ss.WriteLine(" <delete dir=\"${dist.dir}\" failonerror=\"false\" />");
640
641 // justincc: FIXME FIXME FIXME - A temporary OpenSim hack to clean up files when "nant clean" is executed.
642 // Should be replaced with extreme prejudice once anybody finds out if the CleanFiles stuff works or there is
643 // another working mechanism for specifying this stuff
644 ss.WriteLine(" <delete failonerror=\"false\">");
645 ss.WriteLine(" <fileset basedir=\"${bin.dir}\">");
646 ss.WriteLine(" <include name=\"OpenSim*.dll\"/>");
647 ss.WriteLine(" <include name=\"OpenSim*.exe\"/>");
648 ss.WriteLine(" <include name=\"ScriptEngines/*\"/>");
649 ss.WriteLine(" <include name=\"Physics/*\"/>");
650 ss.WriteLine(" <exclude name=\"OpenSim.32BitLaunch.exe\"/>");
651 ss.WriteLine(" <exclude name=\"ScriptEngines/Default.lsl\"/>");
652 ss.WriteLine(" </fileset>");
653 ss.WriteLine(" </delete>");
654
655 if (solution.Cleanup != null && solution.Cleanup.CleanFiles.Count > 0)
656 {
657 foreach (CleanFilesNode cleanFile in solution.Cleanup.CleanFiles)
658 {
659 ss.WriteLine(" <delete failonerror=\"false\">");
660 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
661 ss.WriteLine(" <include name=\"{0}/*\"/>", cleanFile.Pattern);
662 ss.WriteLine(" <include name=\"{0}\"/>", cleanFile.Pattern);
663 ss.WriteLine(" </fileset>");
664 ss.WriteLine(" </delete>");
665 }
666 }
667
668 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
669 foreach (ProjectNode project in solution.Projects)
670 {
671 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
672 ss.Write(" <nant buildfile=\"{0}\"",
673 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
674 ss.WriteLine(" target=\"clean\" />");
675 }
676 ss.WriteLine(" </target>");
677 ss.WriteLine();
678
679 ss.WriteLine(" <target name=\"build\" depends=\"init\" description=\"\">");
680
681 foreach (ProjectNode project in solution.ProjectsTableOrder)
682 {
683 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
684 ss.Write(" <nant buildfile=\"{0}\"",
685 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
686 ss.WriteLine(" target=\"build\" />");
687 }
688 ss.WriteLine(" </target>");
689 ss.WriteLine();
690
691 ss.WriteLine(" <target name=\"build-release\" depends=\"Release, init, build\" description=\"Builds in Release mode\" />");
692 ss.WriteLine();
693 ss.WriteLine(" <target name=\"build-debug\" depends=\"Debug, init, build\" description=\"Builds in Debug mode\" />");
694 ss.WriteLine();
695 //ss.WriteLine(" <target name=\"package\" depends=\"clean, doc, copyfiles, zip\" description=\"Builds in Release mode\" />");
696 ss.WriteLine(" <target name=\"package\" depends=\"clean, doc\" description=\"Builds all\" />");
697 ss.WriteLine();
698
699 ss.WriteLine(" <target name=\"doc\" depends=\"build-release\">");
700 ss.WriteLine(" <echo message=\"Generating all documentation from all builds\" />");
701 foreach (ProjectNode project in solution.Projects)
702 {
703 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
704 ss.Write(" <nant buildfile=\"{0}\"",
705 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + GetProjectExtension(project), "build"), '/'));
706 ss.WriteLine(" target=\"doc\" />");
707 }
708 ss.WriteLine(" </target>");
709 ss.WriteLine();
710 ss.WriteLine("</project>");
711 }
712
713 m_Kernel.CurrentWorkingDirectory.Pop();
714 }
715
716 private void CleanProject(ProjectNode project)
717 {
718 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
719 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name + GetProjectExtension(project), "build");
720 Helper.DeleteIfExists(projectFile);
721 }
722
723 private void CleanSolution(SolutionNode solution)
724 {
725 m_Kernel.Log.Write("Cleaning NAnt build files for", solution.Name);
726
727 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
728 Helper.DeleteIfExists(slnFile);
729
730 foreach (ProjectNode project in solution.Projects)
731 {
732 CleanProject(project);
733 }
734
735 m_Kernel.Log.Write("");
736 }
737
738 #endregion
739
740 #region ITarget Members
741
742 /// <summary>
743 /// Writes the specified kern.
744 /// </summary>
745 /// <param name="kern">The kern.</param>
746 public void Write(Kernel kern)
747 {
748 if (kern == null)
749 {
750 throw new ArgumentNullException("kern");
751 }
752 m_Kernel = kern;
753 foreach (SolutionNode solution in kern.Solutions)
754 {
755 WriteCombine(solution);
756 }
757 m_Kernel = null;
758 }
759
760 /// <summary>
761 /// Cleans the specified kern.
762 /// </summary>
763 /// <param name="kern">The kern.</param>
764 public virtual void Clean(Kernel kern)
765 {
766 if (kern == null)
767 {
768 throw new ArgumentNullException("kern");
769 }
770 m_Kernel = kern;
771 foreach (SolutionNode sol in kern.Solutions)
772 {
773 CleanSolution(sol);
774 }
775 m_Kernel = null;
776 }
777
778 /// <summary>
779 /// Gets the name.
780 /// </summary>
781 /// <value>The name.</value>
782 public string Name
783 {
784 get
785 {
786 return "nant";
787 }
788 }
789
790 #endregion
791 }
792}
diff --git a/Prebuild/src/Core/Targets/SharpDevelop2Target.cs b/Prebuild/src/Core/Targets/SharpDevelop2Target.cs
new file mode 100644
index 0000000..66dd1bc
--- /dev/null
+++ b/Prebuild/src/Core/Targets/SharpDevelop2Target.cs
@@ -0,0 +1,82 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27
28using Prebuild.Core.Attributes;
29
30namespace Prebuild.Core.Targets
31{
32 /// <summary>
33 ///
34 /// </summary>
35 [Target("sharpdev2")]
36 public class SharpDevelop2Target : VS2005Target
37 {
38 #region Properties
39 public override string VersionName
40 {
41 get
42 {
43 return "SharpDevelop2";
44 }
45 }
46 #endregion
47
48 #region Public Methods
49
50 /// <summary>
51 /// Writes the specified kern.
52 /// </summary>
53 /// <param name="kern">The kern.</param>
54 public override void Write(Kernel kern)
55 {
56 base.Write(kern);
57 }
58
59 /// <summary>
60 /// Cleans the specified kern.
61 /// </summary>
62 /// <param name="kern">The kern.</param>
63 public override void Clean(Kernel kern)
64 {
65 base.Clean(kern);
66 }
67
68 /// <summary>
69 /// Gets the name.
70 /// </summary>
71 /// <value>The name.</value>
72 public override string Name
73 {
74 get
75 {
76 return "sharpdev2";
77 }
78 }
79
80 #endregion
81 }
82}
diff --git a/Prebuild/src/Core/Targets/SharpDevelopTarget.cs b/Prebuild/src/Core/Targets/SharpDevelopTarget.cs
new file mode 100644
index 0000000..8e32050
--- /dev/null
+++ b/Prebuild/src/Core/Targets/SharpDevelopTarget.cs
@@ -0,0 +1,425 @@
1#region BSD License
2/*
3Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Text.RegularExpressions;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using Prebuild.Core.Nodes;
33using Prebuild.Core.Utilities;
34
35namespace Prebuild.Core.Targets
36{
37 /// <summary>
38 ///
39 /// </summary>
40 [Target("sharpdev")]
41 public class SharpDevelopTarget : ITarget
42 {
43 #region Fields
44
45 private Kernel m_Kernel;
46
47 #endregion
48
49 #region Private Methods
50
51 private static string PrependPath(string path)
52 {
53 string tmpPath = Helper.NormalizePath(path, '/');
54 Regex regex = new Regex(@"(\w):/(\w+)");
55 Match match = regex.Match(tmpPath);
56 if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
57 {
58 tmpPath = Helper.NormalizePath(tmpPath);
59 }
60 else
61 {
62 tmpPath = Helper.NormalizePath("./" + tmpPath);
63 }
64
65 return tmpPath;
66 }
67
68 private static string BuildReference(SolutionNode solution, ReferenceNode refr)
69 {
70 string ret = "<Reference type=\"";
71 if(solution.ProjectsTable.ContainsKey(refr.Name))
72 {
73 ret += "Project\" refto=\"" + refr.Name;
74 ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />";
75 }
76 else
77 {
78 ProjectNode project = (ProjectNode)refr.Parent;
79 string fileRef = FindFileReference(refr.Name, project);
80
81 if(refr.Path != null || fileRef != null)
82 {
83 ret += "Assembly\" refto=\"";
84
85 string finalPath = (refr.Path != null) ? Helper.MakeFilePath(refr.Path, refr.Name, "dll") : fileRef;
86
87 ret += finalPath;
88 ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />";
89 return ret;
90 }
91
92 ret += "Gac\" refto=\"";
93 try
94 {
95 //Assembly assem = Assembly.Load(refr.Name);
96 ret += refr.Name;// assem.FullName;
97 }
98 catch (System.NullReferenceException e)
99 {
100 e.ToString();
101 ret += refr.Name;
102 }
103 ret += "\" localcopy=\"" + refr.LocalCopy.ToString() + "\" />";
104 }
105
106 return ret;
107 }
108
109 private static string FindFileReference(string refName, ProjectNode project)
110 {
111 foreach(ReferencePathNode refPath in project.ReferencePaths)
112 {
113 string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
114
115 if(File.Exists(fullPath))
116 {
117 return fullPath;
118 }
119 }
120
121 return null;
122 }
123
124 /// <summary>
125 /// Gets the XML doc file.
126 /// </summary>
127 /// <param name="project">The project.</param>
128 /// <param name="conf">The conf.</param>
129 /// <returns></returns>
130 public static string GenerateXmlDocFile(ProjectNode project, ConfigurationNode conf)
131 {
132 if( conf == null )
133 {
134 throw new ArgumentNullException("conf");
135 }
136 if( project == null )
137 {
138 throw new ArgumentNullException("project");
139 }
140 string docFile = (string)conf.Options["XmlDocFile"];
141 if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
142 {
143 return "False";
144 }
145 return "True";
146 }
147
148 private void WriteProject(SolutionNode solution, ProjectNode project)
149 {
150 string csComp = "Csc";
151 string netRuntime = "MsNet";
152 if(project.Runtime == ClrRuntime.Mono)
153 {
154 csComp = "Mcs";
155 netRuntime = "Mono";
156 }
157
158 string projFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx");
159 StreamWriter ss = new StreamWriter(projFile);
160
161 m_Kernel.CurrentWorkingDirectory.Push();
162 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
163
164 using(ss)
165 {
166 ss.WriteLine(
167 "<Project name=\"{0}\" standardNamespace=\"{1}\" description=\"\" newfilesearch=\"None\" enableviewstate=\"True\" version=\"1.1\" projecttype=\"C#\">",
168 project.Name,
169 project.RootNamespace
170 );
171
172 ss.WriteLine(" <Contents>");
173 foreach(string file in project.Files)
174 {
175 string buildAction = "Compile";
176 switch(project.Files.GetBuildAction(file))
177 {
178 case BuildAction.None:
179 buildAction = "Nothing";
180 break;
181
182 case BuildAction.Content:
183 buildAction = "Exclude";
184 break;
185
186 case BuildAction.EmbeddedResource:
187 buildAction = "EmbedAsResource";
188 break;
189
190 default:
191 buildAction = "Compile";
192 break;
193 }
194
195 // Sort of a hack, we try and resolve the path and make it relative, if we can.
196 string filePath = PrependPath(file);
197 ss.WriteLine(" <File name=\"{0}\" subtype=\"Code\" buildaction=\"{1}\" dependson=\"\" data=\"\" />", filePath, buildAction);
198 }
199 ss.WriteLine(" </Contents>");
200
201 ss.WriteLine(" <References>");
202 foreach(ReferenceNode refr in project.References)
203 {
204 ss.WriteLine(" {0}", BuildReference(solution, refr));
205 }
206 ss.WriteLine(" </References>");
207
208 ss.Write(" <DeploymentInformation");
209 ss.Write(" target=\"\"");
210 ss.Write(" script=\"\"");
211 ss.Write(" strategy=\"File\"");
212 ss.WriteLine(" />");
213
214 int count = 0;
215
216 ss.WriteLine(" <Configurations active=\"{0}\">", solution.ActiveConfig);
217
218 foreach(ConfigurationNode conf in project.Configurations)
219 {
220 ss.Write(" <Configuration");
221 ss.Write(" runwithwarnings=\"True\"");
222 ss.Write(" name=\"{0}\"", conf.Name);
223 ss.WriteLine(">");
224 ss.Write(" <CodeGeneration");
225 ss.Write(" runtime=\"{0}\"", netRuntime);
226 ss.Write(" compiler=\"{0}\"", csComp);
227 ss.Write(" compilerversion=\"\"");
228 ss.Write(" warninglevel=\"{0}\"", conf.Options["WarningLevel"]);
229 ss.Write(" nowarn=\"{0}\"", conf.Options["SuppressWarnings"]);
230 ss.Write(" includedebuginformation=\"{0}\"", conf.Options["DebugInformation"]);
231 ss.Write(" optimize=\"{0}\"", conf.Options["OptimizeCode"]);
232 ss.Write(" unsafecodeallowed=\"{0}\"", conf.Options["AllowUnsafe"]);
233 ss.Write(" generateoverflowchecks=\"{0}\"", conf.Options["CheckUnderflowOverflow"]);
234 ss.Write(" mainclass=\"{0}\"", project.StartupObject);
235 ss.Write(" target=\"{0}\"", project.Type);
236 ss.Write(" definesymbols=\"{0}\"", conf.Options["CompilerDefines"]);
237 ss.Write(" generatexmldocumentation=\"{0}\"", GenerateXmlDocFile(project, conf));
238 ss.Write(" win32Icon=\"{0}\"", Helper.NormalizePath(".\\" + project.AppIcon));
239 ss.Write(" noconfig=\"{0}\"", "False");
240 ss.Write(" nostdlib=\"{0}\"", conf.Options["NoStdLib"]);
241 ss.WriteLine(" />");
242
243 ss.Write(" <Execution");
244 ss.Write(" commandlineparameters=\"\"");
245 ss.Write(" consolepause=\"True\"");
246 ss.WriteLine(" />");
247
248 ss.Write(" <Output");
249 ss.Write(" directory=\".\\{0}\"", Helper.NormalizePath(conf.Options["OutputPath"].ToString()));
250 ss.Write(" assembly=\"{0}\"", project.AssemblyName);
251 ss.Write(" executeScript=\"{0}\"", conf.Options["RunScript"]);
252 if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0)
253 {
254 ss.Write(" executeBeforeBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString()));
255 }
256 else
257 {
258 ss.Write(" executeBeforeBuild=\"{0}\"", conf.Options["PreBuildEvent"]);
259 }
260 if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0)
261 {
262 ss.Write(" executeAfterBuild=\"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString()));
263 }
264 else
265 {
266 ss.Write(" executeAfterBuild=\"{0}\"", conf.Options["PostBuildEvent"]);
267 }
268 ss.Write(" executeBeforeBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]);
269 ss.Write(" executeAfterBuildArguments=\"{0}\"", conf.Options["PreBuildEventArgs"]);
270 ss.WriteLine(" />");
271 ss.WriteLine(" </Configuration>");
272
273 count++;
274 }
275 ss.WriteLine(" </Configurations>");
276 ss.WriteLine("</Project>");
277 }
278
279 m_Kernel.CurrentWorkingDirectory.Pop();
280 }
281
282 private void WriteCombine(SolutionNode solution)
283 {
284 m_Kernel.Log.Write("Creating SharpDevelop combine and project files");
285 foreach(ProjectNode project in solution.Projects)
286 {
287 if(m_Kernel.AllowProject(project.FilterGroups))
288 {
289 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
290 WriteProject(solution, project);
291 }
292 }
293
294 m_Kernel.Log.Write("");
295 string combFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx");
296 StreamWriter ss = new StreamWriter(combFile);
297
298 m_Kernel.CurrentWorkingDirectory.Push();
299 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
300
301 using(ss)
302 {
303 ss.WriteLine("<Combine fileversion=\"1.0\" name=\"{0}\" description=\"\">", solution.Name);
304
305 int count = 0;
306 foreach(ProjectNode project in solution.Projects)
307 {
308 if(count == 0)
309 ss.WriteLine(" <StartMode startupentry=\"{0}\" single=\"True\">", project.Name);
310
311 ss.WriteLine(" <Execute entry=\"{0}\" type=\"None\" />", project.Name);
312 count++;
313 }
314 ss.WriteLine(" </StartMode>");
315
316 ss.WriteLine(" <Entries>");
317 foreach(ProjectNode project in solution.Projects)
318 {
319 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
320 ss.WriteLine(" <Entry filename=\"{0}\" />",
321 Helper.MakeFilePath(path, project.Name, "prjx"));
322 }
323 ss.WriteLine(" </Entries>");
324
325 count = 0;
326 foreach(ConfigurationNode conf in solution.Configurations)
327 {
328 if(count == 0)
329 {
330 ss.WriteLine(" <Configurations active=\"{0}\">", conf.Name);
331 }
332
333 ss.WriteLine(" <Configuration name=\"{0}\">", conf.Name);
334 foreach(ProjectNode project in solution.Projects)
335 {
336 ss.WriteLine(" <Entry name=\"{0}\" configurationname=\"{1}\" build=\"True\" />", project.Name, conf.Name);
337 }
338 ss.WriteLine(" </Configuration>");
339
340 count++;
341 }
342 ss.WriteLine(" </Configurations>");
343 ss.WriteLine("</Combine>");
344 }
345
346 m_Kernel.CurrentWorkingDirectory.Pop();
347 }
348
349 private void CleanProject(ProjectNode project)
350 {
351 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
352 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "prjx");
353 Helper.DeleteIfExists(projectFile);
354 }
355
356 private void CleanSolution(SolutionNode solution)
357 {
358 m_Kernel.Log.Write("Cleaning SharpDevelop combine and project files for", solution.Name);
359
360 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "cmbx");
361 Helper.DeleteIfExists(slnFile);
362
363 foreach(ProjectNode project in solution.Projects)
364 {
365 CleanProject(project);
366 }
367
368 m_Kernel.Log.Write("");
369 }
370
371 #endregion
372
373 #region ITarget Members
374
375 /// <summary>
376 /// Writes the specified kern.
377 /// </summary>
378 /// <param name="kern">The kern.</param>
379 public void Write(Kernel kern)
380 {
381 if( kern == null )
382 {
383 throw new ArgumentNullException("kern");
384 }
385 m_Kernel = kern;
386 foreach(SolutionNode solution in kern.Solutions)
387 {
388 WriteCombine(solution);
389 }
390 m_Kernel = null;
391 }
392
393 /// <summary>
394 /// Cleans the specified kern.
395 /// </summary>
396 /// <param name="kern">The kern.</param>
397 public virtual void Clean(Kernel kern)
398 {
399 if( kern == null )
400 {
401 throw new ArgumentNullException("kern");
402 }
403 m_Kernel = kern;
404 foreach(SolutionNode sol in kern.Solutions)
405 {
406 CleanSolution(sol);
407 }
408 m_Kernel = null;
409 }
410
411 /// <summary>
412 /// Gets the name.
413 /// </summary>
414 /// <value>The name.</value>
415 public string Name
416 {
417 get
418 {
419 return "sharpdev";
420 }
421 }
422
423 #endregion
424 }
425}
diff --git a/Prebuild/src/Core/Targets/ToolInfo.cs b/Prebuild/src/Core/Targets/ToolInfo.cs
new file mode 100644
index 0000000..935c674
--- /dev/null
+++ b/Prebuild/src/Core/Targets/ToolInfo.cs
@@ -0,0 +1,197 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Prebuild.Core.Targets
6{
7 /// <summary>
8 ///
9 /// </summary>
10 public struct ToolInfo
11 {
12 string name;
13 string guid;
14 string fileExtension;
15 string xmlTag;
16 string importProject;
17
18 /// <summary>
19 /// Gets or sets the name.
20 /// </summary>
21 /// <value>The name.</value>
22 public string Name
23 {
24 get
25 {
26 return name;
27 }
28 set
29 {
30 name = value;
31 }
32 }
33
34 /// <summary>
35 /// Gets or sets the GUID.
36 /// </summary>
37 /// <value>The GUID.</value>
38 public string Guid
39 {
40 get
41 {
42 return guid;
43 }
44 set
45 {
46 guid = value;
47 }
48 }
49
50 /// <summary>
51 /// Gets or sets the file extension.
52 /// </summary>
53 /// <value>The file extension.</value>
54 public string FileExtension
55 {
56 get
57 {
58 return fileExtension;
59 }
60 set
61 {
62 fileExtension = value;
63 }
64 }
65 public string LanguageExtension
66 {
67 get
68 {
69 switch (this.Name)
70 {
71 case "C#":
72 return ".cs";
73 case "VisualBasic":
74 return ".vb";
75 case "Boo":
76 return ".boo";
77 default:
78 return ".cs";
79 }
80 }
81 }
82 /// <summary>
83 /// Gets or sets the XML tag.
84 /// </summary>
85 /// <value>The XML tag.</value>
86 public string XmlTag
87 {
88 get
89 {
90 return xmlTag;
91 }
92 set
93 {
94 xmlTag = value;
95 }
96 }
97
98 /// <summary>
99 /// Gets or sets the import project property.
100 /// </summary>
101 /// <value>The ImportProject tag.</value>
102 public string ImportProject
103 {
104 get
105 {
106 return importProject;
107 }
108 set
109 {
110 importProject = value;
111 }
112 }
113
114 /// <summary>
115 /// Initializes a new instance of the <see cref="ToolInfo"/> class.
116 /// </summary>
117 /// <param name="name">The name.</param>
118 /// <param name="guid">The GUID.</param>
119 /// <param name="fileExtension">The file extension.</param>
120 /// <param name="xml">The XML.</param>
121 /// <param name="importProject">The import project.</param>
122 public ToolInfo(string name, string guid, string fileExtension, string xml, string importProject)
123 {
124 this.name = name;
125 this.guid = guid;
126 this.fileExtension = fileExtension;
127 this.xmlTag = xml;
128 this.importProject = importProject;
129 }
130
131 /// <summary>
132 /// Initializes a new instance of the <see cref="ToolInfo"/> class.
133 /// </summary>
134 /// <param name="name">The name.</param>
135 /// <param name="guid">The GUID.</param>
136 /// <param name="fileExtension">The file extension.</param>
137 /// <param name="xml">The XML.</param>
138 public ToolInfo(string name, string guid, string fileExtension, string xml)
139 {
140 this.name = name;
141 this.guid = guid;
142 this.fileExtension = fileExtension;
143 this.xmlTag = xml;
144 this.importProject = "$(MSBuildBinPath)\\Microsoft." + xml + ".Targets";
145 }
146
147 /// <summary>
148 /// Equals operator
149 /// </summary>
150 /// <param name="obj">ToolInfo to compare</param>
151 /// <returns>true if toolInfos are equal</returns>
152 public override bool Equals(object obj)
153 {
154 if (obj == null)
155 {
156 throw new ArgumentNullException("obj");
157 }
158 if (obj.GetType() != typeof(ToolInfo))
159 return false;
160
161 ToolInfo c = (ToolInfo)obj;
162 return ((this.name == c.name) && (this.guid == c.guid) && (this.fileExtension == c.fileExtension) && (this.importProject == c.importProject));
163 }
164
165 /// <summary>
166 /// Equals operator
167 /// </summary>
168 /// <param name="c1">ToolInfo to compare</param>
169 /// <param name="c2">ToolInfo to compare</param>
170 /// <returns>True if toolInfos are equal</returns>
171 public static bool operator ==(ToolInfo c1, ToolInfo c2)
172 {
173 return ((c1.name == c2.name) && (c1.guid == c2.guid) && (c1.fileExtension == c2.fileExtension) && (c1.importProject == c2.importProject) && (c1.xmlTag == c2.xmlTag));
174 }
175
176 /// <summary>
177 /// Not equals operator
178 /// </summary>
179 /// <param name="c1">ToolInfo to compare</param>
180 /// <param name="c2">ToolInfo to compare</param>
181 /// <returns>True if toolInfos are not equal</returns>
182 public static bool operator !=(ToolInfo c1, ToolInfo c2)
183 {
184 return !(c1 == c2);
185 }
186
187 /// <summary>
188 /// Hash Code
189 /// </summary>
190 /// <returns>Hash code</returns>
191 public override int GetHashCode()
192 {
193 return name.GetHashCode() ^ guid.GetHashCode() ^ this.fileExtension.GetHashCode() ^ this.importProject.GetHashCode() ^ this.xmlTag.GetHashCode();
194
195 }
196 }
197}
diff --git a/Prebuild/src/Core/Targets/VS2002Target.cs b/Prebuild/src/Core/Targets/VS2002Target.cs
new file mode 100644
index 0000000..2292624
--- /dev/null
+++ b/Prebuild/src/Core/Targets/VS2002Target.cs
@@ -0,0 +1,87 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27
28using Prebuild.Core.Attributes;
29
30namespace Prebuild.Core.Targets
31{
32 /// <summary>
33 ///
34 /// </summary>
35 [Target("vs2002")]
36 public class VS2002Target : VS2003Target
37 {
38 #region Private Methods
39
40 private void SetVS2002()
41 {
42 this.SolutionVersion = "7.00";
43 this.ProductVersion = "7.0.9254";
44 this.SchemaVersion = "1.0";
45 this.VersionName = "2002";
46 this.Version = VSVersion.VS70;
47 }
48
49 #endregion
50
51 #region Public Methods
52
53 /// <summary>
54 /// Writes the specified kern.
55 /// </summary>
56 /// <param name="kern">The kern.</param>
57 public override void Write(Kernel kern)
58 {
59 SetVS2002();
60 base.Write(kern);
61 }
62
63 /// <summary>
64 /// Cleans the specified kern.
65 /// </summary>
66 /// <param name="kern">The kern.</param>
67 public override void Clean(Kernel kern)
68 {
69 SetVS2002();
70 base.Clean(kern);
71 }
72
73 /// <summary>
74 /// Gets the name.
75 /// </summary>
76 /// <value>The name.</value>
77 public override string Name
78 {
79 get
80 {
81 return "vs2002";
82 }
83 }
84
85 #endregion
86 }
87}
diff --git a/Prebuild/src/Core/Targets/VS2003Target.cs b/Prebuild/src/Core/Targets/VS2003Target.cs
new file mode 100644
index 0000000..10e2dc4
--- /dev/null
+++ b/Prebuild/src/Core/Targets/VS2003Target.cs
@@ -0,0 +1,593 @@
1#region BSD License
2/*
3Copyright (c) 2004-2005 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.Collections.Generic;
28using System.IO;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using Prebuild.Core.Nodes;
33using Prebuild.Core.Utilities;
34
35namespace Prebuild.Core.Targets
36{
37 [Target("vs2003")]
38 public class VS2003Target : ITarget
39 {
40
41 #region Fields
42
43 string solutionVersion = "8.00";
44 string productVersion = "7.10.3077";
45 string schemaVersion = "2.0";
46 string versionName = "2003";
47 VSVersion version = VSVersion.VS71;
48
49 readonly Dictionary<string, ToolInfo> m_Tools = new Dictionary<string, ToolInfo>();
50 Kernel m_Kernel;
51
52 /// <summary>
53 /// Gets or sets the solution version.
54 /// </summary>
55 /// <value>The solution version.</value>
56 protected string SolutionVersion
57 {
58 get
59 {
60 return solutionVersion;
61 }
62 set
63 {
64 solutionVersion = value;
65 }
66 }
67 /// <summary>
68 /// Gets or sets the product version.
69 /// </summary>
70 /// <value>The product version.</value>
71 protected string ProductVersion
72 {
73 get
74 {
75 return productVersion;
76 }
77 set
78 {
79 productVersion = value;
80 }
81 }
82 /// <summary>
83 /// Gets or sets the schema version.
84 /// </summary>
85 /// <value>The schema version.</value>
86 protected string SchemaVersion
87 {
88 get
89 {
90 return schemaVersion;
91 }
92 set
93 {
94 schemaVersion = value;
95 }
96 }
97 /// <summary>
98 /// Gets or sets the name of the version.
99 /// </summary>
100 /// <value>The name of the version.</value>
101 protected string VersionName
102 {
103 get
104 {
105 return versionName;
106 }
107 set
108 {
109 versionName = value;
110 }
111 }
112 /// <summary>
113 /// Gets or sets the version.
114 /// </summary>
115 /// <value>The version.</value>
116 protected VSVersion Version
117 {
118 get
119 {
120 return version;
121 }
122 set
123 {
124 version = value;
125 }
126 }
127
128 #endregion
129
130 #region Constructors
131
132 /// <summary>
133 /// Initializes a new instance of the <see cref="VS2003Target"/> class.
134 /// </summary>
135 public VS2003Target()
136 {
137 m_Tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP");
138 m_Tools["VB.NET"] = new ToolInfo("VB.NET", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic");
139 }
140
141 #endregion
142
143 #region Private Methods
144
145 private string MakeRefPath(ProjectNode project)
146 {
147 string ret = "";
148 foreach(ReferencePathNode node in project.ReferencePaths)
149 {
150 try
151 {
152 string fullPath = Helper.ResolvePath(node.Path);
153 if(ret.Length < 1)
154 {
155 ret = fullPath;
156 }
157 else
158 {
159 ret += ";" + fullPath;
160 }
161 }
162 catch(ArgumentException)
163 {
164 m_Kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path);
165 }
166 }
167
168 return ret;
169 }
170
171 private void WriteProject(SolutionNode solution, ProjectNode project)
172 {
173 if(!m_Tools.ContainsKey(project.Language))
174 {
175 throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
176 }
177
178 ToolInfo toolInfo = m_Tools[project.Language];
179 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
180 StreamWriter ps = new StreamWriter(projectFile);
181
182 m_Kernel.CurrentWorkingDirectory.Push();
183 Helper.SetCurrentDir(Path.GetDirectoryName(projectFile));
184
185 using(ps)
186 {
187 ps.WriteLine("<VisualStudioProject>");
188 ps.WriteLine(" <{0}", toolInfo.XmlTag);
189 ps.WriteLine("\t\t\t\tProjectType = \"Local\"");
190 ps.WriteLine("\t\t\t\tProductVersion = \"{0}\"", ProductVersion);
191 ps.WriteLine("\t\t\t\tSchemaVersion = \"{0}\"", SchemaVersion);
192 ps.WriteLine("\t\t\t\tProjectGuid = \"{{{0}}}\"", project.Guid.ToString().ToUpper());
193 ps.WriteLine("\t\t>");
194
195 ps.WriteLine("\t\t\t\t<Build>");
196 ps.WriteLine(" <Settings");
197 ps.WriteLine("\t\t\t\t ApplicationIcon = \"{0}\"",project.AppIcon);
198 ps.WriteLine("\t\t\t\t AssemblyKeyContainerName = \"\"");
199 ps.WriteLine("\t\t\t\t AssemblyName = \"{0}\"", project.AssemblyName);
200 ps.WriteLine("\t\t\t\t AssemblyOriginatorKeyFile = \"\"");
201 ps.WriteLine("\t\t\t\t DefaultClientScript = \"JScript\"");
202 ps.WriteLine("\t\t\t\t DefaultHTMLPageLayout = \"Grid\"");
203 ps.WriteLine("\t\t\t\t DefaultTargetSchema = \"IE50\"");
204 ps.WriteLine("\t\t\t\t DelaySign = \"false\"");
205
206 if(Version == VSVersion.VS70)
207 {
208 ps.WriteLine("\t\t\t\t NoStandardLibraries = \"false\"");
209 }
210
211 ps.WriteLine("\t\t\t\t OutputType = \"{0}\"", project.Type);
212
213 foreach(ConfigurationNode conf in project.Configurations)
214 {
215 if (conf.Options["PreBuildEvent"] != null && conf.Options["PreBuildEvent"].ToString().Length != 0)
216 {
217 ps.WriteLine("\t\t\t\t PreBuildEvent = \"{0}\"", Helper.NormalizePath(conf.Options["PreBuildEvent"].ToString()));
218 }
219 else
220 {
221 ps.WriteLine("\t\t\t\t PreBuildEvent = \"{0}\"", conf.Options["PreBuildEvent"]);
222 }
223 if (conf.Options["PostBuildEvent"] != null && conf.Options["PostBuildEvent"].ToString().Length != 0)
224 {
225 ps.WriteLine("\t\t\t\t PostBuildEvent = \"{0}\"", Helper.NormalizePath(conf.Options["PostBuildEvent"].ToString()));
226 }
227 else
228 {
229 ps.WriteLine("\t\t\t\t PostBuildEvent = \"{0}\"", conf.Options["PostBuildEvent"]);
230 }
231 if (conf.Options["RunPostBuildEvent"] == null)
232 {
233 ps.WriteLine("\t\t\t\t RunPostBuildEvent = \"{0}\"", "OnBuildSuccess");
234 }
235 else
236 {
237 ps.WriteLine("\t\t\t\t RunPostBuildEvent = \"{0}\"", conf.Options["RunPostBuildEvent"]);
238 }
239 break;
240 }
241
242 ps.WriteLine("\t\t\t\t RootNamespace = \"{0}\"", project.RootNamespace);
243 ps.WriteLine("\t\t\t\t StartupObject = \"{0}\"", project.StartupObject);
244 ps.WriteLine("\t\t >");
245
246 foreach(ConfigurationNode conf in project.Configurations)
247 {
248 ps.WriteLine("\t\t\t\t <Config");
249 ps.WriteLine("\t\t\t\t Name = \"{0}\"", conf.Name);
250 ps.WriteLine("\t\t\t\t AllowUnsafeBlocks = \"{0}\"", conf.Options["AllowUnsafe"].ToString().ToLower());
251 ps.WriteLine("\t\t\t\t BaseAddress = \"{0}\"", conf.Options["BaseAddress"]);
252 ps.WriteLine("\t\t\t\t CheckForOverflowUnderflow = \"{0}\"", conf.Options["CheckUnderflowOverflow"].ToString().ToLower());
253 ps.WriteLine("\t\t\t\t ConfigurationOverrideFile = \"\"");
254 ps.WriteLine("\t\t\t\t DefineConstants = \"{0}\"", conf.Options["CompilerDefines"]);
255 ps.WriteLine("\t\t\t\t DocumentationFile = \"{0}\"", GetXmlDocFile(project, conf));//default to the assembly name
256 ps.WriteLine("\t\t\t\t DebugSymbols = \"{0}\"", conf.Options["DebugInformation"].ToString().ToLower());
257 ps.WriteLine("\t\t\t\t FileAlignment = \"{0}\"", conf.Options["FileAlignment"]);
258 ps.WriteLine("\t\t\t\t IncrementalBuild = \"{0}\"", conf.Options["IncrementalBuild"].ToString().ToLower());
259
260 if(Version == VSVersion.VS71)
261 {
262 ps.WriteLine("\t\t\t\t NoStdLib = \"{0}\"", conf.Options["NoStdLib"].ToString().ToLower());
263 ps.WriteLine("\t\t\t\t NoWarn = \"{0}\"", conf.Options["SuppressWarnings"].ToString().ToLower());
264 }
265
266 ps.WriteLine("\t\t\t\t Optimize = \"{0}\"", conf.Options["OptimizeCode"].ToString().ToLower());
267 ps.WriteLine(" OutputPath = \"{0}\"",
268 Helper.EndPath(Helper.NormalizePath(conf.Options["OutputPath"].ToString())));
269 ps.WriteLine(" RegisterForComInterop = \"{0}\"", conf.Options["RegisterComInterop"].ToString().ToLower());
270 ps.WriteLine(" RemoveIntegerChecks = \"{0}\"", conf.Options["RemoveIntegerChecks"].ToString().ToLower());
271 ps.WriteLine(" TreatWarningsAsErrors = \"{0}\"", conf.Options["WarningsAsErrors"].ToString().ToLower());
272 ps.WriteLine(" WarningLevel = \"{0}\"", conf.Options["WarningLevel"]);
273 ps.WriteLine(" />");
274 }
275
276 ps.WriteLine(" </Settings>");
277
278 ps.WriteLine(" <References>");
279 foreach(ReferenceNode refr in project.References)
280 {
281 ps.WriteLine(" <Reference");
282 ps.WriteLine(" Name = \"{0}\"", refr.Name);
283 ps.WriteLine(" AssemblyName = \"{0}\"", refr.Name);
284
285 if(solution.ProjectsTable.ContainsKey(refr.Name))
286 {
287 ProjectNode refProject = solution.ProjectsTable[refr.Name];
288 ps.WriteLine(" Project = \"{{{0}}}\"", refProject.Guid.ToString().ToUpper());
289 ps.WriteLine(" Package = \"{0}\"", toolInfo.Guid.ToUpper());
290 }
291 else
292 {
293 if(refr.Path != null)
294 {
295 ps.WriteLine(" HintPath = \"{0}\"", Helper.MakeFilePath(refr.Path, refr.Name, "dll"));
296 }
297
298 }
299
300 if(refr.LocalCopySpecified)
301 {
302 ps.WriteLine(" Private = \"{0}\"",refr.LocalCopy);
303 }
304
305 ps.WriteLine(" />");
306 }
307 ps.WriteLine(" </References>");
308
309 ps.WriteLine(" </Build>");
310 ps.WriteLine(" <Files>");
311
312 ps.WriteLine(" <Include>");
313
314 foreach(string file in project.Files)
315 {
316 string fileName = file.Replace(".\\", "");
317 ps.WriteLine(" <File");
318 ps.WriteLine(" RelPath = \"{0}\"", fileName);
319 ps.WriteLine(" SubType = \"{0}\"", project.Files.GetSubType(file));
320 ps.WriteLine(" BuildAction = \"{0}\"", project.Files.GetBuildAction(file));
321 ps.WriteLine(" />");
322
323 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
324 {
325 ps.WriteLine(" <File");
326 ps.WriteLine(" RelPath = \"{0}\"", fileName.Substring(0, fileName.LastIndexOf('.')) + ".resx");
327 int slash = fileName.LastIndexOf('\\');
328 if (slash == -1)
329 {
330 ps.WriteLine(" DependentUpon = \"{0}\"", fileName);
331 }
332 else
333 {
334 ps.WriteLine(" DependentUpon = \"{0}\"", fileName.Substring(slash + 1, fileName.Length - slash - 1));
335 }
336 ps.WriteLine(" BuildAction = \"{0}\"", "EmbeddedResource");
337 ps.WriteLine(" />");
338
339 }
340 }
341 ps.WriteLine(" </Include>");
342
343 ps.WriteLine(" </Files>");
344 ps.WriteLine(" </{0}>", toolInfo.XmlTag);
345 ps.WriteLine("</VisualStudioProject>");
346 }
347
348 ps = new StreamWriter(projectFile + ".user");
349 using(ps)
350 {
351 ps.WriteLine("<VisualStudioProject>");
352 ps.WriteLine(" <{0}>", toolInfo.XmlTag);
353 ps.WriteLine(" <Build>");
354
355 ps.WriteLine(" <Settings ReferencePath=\"{0}\">", MakeRefPath(project));
356 foreach(ConfigurationNode conf in project.Configurations)
357 {
358 ps.WriteLine(" <Config");
359 ps.WriteLine(" Name = \"{0}\"", conf.Name);
360 ps.WriteLine(" />");
361 }
362 ps.WriteLine(" </Settings>");
363
364 ps.WriteLine(" </Build>");
365 ps.WriteLine(" </{0}>", toolInfo.XmlTag);
366 ps.WriteLine("</VisualStudioProject>");
367 }
368
369 m_Kernel.CurrentWorkingDirectory.Pop();
370 }
371
372 /// <summary>
373 /// Gets the XML doc file.
374 /// </summary>
375 /// <param name="project">The project.</param>
376 /// <param name="conf">The conf.</param>
377 /// <returns></returns>
378 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
379 {
380 if( conf == null )
381 {
382 throw new ArgumentNullException("conf");
383 }
384 if( project == null )
385 {
386 throw new ArgumentNullException("project");
387 }
388 // if(!(bool)conf.Options["GenerateXmlDocFile"]) //default to none, if the generate option is false
389 // {
390 // return string.Empty;
391 // }
392
393 //default to "AssemblyName.xml"
394 //string defaultValue = Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
395 //return (string)conf.Options["XmlDocFile", defaultValue];
396
397 //default to no XmlDocFile file
398 return (string)conf.Options["XmlDocFile", ""];
399 }
400
401 private void WriteSolution(SolutionNode solution)
402 {
403 m_Kernel.Log.Write("Creating Visual Studio {0} solution and project files", VersionName);
404
405 foreach(ProjectNode project in solution.Projects)
406 {
407 if(m_Kernel.AllowProject(project.FilterGroups))
408 {
409 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
410 WriteProject(solution, project);
411 }
412 }
413
414 m_Kernel.Log.Write("");
415 string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
416 StreamWriter ss = new StreamWriter(solutionFile);
417
418 m_Kernel.CurrentWorkingDirectory.Push();
419 Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile));
420
421 using(ss)
422 {
423 ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", SolutionVersion);
424 foreach(ProjectNode project in solution.Projects)
425 {
426 if(!m_Tools.ContainsKey(project.Language))
427 {
428 throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
429 }
430
431 ToolInfo toolInfo = m_Tools[project.Language];
432
433 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
434 ss.WriteLine("Project(\"{0}\") = \"{1}\", \"{2}\", \"{{{3}}}\"",
435 toolInfo.Guid, project.Name, Helper.MakeFilePath(path, project.Name,
436 toolInfo.FileExtension), project.Guid.ToString().ToUpper());
437
438 ss.WriteLine("\tProjectSection(ProjectDependencies) = postProject");
439 ss.WriteLine("\tEndProjectSection");
440
441 ss.WriteLine("EndProject");
442 }
443
444 ss.WriteLine("Global");
445
446 ss.WriteLine("\tGlobalSection(SolutionConfiguration) = preSolution");
447 foreach(ConfigurationNode conf in solution.Configurations)
448 {
449 ss.WriteLine("\t\t{0} = {0}", conf.Name);
450 }
451 ss.WriteLine("\tEndGlobalSection");
452
453 ss.WriteLine("\tGlobalSection(ProjectDependencies) = postSolution");
454 foreach(ProjectNode project in solution.Projects)
455 {
456 for(int i = 0; i < project.References.Count; i++)
457 {
458 ReferenceNode refr = project.References[i];
459 if(solution.ProjectsTable.ContainsKey(refr.Name))
460 {
461 ProjectNode refProject = solution.ProjectsTable[refr.Name];
462 ss.WriteLine("\t\t({{{0}}}).{1} = ({{{2}}})",
463 project.Guid.ToString().ToUpper()
464 , i,
465 refProject.Guid.ToString().ToUpper()
466 );
467 }
468 }
469 }
470 ss.WriteLine("\tEndGlobalSection");
471
472 ss.WriteLine("\tGlobalSection(ProjectConfiguration) = postSolution");
473 foreach(ProjectNode project in solution.Projects)
474 {
475 foreach(ConfigurationNode conf in solution.Configurations)
476 {
477 ss.WriteLine("\t\t{{{0}}}.{1}.ActiveCfg = {1}|.NET",
478 project.Guid.ToString().ToUpper(),
479 conf.Name);
480
481 ss.WriteLine("\t\t{{{0}}}.{1}.Build.0 = {1}|.NET",
482 project.Guid.ToString().ToUpper(),
483 conf.Name);
484 }
485 }
486 ss.WriteLine("\tEndGlobalSection");
487
488 if(solution.Files != null)
489 {
490 ss.WriteLine("\tGlobalSection(SolutionItems) = postSolution");
491 foreach(string file in solution.Files)
492 {
493 ss.WriteLine("\t\t{0} = {0}", file);
494 }
495 ss.WriteLine("\tEndGlobalSection");
496 }
497
498 ss.WriteLine("\tGlobalSection(ExtensibilityGlobals) = postSolution");
499 ss.WriteLine("\tEndGlobalSection");
500 ss.WriteLine("\tGlobalSection(ExtensibilityAddIns) = postSolution");
501 ss.WriteLine("\tEndGlobalSection");
502
503 ss.WriteLine("EndGlobal");
504 }
505
506 m_Kernel.CurrentWorkingDirectory.Pop();
507 }
508
509 private void CleanProject(ProjectNode project)
510 {
511 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
512
513 ToolInfo toolInfo = m_Tools[project.Language];
514 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
515 string userFile = projectFile + ".user";
516
517 Helper.DeleteIfExists(projectFile);
518 Helper.DeleteIfExists(userFile);
519 }
520
521 private void CleanSolution(SolutionNode solution)
522 {
523 m_Kernel.Log.Write("Cleaning Visual Studio {0} solution and project files", VersionName, solution.Name);
524
525 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
526 string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo");
527
528 Helper.DeleteIfExists(slnFile);
529 Helper.DeleteIfExists(suoFile);
530
531 foreach(ProjectNode project in solution.Projects)
532 {
533 CleanProject(project);
534 }
535
536 m_Kernel.Log.Write("");
537 }
538
539 #endregion
540
541 #region ITarget Members
542
543 /// <summary>
544 /// Writes the specified kern.
545 /// </summary>
546 /// <param name="kern">The kern.</param>
547 public virtual void Write(Kernel kern)
548 {
549 if( kern == null )
550 {
551 throw new ArgumentNullException("kern");
552 }
553 m_Kernel = kern;
554 foreach(SolutionNode sol in m_Kernel.Solutions)
555 {
556 WriteSolution(sol);
557 }
558 m_Kernel = null;
559 }
560
561 /// <summary>
562 /// Cleans the specified kern.
563 /// </summary>
564 /// <param name="kern">The kern.</param>
565 public virtual void Clean(Kernel kern)
566 {
567 if( kern == null )
568 {
569 throw new ArgumentNullException("kern");
570 }
571 m_Kernel = kern;
572 foreach(SolutionNode sol in m_Kernel.Solutions)
573 {
574 CleanSolution(sol);
575 }
576 m_Kernel = null;
577 }
578
579 /// <summary>
580 /// Gets the name.
581 /// </summary>
582 /// <value>The name.</value>
583 public virtual string Name
584 {
585 get
586 {
587 return "vs2003";
588 }
589 }
590
591 #endregion
592 }
593}
diff --git a/Prebuild/src/Core/Targets/VS2005Target.cs b/Prebuild/src/Core/Targets/VS2005Target.cs
new file mode 100644
index 0000000..9c70e26
--- /dev/null
+++ b/Prebuild/src/Core/Targets/VS2005Target.cs
@@ -0,0 +1,147 @@
1#region BSD License
2/*
3Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Text;
29
30using Prebuild.Core.Attributes;
31using Prebuild.Core.Interfaces;
32using Prebuild.Core.Nodes;
33using Prebuild.Core.Utilities;
34
35namespace Prebuild.Core.Targets
36{
37 /// <summary>
38 ///
39 /// </summary>
40 [Target("vs2005")]
41 public class VS2005Target : VSGenericTarget
42 {
43 #region Inner Classes
44
45 #endregion
46
47 #region Fields
48
49 string solutionVersion = "9.00";
50 string productVersion = "8.0.50727";
51 string schemaVersion = "2.0";
52 string versionName = "Visual C# 2005";
53 string name = "vs2005";
54
55 VSVersion version = VSVersion.VS80;
56
57 public override string SolutionTag
58 {
59 get { return "# Visual Studio 2005"; }
60 }
61
62 protected override string GetToolsVersionXml(FrameworkVersion frameworkVersion)
63 {
64 return string.Empty;
65 }
66 /// <summary>
67 /// Gets or sets the solution version.
68 /// </summary>
69 /// <value>The solution version.</value>
70 public override string SolutionVersion
71 {
72 get
73 {
74 return solutionVersion;
75 }
76 }
77 /// <summary>
78 /// Gets or sets the product version.
79 /// </summary>
80 /// <value>The product version.</value>
81 public override string ProductVersion
82 {
83 get
84 {
85 return productVersion;
86 }
87 }
88 /// <summary>
89 /// Gets or sets the schema version.
90 /// </summary>
91 /// <value>The schema version.</value>
92 public override string SchemaVersion
93 {
94 get
95 {
96 return schemaVersion;
97 }
98 }
99 /// <summary>
100 /// Gets or sets the name of the version.
101 /// </summary>
102 /// <value>The name of the version.</value>
103 public override string VersionName
104 {
105 get
106 {
107 return versionName;
108 }
109 }
110 /// <summary>
111 /// Gets or sets the version.
112 /// </summary>
113 /// <value>The version.</value>
114 public override VSVersion Version
115 {
116 get
117 {
118 return version;
119 }
120 }
121 /// <summary>
122 /// Gets the name.
123 /// </summary>
124 /// <value>The name.</value>
125 public override string Name
126 {
127 get
128 {
129 return name;
130 }
131 }
132
133 #endregion
134
135 #region Constructors
136
137 /// <summary>
138 /// Initializes a new instance of the <see cref="VS2005Target"/> class.
139 /// </summary>
140 public VS2005Target()
141 : base()
142 {
143 }
144
145 #endregion
146 }
147}
diff --git a/Prebuild/src/Core/Targets/VS2008Target.cs b/Prebuild/src/Core/Targets/VS2008Target.cs
new file mode 100644
index 0000000..fee4f7f
--- /dev/null
+++ b/Prebuild/src/Core/Targets/VS2008Target.cs
@@ -0,0 +1,127 @@
1using System;
2using System.IO;
3using System.Text;
4
5using Prebuild.Core.Attributes;
6using Prebuild.Core.Interfaces;
7using Prebuild.Core.Nodes;
8using Prebuild.Core.Utilities;
9using System.CodeDom.Compiler;
10
11namespace Prebuild.Core.Targets
12{
13
14 /// <summary>
15 ///
16 /// </summary>
17 [Target("vs2008")]
18 public class VS2008Target : VSGenericTarget
19 {
20 #region Fields
21 string solutionVersion = "10.00";
22 string productVersion = "9.0.21022";
23 string schemaVersion = "2.0";
24 string versionName = "Visual Studio 2008";
25 string name = "vs2008";
26 VSVersion version = VSVersion.VS90;
27
28 /// <summary>
29 /// Gets or sets the solution version.
30 /// </summary>
31 /// <value>The solution version.</value>
32 public override string SolutionVersion
33 {
34 get
35 {
36 return solutionVersion;
37 }
38 }
39 /// <summary>
40 /// Gets or sets the product version.
41 /// </summary>
42 /// <value>The product version.</value>
43 public override string ProductVersion
44 {
45 get
46 {
47 return productVersion;
48 }
49 }
50 /// <summary>
51 /// Gets or sets the schema version.
52 /// </summary>
53 /// <value>The schema version.</value>
54 public override string SchemaVersion
55 {
56 get
57 {
58 return schemaVersion;
59 }
60 }
61 /// <summary>
62 /// Gets or sets the name of the version.
63 /// </summary>
64 /// <value>The name of the version.</value>
65 public override string VersionName
66 {
67 get
68 {
69 return versionName;
70 }
71 }
72 /// <summary>
73 /// Gets or sets the version.
74 /// </summary>
75 /// <value>The version.</value>
76 public override VSVersion Version
77 {
78 get
79 {
80 return version;
81 }
82 }
83 /// <summary>
84 /// Gets the name.
85 /// </summary>
86 /// <value>The name.</value>
87 public override string Name
88 {
89 get
90 {
91 return name;
92 }
93 }
94
95 protected override string GetToolsVersionXml(FrameworkVersion frameworkVersion)
96 {
97 switch (frameworkVersion)
98 {
99 case FrameworkVersion.v3_5:
100 return "ToolsVersion=\"3.5\"";
101 case FrameworkVersion.v3_0:
102 return "ToolsVersion=\"3.0\"";
103 default:
104 return "ToolsVersion=\"2.0\"";
105 }
106 }
107
108 public override string SolutionTag
109 {
110 get { return "# Visual Studio 2008"; }
111 }
112
113 #endregion
114
115 #region Constructors
116
117 /// <summary>
118 /// Initializes a new instance of the <see cref="VS2005Target"/> class.
119 /// </summary>
120 public VS2008Target()
121 : base()
122 {
123 }
124
125 #endregion
126 }
127}
diff --git a/Prebuild/src/Core/Targets/VS2010Target.cs b/Prebuild/src/Core/Targets/VS2010Target.cs
new file mode 100644
index 0000000..ea9f736
--- /dev/null
+++ b/Prebuild/src/Core/Targets/VS2010Target.cs
@@ -0,0 +1,138 @@
1using System;
2using System.IO;
3using System.Text;
4
5using Prebuild.Core.Attributes;
6using Prebuild.Core.Interfaces;
7using Prebuild.Core.Nodes;
8using Prebuild.Core.Utilities;
9using System.CodeDom.Compiler;
10
11namespace Prebuild.Core.Targets
12{
13
14 /// <summary>
15 ///
16 /// </summary>
17 [Target("vs2010")]
18 public class VS2010Target : VSGenericTarget
19 {
20 #region Fields
21
22 string solutionVersion = "11.00";
23 string productVersion = "9.0.30729";
24 string schemaVersion = "2.0";
25 string versionName = "Visual Studio 2010";
26 string name = "vs2010";
27 VSVersion version = VSVersion.VS10;
28
29 #endregion
30
31 #region Properties
32
33 /// <summary>
34 /// Gets or sets the solution version.
35 /// </summary>
36 /// <value>The solution version.</value>
37 public override string SolutionVersion
38 {
39 get
40 {
41 return solutionVersion;
42 }
43 }
44
45 /// <summary>
46 /// Gets or sets the product version.
47 /// </summary>
48 /// <value>The product version.</value>
49 public override string ProductVersion
50 {
51 get
52 {
53 return productVersion;
54 }
55 }
56
57 /// <summary>
58 /// Gets or sets the schema version.
59 /// </summary>
60 /// <value>The schema version.</value>
61 public override string SchemaVersion
62 {
63 get
64 {
65 return schemaVersion;
66 }
67 }
68
69 /// <summary>
70 /// Gets or sets the name of the version.
71 /// </summary>
72 /// <value>The name of the version.</value>
73 public override string VersionName
74 {
75 get
76 {
77 return versionName;
78 }
79 }
80
81 /// <summary>
82 /// Gets or sets the version.
83 /// </summary>
84 /// <value>The version.</value>
85 public override VSVersion Version
86 {
87 get
88 {
89 return version;
90 }
91 }
92
93 /// <summary>
94 /// Gets the name.
95 /// </summary>
96 /// <value>The name.</value>
97 public override string Name
98 {
99 get
100 {
101 return name;
102 }
103 }
104
105 protected override string GetToolsVersionXml(FrameworkVersion frameworkVersion)
106 {
107 switch (frameworkVersion)
108 {
109 case FrameworkVersion.v4_0:
110 case FrameworkVersion.v3_5:
111 return "ToolsVersion=\"4.0\"";
112 case FrameworkVersion.v3_0:
113 return "ToolsVersion=\"3.0\"";
114 default:
115 return "ToolsVersion=\"2.0\"";
116 }
117 }
118
119 public override string SolutionTag
120 {
121 get { return "# Visual Studio 2010"; }
122 }
123
124 #endregion
125
126 #region Constructors
127
128 /// <summary>
129 /// Initializes a new instance of the <see cref="VS2005Target"/> class.
130 /// </summary>
131 public VS2010Target()
132 : base()
133 {
134 }
135
136 #endregion
137 }
138}
diff --git a/Prebuild/src/Core/Targets/VSGenericTarget.cs b/Prebuild/src/Core/Targets/VSGenericTarget.cs
new file mode 100644
index 0000000..6969dd7
--- /dev/null
+++ b/Prebuild/src/Core/Targets/VSGenericTarget.cs
@@ -0,0 +1,922 @@
1#region BSD License
2/*
3Copyright (c) 2008 Matthew Holmes (matthew@wildfiregames.com), John Anderson (sontek@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13 * The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24#endregion
25
26using System;
27using System.Collections.Generic;
28using System.IO;
29using Prebuild.Core.Interfaces;
30using Prebuild.Core.Nodes;
31using Prebuild.Core.Utilities;
32using System.CodeDom.Compiler;
33
34namespace Prebuild.Core.Targets
35{
36
37 /// <summary>
38 ///
39 /// </summary>
40 public abstract class VSGenericTarget : ITarget
41 {
42 #region Fields
43
44 readonly Dictionary<string, ToolInfo> tools = new Dictionary<string, ToolInfo>();
45 Kernel kernel;
46 #endregion
47
48 #region Properties
49 /// <summary>
50 /// Gets or sets the solution version.
51 /// </summary>
52 /// <value>The solution version.</value>
53 public abstract string SolutionVersion { get; }
54 /// <summary>
55 /// Gets or sets the product version.
56 /// </summary>
57 /// <value>The product version.</value>
58 public abstract string ProductVersion { get; }
59 /// <summary>
60 /// Gets or sets the schema version.
61 /// </summary>
62 /// <value>The schema version.</value>
63 public abstract string SchemaVersion { get; }
64 /// <summary>
65 /// Gets or sets the name of the version.
66 /// </summary>
67 /// <value>The name of the version.</value>
68 public abstract string VersionName { get; }
69 /// <summary>
70 /// Gets or sets the version.
71 /// </summary>
72 /// <value>The version.</value>
73 public abstract VSVersion Version { get; }
74 /// <summary>
75 /// Gets the name.
76 /// </summary>
77 /// <value>The name.</value>
78 public abstract string Name { get; }
79
80 protected abstract string GetToolsVersionXml(FrameworkVersion version);
81 public abstract string SolutionTag { get; }
82
83 #endregion
84
85 #region Constructors
86
87 /// <summary>
88 /// Initializes a new instance of the <see cref="VSGenericTarget"/> class.
89 /// </summary>
90 protected VSGenericTarget()
91 {
92 tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP", "$(MSBuildBinPath)\\Microsoft.CSHARP.Targets");
93 tools["Database"] = new ToolInfo("Database", "{4F174C21-8C12-11D0-8340-0000F80270F8}", "dbp", "UNKNOWN");
94 tools["Boo"] = new ToolInfo("Boo", "{45CEA7DC-C2ED-48A6-ACE0-E16144C02365}", "booproj", "Boo", "$(BooBinPath)\\Boo.Microsoft.Build.targets");
95 tools["VisualBasic"] = new ToolInfo("VisualBasic", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic", "$(MSBuildBinPath)\\Microsoft.VisualBasic.Targets");
96 tools["Folder"] = new ToolInfo("Folder", "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", null, null);
97 }
98
99 #endregion
100
101 #region Private Methods
102
103 private string MakeRefPath(ProjectNode project)
104 {
105 string ret = "";
106 foreach (ReferencePathNode node in project.ReferencePaths)
107 {
108 try
109 {
110 string fullPath = Helper.ResolvePath(node.Path);
111 if (ret.Length < 1)
112 {
113 ret = fullPath;
114 }
115 else
116 {
117 ret += ";" + fullPath;
118 }
119 }
120 catch (ArgumentException)
121 {
122 kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path);
123 }
124 }
125
126 return ret;
127 }
128
129 private static ProjectNode FindProjectInSolution(string name, SolutionNode solution)
130 {
131 SolutionNode node = solution;
132
133 while (node.Parent is SolutionNode)
134 node = node.Parent as SolutionNode;
135
136 return FindProjectInSolutionRecursively(name, node);
137 }
138
139 private static ProjectNode FindProjectInSolutionRecursively(string name, SolutionNode solution)
140 {
141 if (solution.ProjectsTable.ContainsKey(name))
142 return solution.ProjectsTable[name];
143
144 foreach (SolutionNode child in solution.Solutions)
145 {
146 ProjectNode node = FindProjectInSolutionRecursively(name, child);
147 if (node != null)
148 return node;
149 }
150
151 return null;
152 }
153
154 private void WriteProject(SolutionNode solution, ProjectNode project)
155 {
156 if (!tools.ContainsKey(project.Language))
157 {
158 throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
159 }
160
161 ToolInfo toolInfo = tools[project.Language];
162 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
163 StreamWriter ps = new StreamWriter(projectFile);
164
165 kernel.CurrentWorkingDirectory.Push();
166 Helper.SetCurrentDir(Path.GetDirectoryName(projectFile));
167
168 #region Project File
169 using (ps)
170 {
171 ps.WriteLine("<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" {0}>", GetToolsVersionXml(project.FrameworkVersion));
172 ps.WriteLine(" <PropertyGroup>");
173 ps.WriteLine(" <ProjectType>Local</ProjectType>");
174 ps.WriteLine(" <ProductVersion>{0}</ProductVersion>", ProductVersion);
175 ps.WriteLine(" <SchemaVersion>{0}</SchemaVersion>", SchemaVersion);
176 ps.WriteLine(" <ProjectGuid>{{{0}}}</ProjectGuid>", project.Guid.ToString().ToUpper());
177
178 // Visual Studio has a hard coded guid for the project type
179 if (project.Type == ProjectType.Web)
180 ps.WriteLine(" <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>");
181 ps.WriteLine(" <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>");
182 ps.WriteLine(" <ApplicationIcon>{0}</ApplicationIcon>", project.AppIcon);
183 ps.WriteLine(" <AssemblyKeyContainerName>");
184 ps.WriteLine(" </AssemblyKeyContainerName>");
185 ps.WriteLine(" <AssemblyName>{0}</AssemblyName>", project.AssemblyName);
186 foreach (ConfigurationNode conf in project.Configurations)
187 {
188 if (conf.Options.KeyFile != "")
189 {
190 ps.WriteLine(" <AssemblyOriginatorKeyFile>{0}</AssemblyOriginatorKeyFile>", conf.Options.KeyFile);
191 ps.WriteLine(" <SignAssembly>true</SignAssembly>");
192 break;
193 }
194 }
195 ps.WriteLine(" <DefaultClientScript>JScript</DefaultClientScript>");
196 ps.WriteLine(" <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>");
197 ps.WriteLine(" <DefaultTargetSchema>IE50</DefaultTargetSchema>");
198 ps.WriteLine(" <DelaySign>false</DelaySign>");
199 ps.WriteLine(" <TargetFrameworkVersion>{0}</TargetFrameworkVersion>", project.FrameworkVersion.ToString().Replace("_", "."));
200
201 ps.WriteLine(" <OutputType>{0}</OutputType>", project.Type == ProjectType.Web ? ProjectType.Library.ToString() : project.Type.ToString());
202 ps.WriteLine(" <AppDesignerFolder>{0}</AppDesignerFolder>", project.DesignerFolder);
203 ps.WriteLine(" <RootNamespace>{0}</RootNamespace>", project.RootNamespace);
204 ps.WriteLine(" <StartupObject>{0}</StartupObject>", project.StartupObject);
205 if (string.IsNullOrEmpty(project.DebugStartParameters))
206 {
207 ps.WriteLine(" <StartArguments>{0}</StartArguments>", project.DebugStartParameters);
208 }
209 ps.WriteLine(" <FileUpgradeFlags>");
210 ps.WriteLine(" </FileUpgradeFlags>");
211
212 ps.WriteLine(" </PropertyGroup>");
213
214 foreach (ConfigurationNode conf in project.Configurations)
215 {
216 ps.Write(" <PropertyGroup ");
217 ps.WriteLine("Condition=\" '$(Configuration)|$(Platform)' == '{0}|{1}' \">", conf.Name, conf.Platform);
218 ps.WriteLine(" <AllowUnsafeBlocks>{0}</AllowUnsafeBlocks>", conf.Options["AllowUnsafe"]);
219 ps.WriteLine(" <BaseAddress>{0}</BaseAddress>", conf.Options["BaseAddress"]);
220 ps.WriteLine(" <CheckForOverflowUnderflow>{0}</CheckForOverflowUnderflow>", conf.Options["CheckUnderflowOverflow"]);
221 ps.WriteLine(" <ConfigurationOverrideFile>");
222 ps.WriteLine(" </ConfigurationOverrideFile>");
223 ps.WriteLine(" <DefineConstants>{0}</DefineConstants>", conf.Options["CompilerDefines"]);
224 ps.WriteLine(" <DocumentationFile>{0}</DocumentationFile>", Helper.NormalizePath(conf.Options["XmlDocFile"].ToString()));
225 ps.WriteLine(" <DebugSymbols>{0}</DebugSymbols>", conf.Options["DebugInformation"]);
226 ps.WriteLine(" <FileAlignment>{0}</FileAlignment>", conf.Options["FileAlignment"]);
227 ps.WriteLine(" <Optimize>{0}</Optimize>", conf.Options["OptimizeCode"]);
228 if (project.Type != ProjectType.Web)
229 ps.WriteLine(" <OutputPath>{0}</OutputPath>",
230 Helper.EndPath(Helper.NormalizePath(conf.Options["OutputPath"].ToString())));
231 else
232 ps.WriteLine(" <OutputPath>{0}</OutputPath>",
233 Helper.EndPath(Helper.NormalizePath("bin\\")));
234
235 ps.WriteLine(" <RegisterForComInterop>{0}</RegisterForComInterop>", conf.Options["RegisterComInterop"]);
236 ps.WriteLine(" <RemoveIntegerChecks>{0}</RemoveIntegerChecks>", conf.Options["RemoveIntegerChecks"]);
237 ps.WriteLine(" <TreatWarningsAsErrors>{0}</TreatWarningsAsErrors>", conf.Options["WarningsAsErrors"]);
238 ps.WriteLine(" <WarningLevel>{0}</WarningLevel>", conf.Options["WarningLevel"]);
239 ps.WriteLine(" <NoStdLib>{0}</NoStdLib>", conf.Options["NoStdLib"]);
240 ps.WriteLine(" <NoWarn>{0}</NoWarn>", conf.Options["SuppressWarnings"]);
241 ps.WriteLine(" <PlatformTarget>{0}</PlatformTarget>", conf.Platform);
242 ps.WriteLine(" </PropertyGroup>");
243 }
244
245 //ps.WriteLine(" </Settings>");
246
247 Dictionary<ReferenceNode, ProjectNode> projectReferences = new Dictionary<ReferenceNode, ProjectNode>();
248 List<ReferenceNode> otherReferences = new List<ReferenceNode>();
249
250 foreach (ReferenceNode refr in project.References)
251 {
252 ProjectNode projectNode = FindProjectInSolution(refr.Name, solution);
253
254 if (projectNode == null)
255 otherReferences.Add(refr);
256 else
257 projectReferences.Add(refr, projectNode);
258 }
259 // Assembly References
260 ps.WriteLine(" <ItemGroup>");
261
262 foreach (ReferenceNode refr in otherReferences)
263 {
264 ps.Write(" <Reference");
265 ps.Write(" Include=\"");
266 ps.Write(refr.Name);
267 ps.WriteLine("\" >");
268 ps.Write(" <Name>");
269 ps.Write(refr.Name);
270 ps.WriteLine("</Name>");
271
272 if(!String.IsNullOrEmpty(refr.Path))
273 {
274 // Use absolute path to assembly (for determining assembly type)
275 string absolutePath = Path.Combine(project.FullPath, refr.Path);
276 if(File.Exists(Helper.MakeFilePath(absolutePath, refr.Name, "exe"))) {
277 // Assembly is an executable (exe)
278 ps.WriteLine(" <HintPath>{0}</HintPath>", Helper.MakeFilePath(refr.Path, refr.Name, "exe"));
279 } else if(File.Exists(Helper.MakeFilePath(absolutePath, refr.Name, "dll"))) {
280 // Assembly is an library (dll)
281 ps.WriteLine(" <HintPath>{0}</HintPath>", Helper.MakeFilePath(refr.Path, refr.Name, "dll"));
282 } else {
283 string referencePath = Helper.MakeFilePath(refr.Path, refr.Name, "dll");
284 kernel.Log.Write(LogType.Warning, "Reference \"{0}\": The specified file doesn't exist.", referencePath);
285 ps.WriteLine(" <HintPath>{0}</HintPath>", Helper.MakeFilePath(refr.Path, refr.Name, "dll"));
286 }
287 }
288
289 ps.WriteLine(" <Private>{0}</Private>", refr.LocalCopy);
290 ps.WriteLine(" </Reference>");
291 }
292 ps.WriteLine(" </ItemGroup>");
293
294 //Project References
295 ps.WriteLine(" <ItemGroup>");
296 foreach (KeyValuePair<ReferenceNode, ProjectNode> pair in projectReferences)
297 {
298 ToolInfo tool = tools[pair.Value.Language];
299 if (tools == null)
300 throw new UnknownLanguageException();
301
302 string path =
303 Helper.MakePathRelativeTo(project.FullPath,
304 Helper.MakeFilePath(pair.Value.FullPath, pair.Value.Name, tool.FileExtension));
305 ps.WriteLine(" <ProjectReference Include=\"{0}\">", path);
306
307 // TODO: Allow reference to visual basic projects
308 ps.WriteLine(" <Name>{0}</Name>", pair.Value.Name);
309 ps.WriteLine(" <Project>{0}</Project>", pair.Value.Guid.ToString("B").ToUpper());
310 ps.WriteLine(" <Package>{0}</Package>", tool.Guid.ToUpper());
311
312 //This is the Copy Local flag in VS
313 ps.WriteLine(" <Private>{0}</Private>", pair.Key.LocalCopy);
314
315 ps.WriteLine(" </ProjectReference>");
316 }
317 ps.WriteLine(" </ItemGroup>");
318
319 // ps.WriteLine(" </Build>");
320 ps.WriteLine(" <ItemGroup>");
321
322 // ps.WriteLine(" <Include>");
323 List<string> list = new List<string>();
324
325 foreach (string path in project.Files)
326 {
327 string lower = path.ToLower();
328 if (lower.EndsWith(".resx"))
329 {
330 string codebehind = String.Format("{0}.Designer{1}", path.Substring(0, path.LastIndexOf('.')), toolInfo.LanguageExtension);
331 if (!list.Contains(codebehind))
332 list.Add(codebehind);
333 }
334
335 }
336
337 foreach (string filePath in project.Files)
338 {
339 // if (file == "Properties\\Bind.Designer.cs")
340 // {
341 // Console.WriteLine("Wait a minute!");
342 // Console.WriteLine(project.Files.GetSubType(file).ToString());
343 // }
344 SubType subType = project.Files.GetSubType(filePath);
345
346 // Visual Studio chokes on file names if forward slash is used as a path separator
347 // instead of backslash. So we must make sure that all file paths written to the
348 // project file use \ as a path separator.
349 string file = filePath.Replace(@"/", @"\");
350
351 if (subType != SubType.Code && subType != SubType.Settings && subType != SubType.Designer
352 && subType != SubType.CodeBehind)
353 {
354 ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
355 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(file));
356 ps.WriteLine(" <SubType>Designer</SubType>");
357 ps.WriteLine(" </EmbeddedResource>");
358 //
359 }
360
361 if (subType == SubType.Designer)
362 {
363 ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file);
364
365 string autogen_name = file.Substring(0, file.LastIndexOf('.')) + ".Designer.cs";
366 string dependent_name = filePath.Substring(0, file.LastIndexOf('.')) + ".cs";
367
368 // Check for a parent .cs file with the same name as this designer file
369 if (File.Exists(Helper.NormalizePath(dependent_name)))
370 {
371 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(dependent_name));
372 }
373 else
374 {
375 ps.WriteLine(" <Generator>ResXFileCodeGenerator</Generator>");
376 ps.WriteLine(" <LastGenOutput>{0}</LastGenOutput>", Path.GetFileName(autogen_name));
377 ps.WriteLine(" <SubType>" + subType + "</SubType>");
378 }
379
380 ps.WriteLine(" </EmbeddedResource>");
381 if (File.Exists(Helper.NormalizePath(autogen_name)))
382 {
383 ps.WriteLine(" <Compile Include=\"{0}\">", autogen_name);
384 //ps.WriteLine(" <DesignTime>True</DesignTime>");
385
386 // If a parent .cs file exists, link this autogen file to it. Otherwise link
387 // to the designer file
388 if (File.Exists(dependent_name))
389 {
390 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(dependent_name));
391 }
392 else
393 {
394 ps.WriteLine(" <AutoGen>True</AutoGen>");
395 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(filePath));
396 }
397
398 ps.WriteLine(" </Compile>");
399 }
400 list.Add(autogen_name);
401 }
402 if (subType == SubType.Settings)
403 {
404 ps.Write(" <{0} ", project.Files.GetBuildAction(filePath));
405 ps.WriteLine("Include=\"{0}\">", file);
406 string fileName = Path.GetFileName(filePath);
407 if (project.Files.GetBuildAction(filePath) == BuildAction.None)
408 {
409 ps.WriteLine(" <Generator>SettingsSingleFileGenerator</Generator>");
410 ps.WriteLine(" <LastGenOutput>{0}</LastGenOutput>", fileName.Substring(0, fileName.LastIndexOf('.')) + ".Designer.cs");
411 }
412 else
413 {
414 ps.WriteLine(" <SubType>Code</SubType>");
415 ps.WriteLine(" <AutoGen>True</AutoGen>");
416 ps.WriteLine(" <DesignTimeSharedInput>True</DesignTimeSharedInput>");
417 string fileNameShort = fileName.Substring(0, fileName.LastIndexOf('.'));
418 string fileNameShorter = fileNameShort.Substring(0, fileNameShort.LastIndexOf('.'));
419 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(fileNameShorter + ".settings"));
420 }
421 ps.WriteLine(" </{0}>", project.Files.GetBuildAction(filePath));
422 }
423 else if (subType != SubType.Designer)
424 {
425 string path = Helper.NormalizePath(file);
426 string path_lower = path.ToLower();
427
428 if (!list.Contains(filePath))
429 {
430 ps.Write(" <{0} ", project.Files.GetBuildAction(filePath));
431
432 int startPos = 0;
433 if (project.Files.GetPreservePath(filePath))
434 {
435 while ((@"./\").IndexOf(file.Substring(startPos, 1)) != -1)
436 startPos++;
437
438 }
439 else
440 {
441 startPos = file.LastIndexOf(Path.GetFileName(path));
442 }
443
444 // be sure to write out the path with backslashes so VS recognizes
445 // the file properly.
446 ps.WriteLine("Include=\"{0}\">", file);
447
448 int last_period_index = file.LastIndexOf('.');
449 string short_file_name = file.Substring(0, last_period_index);
450 string extension = Path.GetExtension(path);
451 // make this upper case, so that when File.Exists tests for the
452 // existence of a designer file on a case-sensitive platform,
453 // it is correctly identified.
454 string designer_format = string.Format(".Designer{0}", extension);
455
456 if (path_lower.EndsWith(designer_format.ToLowerInvariant()))
457 {
458 int designer_index = path.IndexOf(designer_format);
459 string file_name = path.Substring(0, designer_index);
460
461 // There are two corrections to the next lines:
462 // 1. Fix the connection between a designer file and a form
463 // or usercontrol that don't have an associated resx file.
464 // 2. Connect settings files to associated designer files.
465 if (File.Exists(file_name + extension))
466 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(file_name + extension));
467 else if (File.Exists(file_name + ".resx"))
468 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(file_name + ".resx"));
469 else if (File.Exists(file_name + ".settings"))
470 {
471 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(file_name + ".settings"));
472 ps.WriteLine(" <AutoGen>True</AutoGen>");
473 ps.WriteLine(" <DesignTimeSharedInput>True</DesignTimeSharedInput>");
474 }
475 }
476 else if (subType == SubType.CodeBehind)
477 {
478 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", Path.GetFileName(short_file_name));
479 }
480 if (project.Files.GetIsLink(filePath))
481 {
482 string alias = project.Files.GetLinkPath(filePath);
483 alias += file.Substring(startPos);
484 alias = Helper.NormalizePath(alias);
485 ps.WriteLine(" <Link>{0}</Link>", alias);
486 }
487 else if (project.Files.GetBuildAction(filePath) != BuildAction.None)
488 {
489 if (project.Files.GetBuildAction(filePath) != BuildAction.EmbeddedResource)
490 {
491 ps.WriteLine(" <SubType>{0}</SubType>", subType);
492 }
493 }
494
495 if (project.Files.GetCopyToOutput(filePath) != CopyToOutput.Never)
496 {
497 ps.WriteLine(" <CopyToOutputDirectory>{0}</CopyToOutputDirectory>", project.Files.GetCopyToOutput(filePath));
498 }
499
500 ps.WriteLine(" </{0}>", project.Files.GetBuildAction(filePath));
501 }
502 }
503 }
504
505 ps.WriteLine(" </ItemGroup>");
506 ps.WriteLine(" <Import Project=\"" + toolInfo.ImportProject + "\" />");
507 ps.WriteLine(" <PropertyGroup>");
508 ps.WriteLine(" <PreBuildEvent>");
509 ps.WriteLine(" </PreBuildEvent>");
510 ps.WriteLine(" <PostBuildEvent>");
511 ps.WriteLine(" </PostBuildEvent>");
512 ps.WriteLine(" </PropertyGroup>");
513 ps.WriteLine("</Project>");
514 }
515 #endregion
516
517 #region User File
518
519 ps = new StreamWriter(projectFile + ".user");
520 using (ps)
521 {
522 // Get the first configuration from the project.
523 ConfigurationNode firstConfiguration = null;
524
525 if (project.Configurations.Count > 0)
526 {
527 firstConfiguration = project.Configurations[0];
528 }
529
530 ps.WriteLine("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">");
531 //ps.WriteLine( "<VisualStudioProject>" );
532 //ps.WriteLine(" <{0}>", toolInfo.XMLTag);
533 //ps.WriteLine(" <Build>");
534 ps.WriteLine(" <PropertyGroup>");
535 //ps.WriteLine(" <Settings ReferencePath=\"{0}\">", MakeRefPath(project));
536
537 if (firstConfiguration != null)
538 {
539 ps.WriteLine(" <Configuration Condition=\" '$(Configuration)' == '' \">{0}</Configuration>", firstConfiguration.Name);
540 ps.WriteLine(" <Platform Condition=\" '$(Platform)' == '' \">{0}</Platform>", firstConfiguration.Platform);
541 }
542
543 ps.WriteLine(" <ReferencePath>{0}</ReferencePath>", MakeRefPath(project));
544 ps.WriteLine(" <LastOpenVersion>{0}</LastOpenVersion>", ProductVersion);
545 ps.WriteLine(" <ProjectView>ProjectFiles</ProjectView>");
546 ps.WriteLine(" <ProjectTrust>0</ProjectTrust>");
547 ps.WriteLine(" </PropertyGroup>");
548 foreach (ConfigurationNode conf in project.Configurations)
549 {
550 ps.Write(" <PropertyGroup");
551 ps.Write(" Condition = \" '$(Configuration)|$(Platform)' == '{0}|{1}' \"", conf.Name, conf.Platform);
552 ps.WriteLine(" />");
553 }
554 ps.WriteLine("</Project>");
555 }
556 #endregion
557
558 kernel.CurrentWorkingDirectory.Pop();
559 }
560
561 private void WriteSolution(SolutionNode solution, bool writeSolutionToDisk)
562 {
563 kernel.Log.Write("Creating {0} solution and project files", VersionName);
564
565 foreach (SolutionNode child in solution.Solutions)
566 {
567 kernel.Log.Write("...Creating folder: {0}", child.Name);
568 WriteSolution(child, false);
569 }
570
571 foreach (ProjectNode project in solution.Projects)
572 {
573 kernel.Log.Write("...Creating project: {0}", project.Name);
574 WriteProject(solution, project);
575 }
576
577 foreach (DatabaseProjectNode project in solution.DatabaseProjects)
578 {
579 kernel.Log.Write("...Creating database project: {0}", project.Name);
580 WriteDatabaseProject(solution, project);
581 }
582
583 if (writeSolutionToDisk) // only write main solution
584 {
585 kernel.Log.Write("");
586 string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
587
588 using (StreamWriter ss = new StreamWriter(solutionFile))
589 {
590 kernel.CurrentWorkingDirectory.Push();
591 Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile));
592
593 ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", SolutionVersion);
594 ss.WriteLine(SolutionTag);
595
596 WriteProjectDeclarations(ss, solution, solution);
597
598 ss.WriteLine("Global");
599
600 ss.WriteLine("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution");
601 foreach (ConfigurationNode conf in solution.Configurations)
602 {
603 ss.WriteLine("\t\t{0} = {0}", conf.NameAndPlatform);
604 }
605 ss.WriteLine("\tEndGlobalSection");
606
607 ss.WriteLine("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution");
608 WriteConfigurationLines(solution.Configurations, solution, ss);
609 ss.WriteLine("\tEndGlobalSection");
610
611 if (solution.Solutions.Count > 0)
612 {
613 ss.WriteLine("\tGlobalSection(NestedProjects) = preSolution");
614 foreach (SolutionNode embeddedSolution in solution.Solutions)
615 {
616 WriteNestedProjectMap(ss, embeddedSolution);
617 }
618 ss.WriteLine("\tEndGlobalSection");
619 }
620
621 ss.WriteLine("EndGlobal");
622 }
623
624 kernel.CurrentWorkingDirectory.Pop();
625 }
626 }
627
628 private void WriteProjectDeclarations(TextWriter writer, SolutionNode actualSolution, SolutionNode embeddedSolution)
629 {
630 foreach (SolutionNode childSolution in embeddedSolution.Solutions)
631 {
632 WriteEmbeddedSolution(writer, childSolution);
633 WriteProjectDeclarations(writer, actualSolution, childSolution);
634 }
635
636 foreach (ProjectNode project in embeddedSolution.Projects)
637 {
638 WriteProject(actualSolution, writer, project);
639 }
640
641 foreach (DatabaseProjectNode dbProject in embeddedSolution.DatabaseProjects)
642 {
643 WriteProject(actualSolution, writer, dbProject);
644 }
645
646 if (actualSolution.Guid == embeddedSolution.Guid)
647 {
648 WriteSolutionFiles(actualSolution, writer);
649 }
650 }
651
652 private static void WriteNestedProjectMap(TextWriter writer, SolutionNode embeddedSolution)
653 {
654 foreach (ProjectNode project in embeddedSolution.Projects)
655 {
656 WriteNestedProject(writer, embeddedSolution, project.Guid);
657 }
658
659 foreach (DatabaseProjectNode dbProject in embeddedSolution.DatabaseProjects)
660 {
661 WriteNestedProject(writer, embeddedSolution, dbProject.Guid);
662 }
663
664 foreach (SolutionNode child in embeddedSolution.Solutions)
665 {
666 WriteNestedProject(writer, embeddedSolution, child.Guid);
667 WriteNestedProjectMap(writer, child);
668 }
669 }
670
671 private static void WriteNestedProject(TextWriter writer, SolutionNode solution, Guid projectGuid)
672 {
673 WriteNestedFolder(writer, solution.Guid, projectGuid);
674 }
675
676 private static void WriteNestedFolder(TextWriter writer, Guid parentGuid, Guid childGuid)
677 {
678 writer.WriteLine("\t\t{0} = {1}",
679 childGuid.ToString("B").ToUpper(),
680 parentGuid.ToString("B").ToUpper());
681 }
682
683 private static void WriteConfigurationLines(IEnumerable<ConfigurationNode> configurations, SolutionNode solution, TextWriter ss)
684 {
685 foreach (ProjectNode project in solution.Projects)
686 {
687 foreach (ConfigurationNode conf in configurations)
688 {
689 ss.WriteLine("\t\t{0}.{1}.ActiveCfg = {1}",
690 project.Guid.ToString("B").ToUpper(),
691 conf.NameAndPlatform);
692
693 ss.WriteLine("\t\t{0}.{1}.Build.0 = {1}",
694 project.Guid.ToString("B").ToUpper(),
695 conf.NameAndPlatform);
696 }
697 }
698
699 foreach (SolutionNode child in solution.Solutions)
700 {
701 WriteConfigurationLines(configurations, child, ss);
702 }
703 }
704
705 private void WriteSolutionFiles(SolutionNode solution, TextWriter ss)
706 {
707 if(solution.Files != null && solution.Files.Count > 0)
708 WriteProject(ss, "Folder", solution.Guid, "Solution Files", "Solution Files", solution.Files);
709 }
710
711 private void WriteEmbeddedSolution(TextWriter writer, SolutionNode embeddedSolution)
712 {
713 WriteProject(writer, "Folder", embeddedSolution.Guid, embeddedSolution.Name, embeddedSolution.Name, embeddedSolution.Files);
714 }
715
716 private void WriteProject(SolutionNode solution, TextWriter ss, ProjectNode project)
717 {
718 WriteProject(ss, solution, project.Language, project.Guid, project.Name, project.FullPath);
719 }
720
721 private void WriteProject(SolutionNode solution, TextWriter ss, DatabaseProjectNode dbProject)
722 {
723 if (solution.Files != null && solution.Files.Count > 0)
724 WriteProject(ss, solution, "Database", dbProject.Guid, dbProject.Name, dbProject.FullPath);
725 }
726
727 const string ProjectDeclarationBeginFormat = "Project(\"{0}\") = \"{1}\", \"{2}\", \"{3}\"";
728 const string ProjectDeclarationEndFormat = "EndProject";
729
730 private void WriteProject(TextWriter ss, SolutionNode solution, string language, Guid guid, string name, string projectFullPath)
731 {
732 if (!tools.ContainsKey(language))
733 throw new UnknownLanguageException("Unknown .NET language: " + language);
734
735 ToolInfo toolInfo = tools[language];
736
737 string path = Helper.MakePathRelativeTo(solution.FullPath, projectFullPath);
738
739 path = Helper.MakeFilePath(path, name, toolInfo.FileExtension);
740
741 WriteProject(ss, language, guid, name, path);
742 }
743
744 private void WriteProject(TextWriter writer, string language, Guid projectGuid, string name, string location)
745 {
746 WriteProject(writer, language, projectGuid, name, location, null);
747 }
748
749 private void WriteProject(TextWriter writer, string language, Guid projectGuid, string name, string location, FilesNode files)
750 {
751 if (!tools.ContainsKey(language))
752 throw new UnknownLanguageException("Unknown .NET language: " + language);
753
754 ToolInfo toolInfo = tools[language];
755
756 writer.WriteLine(ProjectDeclarationBeginFormat,
757 toolInfo.Guid,
758 name,
759 location,
760 projectGuid.ToString("B").ToUpper());
761
762 if (files != null)
763 {
764 writer.WriteLine("\tProjectSection(SolutionItems) = preProject");
765
766 foreach (string file in files)
767 writer.WriteLine("\t\t{0} = {0}", file);
768
769 writer.WriteLine("\tEndProjectSection");
770 }
771
772 writer.WriteLine(ProjectDeclarationEndFormat);
773 }
774
775 private void WriteDatabaseProject(SolutionNode solution, DatabaseProjectNode project)
776 {
777 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "dbp");
778 IndentedTextWriter ps = new IndentedTextWriter(new StreamWriter(projectFile), " ");
779
780 kernel.CurrentWorkingDirectory.Push();
781
782 Helper.SetCurrentDir(Path.GetDirectoryName(projectFile));
783
784 using (ps)
785 {
786 ps.WriteLine("# Microsoft Developer Studio Project File - Database Project");
787 ps.WriteLine("Begin DataProject = \"{0}\"", project.Name);
788 ps.Indent++;
789 ps.WriteLine("MSDTVersion = \"80\"");
790 // TODO: Use the project.Files property
791 if (ContainsSqlFiles(Path.GetDirectoryName(projectFile)))
792 WriteDatabaseFoldersAndFiles(ps, Path.GetDirectoryName(projectFile));
793
794 ps.WriteLine("Begin DBRefFolder = \"Database References\"");
795 ps.Indent++;
796 foreach (DatabaseReferenceNode reference in project.References)
797 {
798 ps.WriteLine("Begin DBRefNode = \"{0}\"", reference.Name);
799 ps.Indent++;
800 ps.WriteLine("ConnectStr = \"{0}\"", reference.ConnectionString);
801 ps.WriteLine("Provider = \"{0}\"", reference.ProviderId.ToString("B").ToUpper());
802 //ps.WriteLine("Colorizer = 5");
803 ps.Indent--;
804 ps.WriteLine("End");
805 }
806 ps.Indent--;
807 ps.WriteLine("End");
808 ps.Indent--;
809 ps.WriteLine("End");
810
811 ps.Flush();
812 }
813
814 kernel.CurrentWorkingDirectory.Pop();
815 }
816
817 private static bool ContainsSqlFiles(string folder)
818 {
819 if(Directory.GetFiles(folder, "*.sql").Length > 0)
820 return true; // if the folder contains 1 .sql file, that's good enough
821
822 foreach (string child in Directory.GetDirectories(folder))
823 {
824 if (ContainsSqlFiles(child))
825 return true; // if 1 child folder contains a .sql file, still good enough
826 }
827
828 return false;
829 }
830
831 private static void WriteDatabaseFoldersAndFiles(IndentedTextWriter writer, string folder)
832 {
833 foreach (string child in Directory.GetDirectories(folder))
834 {
835 if (ContainsSqlFiles(child))
836 {
837 writer.WriteLine("Begin Folder = \"{0}\"", Path.GetFileName(child));
838 writer.Indent++;
839 WriteDatabaseFoldersAndFiles(writer, child);
840 writer.Indent--;
841 writer.WriteLine("End");
842 }
843 }
844 foreach (string file in Directory.GetFiles(folder, "*.sql"))
845 {
846 writer.WriteLine("Script = \"{0}\"", Path.GetFileName(file));
847 }
848 }
849
850 private void CleanProject(ProjectNode project)
851 {
852 kernel.Log.Write("...Cleaning project: {0}", project.Name);
853
854 ToolInfo toolInfo = tools[project.Language];
855 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
856 string userFile = projectFile + ".user";
857
858 Helper.DeleteIfExists(projectFile);
859 Helper.DeleteIfExists(userFile);
860 }
861
862 private void CleanSolution(SolutionNode solution)
863 {
864 kernel.Log.Write("Cleaning {0} solution and project files", VersionName, solution.Name);
865
866 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
867 string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo");
868
869 Helper.DeleteIfExists(slnFile);
870 Helper.DeleteIfExists(suoFile);
871
872 foreach (ProjectNode project in solution.Projects)
873 {
874 CleanProject(project);
875 }
876
877 kernel.Log.Write("");
878 }
879
880 #endregion
881
882 #region ITarget Members
883
884 /// <summary>
885 /// Writes the specified kern.
886 /// </summary>
887 /// <param name="kern">The kern.</param>
888 public virtual void Write(Kernel kern)
889 {
890 if (kern == null)
891 {
892 throw new ArgumentNullException("kern");
893 }
894 kernel = kern;
895 foreach (SolutionNode sol in kernel.Solutions)
896 {
897 WriteSolution(sol, true);
898 }
899 kernel = null;
900 }
901
902 /// <summary>
903 /// Cleans the specified kern.
904 /// </summary>
905 /// <param name="kern">The kern.</param>
906 public virtual void Clean(Kernel kern)
907 {
908 if (kern == null)
909 {
910 throw new ArgumentNullException("kern");
911 }
912 kernel = kern;
913 foreach (SolutionNode sol in kernel.Solutions)
914 {
915 CleanSolution(sol);
916 }
917 kernel = null;
918 }
919
920 #endregion
921 }
922}
diff --git a/Prebuild/src/Core/Targets/VSVersion.cs b/Prebuild/src/Core/Targets/VSVersion.cs
new file mode 100644
index 0000000..699b5ca
--- /dev/null
+++ b/Prebuild/src/Core/Targets/VSVersion.cs
@@ -0,0 +1,54 @@
1#region BSD License
2/*
3Copyright (c) 2008-2009 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com), John Anderson (sontek@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26namespace Prebuild.Core.Targets
27{
28 /// <summary>
29 ///
30 /// </summary>
31 public enum VSVersion
32 {
33 /// <summary>
34 /// Visual Studio 2002
35 /// </summary>
36 VS70,
37 /// <summary>
38 /// Visual Studio 2003
39 /// </summary>
40 VS71,
41 /// <summary>
42 /// Visual Studio 2005
43 /// </summary>
44 VS80,
45 /// <summary>
46 /// Visual Studio 2008
47 /// </summary>
48 VS90,
49 /// <summary>
50 /// Visual Studio 2010
51 /// </summary>
52 VS10
53 }
54}
diff --git a/Prebuild/src/Core/Targets/XcodeTarget.cs b/Prebuild/src/Core/Targets/XcodeTarget.cs
new file mode 100644
index 0000000..5393cec
--- /dev/null
+++ b/Prebuild/src/Core/Targets/XcodeTarget.cs
@@ -0,0 +1,594 @@
1#region BSD License
2/*
3Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com), Dan Moorehead (dan05a@gmail.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26using System;
27using System.IO;
28using System.Reflection;
29using System.Text.RegularExpressions;
30
31using Prebuild.Core.Attributes;
32using Prebuild.Core.Interfaces;
33using Prebuild.Core.Nodes;
34using Prebuild.Core.Utilities;
35
36namespace Prebuild.Core.Targets
37{
38 /// <summary>
39 ///
40 /// </summary>
41 [Target("xcode")]
42 public class XcodeTarget : ITarget
43 {
44 #region Fields
45
46 private Kernel m_Kernel;
47
48 #endregion
49
50 #region Private Methods
51
52 private static string PrependPath(string path)
53 {
54 string tmpPath = Helper.NormalizePath(path, '/');
55 Regex regex = new Regex(@"(\w):/(\w+)");
56 Match match = regex.Match(tmpPath);
57 //if(match.Success || tmpPath[0] == '.' || tmpPath[0] == '/')
58 //{
59 tmpPath = Helper.NormalizePath(tmpPath);
60 //}
61 // else
62 // {
63 // tmpPath = Helper.NormalizePath("./" + tmpPath);
64 // }
65
66 return tmpPath;
67 }
68
69 private static string BuildReference(SolutionNode solution, ReferenceNode refr)
70 {
71 string ret = "";
72 if (solution.ProjectsTable.ContainsKey(refr.Name))
73 {
74 ProjectNode project = (ProjectNode)solution.ProjectsTable[refr.Name];
75 string fileRef = FindFileReference(refr.Name, project);
76 string finalPath = Helper.NormalizePath(Helper.MakeFilePath(project.FullPath + "/${build.dir}/", refr.Name, "dll"), '/');
77 ret += finalPath;
78 return ret;
79 }
80 else
81 {
82 ProjectNode project = (ProjectNode)refr.Parent;
83 string fileRef = FindFileReference(refr.Name, project);
84
85 if (refr.Path != null || fileRef != null)
86 {
87 string finalPath = (refr.Path != null) ? Helper.NormalizePath(refr.Path + "/" + refr.Name + ".dll", '/') : fileRef;
88 ret += finalPath;
89 return ret;
90 }
91
92 try
93 {
94 //Assembly assem = Assembly.Load(refr.Name);
95 //if (assem != null)
96 //{
97 //ret += (refr.Name + ".dll");
98 //}
99 //else
100 //{
101 ret += (refr.Name + ".dll");
102 //}
103 }
104 catch (System.NullReferenceException e)
105 {
106 e.ToString();
107 ret += refr.Name + ".dll";
108 }
109 }
110 return ret;
111 }
112
113 private static string BuildReferencePath(SolutionNode solution, ReferenceNode refr)
114 {
115 string ret = "";
116 if (solution.ProjectsTable.ContainsKey(refr.Name))
117 {
118 ProjectNode project = (ProjectNode)solution.ProjectsTable[refr.Name];
119 string fileRef = FindFileReference(refr.Name, project);
120 string finalPath = Helper.NormalizePath(Helper.MakeReferencePath(project.FullPath + "/${build.dir}/"), '/');
121 ret += finalPath;
122 return ret;
123 }
124 else
125 {
126 ProjectNode project = (ProjectNode)refr.Parent;
127 string fileRef = FindFileReference(refr.Name, project);
128
129 if (refr.Path != null || fileRef != null)
130 {
131 string finalPath = (refr.Path != null) ? Helper.NormalizePath(refr.Path, '/') : fileRef;
132 ret += finalPath;
133 return ret;
134 }
135
136 try
137 {
138 Assembly assem = Assembly.Load(refr.Name);
139 if (assem != null)
140 {
141 ret += "";
142 }
143 else
144 {
145 ret += "";
146 }
147 }
148 catch (System.NullReferenceException e)
149 {
150 e.ToString();
151 ret += "";
152 }
153 }
154 return ret;
155 }
156
157 private static string FindFileReference(string refName, ProjectNode project)
158 {
159 foreach (ReferencePathNode refPath in project.ReferencePaths)
160 {
161 string fullPath = Helper.MakeFilePath(refPath.Path, refName, "dll");
162
163 if (File.Exists(fullPath))
164 {
165 return fullPath;
166 }
167 }
168
169 return null;
170 }
171
172 /// <summary>
173 /// Gets the XML doc file.
174 /// </summary>
175 /// <param name="project">The project.</param>
176 /// <param name="conf">The conf.</param>
177 /// <returns></returns>
178 public static string GetXmlDocFile(ProjectNode project, ConfigurationNode conf)
179 {
180 if (conf == null)
181 {
182 throw new ArgumentNullException("conf");
183 }
184 if (project == null)
185 {
186 throw new ArgumentNullException("project");
187 }
188 string docFile = (string)conf.Options["XmlDocFile"];
189 // if(docFile != null && docFile.Length == 0)//default to assembly name if not specified
190 // {
191 // return Path.GetFileNameWithoutExtension(project.AssemblyName) + ".xml";
192 // }
193 return docFile;
194 }
195
196 private void WriteProject(SolutionNode solution, ProjectNode project)
197 {
198 string projFile = Helper.MakeFilePath(project.FullPath, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build");
199 StreamWriter ss = new StreamWriter(projFile);
200
201 m_Kernel.CurrentWorkingDirectory.Push();
202 Helper.SetCurrentDir(Path.GetDirectoryName(projFile));
203 bool hasDoc = false;
204
205 using (ss)
206 {
207 ss.WriteLine("<?xml version=\"1.0\" ?>");
208 ss.WriteLine("<project name=\"{0}\" default=\"build\">", project.Name);
209 ss.WriteLine(" <target name=\"{0}\">", "build");
210 ss.WriteLine(" <echo message=\"Build Directory is ${project::get-base-directory()}/${build.dir}\" />");
211 ss.WriteLine(" <mkdir dir=\"${project::get-base-directory()}/${build.dir}\" />");
212 ss.WriteLine(" <copy todir=\"${project::get-base-directory()}/${build.dir}\">");
213 ss.WriteLine(" <fileset basedir=\"${project::get-base-directory()}\">");
214 foreach (ReferenceNode refr in project.References)
215 {
216 if (refr.LocalCopy)
217 {
218 ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, refr)) + "\" />", '/'));
219 }
220 }
221 ss.WriteLine(" </fileset>");
222 ss.WriteLine(" </copy>");
223 ss.Write(" <csc");
224 ss.Write(" target=\"{0}\"", project.Type.ToString().ToLower());
225 ss.Write(" debug=\"{0}\"", "${build.debug}");
226 foreach (ConfigurationNode conf in project.Configurations)
227 {
228 if (conf.Options.KeyFile != "")
229 {
230 ss.Write(" keyfile=\"{0}\"", conf.Options.KeyFile);
231 break;
232 }
233 }
234 foreach (ConfigurationNode conf in project.Configurations)
235 {
236 ss.Write(" unsafe=\"{0}\"", conf.Options.AllowUnsafe);
237 break;
238 }
239 foreach (ConfigurationNode conf in project.Configurations)
240 {
241 ss.Write(" define=\"{0}\"", conf.Options.CompilerDefines);
242 break;
243 }
244 foreach (ConfigurationNode conf in project.Configurations)
245 {
246 if (GetXmlDocFile(project, conf) != "")
247 {
248 ss.Write(" doc=\"{0}\"", "${project::get-base-directory()}/${build.dir}/" + GetXmlDocFile(project, conf));
249 hasDoc = true;
250 }
251 break;
252 }
253 ss.Write(" output=\"{0}", "${project::get-base-directory()}/${build.dir}/${project::get-name()}");
254 if (project.Type == ProjectType.Library)
255 {
256 ss.Write(".dll\"");
257 }
258 else
259 {
260 ss.Write(".exe\"");
261 }
262 if (project.AppIcon != null && project.AppIcon.Length != 0)
263 {
264 ss.Write(" win32icon=\"{0}\"", Helper.NormalizePath(project.AppIcon, '/'));
265 }
266 ss.WriteLine(">");
267 ss.WriteLine(" <resources prefix=\"{0}\" dynamicprefix=\"true\" >", project.RootNamespace);
268 foreach (string file in project.Files)
269 {
270 switch (project.Files.GetBuildAction(file))
271 {
272 case BuildAction.EmbeddedResource:
273 ss.WriteLine(" {0}", "<include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
274 break;
275 default:
276 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings)
277 {
278 ss.WriteLine(" <include name=\"{0}\" />", file.Substring(0, file.LastIndexOf('.')) + ".resx");
279 }
280 break;
281 }
282 }
283 //if (project.Files.GetSubType(file).ToString() != "Code")
284 //{
285 // ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
286
287 ss.WriteLine(" </resources>");
288 ss.WriteLine(" <sources failonempty=\"true\">");
289 foreach (string file in project.Files)
290 {
291 switch (project.Files.GetBuildAction(file))
292 {
293 case BuildAction.Compile:
294 ss.WriteLine(" <include name=\"" + Helper.NormalizePath(PrependPath(file), '/') + "\" />");
295 break;
296 default:
297 break;
298 }
299 }
300 ss.WriteLine(" </sources>");
301 ss.WriteLine(" <references basedir=\"${project::get-base-directory()}\">");
302 ss.WriteLine(" <lib>");
303 ss.WriteLine(" <include name=\"${project::get-base-directory()}\" />");
304 ss.WriteLine(" <include name=\"${project::get-base-directory()}/${build.dir}\" />");
305 ss.WriteLine(" </lib>");
306 foreach (ReferenceNode refr in project.References)
307 {
308 ss.WriteLine(" <include name=\"{0}", Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReference(solution, refr)) + "\" />", '/'));
309 }
310 ss.WriteLine(" </references>");
311
312 ss.WriteLine(" </csc>");
313 ss.WriteLine(" </target>");
314
315 ss.WriteLine(" <target name=\"clean\">");
316 ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />");
317 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
318 ss.WriteLine(" </target>");
319
320 ss.WriteLine(" <target name=\"doc\" description=\"Creates documentation.\">");
321 if (hasDoc)
322 {
323 ss.WriteLine(" <property name=\"doc.target\" value=\"\" />");
324 ss.WriteLine(" <if test=\"${platform::is-unix()}\">");
325 ss.WriteLine(" <property name=\"doc.target\" value=\"Web\" />");
326 ss.WriteLine(" </if>");
327 ss.WriteLine(" <ndoc failonerror=\"false\" verbose=\"true\">");
328 ss.WriteLine(" <assemblies basedir=\"${project::get-base-directory()}\">");
329 ss.Write(" <include name=\"${build.dir}/${project::get-name()}");
330 if (project.Type == ProjectType.Library)
331 {
332 ss.WriteLine(".dll\" />");
333 }
334 else
335 {
336 ss.WriteLine(".exe\" />");
337 }
338
339 ss.WriteLine(" </assemblies>");
340 ss.WriteLine(" <summaries basedir=\"${project::get-base-directory()}\">");
341 ss.WriteLine(" <include name=\"${build.dir}/${project::get-name()}.xml\"/>");
342 ss.WriteLine(" </summaries>");
343 ss.WriteLine(" <referencepaths basedir=\"${project::get-base-directory()}\">");
344 ss.WriteLine(" <include name=\"${build.dir}\" />");
345 // foreach(ReferenceNode refr in project.References)
346 // {
347 // string path = Helper.NormalizePath(Helper.MakePathRelativeTo(project.FullPath, BuildReferencePath(solution, refr)), '/');
348 // if (path != "")
349 // {
350 // ss.WriteLine(" <include name=\"{0}\" />", path);
351 // }
352 // }
353 ss.WriteLine(" </referencepaths>");
354 ss.WriteLine(" <documenters>");
355 ss.WriteLine(" <documenter name=\"MSDN\">");
356 ss.WriteLine(" <property name=\"OutputDirectory\" value=\"${project::get-base-directory()}/${build.dir}/doc/${project::get-name()}\" />");
357 ss.WriteLine(" <property name=\"OutputTarget\" value=\"${doc.target}\" />");
358 ss.WriteLine(" <property name=\"HtmlHelpName\" value=\"${project::get-name()}\" />");
359 ss.WriteLine(" <property name=\"IncludeFavorites\" value=\"False\" />");
360 ss.WriteLine(" <property name=\"Title\" value=\"${project::get-name()} SDK Documentation\" />");
361 ss.WriteLine(" <property name=\"SplitTOCs\" value=\"False\" />");
362 ss.WriteLine(" <property name=\"DefaulTOC\" value=\"\" />");
363 ss.WriteLine(" <property name=\"ShowVisualBasic\" value=\"True\" />");
364 ss.WriteLine(" <property name=\"AutoDocumentConstructors\" value=\"True\" />");
365 ss.WriteLine(" <property name=\"ShowMissingSummaries\" value=\"${build.debug}\" />");
366 ss.WriteLine(" <property name=\"ShowMissingRemarks\" value=\"${build.debug}\" />");
367 ss.WriteLine(" <property name=\"ShowMissingParams\" value=\"${build.debug}\" />");
368 ss.WriteLine(" <property name=\"ShowMissingReturns\" value=\"${build.debug}\" />");
369 ss.WriteLine(" <property name=\"ShowMissingValues\" value=\"${build.debug}\" />");
370 ss.WriteLine(" <property name=\"DocumentInternals\" value=\"False\" />");
371 ss.WriteLine(" <property name=\"DocumentPrivates\" value=\"False\" />");
372 ss.WriteLine(" <property name=\"DocumentProtected\" value=\"True\" />");
373 ss.WriteLine(" <property name=\"DocumentEmptyNamespaces\" value=\"${build.debug}\" />");
374 ss.WriteLine(" <property name=\"IncludeAssemblyVersion\" value=\"True\" />");
375 ss.WriteLine(" </documenter>");
376 ss.WriteLine(" </documenters>");
377 ss.WriteLine(" </ndoc>");
378 }
379 ss.WriteLine(" </target>");
380 ss.WriteLine("</project>");
381 }
382 m_Kernel.CurrentWorkingDirectory.Pop();
383 }
384
385 private void WriteCombine(SolutionNode solution)
386 {
387 m_Kernel.Log.Write("Creating Xcode build files");
388 foreach (ProjectNode project in solution.Projects)
389 {
390 if (m_Kernel.AllowProject(project.FilterGroups))
391 {
392 m_Kernel.Log.Write("...Creating project: {0}", project.Name);
393 WriteProject(solution, project);
394 }
395 }
396
397 m_Kernel.Log.Write("");
398 DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(solution.FullPath, solution.Name + ".xcodeproj"));
399 if (!directoryInfo.Exists)
400 {
401 directoryInfo.Create();
402 }
403 string combFile = Helper.MakeFilePath(Path.Combine(solution.FullPath, solution.Name + ".xcodeproj"), "project", "pbxproj");
404 StreamWriter ss = new StreamWriter(combFile);
405
406 m_Kernel.CurrentWorkingDirectory.Push();
407 Helper.SetCurrentDir(Path.GetDirectoryName(combFile));
408
409 using (ss)
410 {
411 ss.WriteLine("<?xml version=\"1.0\" ?>");
412 ss.WriteLine("<project name=\"{0}\" default=\"build\">", solution.Name);
413 ss.WriteLine(" <echo message=\"Using '${nant.settings.currentframework}' Framework\"/>");
414 ss.WriteLine();
415
416 //ss.WriteLine(" <property name=\"dist.dir\" value=\"dist\" />");
417 //ss.WriteLine(" <property name=\"source.dir\" value=\"source\" />");
418 ss.WriteLine(" <property name=\"bin.dir\" value=\"bin\" />");
419 ss.WriteLine(" <property name=\"obj.dir\" value=\"obj\" />");
420 ss.WriteLine(" <property name=\"doc.dir\" value=\"doc\" />");
421 ss.WriteLine(" <property name=\"project.main.dir\" value=\"${project::get-base-directory()}\" />");
422
423 foreach (ConfigurationNode conf in solution.Configurations)
424 {
425 // Set the project.config to a non-debug configuration
426 if (conf.Options["DebugInformation"].ToString().ToLower() != "true")
427 {
428 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name);
429 }
430 ss.WriteLine();
431 ss.WriteLine(" <target name=\"{0}\" description=\"\">", conf.Name);
432 ss.WriteLine(" <property name=\"project.config\" value=\"{0}\" />", conf.Name);
433 ss.WriteLine(" <property name=\"build.debug\" value=\"{0}\" />", conf.Options["DebugInformation"].ToString().ToLower());
434 ss.WriteLine(" </target>");
435 ss.WriteLine();
436 }
437
438 ss.WriteLine(" <target name=\"net-1.1\" description=\"Sets framework to .NET 1.1\">");
439 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-1.1\" />");
440 ss.WriteLine(" </target>");
441 ss.WriteLine();
442
443 ss.WriteLine(" <target name=\"net-2.0\" description=\"Sets framework to .NET 2.0\">");
444 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"net-2.0\" />");
445 ss.WriteLine(" </target>");
446 ss.WriteLine();
447
448 ss.WriteLine(" <target name=\"mono-2.0\" description=\"Sets framework to mono 2.0\">");
449 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-2.0\" />");
450 ss.WriteLine(" </target>");
451 ss.WriteLine();
452
453 ss.WriteLine(" <target name=\"mono-1.0\" description=\"Sets framework to mono 1.0\">");
454 ss.WriteLine(" <property name=\"nant.settings.currentframework\" value=\"mono-1.0\" />");
455 ss.WriteLine(" </target>");
456 ss.WriteLine();
457
458 ss.WriteLine(" <target name=\"init\" description=\"\">");
459 ss.WriteLine(" <call target=\"${project.config}\" />");
460 ss.WriteLine(" <sysinfo />");
461 ss.WriteLine(" <echo message=\"Platform ${sys.os.platform}\" />");
462 ss.WriteLine(" <property name=\"build.dir\" value=\"${bin.dir}/${project.config}\" />");
463 ss.WriteLine(" </target>");
464 ss.WriteLine();
465
466 ss.WriteLine(" <target name=\"clean\" description=\"\">");
467 ss.WriteLine(" <echo message=\"Deleting all builds from all configurations\" />");
468 //ss.WriteLine(" <delete dir=\"${dist.dir}\" failonerror=\"false\" />");
469 ss.WriteLine(" <delete dir=\"${bin.dir}\" failonerror=\"false\" />");
470 ss.WriteLine(" <delete dir=\"${obj.dir}\" failonerror=\"false\" />");
471 //foreach(ProjectNode project in solution.Projects)
472 //{
473 // string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
474 // ss.Write(" <nant buildfile=\"{0}\"",
475 // Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"),'/'));
476 // ss.WriteLine(" target=\"clean\" />");
477 //}
478 ss.WriteLine(" </target>");
479 ss.WriteLine();
480
481 ss.WriteLine(" <target name=\"build\" depends=\"init\" description=\"\">");
482
483 foreach (ProjectNode project in solution.ProjectsTableOrder)
484 {
485 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
486 ss.Write(" <nant buildfile=\"{0}\"",
487 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"), '/'));
488 ss.WriteLine(" target=\"build\" />");
489 }
490 ss.WriteLine(" </target>");
491 ss.WriteLine();
492
493 ss.WriteLine(" <target name=\"build-release\" depends=\"Release, init, build\" description=\"Builds in Release mode\" />");
494 ss.WriteLine();
495 ss.WriteLine(" <target name=\"build-debug\" depends=\"Debug, init, build\" description=\"Builds in Debug mode\" />");
496 ss.WriteLine();
497 //ss.WriteLine(" <target name=\"package\" depends=\"clean, doc, copyfiles, zip\" description=\"Builds in Release mode\" />");
498 ss.WriteLine(" <target name=\"package\" depends=\"clean, doc\" description=\"Builds all\" />");
499 ss.WriteLine();
500
501 ss.WriteLine(" <target name=\"doc\" depends=\"build-release\">");
502 ss.WriteLine(" <echo message=\"Generating all documentation from all builds\" />");
503 foreach (ProjectNode project in solution.Projects)
504 {
505 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
506 ss.Write(" <nant buildfile=\"{0}\"",
507 Helper.NormalizePath(Helper.MakeFilePath(path, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build"), '/'));
508 ss.WriteLine(" target=\"doc\" />");
509 }
510 ss.WriteLine(" </target>");
511 ss.WriteLine();
512 ss.WriteLine("</project>");
513 }
514
515 m_Kernel.CurrentWorkingDirectory.Pop();
516 }
517
518 private void CleanProject(ProjectNode project)
519 {
520 m_Kernel.Log.Write("...Cleaning project: {0}", project.Name);
521 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name + (project.Type == ProjectType.Library ? ".dll" : ".exe"), "build");
522 Helper.DeleteIfExists(projectFile);
523 }
524
525 private void CleanSolution(SolutionNode solution)
526 {
527 m_Kernel.Log.Write("Cleaning Xcode build files for", solution.Name);
528
529 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "build");
530 Helper.DeleteIfExists(slnFile);
531
532 foreach (ProjectNode project in solution.Projects)
533 {
534 CleanProject(project);
535 }
536
537 m_Kernel.Log.Write("");
538 }
539
540 #endregion
541
542 #region ITarget Members
543
544 /// <summary>
545 /// Writes the specified kern.
546 /// </summary>
547 /// <param name="kern">The kern.</param>
548 public void Write(Kernel kern)
549 {
550 if (kern == null)
551 {
552 throw new ArgumentNullException("kern");
553 }
554 m_Kernel = kern;
555 foreach (SolutionNode solution in kern.Solutions)
556 {
557 WriteCombine(solution);
558 }
559 m_Kernel = null;
560 }
561
562 /// <summary>
563 /// Cleans the specified kern.
564 /// </summary>
565 /// <param name="kern">The kern.</param>
566 public virtual void Clean(Kernel kern)
567 {
568 if (kern == null)
569 {
570 throw new ArgumentNullException("kern");
571 }
572 m_Kernel = kern;
573 foreach (SolutionNode sol in kern.Solutions)
574 {
575 CleanSolution(sol);
576 }
577 m_Kernel = null;
578 }
579
580 /// <summary>
581 /// Gets the name.
582 /// </summary>
583 /// <value>The name.</value>
584 public string Name
585 {
586 get
587 {
588 return "xcode";
589 }
590 }
591
592 #endregion
593 }
594}