rakish 0.9.01.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,897 @@
1
+
2
+ module Rakish
3
+
4
+ LoadableModule.onLoaded(Module.new do
5
+
6
+ include Logger;
7
+
8
+ # :nodoc:
9
+ VALID_DEBUGTYPES = {
10
+ 'Debug'=>true,
11
+ 'Release'=>true,
12
+ # 'Checked'=>true
13
+ };
14
+ # :nodoc:
15
+ VALID_LINKTYPES = {
16
+ 'MT'=>true,
17
+ 'MTd'=>true,
18
+ 'MD'=>true,
19
+ 'MDd'=>true
20
+ };
21
+
22
+ # :nodoc:
23
+ VALID_COMPILERS = {
24
+ # 'VC5'=>true,
25
+ # 'VC6'=>true,
26
+ # 'VC7'=>true,
27
+ 'VC8'=>true,
28
+ # 'VC9'=>true,
29
+ 'VC10'=>true,
30
+ # 'ICL'=>true
31
+ };
32
+
33
+ # C++ build tools
34
+ # Not really part of public distributioin - too littered with local stuff
35
+ # specific to my main builds This needs to be converted to work in a more configurable way
36
+ class Win32Tools
37
+ include CTools
38
+
39
+ # platform specific file extensions
40
+ # TODO - make these project wide dependent on platform ???
41
+ def OBJEXT
42
+ '.obj'
43
+ end
44
+ def LIBEXT
45
+ '.lib'
46
+ end
47
+ def DLLEXT
48
+ '.dll'
49
+ end
50
+ def EXEEXT
51
+ '.exe'
52
+ end
53
+
54
+ def initialize(args)
55
+
56
+ splitcfgs = args[:split];
57
+
58
+ @platform = splitcfgs[0];
59
+ @platformType = args[:platformType];
60
+ @platformBits = args[:platformBits];
61
+
62
+ @compiler = args[:compiler];
63
+ @linkType = args[:linkType];
64
+ @debugType = args[:debugType];
65
+
66
+ cppOpts = ' -nologo';
67
+ cppWarnings = '';
68
+ linkOpts = '';
69
+ sdkLibs = [];
70
+ ipaths=[];
71
+
72
+ tpp = GlobalConfig.instance.thirdPartyPath;
73
+
74
+ case(@platformBits)
75
+ when '32'
76
+ machineSpec = '-machine:x86';
77
+ when '64'
78
+ machineSpec = '-machine:x64';
79
+ end
80
+
81
+ # if ($(WINDOWS_CLR),1)
82
+ # CPP_OPTIONS += -clr -EHa
83
+ # else
84
+ cppOpts += ' -EHsc'
85
+ # end
86
+
87
+ linkOpts += "#{machineSpec} -incremental:no -release -ignore:4089 -ignore:4049 -ignore:4217 -ignore:4248"
88
+
89
+ case(@debugType)
90
+ when 'Debug'
91
+ cppOpts += ' -Zi -Od'
92
+ linkOpts += ' -debug -nodefaultlib'
93
+ when 'Checked'
94
+ cppOpts += ' -Zi -Ox'
95
+ linkOpts += ' -debug -nodefaultlib'
96
+ when 'Release'
97
+ linkOpts += ' -nodefaultlib'
98
+ cppOpts += ' -O3 -Qprec-div-'
99
+ when 'ICL'
100
+ cppOpts += ' -O3 -Qprec-div-'
101
+ else
102
+ cppOpts += ' -Ox'
103
+ end
104
+
105
+ # CPP_OPTIONS_DEBUG := -Zi
106
+ # LINK_OPTIONS_DEBUG := -debug
107
+ #
108
+ # ifeq ($(WINDOWS_CLR),1)
109
+ # LINK_OPTIONS += -dynamicbase -nxcompat
110
+ # LINK_OPTIONS_DEBUG += -assemblydebug
111
+ # endif
112
+ #
113
+ # ifeq ($(DEBUGTYPE),Debug)
114
+ # CPP_OPTIONS += $(CPP_OPTIONS_DEBUG) -Od
115
+ # LINK_OPTIONS += -nodefaultlib $(LINK_OPTIONS_DEBUG)
116
+ # SDK_LIB += chkstk.obj
117
+ # DEBUGTYPEREF := Debug
118
+ # endif
119
+ # ifeq ($(DEBUGTYPE),Checked)
120
+ # CPP_OPTIONS += $(CPP_OPTIONS_DEBUG) -Ox
121
+ # LINK_OPTIONS += -nodefaultlib $(LINK_OPTIONS_DEBUG)
122
+ # DEBUGTYPEREF := Release
123
+ # endif
124
+ # ifeq ($(DEBUGTYPE),Release)
125
+ # ifeq ($(COMPILER),ICL)
126
+ # CPP_OPTIONS += -O3 -Qprec-div-
127
+ # else
128
+ # CPP_OPTIONS += -Ox
129
+ # endif
130
+ # LINK_OPTIONS += -nodefaultlib
131
+ # DEBUGTYPEREF := Release
132
+ # endif
133
+ # ifeq ($(COMPILER),ICL)
134
+ # COMPILERREF := VC8
135
+ # else
136
+ # COMPILERREF := $(COMPILER)
137
+ # endif
138
+
139
+ cppWarnings = ' -W3'
140
+ case(@compiler)
141
+ when 'VC9'
142
+ when 'VC10'
143
+ else
144
+ cppWarnings += ' -Wp64'
145
+ end
146
+
147
+ case(@linkType)
148
+ when 'MT'
149
+ @BASELINKAGE = 'Static'
150
+ cppOpts += " -MT"
151
+ @linkDefines=['NDEBUG','_MT'];
152
+ sdkLibs << 'libcmt.lib'
153
+ sdkLibs << 'libcpmt.lib'
154
+ when 'MTd'
155
+ @BASELINKAGE = 'Static'
156
+ cppOpts += " -MTd"
157
+ @linkDefines=['_DEBUG','_MT'];
158
+ sdkLibs << 'libcmtd.lib'
159
+ sdkLibs << 'libcpmtd.lib'
160
+ # DEBUG_CRT := 1
161
+ when 'MD'
162
+ @BASELINKAGE = 'Dynamic'
163
+ cppOpts += " -MD"
164
+ @linkDefines=['NDEBUG', '_MT', '_DLL'];
165
+ sdkLibs << 'msvcrt.lib'
166
+ # ifeq ($(WINDOWS_CLR),1)
167
+ # sdkLibs << 'msvcmrt.lib'
168
+ # end
169
+ sdkLibs << 'msvcprt.lib'
170
+ when 'MDd'
171
+ @BASELINKAGE = 'Dynamic'
172
+ cppOpts += " -MDd"
173
+ @linkDefines=['_DEBUG', '_MT', '_DLL'];
174
+ sdkLibs << 'msvcrtd.lib'
175
+ # ifeq ($(WINDOWS_CLR),1)
176
+ # sdkLibs << 'msvcmrtd.lib'
177
+ # end
178
+ sdkLibs << 'msvcprtd.lib'
179
+ # DEBUG_CRT := 1
180
+ else
181
+ @linkDefines=[]
182
+ end
183
+
184
+ if(@debugType === 'Debug')
185
+ # ifeq ($(DEBUG_CRT),1)
186
+ # ifneq ($(WINDOWS_CLR),1)
187
+ # cppOpts += " -RTC1"
188
+ # end
189
+ # cppOpts += " -Gs0"
190
+ # end
191
+ end
192
+
193
+ unless(@compiler === 'VC6')
194
+ # cppOpts += " -showIncludes"
195
+ case(@linkType)
196
+ when 'MT'
197
+ sdkLibs << 'atls.lib'
198
+ sdkLibs << 'comsuppw.lib'
199
+ when 'MTd'
200
+ sdkLibs << 'atlsd.lib'
201
+ sdkLibs << 'comsuppwd.lib'
202
+
203
+ when 'MD'
204
+ sdkLibs << 'atls.lib'
205
+ sdkLibs << 'comsuppw.lib'
206
+ when 'MDd'
207
+ sdkLibs << 'atlsd.lib'
208
+ sdkLibs << 'comsuppwd.lib'
209
+ end
210
+ end
211
+
212
+ unless(@compiler === 'VC7')
213
+ cppOpts += " -bigobj"
214
+ end
215
+
216
+ # select tool executables and OS sdk library paths
217
+ case(@compiler)
218
+ when 'VC6'
219
+ @CVTRES_EXE = "#{tpp}/tools/msvc6/bin/cvtres.exe"
220
+ @MSVC_EXE = "#{tpp}/tools/msvc6/bin/cl.exe"
221
+ @LINK_EXE = "#{tpp}/tools/msvc6/bin/link.exe"
222
+
223
+ cppOpts += " -GX";
224
+ " -I#{tpp}/tools/msvc6/include";
225
+ ipaths << "#{tpp}/tools/msvc7/include";
226
+ ipaths << "#{tpp}/tools/msvc8/include";
227
+ cppOpts += " -libpath:#{tpp}/tools/msvc6/lib";
228
+ when 'VC7'
229
+ @CVTRES_EXE = "#{tpp}/tools/msvc7/bin/cvtres.exe"
230
+ @MSVC_EXE ="#{tpp}/tools/msvc7/bin/cl.exe"
231
+ @LINK_EXE = "#{tpp}/tools/msvc7/bin/link.exe"
232
+
233
+ cppOpts += " -GX"
234
+ ipaths << "#{tpp}/tools/msvc7/include\""
235
+ ipaths << "#{tpp}/tools/msvc7/atlmfc/include\""
236
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc7/lib\""
237
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc7/atlmfc/lib\""
238
+ when 'VC8'
239
+ @CVTRES_EXE = "#{tpp}/tools/msvc8/bin/cvtres.exe"
240
+ ipaths << "#{tpp}/tools/msvc8/include"
241
+ ipaths << "#{tpp}/tools/msvc8/atlmfc/include"
242
+
243
+ if(@platform === "Win32")
244
+ @MSVC_EXE ="#{tpp}/tools/msvc8/bin/cl.exe"
245
+ @LINK_EXE = "#{tpp}/tools/msvc8/bin/link.exe"
246
+ @LIB_EXE = "#{tpp}/tools/msvc8/bin/lib.exe"
247
+
248
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc8/lib\""
249
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc8/atlmfc/lib\""
250
+ else
251
+ @MSVC_EXE ="#{tpp}/tools/msvc8/bin/x86_x64/cl.exe"
252
+ @LINK_EXE = "#{tpp}/tools/msvc8/bin/x86_x64/link.exe"
253
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc8/lib/x64\""
254
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc8/atlmfc/lib/amd64\""
255
+ end
256
+ when 'VC9'
257
+ @CVTRES_EXE = "#{tpp}/tools/msvc9/bin/cvtres.exe"
258
+ ipaths << "#{tpp}/tools/msvc9/include"
259
+ ipaths << "#{tpp}/tools/msvc9/atlmfc/include"
260
+ if(@platform === "Win32")
261
+ @MSVC_EXE = "#{tpp}/tools/msvc9/bin/cl.exe"
262
+ @LINK_EXE = "#{tpp}/tools/msvc9/bin/link.exe"
263
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc9/lib\""
264
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc9/atlmfc/lib\""
265
+ else
266
+ @MSVC_EXE = "#{tpp}/tools/msvc9/bin/x86_amd64/cl.exe"
267
+ @LINK_EXE = "#{tpp}/tools/msvc9/bin/x86_amd64/link.exe"
268
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc9/lib/amd64\""
269
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc9/atlmfc/lib/amd64\""
270
+ end
271
+ when 'VC10'
272
+ @CVTRES_EXE = "#{tpp}/tools/msvc10/bin/cvtres.exe"
273
+ ipaths << "#{tpp}/tools/msvc10/include"
274
+ ipaths << "#{tpp}/tools/msvc10/atlmfc/include"
275
+ if(@platform === "Win32")
276
+ @MSVC_EXE = "#{tpp}/tools/msvc10/bin/cl.exe"
277
+ @LINK_EXE = "#{tpp}/tools/msvc10/bin/link.exe"
278
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc10/lib\""
279
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc10/atlmfc/lib\""
280
+ else
281
+ @MSVC_EXE = "#{tpp}/tools/msvc10/bin/x86_amd64/cl.exe"
282
+ @LINK_EXE = "#{tpp}/tools/msvc10/bin/x86_amd64/link.exe"
283
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc10/lib/amd64\""
284
+ linkOpts += " -libpath:\"#{tpp}/tools/msvc10/atlmfc/lib/amd64\""
285
+ end
286
+ end
287
+
288
+ @RC_EXE = "#{tpp}/tools/winsdk/bin/rc.exe"
289
+
290
+ # items from appropriate windows SDKs
291
+ ipaths << "#{tpp}/tools/winsdk/Include"
292
+ ipaths << "#{tpp}/include/Win32"
293
+ ipaths << "#{tpp}/include"
294
+
295
+ if(@platform === "Win32")
296
+ sdkLibPath = "#{tpp}/tools/winsdk/lib"
297
+ else
298
+ sdkLibPath = "#{tpp}/tools/winsdk/lib/x64"
299
+ end
300
+ linkOpts += " -libpath:\"#{sdkLibPath}\""
301
+
302
+ sdkLibs << 'oldnames.lib';
303
+
304
+ [
305
+ 'gdi32.lib',
306
+ 'glu32.lib',
307
+ 'kernel32.lib',
308
+ 'ole32.lib',
309
+ 'opengl32.lib',
310
+ 'rpcrt4.lib',
311
+ 'shell32.lib',
312
+ 'user32.lib',
313
+ 'winmm.lib',
314
+ 'strmiids.lib',
315
+ 'uuid.lib',
316
+ 'ws2_32.lib',
317
+ 'wsock32.lib',
318
+ 'advapi32.lib',
319
+ 'comdlg32.lib',
320
+ 'comctl32.lib',
321
+ 'oleaut32.lib',
322
+ 'winhttp.lib',
323
+ 'quartz.lib',
324
+ 'dsound.lib',
325
+ 'userenv.lib',
326
+ 'wldap32.lib',
327
+ 'shlwapi.lib',
328
+ 'version.lib',
329
+ 'netapi32.lib',
330
+ 'usp10.lib',
331
+ 'psapi.lib',
332
+ 'msimg32.lib',
333
+ 'wininet.lib',
334
+ 'winspool.lib',
335
+ 'odbc32.lib',
336
+ 'odbccp32.lib',
337
+ 'crypt32.lib',
338
+ 'secur32.lib',
339
+ 't2embed.lib',
340
+ 'setupapi.lib',
341
+ 'dbghelp.lib',
342
+ 'cryptui.lib'
343
+ ].each do |lib|
344
+ sdkLibs << File.join(sdkLibPath,lib);
345
+ end
346
+
347
+ includesManifest = true;
348
+ case(@compiler)
349
+ when 'VC8'
350
+ @ManifestSource = "#{tpp}/tools/msvc8/manifest/#{@platform}-#{@linkType}.manifest"
351
+ linkOpts += " -manifest:no"
352
+ when 'VC9'
353
+ @ManifestSource = "#{tpp}/tools/msvc9/manifest/#{@platform}-#{@linkType}.manifest"
354
+ linkOpts += " -manifest:no"
355
+ when 'VC10'
356
+ @ManifestSource = "#{tpp}/tools/msvc10/manifest/#{@platform}-#{@linkType}.manifest"
357
+ linkOpts += " -manifest:no"
358
+ when 'ICL'
359
+ @ManifestSource = "#{tpp}/tools/msvc8/manifest/#{@platform}-#{@linkType}.manifest"
360
+ linkOpts += " -manifest:no"
361
+ else
362
+ includesManifest = false;
363
+ end
364
+
365
+ # assign results to instance variables
366
+ @CPP_OPTIONS = cppOpts;
367
+ @CPP_WARNINGS = cppWarnings;
368
+ @SDK_LIBS = sdkLibs;
369
+ @LINK_OPTS = linkOpts;
370
+ @MACHINE_SPEC = machineSpec;
371
+ @systemIncludePaths = ipaths;
372
+ end
373
+
374
+ def systemIncludePaths
375
+ @systemIncludePaths
376
+ end
377
+
378
+ def ensureConfigOptions(cfg)
379
+
380
+ cfg.cppDefine(
381
+ @linkDefines,
382
+ 'ARTD_WINDOWS=',
383
+ 'WIN32',
384
+ '_LIB',
385
+ '_WINDOWS',
386
+ '_USRDLL',
387
+ '_CRT_SECURE_NO_DEPRECATE',
388
+ '_CRT_NONSTDC_NO_DEPRECATE',
389
+ '_MBCS',
390
+ '_UNICODE',
391
+ 'UNICODE',
392
+ 'NOMINMAX',
393
+ '_SCL_SECURE_NO_WARNINGS',
394
+ 'STRSAFE_NO_DEPRECATE',
395
+ "ARTD_PLATFORMTYPE=#{@platformType}",
396
+ "ARTD_PLATFORMBITS=#{@platformBits}",
397
+ "ARTD_COMPILERTYPE=#{@compiler}",
398
+ "ARTD_LINKAGETYPE=#{@linkType}",
399
+ "ARTD_DEBUGTYPE=#{@debugType}"
400
+ );
401
+
402
+ cfg.cppDefineIfNot(
403
+ 'WINVER=0x0501',
404
+ '_FILE_OFFSET_BITS=64',
405
+ '_WIN32_WINNT=0x0501',
406
+ '_WIN32_WINDOWS=0x0410',
407
+ '_WIN32_IE=0x0600'
408
+ );
409
+
410
+ end
411
+
412
+ # will format and cache into the config the /I and /D and other constant
413
+ # compiler flags for the specific configuration and cache it in the configuration
414
+ def getFormattedMSCFlags(cfig)
415
+
416
+ unless(cfl = cfig.getMy(:msvcFlags_))
417
+ # if not cached build command line string
418
+ cfl = @CPP_OPTIONS;
419
+ cfl += @CPP_WARNINGS;
420
+
421
+ if(false)
422
+ cfig.cflags.each do |cf|
423
+ cfl += (' ' + cf)
424
+ end
425
+ end
426
+
427
+ # format include paths
428
+ cfig.includePaths.each do |dir|
429
+ cfl += " /I\"#{dir}\"";
430
+ end
431
+
432
+ # format CPP macro defs
433
+ cfig.cppDefines.each do |k,v|
434
+ cfl += " /D\"#{k}#{v ? '='+v : ''}\""
435
+ end
436
+ cfig.set(:msvcFlags_,cfl)
437
+ end
438
+ cfl
439
+ end
440
+
441
+ @@compileCPPAction = lambda do |t|
442
+ t.config.ctools.doCompileCpp(t)
443
+ end
444
+ @@compileCAction = @@compileCPPAction;
445
+
446
+ @@compileRCAction = lambda do |t|
447
+ t.config.ctools.doCompileRc(t)
448
+ end
449
+
450
+ @@CompileForSuffix = {};
451
+
452
+ def self.addCompileAction(suff,action)
453
+ @@CompileForSuffix[suff] = action;
454
+ end
455
+
456
+
457
+ addCompileAction('.cpp', @@compileCPPAction);
458
+ addCompileAction('.c', @@compileCAction);
459
+ addCompileAction('.rc', @@compileRCAction);
460
+
461
+ def getCompileActionForSuffix(suff)
462
+ @@CompileForSuffix[suff]
463
+ end
464
+
465
+ def doCompileCpp(t)
466
+
467
+ cppfile = t.source;
468
+ objfile = t.name;
469
+ cfig = t.config;
470
+
471
+ cmdline = "\"#{@MSVC_EXE}\" \"#{cppfile}\" -Fd\"#{cfig.nativeObjDir}/vc80.pdb\" -c -Fo\"#{objfile}\" ";
472
+ cmdline += getFormattedMSCFlags(cfig)
473
+ cmdline += ' /showIncludes'
474
+
475
+ log.info("\n#{cmdline}\n") if(cfig.verbose?)
476
+
477
+ included = Rakish::FileSet.new
478
+
479
+ IO.popen(cmdline) do |output|
480
+ while line = output.gets do
481
+ if line =~ /^Note: including file: +/
482
+ line = $'.strip.gsub(/\\/,'/')
483
+ next if( line =~ /^[^\/]+\/Program Files\/Microsoft /i )
484
+ included << line
485
+ next
486
+ end
487
+ log.info line.strip!
488
+ end
489
+ end
490
+
491
+ STDOUT.flush # for the visual C command window.
492
+
493
+ depfile = objfile.ext('.raked');
494
+ updateDependsFile(t,depfile,included);
495
+ end
496
+
497
+ # Override for CTools
498
+ def initCompileTask(cfg)
499
+ cfg.project.addCleanFiles("#{cfg.nativeObjectPath()}/*#{OBJEXT()}",
500
+ "#{cfg.nativeObjectPath()}/*.sbr");
501
+ Rake::Task.define_task :compile => [:includes,
502
+ cfg.nativeObjectPath(),
503
+ :depends]
504
+ end
505
+
506
+
507
+ @@buildLibAction = lambda do |t|
508
+ t.config.ctools.doBuildLib(t)
509
+ end
510
+ def doBuildLib(t)
511
+
512
+ cfg = t.config;
513
+
514
+
515
+ #STATIC_LIB_FILES += $(addsuffix .lib,$(call GET_REFERENCES,$(STATIC_LIBS),$(OUTPUT_PATH)))
516
+ #SHARED_LIBS_FILES := $(addsuffix .lib,$(call GET_REFERENCES,$(SHARED_LIBS),$(OUTPUT_PATH)))
517
+ #
518
+ #$(TARGET_FILE): $(OBJS) $(STATIC_LIB_FILES)
519
+
520
+ # assemble a static library
521
+ log.info("asembling #{File.basename(t.name)}")
522
+ deleteFile(t.name)
523
+ writeLinkref(cfg,cfg.targetBaseName,t.name);
524
+ lnkfile = t.name.pathmap("#{cfg.nativeObjectPath}/%f.response");
525
+
526
+ # echo -n $(PROJECT_TARGET_NAME)-$(nativeOutputSuffix) > $(TARGET_REF)
527
+ # @echo -n "$(CPP_OBJS_BASE) $(C_OBJS_BASE)" > $(TARGET_LOBJ)
528
+
529
+ File.open(lnkfile,'w') do |f|
530
+ f.puts("#{@LIB_OPTIONS} -nodefaultlib -out:\"#{t.name}\"" );
531
+ # object files
532
+ objs = t.prerequisites
533
+ objs.flatten.each do |obj|
534
+ obj = obj.to_s
535
+ next unless obj.pathmap('%x') == '.obj'
536
+ f.puts("\"#{obj}\"");
537
+ end
538
+ # library files
539
+ # @echo -n " $(STATIC_LIB_FILES) $(SHARED_LIBS_FILES)" >> $(TARGET_LNK)
540
+ end
541
+
542
+ cmdline = "\"#{@LINK_EXE}\" -lib -nologo @#{lnkfile}\""
543
+ system( cmdline );
544
+ end
545
+
546
+ @@linkDllAction = lambda do |t|
547
+ t.config.ctools.doLinkDll(t)
548
+ end
549
+ def doLinkDll(t)
550
+
551
+ # link a dynamic library
552
+ cfg = t.config;
553
+
554
+ log.info("linking #{File.basename(t.name)}")
555
+ deleteFile(t.name);
556
+ writeLinkref(cfg,cfg.targetBaseName,t.sources[:implib]);
557
+
558
+ lnkfile = t.name.pathmap("#{cfg.nativeObjectPath()}/%f.response");
559
+
560
+ # build linker source file
561
+ begin
562
+
563
+ #STATIC_LIB_FILES += $(addprefix $(OUTPUT_PATH)/,$(addsuffix -$(UNVERSIONED_SUFFIX).lobj,$(STATIC_LIBS)))
564
+ #SHARED_LIBS_FILES := $(addsuffix .lib,$(call GET_REFERENCES,$(SHARED_LIBS),$(OUTPUT_PATH)))
565
+ #
566
+
567
+ File.open(lnkfile,'w') do |f|
568
+ f.puts("-map:\"#{t.sources[:mapfile]}\"");
569
+ f.puts("-pdb:\"#{t.sources[:pdbfile]}\"");
570
+ f.puts("-implib:\"#{t.sources[:implib]}\"");
571
+ f.puts("-DLL #{@LINK_OPTS}");
572
+
573
+ # library search paths
574
+ eachof cfg.libpaths do |lpath|
575
+ f.puts("-libpath:\"#{lpath}\"");
576
+ end
577
+
578
+ # libraries
579
+ libs=[]
580
+
581
+ libs << @SDK_LIBS;
582
+ libs << cfg.dependencyLibs
583
+ libs << cfg.libs
584
+ libs.flatten.each do |obj|
585
+ f.puts("\"#{obj}\"");
586
+ end
587
+
588
+ f.puts("-nodefaultlib -out:\"#{t.name}\"");
589
+
590
+ # object files
591
+ objs=[]
592
+ objs << t.sources[:userobjs];
593
+ objs << t.sources[:autores];
594
+ objs.flatten.each do |obj|
595
+ obj = obj.to_s
596
+ next unless obj.pathmap('%x') == '.obj'
597
+ f.puts("\"#{obj}\"");
598
+ end
599
+ end
600
+ rescue => e
601
+ log.error("error precessing: #{lnkfile} #{e}")
602
+ raise e
603
+ end
604
+
605
+ cmdline = "\"#{@LINK_EXE}\" -nologo @\"#{lnkfile}\"";
606
+ log.info(cmdline) if(cfg.verbose?)
607
+ system( cmdline );
608
+
609
+ #ifeq ($(RUN_SIGNTOOL),1)
610
+ # @echo "Signing $(notdir $(TARGET_FILE))"; \
611
+ # $(SIGNTOOL_EXE) -in $(TARGET_FILE) -out $(TARGET_FILE).signed
612
+ # @rm $(TARGET_FILE); \
613
+ # mv $(TARGET_FILE).signed $(TARGET_FILE)
614
+ #endif
615
+ end
616
+
617
+ @@linkAppAction = lambda do |t|
618
+ t.config.ctools.doLinkApp(t)
619
+ end
620
+ def doLinkApp(t)
621
+
622
+ cfg = t.config;
623
+ # link an application
624
+ log.info("linking #{File.basename(t.name)}")
625
+
626
+ deleteFile(t.name);
627
+ lnkfile = t.name.pathmap("#{cfg.nativeObjectPath}/%f.response");
628
+
629
+ # build linker source file
630
+ begin
631
+ File.open(lnkfile,'w') do |f|
632
+ f.puts("-out:\"#{t.name}\"");
633
+ f.puts("-map:\"#{t.sources[:mapfile]}\"");
634
+ f.puts("-pdb:\"#{t.sources[:pdbfile]}\"");
635
+ f.puts("#{@LINK_OPTS}");
636
+
637
+ # library search paths
638
+ eachof cfg.libpaths do |lpath|
639
+ f.puts("-libpath:\"#{lpath}\"");
640
+ end
641
+
642
+ # object files
643
+ objs=[]
644
+ objs << t.sources[:userobjs];
645
+ objs <<= t.sources[:autores];
646
+ objs.flatten.each do |obj|
647
+ obj = obj.to_s
648
+ next unless obj.pathmap('%x') == '.obj'
649
+ f.puts("\"#{obj}\"");
650
+ end
651
+
652
+ libs=[]
653
+ libs << @SDK_LIBS;
654
+ libs << cfg.dependencyLibs
655
+ libs << cfg.libs
656
+ libs.flatten.each do |obj|
657
+ f.puts("\"#{obj}\"");
658
+ end
659
+ end
660
+ rescue => e
661
+ log.error("error precessing: #{lnkfile} #{e}")
662
+ raise e
663
+ end
664
+
665
+ cmdline = "\"#{@LINK_EXE}\" -nologo @\"#{lnkfile}\"";
666
+ log.info(cmdline) if(cfg.verbose?)
667
+ system( cmdline );
668
+ end
669
+
670
+ @@makeManifestAction = lambda do |t|
671
+ t.config.tools.doMakeManifest(t)
672
+ end
673
+ def doMakeManifest(t)
674
+ log.info("Generating #{File.basename(t.name)}");
675
+ data = t.data;
676
+ cp(@ManifestSource, data[:txt],:verbose => false)
677
+ File.open(t.name,'w') do |f|
678
+ f.puts "#include <windows.h>"
679
+ if(@BASELINKAGE === 'Dynamic' && t.config.isLibrary)
680
+ id = 'ISOLATIONAWARE_MANIFEST_RESOURCE_ID'
681
+ else
682
+ id = 'CREATEPROCESS_MANIFEST_RESOURCE_ID'
683
+ end
684
+ f.puts "#{id} RT_MANIFEST \"#{File.basename(data[:txt])}\""
685
+ end
686
+ end
687
+
688
+ def doCompileRc(t)
689
+ compileRcFile(t.config,t.sources[0],t.name.pathmap('%X.res'));
690
+ compileResFile(t.config,t.name.pathmap('%X.res'),t.name);
691
+ end
692
+
693
+ def compileRcFile(cfg,rc,res)
694
+ log.info(rc.pathmap('%f'));
695
+ cmdline = "\"#{@RC_EXE}\" -nologo -I\"#{cfg.thirdPartyPath}/tools/winsdk/include\""
696
+ cmdline += " -I\"#{cfg.thirdPartyPath}/tools/msvc9/include\""
697
+ cmdline += " -I\"#{cfg.thirdPartyPath}/tools/msvc9/atlmfc/include\""
698
+ cmdline += " -fo\"#{res}\" \"#{rc}\""
699
+ system cmdline
700
+ end
701
+
702
+ def compileResFile(cfg,res,obj)
703
+ cmdline = "\"#{@CVTRES_EXE}\" #{@MACHINE_SPEC} -nologo -out:\"#{obj}\" \"#{res}\""
704
+ system(cmdline)
705
+ end
706
+
707
+ def getAutoResourcesObjs(cfg)
708
+
709
+ return []; # for now
710
+
711
+ resobjs=[]
712
+ rcobjs=[]
713
+ basePath = File.join(cfg.nativeObjectPath,cfg.targetBaseName);
714
+
715
+ if(@ManifestSource) # not present if not needed
716
+ manifest_rc = "#{basePath}.manifest.rc"
717
+ tsk = lookupTask(manifest_rc)
718
+ unless(tsk)
719
+ manifest_txt = "#{basePath}.manifest"
720
+ # manifest resource
721
+ cfg.project.addCleanFiles(manifest_rc,manifest_txt);
722
+
723
+ tsk = Rake::FileTask.define_task manifest_rc => [ cfg.nativeObjectPath, cfg.projectFile, @ManifestSource ]
724
+ tsk.enhance &@@makeManifestAction;
725
+ tsk.config = cfg
726
+ tsk.data = { :txt=>manifest_txt }
727
+ end
728
+ rcobjs <<= tsk
729
+ end
730
+
731
+ autores_obj = "#{basePath}.auto_resources.obj"
732
+ tsk = lookupTask(autores_obj)
733
+ unless(tsk)
734
+ autores_rc = "#{basePath}.auto_resources.rc"
735
+ autores_res = "#{basePath}.auto_resources.res"
736
+
737
+ cfg.project.addCleanFiles(autores_rc,autores_res,autores_obj);
738
+
739
+ restask = Rake::FileTask.define_task autores_obj => [ cfg.nativeObjectPath, cfg.projectFile, rcobjs].flatten do |t|
740
+ log.info("Generating #{t.name}")
741
+ File.open(autores_rc,'w') do |f|
742
+ t.sources.each do |src|
743
+ f.puts("#include \"#{File.basename(src.to_s)}\"")
744
+ end
745
+ end
746
+ compileRcFile(cfg,autores_rc,autores_res);
747
+ compileResFile(cfg,autores_res,t.name);
748
+ end
749
+ restask.sources = rcobjs;
750
+ resobjs <<= restask;
751
+ end
752
+ return(resobjs)
753
+ end
754
+
755
+ @@resolveLinkAction_ = lambda do |t|
756
+ end
757
+
758
+ def createLinkTask(objs,cfg)
759
+
760
+ case(cfg.targetType)
761
+
762
+ when 'APP'
763
+
764
+ targetName = "#{cfg.binDir()}/#{cfg.targetName}.exe";
765
+
766
+ resobjs = getAutoResourcesObjs(cfg)
767
+ mapfile = targetName.pathmap("%X.map");
768
+ pdbfile = targetName.pathmap("%X.pdb");
769
+ cfg.project.addCleanFiles(mapfile,pdbfile);
770
+
771
+ doLink = Rake::FileTask.define_task targetName => resobjs, &@@linkAppAction;
772
+ doLink.sources = {
773
+ :userobjs=>objs,
774
+ :autores=>resobjs,
775
+ :mapfile=>mapfile,
776
+ :pdbfile=>pdbfile,
777
+ }
778
+
779
+ when 'LIB'
780
+
781
+ targetName = "#{cfg.nativeLibDir()}/#{cfg.targetName}.lib";
782
+ doLink = Rake::FileTask.define_task targetName,
783
+ &@@buildLibAction;
784
+
785
+ when 'DLL'
786
+
787
+ targetName = "#{cfg.binDir()}/#{cfg.targetName}.dll";
788
+
789
+ #LIBS_DEP_WINDOWS := $(subst $(THIRD_PARTY_PATH),$(THIRD_PARTY_PATH),$(THIRD_PARTY_LIB_FILES) $(SPECIFIC_LIBS))
790
+ #$(TARGET_FILE): $(OBJS) $(STATIC_LIB_FILES) $(AUTORESOURCES_OBJ) $(LIBS_DEP_WINDOWS)
791
+
792
+ resobjs = getAutoResourcesObjs(cfg)
793
+
794
+ mapfile = targetName.pathmap("%X.map");
795
+ pdbfile = targetName.pathmap("%X.pdb");
796
+ implib = "#{cfg.binDir()}/#{cfg.targetName}.lib";
797
+
798
+ cfg.project.addCleanFiles(mapfile,pdbfile,implib);
799
+
800
+ doLink = Rake::FileTask.define_task targetName => resobjs, &@@linkDllAction;
801
+ doLink.sources = {
802
+ :userobjs=>objs,
803
+ :autores=>resobjs,
804
+ :mapfile=>mapfile,
805
+ :pdbfile=>pdbfile,
806
+ :implib=>implib
807
+ }
808
+
809
+ else
810
+ log.info("unsupported target type #{cfg.targetType}");
811
+ return(false);
812
+ end
813
+
814
+ cfg.project.addCleanFiles(targetName);
815
+
816
+ doLink.config = cfg;
817
+ doLink.enhance(objs);
818
+
819
+ # create a "setup" task to resolve everything and set up the link.
820
+ tsk = task "#{cfg.targetName}.#{cfg.targetType}.resolve", &@@resolveLinkAction_;
821
+ tsk.config = doLink;
822
+
823
+ [ tsk, doLink ] # note this returns an array !!!
824
+ end
825
+
826
+ end
827
+
828
+
829
+ def self.getConfiguredTools(cfgs,strCfg)
830
+
831
+ if(cfgs.length != 4)
832
+ raise InvalidConfigError.new(strCfg, "must be 4 \"-\" separated elements");
833
+ end
834
+
835
+ error = false;
836
+ compiler = nil
837
+ linkType = nil;
838
+ debugType = nil;
839
+
840
+ cfgs.each do |cfg|
841
+ cmp = VALID_COMPILERS[cfg];
842
+ if(cmp)
843
+ error = compiler;
844
+ compiler = cfg;
845
+ next
846
+ end
847
+ cmp = VALID_LINKTYPES[cfg];
848
+ if(cmp)
849
+ error = linkType;
850
+ linkType = cfg;
851
+ next
852
+ end
853
+ cmp = VALID_DEBUGTYPES[cfg];
854
+ if(cmp)
855
+ error = debugType;
856
+ debugType = cfg;
857
+ next
858
+ end
859
+ end
860
+
861
+ if(error)
862
+ raise InvalidConfigError.new(strCfg, "element present more than once");
863
+ end
864
+
865
+ if(!(compiler && linkType && debugType))
866
+ raise InvalidConfigError.new(strCfg, "invalid or missing element");
867
+ end
868
+
869
+ # ensure order of elements is "standard"
870
+ cfgs[1] = compiler;
871
+ cfgs[2] = linkType;
872
+ cfgs[3] = debugType;
873
+
874
+ platformBits = '32';
875
+ if(cfgs[0] =~ /\d+/)
876
+ platformType = $`;
877
+ platformBits = $&;
878
+ end
879
+ if(platformType === 'Win')
880
+ platformType = 'Windows';
881
+ end
882
+
883
+ args= {
884
+ :split=>cfgs,
885
+ :platformBits=>platformBits,
886
+ :platformType=>platformType,
887
+ :compiler=>compiler,
888
+ :linkType=>linkType,
889
+ :debugType=>debugType
890
+ }
891
+ return( Win32Tools.new(args));
892
+ # log.debug { "config validated #{cfgs.join('-')}" };
893
+ end
894
+
895
+ end);
896
+
897
+ end # Rakish