-
Notifications
You must be signed in to change notification settings - Fork 5
/
wx-config-win.cpp
2608 lines (2121 loc) · 91.1 KB
/
wx-config-win.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
////////////////////////////////////////////////////////////////////////////////////////////////////
// Name: wx-config-win.cpp
// Purpose: A wx-config implementation for Windows
// Author: Takeshi Miya
// Created: 2006-03-23
// Copyright: (c) Takeshi Miya
// Licence: wxWidgets licence
// $Rev$
// $URL$
// $Date$
// $Id$
////////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <cstdlib>
#include <map>
#include <fstream>
#include <algorithm>
#include <vector>
#include <windows.h>
// -------------------------------------------------------------------------------------------------
std::string getSvnRevision()
{
std::string str = "$Rev$";
if (str.length() > 8)
return str.substr(6, str.length()-8);
else
return "X";
}
std::string getSvnDate()
{
std::string str = "$Date$";
if (str.length() > 16)
return str.substr(7, 10);
else
return "2006-XX-XX";
}
static const std::string g_tokError = "wx-config Error: ";
static const std::string g_tokWarning = "wx-config Warning: ";
// -------------------------------------------------------------------------------------------------
/// Program options
class Options
{
public:
std::string& operator[](const std::string& key)
{
return m_vars[key];
}
bool keyExists(const std::string& key) const
{
return m_vars.count(key) != 0;
}
const std::string& keyValue(const std::string& key) const
{
return m_vars.find(key)->second;
}
std::map<std::string,std::string>& getVars()
{
return m_vars;
}
protected:
std::map<std::string,std::string> m_vars;
};
// -------------------------------------------------------------------------------------------------
/// File build.cfg/config.* options
class BuildFileOptions : public Options
{
public:
BuildFileOptions(const std::string& filepath)
{
parse(filepath);
}
bool parse(const std::string& filepath)
{
std::string line;
std::ifstream file(filepath.c_str());
if (file.is_open())
{
while (!file.eof() )
{
std::getline(file, line);
// it's a comment line
if (line.find_first_of('#') != std::string::npos)
continue;
// strip spaces
line.erase( std::remove(line.begin(), line.end(), ' '), line.end() );
split(line);
}
file.close();
if (!m_vars.empty())
return true;
}
else
std::cout << g_tokError << "Unable to open file '" << filepath.c_str() << "'." << std::endl;
return false;
}
protected:
void split(const std::string& line)
{
size_t sep = line.find('=');
if (sep != std::string::npos)
{
std::string key = line.substr(0, sep);
std::string val = line.substr(sep+1, line.size()-sep-1);
m_vars[key] = val;
}
}
};
// -------------------------------------------------------------------------------------------------
/// File setup.h options
class SetupHOptions
{
public:
bool& operator[](const std::string& key)
{
return m_vars[key];
}
bool keyExists(const std::string& key) const
{
return m_vars.count(key) != 0;
}
bool keyValue(const std::string& key) const
{
return m_vars.find(key)->second;
}
typedef std::map<std::string,bool> StringBoolMap;
StringBoolMap& getVars()
{
return m_vars;
}
protected:
StringBoolMap m_vars;
public:
SetupHOptions(const std::string& filepath)
{
parse(filepath);
}
bool parse(const std::string& filepath)
{
std::string line;
std::ifstream file(filepath.c_str());
if (file.is_open())
{
while (!file.eof())
{
std::getline(file, line);
// does the splitting/parsing
split(line);
}
file.close();
if (!m_vars.empty())
return true;
}
else
std::cout << g_tokError << "Unable to open file '" << filepath.c_str() << "'." << std::endl;
return false;
}
void printDebug()
{
std::cout << "DEBUG: setup.h contents BEGIN -------------------------------------------------" << std::endl;
for (StringBoolMap::iterator it = m_vars.begin(); it != m_vars.end(); ++it)
std::cout << it->first << "=" << it->second << std::endl;
std::cout << "DEBUG: setup.h contents END ---------------------------------------------------" << std::endl;
}
protected:
void split(std::string& line)
{
// it's a comment line
if (line.find_first_of('/') != std::string::npos)
return; // skips the line
// strip spaces and tabs
line.erase( std::remove(line.begin(), line.end(), ' '), line.end() );
line.erase( std::remove(line.begin(), line.end(), '\t'), line.end() );
std::string tokDefine("#define");
size_t posDefine = line.find_first_of(tokDefine);
// it's a #define line
if (posDefine != std::string::npos)
{
std::string key;
bool val;
// resolves val, checking if last char is 0 or 1
char lastChar = line.at(line.length()-1); // TODO: I don't like this line :P
if (lastChar == '0')
val = false;
else if (lastChar == '1')
val = true;
else
return; // skips the line
// resolves key
size_t startPos = posDefine + tokDefine.length();
key = line.substr(startPos, line.length() - startPos - 1);
// finally saves the parsed data!
m_vars[key] = val;
}
}
};
// -------------------------------------------------------------------------------------------------
/// Command line options
class CmdLineOptions : public Options
{
public:
CmdLineOptions(int argc, char* argv[])
{
parse(argc, argv);
}
bool validArgs()
{
bool valid = keyExists("--compiler") ||
keyExists("--easymode") ||
keyExists("--variable") ||
keyExists("--define-variable") ||
keyExists("--prefix") ||
keyExists("--wxcfg") ||
keyExists("--libs") ||
keyExists("--cflags") ||
keyExists("--cxxflags") ||
keyExists("--cppflags") ||
keyExists("--rcflags") ||
keyExists("--list") ||
keyExists("--debug") ||
keyExists("--unicode") ||
keyExists("--static") ||
keyExists("--universal") ||
keyExists("--release") ||
keyExists("--version") ||
keyExists("--basename") ||
keyExists("--cc") ||
keyExists("--cxx") ||
keyExists("--ld") ||
keyExists("-v");
// TODO: not all flags are being validated
if(!valid)
{
if (m_vars.size() > 1 && !keyExists("--help"))
std::cout << g_tokError << "Unrecognised option: '" << m_vars.begin()->first << "'\n" << std::endl;
std::cerr << "Usage: wx-config [options]\n";
std::cerr << "Options:\n";
std::cerr << " --prefix[=DIR] Path of the wxWidgets installation (ie. C:\\wxWidgets2.6.3)\n";
std::cerr << " --wxcfg[=DIR] Relative path of the build.cfg file (ie. gcc_dll\\mswud)\n";
// std::cerr << " --list Lists all the library configurations. [NOT IMPLEMENTED]\n";
std::cerr << " --cflags Outputs all pre-processor and compiler flags.\n";
std::cerr << " --cxxflags Same as --cflags but for C++.\n";
std::cerr << " --rcflags Outputs all resource compiler flags. [UNTESTED]\n";
std::cerr << " --libs Outputs all linker flags.\n";
std::cerr << std::endl;
std::cerr << " --debug[=yes|no] Uses a debug configuration if found.\n";
std::cerr << " --unicode[=yes|no] Uses an unicode configuration if found.\n";
std::cerr << " --static[=yes|no] Uses a static configuration if found.\n";
std::cerr << " --universal[=yes|no] Uses an universal configuration if found.\n";
// std::cerr << " --easymode[=yes|no] Outputs warnings, and optimize flags.\n";
std::cerr << " --compiler[=gcc,dmc,vc] Selects the compiler.\n";
// std::cerr << " --variable=NAME Returns the value of a defined variable.\n";
// std::cerr << " --define-variable=NAME=VAL Sets a global value for a variable.\n";
std::cerr << " --release Outputs the wxWidgets release number.\n";
std::cerr << " --version Outputs the wxWidgets version.\n";
std::cerr << " --basename Outputs the base name of the wxWidgets libraries.\n";
std::cerr << " --cc Outputs the name of the C compiler.\n";
std::cerr << " --cxx Outputs the name of the C++ compiler.\n";
std::cerr << " --ld Outputs the linker command.\n";
std::cerr << " -v Outputs the revision of wx-config.\n";
std::cerr << std::endl;
std::cerr << " Note that using --prefix is not needed if you have defined the \n";
std::cerr << " environmental variable WXWIN.\n";
std::cerr << std::endl;
std::cerr << " Also note that using --wxcfg is not needed if you have defined the \n";
std::cerr << " environmental variable WXCFG.\n";
std::cerr << std::endl;
}
return valid;
}
bool parse(int argc, char* argv[])
{
for(int i=0; i<argc; ++i)
{
std::string line;
line = argv[i];
split(line);
}
parseLibs(argv[argc-1]);
return true;
}
std::vector<std::string> getLibs() const
{
return m_libs;
}
protected:
void split(const std::string& line)
{
size_t sep = line.find("=");
if (sep != std::string::npos)
{
std::string key = line.substr(0, sep);
std::string val = line.substr(sep+1, line.size()-sep-1);
m_vars[key] = val;
}
else
m_vars[line] = "";
}
bool libExists(const std::string& lib)
{
return std::find(m_libs.begin(), m_libs.end(), lib) != m_libs.end();
}
void addLib(const std::string& lib)
{
// adds the lib if its not present already
if (!libExists(lib))
m_libs.push_back(lib);
}
void parseLibs(const std::string libs)
{
std::string param = libs;
// if the last parameter doesn't haves a -- switch
if (param.find("--") == std::string::npos)
{
// saves in the vector, comma separated text like "text1,text2,text3,text4"
while(true)
{
size_t comma = param.find(",");
if (comma != std::string::npos)
{
m_libs.push_back(param.substr(0, comma));
param = param.substr(comma+1, param.size()-comma-1);
}
else
{
m_libs.push_back(param);
break;
}
}
}
// assuming magic keyword 'std' as a lib parameter for non-monolithic
// magic keyword std: links with xrc,qa,html,adv,core,base_xml,base_net,base
if (m_libs.empty() || libExists("std"))
{
addLib("xrc");
addLib("qa");
addLib("html");
addLib("adv");
addLib("core");
addLib("xml");
addLib("net");
addLib("base");
}
}
std::vector<std::string> m_libs;
};
// -------------------------------------------------------------------------------------------------
/// Struct to keep programs
struct CompilerPrograms
{
std::string cc; // C compiler
std::string cxx; // C++ compiler
std::string ld; // dynamic libs linker
std::string lib; // static libs linker
std::string windres; // resource compiler
};
/// Struct to keep switches
struct CompilerSwitches
{
std::string includeDirs; // -I
std::string resIncludeDirs; // --include-dir
std::string libDirs; // -L
std::string linkLibs; // -l
std::string libPrefix; // lib
std::string libExtension; // a
std::string defines; // -D
std::string resDefines; // --define
std::string genericSwitch; // -
std::string objectExtension; // o
bool forceLinkerUseQuotes; // use quotes for filenames in linker command line (needed or not)?
bool forceCompilerUseQuotes; // use quotes for filenames in compiler command line (needed or not)?
bool linkerNeedsLibPrefix; // when adding a link library, linker needs prefix?
bool linkerNeedsLibExtension; // when adding a link library, linker needs extension?
bool supportsPCH; // supports precompiled headers?
std::string PCHExtension; // precompiled headers extension
};
static bool g_sEasyMode = false;
void checkEasyMode(CmdLineOptions& cl)
{
if (cl.keyExists("--easymode"))
{
if (cl["--easymode"] == "no")
g_sEasyMode = false;
else if (cl["--easymode"] == "yes" || cl["--easymode"].empty())
g_sEasyMode = true;
}
}
/// Compiler abstract base class
class Compiler
{
public:
Compiler(const std::string& name) : m_name(name) {}
// ~Compiler();
std::string easyMode(const std::string& str)
{
if (g_sEasyMode)
return str;
else
return std::string();
}
std::string addFlag(const std::string& flag)
{
if (flag.empty())
return "";
return flag + " ";
}
std::string addLib(const std::string& lib)
{
std::string result;
result = m_switches.linkLibs;
if (m_switches.linkerNeedsLibPrefix)
result += m_switches.libPrefix;
result += lib;
if (m_switches.linkerNeedsLibExtension)
result += "." + m_switches.libExtension;
result += " ";
if (lib.empty())
return "";
return result;
}
std::string addDefine(const std::string& define)
{
if (define.empty())
return "";
return m_switches.defines + define + " ";
}
std::string addResDefine(const std::string& resDefine)
{
if (resDefine.empty())
return "";
return m_switches.resDefines + " " + resDefine + " ";
}
std::string addIncludeDir(const std::string& includeDir)
{
if (includeDir.empty())
return "";
return m_switches.includeDirs + includeDir + " ";
}
std::string addLinkerDir(const std::string& libDir)
{
if (libDir.empty())
return "";
return m_switches.libDirs + libDir + " ";
}
std::string addResIncludeDir(const std::string& resIncludeDir)
{
if (resIncludeDir.empty())
return "";
return m_switches.resIncludeDirs + " " + resIncludeDir + " ";
}
/*
std::string addResLinkerDir(const std::string& resLibDir)
{
if (resLibDir.empty())
return "";
return m_switches.libDirs + libDir + " ";
}*/
std::string getName() const
{
return m_name;
}
void process_3(Options& po, const CmdLineOptions& cl, BuildFileOptions& cfg)
{
SetupHOptions sho(po["wxcfgsetuphfile"]);
// FIXME: proper place of this would be in a first hook, say process_1();
if (cl.keyExists("--define-variable"))
{
std::string strDef = cl.keyValue("--define-variable");
size_t sep = strDef.find("=");
if (sep != std::string::npos)
{
std::string key = strDef.substr(0, sep);
std::string val = strDef.substr(sep+1, strDef.size()-sep-1);
po[key] = val;
cfg[key] = val;
if (val == "1" || val == "true")
sho[key] = true;
else if (val == "0" || val == "false")
sho[key] = false;
}
else
{
std::cout << g_tokError << "Failed to define a variable as '" << cl.keyValue("--define-variable") << "'." << std::endl;
std::cout << "The syntax is --define-variable=VARIABLENAME=VARIABLEVALUE" << std::endl;
exit(1);
}
}
/// Overriding flags sho->cfg!!
/// This makes sho variables haves more privilege than cfg ones
//-------------------------------------------------------------
if (sho.keyExists("wxUSE_UNICODE_MSLU"))
sho["wxUSE_UNICODE_MSLU"] ? cfg["MSLU"] = "1" : cfg["MSLU"] = "0";
// TODO: probably better!!!:
if (cfg.keyExists("MSLU"))
sho["wxUSE_UNICODE_MSLU"] ? cfg["MSLU"] = "1" : cfg["MSLU"] = "0";
//-------------------------------------------------------------
/// Overriding compiler programs
if (cfg.keyExists("CC"))
m_programs.cc = cfg["CC"];
if (cfg.keyExists("CXX"))
m_programs.cxx = cfg["CXX"];
if (cfg.keyExists("LD"))
m_programs.ld = cfg["LD"];
if (cfg.keyExists("LIB"))
m_programs.lib = cfg["LIB"];
if (cfg.keyExists("WINDRES"))
m_programs.windres = cfg["WINDRES"];
//-------------------------------------------------------------
// BASENAME variables
po["LIB_BASENAME_MSW"] = "wx" + po["PORTNAME"] + po["WXUNIVNAME"] + po["WX_RELEASE_NODOT"];
po["LIB_BASENAME_MSW"] += po["WXUNICODEFLAG"] + po["WXDEBUGFLAG"] + cfg["WX_LIB_FLAVOUR"];
po["LIB_BASENAME_BASE"] = "wxbase" + po["WX_RELEASE_NODOT"] + po["WXUNICODEFLAG"];
po["LIB_BASENAME_BASE"] += po["WXDEBUGFLAG"] + cfg["WX_LIB_FLAVOUR"];
for (size_t i=0; i<cl.getLibs().size(); ++i)
{
std::string lib = cl.getLibs()[i];
if (lib == "base")
{
if (cfg["MONOLITHIC"] == "0")
po["__WXLIB_BASE_p"] = addLib(po["LIB_BASENAME_BASE"]);
}
else if (lib == "net")
{
if (cfg["MONOLITHIC"] == "0")
po["__WXLIB_NET_p"] = addLib(po["LIB_BASENAME_BASE"] + "_net");
}
else if (lib == "xml")
{
if (cfg["MONOLITHIC"] == "0")
po["__WXLIB_XML_p"] = addLib(po["LIB_BASENAME_BASE"] + "_xml");
}
else if (lib == "core")
{
if (cfg["MONOLITHIC"] == "0")
if (cfg["USE_GUI"] == "1")
po["__WXLIB_CORE_p"] = addLib(po["LIB_BASENAME_MSW"] + "_core");
}
else if (lib == "adv")
{
if (cfg["MONOLITHIC"] == "0")
if (cfg["USE_GUI"] == "1")
po["__WXLIB_ADV_p"] = addLib(po["LIB_BASENAME_MSW"] + "_adv");
}
else if (lib == "qa")
{
if (cfg["MONOLITHIC"] == "0")
{
if (cfg["USE_GUI"] == "1")
{
if (cfg["USE_QA"] == "1")
{
po["__WXLIB_QA_p"] = addLib(po["LIB_BASENAME_MSW"] + "_qa");
po["__WXLIB_CORE_p"] = addLib(po["LIB_BASENAME_MSW"] + "_core");
po["__WXLIB_XML_p"] = addLib(po["LIB_BASENAME_BASE"] + "_xml");
}
}
}
}
else if (lib == "xrc")
{
if (cfg["MONOLITHIC"] == "0")
{
if (cfg["USE_GUI"] == "1")
{
if (cfg["USE_XRC"] == "1")
{
po["__WXLIB_XRC_p"] = addLib(po["LIB_BASENAME_MSW"] + "_xrc");
po["__WXLIB_XML_p"] = addLib(po["LIB_BASENAME_BASE"] + "_xml");
po["__WXLIB_ADV_p"] = addLib(po["LIB_BASENAME_MSW"] + "_adv");
po["__WXLIB_HTML_p"] = addLib(po["LIB_BASENAME_MSW"] + "_html");
}
}
}
}
else if (lib == "aui")
{
if (cfg["MONOLITHIC"] == "0")
if (cfg["USE_GUI"] == "1")
if (cfg["USE_AUI"] == "1")
po["__WXLIB_AUI_p"] = addLib(po["LIB_BASENAME_MSW"] + "_aui");
}
else if (lib == "html")
{
if (cfg["MONOLITHIC"] == "0")
if (cfg["USE_GUI"] == "1")
if (cfg["USE_HTML"] == "1")
po["__WXLIB_HTML_p"] = addLib(po["LIB_BASENAME_MSW"] + "_html");
}
else if (lib == "media")
{
if (cfg["MONOLITHIC"] == "0")
if (cfg["USE_GUI"] == "1")
// if (cfg["USE_MEDIA"] == "1") // TODO: wx2.7 CVS haves an USE_MEDIA
po["__WXLIB_MEDIA_p"] = addLib(po["LIB_BASENAME_MSW"] + "_media");
}
else if (lib == "odbc")
{
if (cfg["MONOLITHIC"] == "0")
if (sho["wxUSE_ODBC"])
po["__WXLIB_ODBC_p"] = addLib(po["LIB_BASENAME_BASE"] + "_odbc");
}
else if (lib == "dbgrid")
{
if (cfg["MONOLITHIC"] == "0")
{
if (cfg["USE_GUI"] == "1")
{
if (sho["wxUSE_ODBC"])
{
po["__WXLIB_DBGRID_p"] = addLib(po["LIB_BASENAME_MSW"] + "_dbgrid");
po["__WXLIB_ODBC_p"] = addLib(po["LIB_BASENAME_BASE"] + "_odbc");
po["__WXLIB_ADV_p"] = addLib(po["LIB_BASENAME_MSW"] + "_adv");
}
}
}
}
else if (lib == "opengl" || lib == "gl")
{
// TODO: it's opengl or gl?
/// Doesn't matter if it's monolithic or not
if (cfg["USE_OPENGL"] == "1")
if (cfg["USE_GUI"] == "1")
po["__WXLIB_OPENGL_p"] = addLib(po["LIB_BASENAME_MSW"] + "_gl");
po["__WXLIB_OPENGL_p"] += addLib("opengl32");
po["__WXLIB_OPENGL_p"] += addLib("glu32");
}
else
{
/// Doesn't matter if it's monolithic or not
po["__WXLIB_ARGS_p"] += addLib(po["LIB_BASENAME_MSW"] + "_" + lib);
}
}
if (cfg["MONOLITHIC"] == "1")
po["__WXLIB_MONO_p"] = addLib(po["LIB_BASENAME_MSW"]);
/// External libs (to wxWidgets)
if (cfg["USE_GUI"] == "1")
if (sho["wxUSE_LIBTIFF"])
po["__LIB_TIFF_p"] = addLib("wxtiff" + po["WXDEBUGFLAG"]);
if (cfg["USE_GUI"] == "1")
if (sho["wxUSE_LIBJPEG"])
po["__LIB_JPEG_p"] = addLib("wxjpeg" + po["WXDEBUGFLAG"]);
if (cfg["USE_GUI"] == "1")
if (sho["wxUSE_LIBPNG"] && sho["wxUSE_ZLIB"])
po["__LIB_PNG_p"] = addLib("wxpng" + po["WXDEBUGFLAG"]);
if (sho["wxUSE_ZLIB"])
po["__LIB_ZLIB_p"] = addLib("wxzlib" + po["WXDEBUGFLAG"]);
if (sho["wxUSE_REGEX"])
po["__LIB_REGEX_p"] = addLib("wxregex" + po["WXUNICODEFLAG"] + po["WXDEBUGFLAG"]);
// FIXME: in truth the check should be for wxUSE_XML but... the sho parser is very simple :P
if (sho["wxUSE_XRC"])
po["__LIB_EXPAT_p"] = addLib("wxexpat" + po["WXDEBUGFLAG"]);
if (cfg["MSLU"] == "1")
po["__LIB_UNICOWS_p"] = addLib("unicows");
if (cfg["USE_GDIPLUS"] == "1")
po["__GDIPLUS_LIB_p"] = addLib("gdiplus");
po["__LIB_KERNEL32_p"] = addLib("kernel32");
po["__LIB_USER32_p"] = addLib("user32");
po["__LIB_GDI32_p"] = addLib("gdi32");
po["__LIB_COMDLG32_p"] = addLib("comdlg32");
po["__LIB_WINSPOOL_p"] = addLib("winspool");
po["__LIB_WINMM_p"] = addLib("winmm");
po["__LIB_SHELL32_p"] = addLib("shell32");
po["__LIB_COMCTL32_p"] = addLib("comctl32");
if (sho["wxUSE_OLE"])
po["__LIB_OLE32_p"] = addLib("ole32");
if (sho["wxUSE_OLE"])
po["__LIB_OLEAUT32_p"] = addLib("oleaut32");
if (sho["wxUSE_OLE"])
po["__LIB_OLEACC_p"] = addLib("oleacc"); // NOTE: not being used
if (sho["wxUSE_OLE"])
po["__LIB_OLE2W32_p"] = addLib("ole2w32"); // NOTE: not being used
po["__LIB_UUID_p"] = addLib("uuid");
po["__LIB_RPCRT4_p"] = addLib("rpcrt4");
po["__LIB_ADVAPI32_p"] = addLib("advapi32");
if (sho["wxUSE_SOCKETS"])
po["__LIB_WSOCK32_p"] = addLib("wsock32");
if (sho["wxUSE_ODBC"])
po["__LIB_ODBC32_p"] = addLib("odbc32");
/* TODO: From BAKEFILE
<!-- link-in system libs that wx depends on: -->
<!-- If on borland, we don't need to do much -->
<if cond="FORMAT=='borland'">
<sys-lib>ole2w32</sys-lib>
<sys-lib>odbc32</sys-lib>
</if>
<!-- Non-borland, on the other hand... -->
<if cond="FORMAT not in ['borland','msevc4prj']">
<sys-lib>kernel32</sys-lib>
<sys-lib>user32</sys-lib>
<sys-lib>gdi32</sys-lib>
<sys-lib>comdlg32</sys-lib>
<sys-lib>winspool</sys-lib>
<sys-lib>winmm</sys-lib>
<sys-lib>shell32</sys-lib>
<sys-lib>comctl32</sys-lib>
<sys-lib>ole32</sys-lib>
<sys-lib>oleaut32</sys-lib>
<sys-lib>uuid</sys-lib>
<sys-lib>rpcrt4</sys-lib>
<sys-lib>advapi32</sys-lib>
<sys-lib>wsock32</sys-lib>
<sys-lib>odbc32</sys-lib>
</if>
<!-- Libs common to both borland and MSVC -->
<if cond="FORMAT=='msvc' or FORMAT=='msvc6prj' or FORMAT=='borland'">
<sys-lib>oleacc</sys-lib>
*/
}
std::string getAllLibs(Options& po)
{
std::string libs;
libs += po["__WXLIB_ARGS_p"] + po["__WXLIB_OPENGL_p"] + po["__WXLIB_MEDIA_p"];
libs += po["__WXLIB_DBGRID_p"] + po["__WXLIB_ODBC_p"] + po["__WXLIB_XRC_p"];
libs += po["__WXLIB_QA_p"] + po["__WXLIB_AUI_p"] + po["__WXLIB_HTML_p"] + po["__WXLIB_ADV_p"];
libs += po["__WXLIB_CORE_p"] + po["__WXLIB_XML_p"] + po["__WXLIB_NET_p"];
libs += po["__WXLIB_BASE_p"] + po["__WXLIB_MONO_p"];
libs += po["__LIB_TIFF_p"] + po["__LIB_JPEG_p"] + po["__LIB_PNG_p"];
libs += po["__LIB_ZLIB_p"] + po["__LIB_REGEX_p"] + po["__LIB_EXPAT_p"];
libs += po["EXTRALIBS_FOR_BASE"] + po["__UNICOWS_LIB_p"] + po["__GDIPLUS_LIB_p"];
libs += po["__LIB_KERNEL32_p"] + po["__LIB_USER32_p"] + po["__LIB_GDI32_p"];
libs += po["__LIB_COMDLG32_p"] + po["__LIB_REGEX_p"] + po["__LIB_WINSPOOL_p"];
libs += po["__LIB_WINMM_p"] + po["__LIB_SHELL32_p"] + po["__LIB_COMCTL32_p"];
libs += po["__LIB_OLE32_p"] + po["__LIB_OLEAUT32_p"] + po["__LIB_UUID_p"];
libs += po["__LIB_RPCRT4_p"] + po["__LIB_ADVAPI32_p"] + po["__LIB_WSOCK32_p"];
libs += po["__LIB_ODBC32_p"];
return libs;
}
void getVariablesValues(Options& po, const CmdLineOptions& cl, BuildFileOptions& cfg)
{
if (cl.keyExists("--variable"))
{
std::string var = cl.keyValue("--variable");
if (po.keyExists(var))
po["variable"] += "PO: " + var + "=" + po[var] + "\n";
else
po["variable"] += "PO: " + var + " does not exist.\n";
if (cfg.keyExists(var))
po["variable"] += "CFG: " + var + "=" + cfg[var] + "\n";
else
po["variable"] += "CFG: " + var + " does not exist.\n";
}
}
protected:
// set the following members in your class
std::string m_name;
CompilerPrograms m_programs;
CompilerSwitches m_switches;
};
// -------------------------------------------------------------------------------------------------
/// MinGW compiler
class CompilerMinGW : public Compiler
{
public:
CompilerMinGW() : Compiler("gcc")
{
m_programs.cc = "mingw32-gcc";
m_programs.cxx = "mingw32-g++";
m_programs.ld = "mingw32-g++ -shared -fPIC -o ";
m_programs.lib = "ar.exe";
m_programs.windres = "windres";
m_switches.includeDirs = "-I";
m_switches.resIncludeDirs = "--include-dir";
m_switches.libDirs = "-L";
m_switches.linkLibs = "-l";
m_switches.libPrefix = "lib";
m_switches.libExtension = "a";
m_switches.defines = "-D";
m_switches.resDefines = "--define";
m_switches.genericSwitch = "-";
m_switches.forceCompilerUseQuotes = false;
m_switches.forceLinkerUseQuotes = false;
m_switches.linkerNeedsLibPrefix = false;
m_switches.linkerNeedsLibExtension = false;
m_switches.supportsPCH = true;
m_switches.PCHExtension = "h.gch";
}
void process(Options& po, const CmdLineOptions& cl)
{
/// Searchs for '<prefix>\build\msw\config.*' first
std::string cfg_first = po["prefix"] + "\\build\\msw\\config." + getName();
/// config.* options
BuildFileOptions cfg(cfg_first);
/// build.cfg options
cfg.parse(po["wxcfgfile"]);
// ### Variables: ###
po["WX_RELEASE_NODOT"] = cfg["WXVER_MAJOR"] + cfg["WXVER_MINOR"];
if (po["WX_RELEASE_NODOT"].empty())
po["WX_RELEASE_NODOT"] = "26";
// ### Conditionally set variables: ###
if (cfg["GCC_VERSION"] == "2.95")
po["GCCFLAGS"] = addFlag("-fvtable-thunks");
if (cfg["USE_GUI"] == "0")
po["PORTNAME"] = "base";
if (cfg["USE_GUI"] == "1")
po["PORTNAME"] = "msw";
if (cfg["BUILD"] == "debug" && cfg["DEBUG_FLAG"] == "default")
po["WXDEBUGFLAG"] = "d";
if (cfg["DEBUG_FLAG"] == "1")
po["WXDEBUGFLAG"] = "d";
if (cfg["UNICODE"] == "1")
po["WXUNICODEFLAG"] = "u";
if (cfg["WXUNIV"] == "1")
po["WXUNIVNAME"] = "univ";
if (cfg["SHARED"] == "1")
po["WXDLLFLAG"] = "dll";
if (cfg["SHARED"] == "0")
po["LIBTYPE_SUFFIX"] = "lib";
if (cfg["SHARED"] == "1")
po["LIBTYPE_SUFFIX"] = "dll";
if (cfg["MONOLITHIC"] == "0")
po["EXTRALIBS_FOR_BASE"] = "";
if (cfg["MONOLITHIC"] == "1")
po["EXTRALIBS_FOR_BASE"] = "";
if (cfg["BUILD"] == "debug")
po["__OPTIMIZEFLAG_2"] = addFlag("-O0");
if (cfg["BUILD"] == "release")
po["__OPTIMIZEFLAG_2"] = addFlag("-O2");
if (cfg["USE_RTTI"] == "1")
po["__RTTIFLAG_5"] = addFlag("");
if (cfg["USE_EXCEPTIONS"] == "0")
po["__EXCEPTIONSFLAG_6"] = addFlag("-fno-exceptions");
if (cfg["USE_EXCEPTIONS"] == "1")
po["__EXCEPTIONSFLAG_6"] = addFlag("");
if (cfg["WXUNIV"] == "1")
po["__WXUNIV_DEFINE_p"] = addDefine("__WXUNIVERSAL__");
if (cfg["WXUNIV"] == "1")
po["__WXUNIV_DEFINE_p_1"] = addResDefine("__WXUNIVERSAL__");
if (cfg["BUILD"] == "debug" && cfg["DEBUG_FLAG"] == "default")
po["__DEBUG_DEFINE_p"] = addDefine("__WXDEBUG__");
if (cfg["DEBUG_FLAG"] == "1")
po["__DEBUG_DEFINE_p"] = addDefine("__WXDEBUG__");