Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SConstruct - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0b73d7b33f92270c1179c82088d2f3cd2c989423 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
#!/usr/bin/env python
import string
import os
import time
import sys
from distutils import sysconfig
import SCons.Script

appname = ''
playername = ''
config_guess = ''

if hex(sys.hexversion) < 0x2030000:
	print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
	print
	print "You need at least Python 2.3 to build Blender with SCons"
	print
	print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
	sys.exit()

if sys.platform != 'win32':
	sys.stdout = os.popen("tee build.log", "w")
	sys.stderr = sys.stdout
	# guess at the platform, used to maintain the tarball naming scheme
	config_guess = os.popen("SRCHOME=source/ source/tools/guess/guessconfig").read()[:-1]
else:
	config_guess = "windows"
	
if sys.platform == 'darwin':
	appname = 'blender'
	playername = 'blenderplayer'
else:
	appname = 'blender$PROGSUFFIX'
	playername = 'blenderplayer$PROGSUFFIX'

# This is a flag to determine whether to read all sconscripts and
# set up the build environments or not
# when issuing 'scons clean' this is set to 1
# and all reading is skipped and a 'clean' target
# will clean the root_build_dir from all
# object files
enable_clean = 0

all_args = sys.argv[1:]
parser =  SCons.Script.OptParser()
options, targets = parser.parse_args(all_args)
if ('clean' in targets):
	enable_clean = 1
	
# Build directory.
root_build_dir = '..' + os.sep + 'build' + os.sep + sys.platform + os.sep

# Create the build directory. SCons does this automatically, but since we
# don't want to put scons-generated .sconsign files in the source tree, but in
# the root_build_dir, we have to create that dir ourselves before SCons tries
# to access/create the file containing .sconsign data.
if os.path.isdir (root_build_dir) == 0:
    os.makedirs (root_build_dir)

# User configurable options file. This can be controlled by the user by running
# scons with the following argument: CONFIG=user_config_options_file
config_file = ARGUMENTS.get('CONFIG', 'config.opts')

# Blender version.
version='2.34'
shortversion = '234' # for wininst target -> nsis installer creation

sdl_env = Environment ()
freetype_env = Environment ()
env = Environment ()

if sys.platform == 'linux2' or sys.platform == 'linux-i386':
    use_international = 'false'
    use_gameengine = 'true'
    use_openal = 'false'
    use_fmod = 'false'
    use_quicktime = 'false'
    use_sumo = 'true'
    use_ode = 'false'
    use_buildinfo = 'true'
    build_blender_dynamic = 'true'
    build_blender_static = 'false'
    build_blender_player = 'true'
    build_blender_plugin = 'false'
    release_flags = ['-O2']
    debug_flags = ['-O2', '-g']
    extra_flags = ['-pipe', '-funsigned-char']
    cxxflags = []
    defines = []
    warn_flags = ['-Wall', '-W']
    window_system = 'X11'
    platform_libs = ['m', 'util', 'stdc++']
    platform_libpath = []
    platform_linkflags = ['-pthread']
    extra_includes = []
    # z library information
    z_lib = ['z']
    z_libpath = ['/usr/lib']
    z_include = ['/usr/include']
    # png library information
    png_lib = ['png']
    png_libpath = ['/usr/lib']
    png_include = ['/usr/include']
    # jpeg library information
    jpeg_lib = ['jpeg']
    jpeg_libpath = ['/usr/lib']
    jpeg_include = ['/usr/include']
    # OpenGL library information
    opengl_lib = ['GL', 'GLU']
    opengl_static = ['/usr/lib/libGL.a', '/usr/lib/libGLU.a']
    opengl_libpath = ['/usr/lib', '/usr/X11R6/lib']
    opengl_include = ['/usr/include']
    # SDL library information
    sdl_env.ParseConfig ('sdl-config --cflags --libs')
    sdl_cflags = sdl_env.Dictionary()['CCFLAGS']
    sdl_include = sdl_env.Dictionary()['CPPPATH']
    sdl_libpath = sdl_env.Dictionary()['LIBPATH']
    sdl_lib = sdl_env.Dictionary()['LIBS']
    # SOLID library information
    solid_lib = []                                              # TODO
    solid_libpath = []                                          # TODO
    solid_include = ['#extern/solid']
    qhull_lib = []                                              # TODO
    qhull_libpath = []                                          # TODO
    qhull_include = ['#extern/qhull/include']
    # ODE library information
    ode_lib = ['ode']
    ode_libpath = ['#../lib/linux-glibc2.2.5-i386/ode/lib']
    ode_include = ['#../lib/linux-glibc2.2.5-i386/ode/include']
    # Python library information
    python_lib = ['python%d.%d' % sys.version_info[0:2]]
    python_libpath = [sysconfig.get_python_lib (0, 1) + '/config']
    python_include = [sysconfig.get_python_inc ()]
    python_linkflags = Split (sysconfig.get_config_var('LINKFORSHARED'))
    # International support information
    ftgl_lib = ['ftgl']
    ftgl_libpath = ['#../lib/linux-glibc2.2.5-i386/ftgl/lib']
    ftgl_include = ['#../lib/linux-glibc2.2.5-i386/ftgl/include']
    freetype_env.ParseConfig ('pkg-config --cflags --libs freetype2 2>/dev/null || freetype-config --cflags --libs 2>/dev/null')
    freetype_lib = freetype_env.Dictionary()['LIBS']
    freetype_libpath = freetype_env.Dictionary()['LIBPATH']
    freetype_include = freetype_env.Dictionary()['CPPPATH']
    gettext_lib = []
    gettext_libpath = []
    gettext_include = []
    # OpenAL library information
    openal_lib = ['openal']
    openal_libpath = ['/usr/lib']
    openal_include = ['/usr/include']

elif sys.platform == 'darwin':
    use_international = 'true'
    use_gameengine = 'true'
    use_openal = 'true'
    use_fmod = 'false'
    use_quicktime = 'true'
    use_precomp = 'true'
    use_sumo = 'true'
    use_ode = 'false'
    use_buildinfo = 'true'
    build_blender_dynamic = 'true'
    build_blender_static = 'false'
    build_blender_player = 'true'
    build_blender_plugin = 'false'
    # TODO: replace darwin-6.1-powerpc with the actual directiory on the
    #       build machine
    # darwin-6.1 is the name of cvs precomp folder
    # a symbolic link named darwin-X.Y-powerpc must be manually done
    #for now. X-Y is darwin kernel rev number
    darwin_precomp = '#../lib/darwin-6.1-powerpc/'
    fink_path = '/sw/'
    # TODO : try -mpowerpc -mpowerpc-gopt -mpowerpc-gfxopt optims
    #           doing actual profiling
    extra_flags = ['-pipe', '-fPIC', '-funsigned-char', '-ffast-math', '-mpowerpc'] 
    
    # , '-malign-natural'] malign is causing problems with jpeg lib but worth a 1-2% speedup
    #'-force_cpusubtype_ALL', '-mpowerpc-gpopt', 
    cxxflags = []
    defines = ['_THREAD_SAFE' ]
    if use_quicktime == 'true':
        defines += ['WITH_QUICKTIME']
    warn_flags = ['-Wall']    # , '-W'
    release_flags = ['-O3']
    debug_flags = ['-g']
    window_system = 'CARBON'
    # z library information
    z_lib = ['z']
    z_libpath = []
    z_include = []
    # TODO : add a flag to allow each lib to be build from fink or precomp
    #        without having to have to specify the path manually in config.opts.    
    # png library information
    png_lib = ['libpng']
    png_libpath = [darwin_precomp + 'png/lib']
    png_include = [darwin_precomp + 'png/include']
    # jpeg library information
    jpeg_lib = ['libjpeg']
    jpeg_libpath = [darwin_precomp + 'jpeg/lib']
    jpeg_include = [darwin_precomp + 'jpeg/include']
    # OpenGL library information
    opengl_lib = ['GL', 'GLU']
    opengl_static = []
    opengl_libpath = []
    opengl_include = []
    # SDL specific stuff.
    sdl_env.ParseConfig ('sdl-config --cflags --libs')
    sdl_cflags = sdl_env.Dictionary()['CCFLAGS']
    # Want to use precompiled libraries?
    if use_precomp == 'true':
        sdl_include = [darwin_precomp + 'sdl/include']
        sdl_libpath = [darwin_precomp + 'sdl/lib']
        sdl_lib = ['libSDL.a']
    platform_libs = ['stdc++'] 
    extra_includes = ['/sw/include']
    platform_libpath = ['/System/Library/Frameworks/OpenGL.framework/Libraries']
    platform_linkflags = []
    # SOLID library information
    solid_lib = ['libsolid']                                          
    solid_libpath = [darwin_precomp + 'solid/lib']                                          
    solid_include = [darwin_precomp + 'solid/include']
    qhull_lib = ['libqhull']                                          
    qhull_libpath = [darwin_precomp + 'qhull/lib']                                          
    qhull_include = [darwin_precomp + 'qhull/include']
    # ODE library information
    ode_lib = ['libode']                                             
    ode_libpath = [darwin_precomp + 'ode/lib']                                          
    ode_include = [darwin_precomp + 'ode/include/ode']
    # Python variables.
    # TODO : fill vars differently if we are on 10.2 or 10.3
    # python_lib = ['python%d.%d' % sys.version_info[0:2]]
    # python_libpath = [sysconfig.get_python_lib (0, 1) + '/config']
    # python_include = [sysconfig.get_python_inc ()]
    # python_linkflags = Split (sysconfig.get_config_var('LINKFORSHARED'))
    python_lib = []
    python_libpath = ['/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/config']
    python_include = ['/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3']
    python_linkflags = ['-u', '__dummy', '-u', '_PyMac_Error', 
                        '-framework', 'System',
                        '-framework', 'Python',
                        '-framework', 'CoreServices',
                        '-framework', 'Foundation',
                        '-framework', 'OpenGL']
    # International stuff
    ftgl_lib = ['ftgl']
    ftgl_libpath = [darwin_precomp + 'ftgl/lib']
    ftgl_include = [darwin_precomp + 'ftgl/include']
    freetype_lib = ['libfreetype']
    freetype_libpath = [darwin_precomp + 'freetype/lib']
    freetype_include = [darwin_precomp + 'freetype/include']
    gettext_lib = ['libintl']
    gettext_libpath = [darwin_precomp + 'gettext/lib']
    gettext_include = [darwin_precomp + 'gettext/include']
    # OpenAL library information
    openal_lib = ['libopenal']
    openal_libpath = [darwin_precomp + 'openal/lib']
    openal_include = [darwin_precomp + 'openal/include']

elif sys.platform == 'cygwin':
    use_international = 'false'
    use_gameengine = 'false'
    use_openal = 'false'
    use_fmod = 'false'
    use_quicktime = 'false'
    use_sumo = 'false'
    use_ode = 'false'
    use_buildinfo = 'false'
    build_blender_dynamic = 'true'
    build_blender_static = 'false'
    build_blender_player = 'false'
    build_blender_plugin = 'false'
    release_flags = ['-O2']
    debug_flags = ['-O2', '-g']
    extra_flags = ['-pipe', '-mno-cygwin', '-mwindows', '-funsigned-char']
    cxxflags = []
    defines = ['FREE_WINDOWS']
    warn_flags = ['-Wall', '-Wno-char-subscripts']
    platform_libs = ['png', 'jpeg', 'netapi32',
                     'opengl32', 'glu32', 'winmm',
                     'mingw32']
    platform_libpath = ['/usr/lib/w32api', '/lib/w32api']
    platform_linkflags = ['-mwindows', '-mno-cygwin', '-mconsole']
    window_system = 'WIN32'
    extra_includes = []
    # z library information
    z_lib = ['z']
    z_libpath = ['#../lib/windows/zlib/lib']
    z_include = ['#../lib/windows/zlib/include']
    # png library information
    png_lib = ['png']
    png_libpath = ['#../lib/windows/png/lib']
    png_include = ['#../lib/windows/png/include']
    # jpeg library information
    jpeg_lib = ['jpeg']
    jpeg_libpath = ['#../lib/windows/jpeg/lib']
    jpeg_include = ['#../lib/windows/jpeg/include']
    # OpenGL library information
    opengl_lib = ['opengl32', 'glu32']
    opengl_static = []
    opengl_libpath = []
    opengl_include = []
    # SDL specific stuff.
    sdl_include = ['#../lib/windows/sdl/include']
    sdl_libpath = ['#../lib/windows/sdl/lib']
    sdl_lib = ['SDL']
    sdl_cflags = []
    #sdl_cflags = '-DWIN32'
    # SOLID library information
    solid_lib = []                                              # TODO
    solid_libpath = []                                          # TODO
    solid_include = ['#extern/solid']
    qhull_lib = []                                              # TODO
    qhull_libpath = []                                          # TODO
    qhull_include = ['#extern/qhull/include']
    # ODE library information
    ode_lib = ['ode']
    ode_libpath = ['#../lib/windows/gcc/ode/lib']
    ode_include = ['#../lib/windows/gcc/ode/include']
    # Python library information
    python_include = ['#../lib/windows/python/include/python2.2']
    python_libpath = ['#../lib/windows/python/lib']
    python_lib = ['python22']
    python_linkflags = []
    # International stuff
    ftgl_lib = ['ftgl']
    ftgl_libpath = ['#../lib/windows/gcc/ftgl/lib']
    ftgl_include = ['#../lib/windows/gcc/ftgl/include']
    freetype_lib = ['freetype']
    freetype_libpath = ['#../lib/windows/gcc/freetype/lib']
    freetype_include = ['#../lib/windows/gcc/freetype/include']
    gettext_lib = []
    gettext_libpath = []
    gettext_include = []
    # OpenAL library information
    openal_lib = []
    openal_libpath = []
    openal_include = []

elif sys.platform == 'win32':
    use_international = 'true'
    use_gameengine = 'true'
    use_openal = 'true'
    use_fmod = 'false'
    use_quicktime = 'true'
    use_sumo = 'true'
    use_ode = 'false'
    use_buildinfo = 'true'
    build_blender_dynamic = 'true'
    build_blender_static = 'false'
    build_blender_player = 'true'
    build_blender_plugin = 'false'
    release_flags = ['/Og', '/Ot', '/Ob1', '/Op', '/G6']
    debug_flags = ['/Zi', '/Fr${TARGET.base}.sbr']
    extra_flags = ['/EHsc', '/J', '/W3', '/Gd', '/MT']
    cxxflags = []
    defines = ['WIN32', '_CONSOLE']
    defines += ['WITH_QUICKTIME']
    defines += ['_LIB', 'USE_OPENAL']
    defines += ['FTGL_LIBRARY_STATIC']
    warn_flags = []
    platform_libs = [ 'qtmlClient', 'soundsystem',
                     'ws2_32', 'dxguid', 'vfw32', 'winmm',
                     'iconv', 'kernel32', 'user32', 'gdi32',
                     'winspool', 'comdlg32', 'advapi32', 'shell32',
                     'ole32', 'oleaut32', 'uuid', 'odbc32', 'odbccp32',
                     'libcmt', 'libc']
    platform_libpath = ['#../lib/windows/iconv/lib',
                        '#../lib/windows/QTDevWin/Libraries']
    platform_linkflags = [
                        '/SUBSYSTEM:CONSOLE',
                        '/MACHINE:IX86',
                        '/ENTRY:mainCRTStartup',
                        '/INCREMENTAL:NO',
                        '/NODEFAULTLIB:"msvcprt.lib"',
                        '/NODEFAULTLIB:"glut32.lib"',
                        '/NODEFAULTLIB:"libcd.lib"',
                        #'/NODEFAULTLIB:"libc.lib"',
                        '/NODEFAULTLIB:"libcpd.lib"',
                        '/NODEFAULTLIB:"libcp.lib"',
                        '/NODEFAULTLIB:"libcmtd.lib"',
                        ]
    window_system = 'WIN32'
    extra_includes = []
    if use_quicktime == 'true':
        extra_includes += ['#../lib/windows/QTDevWin/CIncludes']
    # z library information
    z_lib = ['libz_st']
    z_libpath = ['#../lib/windows/zlib/lib']
    z_include = ['#../lib/windows/zlib/include']
    # png library information
    png_lib = ['libpng_st']
    png_libpath = ['#../lib/windows/png/lib']
    png_include = ['#../lib/windows/png/include']
    # jpeg library information
    jpeg_lib = ['libjpeg']
    jpeg_libpath = ['#../lib/windows/jpeg/lib']
    jpeg_include = ['#../lib/windows/jpeg/include']
    # OpenGL library information
    opengl_lib = ['opengl32', 'glu32']
    opengl_static = []
    opengl_libpath = []
    opengl_include = ['/usr/include']
    # SDL library information
    sdl_include = ['#../lib/windows/sdl/include']
    sdl_libpath = ['#../lib/windows/sdl/lib']
    sdl_lib = ['SDL']
    sdl_cflags = []
    window_system = 'WIN32'
    # SOLID library information
    solid_lib = ['extern/solid']
    solid_libpath = ['#../lib/windows/solid/lib']
    solid_include = ['#extern/solid']
    qhull_lib = ['qhull']
    qhull_libpath = ['#../lib/windows/qhull/lib']
    qhull_include = ['#extern/qhull/include']
    # ODE library information
    ode_lib = []                                                # TODO
    ode_libpath = ['#../lib/windows/ode/lib']
    ode_include = ['#../lib/windows/ode/include']
    # Python lib name
    python_include = ['#../lib/windows/python/include/python2.3']
    python_libpath = ['#../lib/windows/python/lib']
    python_lib = ['python23']
    python_linkflags = []
    # International stuff
    ftgl_lib = ['ftgl_static_ST']
    ftgl_libpath = ['#../lib/windows/ftgl/lib']
    ftgl_include = ['#../lib/windows/ftgl/include']
    freetype_lib = ['freetype2ST']
    freetype_libpath = ['#../lib/windows/freetype/lib']
    freetype_include = ['#../lib/windows/freetype/include']
    gettext_lib = ['gnu_gettext']
    gettext_libpath = ['#../lib/windows/gettext/lib']
    gettext_include = ['#../lib/windows/gettext/include']
    # OpenAL library information
    openal_lib = ['openal_static']
    openal_libpath = ['#../lib/windows/openal/lib']
    openal_include = ['#../lib/windows/openal/include']

elif string.find (sys.platform, 'sunos') != -1:
    use_international = 'true'
    use_gameengine = 'false'
    use_openal = 'false'
    use_fmod = 'false'
    use_quicktime = 'false'
    use_sumo = 'false'
    use_ode = 'false'
    use_buildinfo = 'false'
    build_blender_dynamic = 'true'
    build_blender_static = 'false'
    build_blender_player = 'false'
    build_blender_plugin = 'false'
    release_flags = ['-O2']
    debug_flags = ['-O2', '-g']
    extra_flags = ['-pipe', '-fPIC', '-funsigned-char', '-DSUN_OGL_NO_VERTEX_MACROS']
    cxxflags = []
    defines = []
    warn_flags = ['-Wall', '-W']
    window_system = 'X11'
    platform_libs = ['stdc++', 'dl', 'm']
    platform_libpath = []
    platform_linkflags = []
    extra_includes = []
    # z library information
    z_lib = ['z']
    z_libpath = []
    z_include = []
    # png library information
    png_lib = ['png']
    png_libpath = []
    png_include = []
    # jpeg library information
    jpeg_lib = ['jpeg']
    jpeg_libpath = []
    jpeg_include = []
    # OpenGL library information
    opengl_lib = ['GL', 'GLU', 'X11']
    opengl_static = []
    opengl_libpath = ['/usr/openwin/include']
    opengl_include = ['/usr/openwin/lib']
    # SDL library information
    sdl_env.ParseConfig ('sdl-config --cflags --libs')
    sdl_cflags = sdl_env.Dictionary()['CCFLAGS']
    sdl_include = sdl_env.Dictionary()['CPPPATH']
    sdl_libpath = sdl_env.Dictionary()['LIBPATH']
    sdl_lib = sdl_env.Dictionary()['LIBS']
    # SOLID library information
    solid_lib = []                                              # TODO
    solid_libpath = []                                          # TODO
    solid_include = ['#extern/solid']
    qhull_lib = []                                              # TODO
    qhull_libpath = []                                          # TODO
    qhull_include = ['#extern/qhull/include']
    # ODE library information
    ode_lib = []                                                # TODO
    ode_libpath = []                                            # TODO
    ode_include = ['#extern/ode/dist/include/ode']
    # Python variables.
    python_lib = ['python%d.%d' % sys.version_info[0:2]]
    python_libpath = [sysconfig.get_python_lib (0, 1) + '/config']
    python_include = [sysconfig.get_python_inc ()]
    python_linkflags = []
    # International support information
    ftgl_lib = ['ftgl']
    ftgl_libpath = ['#../lib/solaris-2.8-sparc/ftgl/lib']
    ftgl_include = ['#../lib/solaris-2.8-sparc/ftgl/include']
    freetype_lib = ['freetype']
    freetype_libpath = ['#../lib/solaris-2.8-sparc/freetype/lib']
    freetype_include = ['#../lib/solaris-2.8-sparc/freetype/include']
    gettext_lib = []
    gettext_libpath = []
    gettext_include = []
    # OpenAL library information
    openal_lib = []
    openal_libpath = []
    openal_include = []

elif string.find (sys.platform, 'irix') != -1:
    use_international = 'false'
    use_gameengine = 'false'
    use_openal = 'false'
    use_fmod = 'false'
    use_quicktime = 'false'
    use_sumo = 'false'
    use_ode = 'false'
    use_buildinfo = 'false'
    build_blender_dynamic = 'true'
    build_blender_static = 'false'
    build_blender_player = 'false'
    build_blender_plugin = 'false'
    irix_precomp = '#../lib/irix-6.5-mips'
    extra_flags = ['-n32', '-mips3', '-Xcpluscomm']
    cxxflags = ['-n32', '-mips3', '-Xcpluscomm', '-LANG:std']
    cxxflags += ['-LANG:libc_in_namespace_std=off']
    
    window_system = 'X11'
    release_flags = ['-O2', '-OPT:Olimit=0']
    debug_flags = ['-O2', '-g']
    defines = []
    warn_flags = ['-fullwarn', '-woff', '1001,1110,1201,1209,1355,1424,1681,3201']
    platform_libs = ['movieGL', 'Xmu', 'Xext', 'X11',
                     'c', 'm', 'dmedia', 'cl', 'audio',
                     'Cio', 'pthread']
    platform_libpath = ['/usr/lib32/mips3',
                        '/lib/freeware/lib32',
                        '/usr/lib32']
    platform_linkflags = ['-mips3', '-n32']
    extra_includes = ['/usr/freeware/include',
                      '/usr/include']
    # z library information
    z_lib = ['z']
    z_libpath = []
    z_include = []
    # png library information
    png_lib = ['png']
    png_libpath = [irix_precomp + '/png/lib']
    png_include = [irix_precomp + '/png/include']
    # jpeg library information
    jpeg_lib = ['jpeg']
    jpeg_libpath = [irix_precomp + '/jpeg/lib']
    jpeg_include = [irix_precomp + '/jpeg/include']
    # OpenGL library information
    opengl_lib = ['GL', 'GLU']
    opengl_static = []
    opengl_libpath = []
    opengl_include = []
    # SDL library information
    sdl_cflags = []
    sdl_include = [irix_precomp + '/sdl/include/SDL']
    sdl_libpath = [irix_precomp + '/sdl/lib']
    sdl_lib = ['SDL', 'libSDL.a']
    # SOLID library information
    solid_lib = []                                              # TODO
    solid_libpath = []                                          # TODO
    solid_include = [irix_precomp + '/solid/include']
    qhull_lib = []                                              # TODO
    qhull_libpath = []                                          # TODO
    qhull_include = ['#extern/qhull/include']
    # ODE library information
    ode_lib = []                                                # TODO
    ode_libpath = []                                            # TODO
    ode_include = [irix_precomp + '/ode/include']
    # Python library information
    python_libpath = [irix_precomp + '/python/lib/python2.2/config']
    python_include = [irix_precomp + '/python/include/python2.2']
    python_lib = ['python2.2']
    python_linkflags = []
    # International support information
    ftgl_lib = ['ftgl']
    ftgl_libpath = [irix_precomp + '/ftgl/lib']
    ftgl_include = [irix_precomp + '/ftgl/include']
    freetype_lib = ['freetype']
    freetype_libpath = [irix_precomp + '/freetype/lib']
    freetype_include = [irix_precomp + '/freetype/include']
    gettext_lib = []
    gettext_libpath = []
    gettext_include = []
    # OpenAL library information
    openal_lib = []
    openal_libpath = []
    openal_include = []

elif string.find (sys.platform, 'hp-ux') != -1:
    window_system = 'X11'
    defines = []

elif sys.platform=='openbsd3':
    print "Building for OpenBSD 3.x"
    use_international = 'false'
    use_gameengine = 'false'
    use_openal = 'false'
    use_fmod = 'false'
    use_quicktime = 'false'
    use_sumo = 'false'
    use_ode = 'false'
    use_buildinfo = 'true'
    build_blender_dynamic = 'true'
    build_blender_static = 'false'
    build_blender_player = 'false'
    build_blender_plugin = 'false'
    release_flags = ['-O2']
    debug_flags = ['-O2', '-g']
    extra_flags = ['-pipe', '-fPIC', '-funsigned-char']
    cxxflags = []
    defines = []
    warn_flags = ['-Wall','-W']
    window_system = 'X11'
    platform_libs = ['m', 'stdc++', 'pthread', 'util']
    platform_libpath = []
    platform_linkflags = []
    extra_includes = []
    z_lib = ['z']
    z_libpath = ['/usr/lib']
    z_include = ['/usr/include']
    # png library information
    png_lib = ['png']
    png_libpath = ['/usr/local/lib']
    png_include = ['/usr/local/include']
    # jpeg library information
    jpeg_lib = ['jpeg']
    jpeg_libpath = ['/usr/local/lib']
    jpeg_include = ['/usr/local/include']
    # OpenGL library information
    opengl_lib = ['GL', 'GLU']
    opengl_static = ['/usr/lib/libGL.a', '/usr/lib/libGLU.a']
    opengl_libpath = ['/usr/lib', '/usr/X11R6/lib']
    opengl_include = ['/usr/X11R6/include/']
    # SDL library information
    sdl_env.ParseConfig ('sdl-config --cflags --libs')
    sdl_cflags = sdl_env.Dictionary()['CCFLAGS']
    sdl_include = sdl_env.Dictionary()['CPPPATH']
    sdl_libpath = sdl_env.Dictionary()['LIBPATH']
    sdl_lib = sdl_env.Dictionary()['LIBS']
    # SOLID library information
    solid_lib = []                     # TODO
    solid_libpath = []        # TODO
    solid_include = ['#extern/solid']
    qhull_lib = []       # TODO
    qhull_libpath = []  # TODO
    qhull_include = ['#extern/qhull/include']
    # ODE library information
    ode_lib = ['ode']
    ode_libpath = ['#../lib/linux-glibc2.2.5-i386/ode/lib']
    ode_include = ['#../lib/linux-glibc2.2.5-i386/ode/include']
    # Python library information
    python_lib = ['python%d.%d' % sys.version_info[0:2]]
    python_libpath = [sysconfig.get_python_lib (0, 1) + '/config']
    python_include = [sysconfig.get_python_inc ()]
    python_linkflags = []
    # International support information
    ftgl_lib = ['ftgl']
    ftgl_libpath = ['#../lib/linux-glibc2.2.5-i386/ftgl/lib']
    ftgl_include = ['#../lib/linux-glibc2.2.5-i386/ftgl/include']
    freetype_env.ParseConfig('pkg-config --cflags --libs freetype2')
    freetype_lib = freetype_env.Dictionary()['LIBS']
    freetype_libpath = freetype_env.Dictionary()['LIBPATH']
    freetype_include = freetype_env.Dictionary()['CPPPATH']
    gettext_lib = []
    gettext_libpath = []
    gettext_include = []
    # OpenAL library information
    openal_lib = ['openal']
    openal_libpath = ['/usr/lib']
    openal_include = ['/usr/include']

else:
    print "Unknown platform %s"%sys.platform
    exit

#-----------------------------------------------------------------------------
# End of platform specific section
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# User configurable options to be saved in a config file.
#-----------------------------------------------------------------------------
# Checking for an existing config file - use that one if it exists,
# otherwise create one.
my_defines = []
my_ccflags = []
my_cxxflags = []
my_ldflags = []
if os.path.exists (config_file):
    print "Using config file: " + config_file
else:
    print "Creating new config file: " + config_file
    env_dict = env.Dictionary()
    config=open (config_file, 'w')
    config.write ("# Configuration file containing user definable options.\n")
    config.write ("VERSION = '2.33-cvs'\n")
    config.write ("BUILD_BINARY = 'release'\n")
    config.write ("USE_BUILDINFO = %r\n"%(use_buildinfo))
    config.write ("BUILD_BLENDER_DYNAMIC = %r\n"%(build_blender_dynamic))
    config.write ("BUILD_BLENDER_STATIC = %r\n"%(build_blender_static))
    config.write ("BUILD_BLENDER_PLAYER = %r\n"%(build_blender_player))
    config.write ("BUILD_BLENDER_PLUGIN = %r\n"%(build_blender_plugin))
    config.write ("BUILD_DIR = %r\n"%(root_build_dir))
    
    config.write ("\n# Extra compiler flags can be defined here.\n")
    config.write ("DEFINES = %s\n"%(my_defines))
    config.write ("CCFLAGS = %s\n"%(my_ccflags))
    config.write ("CXXFLAGS = %s\n"%(my_cxxflags))
    config.write ("LDFLAGS = %s\n"%(my_ldflags))

    config.write ("USE_INTERNATIONAL = %r\n"%(use_international))
    config.write ("BUILD_GAMEENGINE = %r\n"%(use_gameengine))
    if use_ode == 'true':
        config.write ("USE_PHYSICS = 'ode'\n")
    else:
        config.write ("USE_PHYSICS = 'solid'\n")
    config.write ("USE_OPENAL = %r\n"%(use_openal))
    config.write ("USE_FMOD = %r\n"%(use_fmod))
    config.write ("USE_QUICKTIME = %r\n"%(use_quicktime))
    config.write ("\n# Compiler information.\n")
    config.write ("HOST_CC = %r\n"%(env_dict['CC']))
    config.write ("HOST_CXX = %r\n"%(env_dict['CXX']))
    config.write ("TARGET_CC = %r\n"%(env_dict['CC']))
    config.write ("TARGET_CXX = %r\n"%(env_dict['CXX']))
    config.write ("TARGET_AR = %r\n"%(env_dict['AR']))
    config.write ("PATH = %r\n"%(os.environ['PATH']))
    config.write ("\n# External library information.\n")
    config.write ("PLATFORM_LIBS = %r\n"%(platform_libs))
    config.write ("PLATFORM_LIBPATH = %r\n"%(platform_libpath))
    config.write ("PLATFORM_LINKFLAGS = %r\n"%(platform_linkflags))
    config.write ("PYTHON_INCLUDE = %r\n"%(python_include))
    config.write ("PYTHON_LIBPATH = %r\n"%(python_libpath))
    config.write ("PYTHON_LIBRARY = %r\n"%(python_lib))
    config.write ("PYTHON_LINKFLAGS = %r\n"%(python_linkflags))
    config.write ("SDL_CFLAGS = %r\n"%(sdl_cflags))
    config.write ("SDL_INCLUDE = %r\n"%(sdl_include))
    config.write ("SDL_LIBPATH = %r\n"%(sdl_libpath))
    config.write ("SDL_LIBRARY = %r\n"%(sdl_lib))
    config.write ("Z_INCLUDE = %r\n"%(z_include))
    config.write ("Z_LIBPATH = %r\n"%(z_libpath))
    config.write ("Z_LIBRARY = %r\n"%(z_lib))
    config.write ("PNG_INCLUDE = %r\n"%(png_include))
    config.write ("PNG_LIBPATH = %r\n"%(png_libpath))
    config.write ("PNG_LIBRARY = %r\n"%(png_lib))
    config.write ("JPEG_INCLUDE = %r\n"%(jpeg_include))
    config.write ("JPEG_LIBPATH = %r\n"%(jpeg_libpath))
    config.write ("JPEG_LIBRARY = %r\n"%(jpeg_lib))
    config.write ("OPENGL_INCLUDE = %r\n"%(opengl_include))
    config.write ("OPENGL_LIBPATH = %r\n"%(opengl_libpath))
    config.write ("OPENGL_LIBRARY = %r\n"%(opengl_lib))
    config.write ("OPENGL_STATIC = %r\n"%(opengl_static))
    config.write ("\n# The following information is only necessary when you've enabled support for\n")
    config.write ("# the game engine.\n")
    config.write ("SOLID_INCLUDE = %r\n"%(solid_include))
    config.write ("SOLID_LIBPATH = %r\n"%(solid_libpath))
    config.write ("SOLID_LIBRARY = %r\n"%(solid_lib))
    config.write ("QHULL_INCLUDE = %r\n"%(qhull_include))
    config.write ("QHULL_LIBPATH = %r\n"%(qhull_libpath))
    config.write ("QHULL_LIBRARY = %r\n"%(qhull_lib))
    config.write ("ODE_INCLUDE = %r\n"%(ode_include))
    config.write ("ODE_LIBPATH = %r\n"%(ode_libpath))
    config.write ("ODE_LIBRARY = %r\n"%(ode_lib))
    config.write ("OPENAL_INCLUDE = %r\n"%(openal_include))
    config.write ("OPENAL_LIBPATH = %r\n"%(openal_libpath))
    config.write ("OPENAL_LIBRARY = %r\n"%(openal_lib))
    config.write ("\n# The following information is only necessary when building with\n")
    config.write ("# internationalization support.\n");
    config.write ("FTGL_INCLUDE = %r\n"%(ftgl_include))
    config.write ("FTGL_LIBPATH = %r\n"%(ftgl_libpath))
    config.write ("FTGL_LIBRARY = %r\n"%(ftgl_lib))
    config.write ("FREETYPE_INCLUDE = %r\n"%(freetype_include))
    config.write ("FREETYPE_LIBPATH = %r\n"%(freetype_libpath))
    config.write ("FREETYPE_LIBRARY = %r\n"%(freetype_lib))
    config.write ("GETTEXT_INCLUDE = %r\n"%(gettext_include))
    config.write ("GETTEXT_LIBPATH = %r\n"%(gettext_libpath))
    config.write ("GETTEXT_LIBRARY = %r\n"%(gettext_lib))
    config.close ()

#-----------------------------------------------------------------------------
# Read the options from the config file and update the various necessary flags
#-----------------------------------------------------------------------------
list_opts = []
user_options_env = Environment ()
user_options = Options (config_file)
user_options.AddOptions (
        ('VERSION', 'Blender version', version),
        (EnumOption ('BUILD_BINARY', 'release',
                     'Select a release or debug binary.',
                     allowed_values = ('release', 'debug'))),
        (BoolOption ('USE_BUILDINFO',
                     'Set to 1 if you want to add build information.',
                     'false')),
        (BoolOption ('BUILD_BLENDER_DYNAMIC',
                     'Set to 1 if you want to build blender with hardware accellerated OpenGL support.',
                     'true')),
        (BoolOption ('BUILD_BLENDER_STATIC',
                     'Set to 1 if you want to build blender with software OpenGL support.',
                     'false')),
        (BoolOption ('BUILD_BLENDER_PLAYER',
                     'Set to 1 if you want to build the blender player.',
                     'false')),
        (BoolOption ('BUILD_BLENDER_PLUGIN',
                     'Set to 1 if you want to build the blender plugin.',
                     'false')),
        ('BUILD_DIR', 'Target directory for intermediate files.',
                     root_build_dir),
        (BoolOption ('USE_INTERNATIONAL',
                     'Set to 1 to have international support.',
                     'false')),
        (EnumOption ('USE_PHYSICS', 'solid',
                     'Select which physics engine to use.',
                     allowed_values = ('ode', 'solid'))),
        (BoolOption ('BUILD_GAMEENGINE',
                     'Set to 1 to build blender with game engine support.',
                     'false')),
        (BoolOption ('USE_OPENAL',
                     'Set to 1 to build the game engine with OpenAL support.',
                     'false')),
        (BoolOption ('USE_FMOD',
                     'Set to 1 to build the game engine with FMod support.',
                     'false')),
        (BoolOption ('USE_QUICKTIME',
                     'Set to 1 to add support for QuickTime.',
                     'false')),
        ('HOST_CC', 'C compiler for the host platfor. This is the same as target platform when not cross compiling.'),
        ('HOST_CXX', 'C++ compiler for the host platform. This is the same as target platform when not cross compiling.'),
        ('TARGET_CC', 'C compiler for the target platform.'),
        ('TARGET_CXX', 'C++ compiler for the target platform.'),
        ('TARGET_AR', 'Linker command for linking libraries.'),
        ('PATH', 'Standard search path'),
        ('PLATFORM_LIBS', 'Platform specific libraries.'),
        ('PLATFORM_LIBPATH', 'Platform specific library link path.'),
        ('PLATFORM_LINKFLAGS', 'Platform specific linkflags'),
        ('PYTHON_INCLUDE', 'Include directory for Python header files.'),
        ('PYTHON_LIBPATH', 'Library path where the Python lib is located.'),
        ('PYTHON_LIBRARY', 'Python library name.'),
        ('PYTHON_LINKFLAGS', 'Python specific linkflags.'),
        ('SDL_CFLAGS', 'Necessary CFLAGS when using sdl functionality.'),
        ('SDL_INCLUDE', 'Include directory for SDL header files.'),
        ('SDL_LIBPATH', 'Library path where the SDL library is located.'),
        ('SDL_LIBRARY', 'SDL library name.'),
        ('Z_INCLUDE', 'Include directory for zlib header files.'),
        ('Z_LIBPATH', 'Library path where the zlib library is located.'),
        ('Z_LIBRARY', 'Z library name.'),
        ('PNG_INCLUDE', 'Include directory for png header files.'),
        ('PNG_LIBPATH', 'Library path where the png library is located.'),
        ('PNG_LIBRARY', 'png library name.'),
        ('JPEG_INCLUDE', 'Include directory for jpeg header files.'),
        ('JPEG_LIBPATH', 'Library path where the jpeg library is located.'),
        ('JPEG_LIBRARY', 'jpeg library name.'),
        ('OPENGL_INCLUDE', 'Include directory for OpenGL header files.'),
        ('OPENGL_LIBPATH', 'Library path where the OpenGL libraries are located.'),
        ('OPENGL_LIBRARY', 'OpenGL library names.'),
        ('OPENGL_STATIC', 'Linker flags for static linking of Open GL.'),
        ('SOLID_INCLUDE', 'Include directory for SOLID header files.'),
        ('SOLID_LIBPATH', 'Library path where the SOLID library is located.'),
        ('SOLID_LIBRARY', 'SOLID library name.'),
        ('QHULL_INCLUDE', 'Include directory for QHULL header files.'),
        ('QHULL_LIBPATH', 'Library path where the QHULL library is located.'),
        ('QHULL_LIBRARY', 'QHULL library name.'),
        ('ODE_INCLUDE', 'Include directory for ODE header files.'),
        ('ODE_LIBPATH', 'Library path where the ODE library is located.'),
        ('ODE_LIBRARY', 'ODE library name.'),
        ('OPENAL_INCLUDE', 'Include directory for OpenAL header files.'),
        ('OPENAL_LIBPATH', 'Library path where the OpenAL library is located.'),
        ('OPENAL_LIBRARY', 'OpenAL library name.'),
        ('FTGL_INCLUDE', 'Include directory for ftgl header files.'),
        ('FTGL_LIBPATH', 'Library path where the ftgl library is located.'),
        ('FTGL_LIBRARY', 'ftgl library name.'),
        ('FREETYPE_INCLUDE', 'Include directory for freetype2 header files.'),
        ('FREETYPE_LIBPATH', 'Library path where the freetype2 library is located.'),
        ('FREETYPE_LIBRARY', 'Freetype2 library name.'),
        ('GETTEXT_INCLUDE', 'Include directory for gettext header files.'),
        ('GETTEXT_LIBPATH', 'Library path where the gettext library is located.'),
        ('GETTEXT_LIBRARY', 'gettext library name.'),

        ('DEFINES', 'Extra Preprocessor defines.'),
        ('CCFLAGS', 'Extra C Compiler flags.'),
        ('CXXFLAGS','Extra C++ Compiler flags.'),
        ('LDFLAGS', 'Extra Linker flags.')
    )
user_options.Update (user_options_env)
user_options_dict = user_options_env.Dictionary()

root_build_dir = user_options_dict['BUILD_DIR']
    
if user_options_dict['BUILD_GAMEENGINE'] == 1:
    defines += ['GAMEBLENDER=1']
    if user_options_dict['USE_PHYSICS'] == 'ode':
        defines += ['USE_ODE']
    else:
        defines += ['USE_SUMO_SOLID']
else:
    defines += ['GAMEBLENDER=0']

if user_options_dict['BUILD_BINARY'] == 'release':
    cflags = extra_flags + release_flags + warn_flags
    defines += ['NDEBUG']
else:
    cflags = extra_flags + debug_flags + warn_flags
    if sys.platform == 'win32':
        #defines += ['_DEBUG'] specifying this makes msvc want to link to python22_d.lib??
        platform_linkflags += ['/DEBUG','/PDB:blender.pdb']

defines += user_options_dict['DEFINES']
cflags += user_options_dict['CCFLAGS']
cxxflags += user_options_dict['CXXFLAGS']
platform_linkflags += user_options_dict['LDFLAGS']

#-----------------------------------------------------------------------------
# Generic library generation environment. This one is the basis for each
# library.
#-----------------------------------------------------------------------------
library_env = env.Copy ()
library_env.Replace (CC = user_options_dict['TARGET_CC'])
library_env.Replace (CXX = user_options_dict['TARGET_CXX'])
library_env.Replace (PATH = user_options_dict['PATH'])
library_env.Replace (AR = user_options_dict['TARGET_AR'])
library_env.Append (CCFLAGS = cflags)
library_env.Append (CXXFLAGS = cxxflags)
library_env.Append (CPPDEFINES = defines)
library_env.SConsignFile (root_build_dir+'scons-signatures')

#-----------------------------------------------------------------------------
# Settings to be exported to other SConscript files
#-----------------------------------------------------------------------------

if enable_clean==0: # only read SConscripts when not cleaning, this to cut overhead
	Export ('cflags')
	Export ('defines')
	Export ('window_system')
	Export ('extra_includes')
	Export ('user_options_dict')
	Export ('library_env')
	
	BuildDir (root_build_dir+'/extern', 'extern', duplicate=0)
	SConscript (root_build_dir+'extern/SConscript')
	BuildDir (root_build_dir+'/intern', 'intern', duplicate=0)
	SConscript (root_build_dir+'intern/SConscript')
	BuildDir (root_build_dir+'/source', 'source', duplicate=0)
	SConscript (root_build_dir+'source/SConscript')
	
	libpath = (['#'+root_build_dir+'/lib'])
	
	link_env = library_env.Copy ()
	link_env.Append (LIBPATH=libpath)


def common_libs(env):
	"""
	Append to env all libraries that are common to Blender and Blenderplayer
	"""
	env.Append (LIBS=[
		'blender_blenloader',
		'blender_readblenfile',
		'blender_img',
		'blender_blenkernel',
		'blender_blenpluginapi',
		'blender_imbuf',
		'blender_avi',
		'blender_blenlib',
		'blender_makesdna',
		'blender_kernel',
		'blender_GHOST',
		'blender_STR',
		'blender_guardedalloc',
		'blender_CTR',
		'blender_MEM',
		'blender_MT',
		'blender_BMF',
		'soundsystem'])
	if user_options_dict['USE_QUICKTIME'] == 1:
		env.Append (LIBS=['blender_quicktime'])


def international_libs(env):
	"""
	Append international font support libraries
	"""
	if user_options_dict['USE_INTERNATIONAL'] == 1:
		env.Append (LIBS=user_options_dict['FREETYPE_LIBRARY'])
		env.Append (LIBPATH=user_options_dict['FREETYPE_LIBPATH'])
		env.Append (LIBS=['blender_FTF'])
		env.Append (LIBS=user_options_dict['FTGL_LIBRARY'])
		env.Append (LIBPATH=user_options_dict['FTGL_LIBPATH'])
		env.Append (LIBS=user_options_dict['FREETYPE_LIBRARY'])

def blender_libs(env):
	"""
	Blender only libs (not in player)
	"""
	env.Append( LIBS=['blender_creator',
		'blender_blendersrc',
		'blender_render',
		'blender_yafray',
		'blender_renderconverter',
		'blender_radiosity',
		'blender_LOD',
		'blender_BSP',
		'blender_blenkernel',
		'blender_IK',
		'blender_ONL'])

def ketsji_libs(env):
	"""
	Game Engine libs
	"""
	if user_options_dict['BUILD_GAMEENGINE'] == 1:
		env.Append (LIBS=['KX_blenderhook',
				'KX_converter',
				'PHY_Dummy',
				'PHY_Physics',
				'KX_ketsji',
				'SCA_GameLogic',
				'RAS_rasterizer',
				'RAS_OpenGLRasterizer',
				'blender_expressions',
				'SG_SceneGraph',
				'blender_MT',
				'KX_blenderhook',
				'KX_network',
				'blender_kernel',
				'NG_network',
				'NG_loopbacknetwork'])
		if user_options_dict['USE_PHYSICS'] == 'solid':
			env.Append (LIBS=['PHY_Sumo', 'PHY_Physics', 'blender_MT', 'extern_solid', 'extern_qhull'])
		else:
			env.Append (LIBS=['PHY_Ode',
					'PHY_Physics'])
			env.Append (LIBS=user_options_dict['ODE_LIBRARY'])
			env.Append (LIBPATH=user_options_dict['ODE_LIBPATH'])

def player_libs(env):
	"""
	Player libraries
	"""
	env.Append (LIBS=['GPG_ghost',
			'GPC_common'])

def player_libs2(env):
	"""
	Link order shenannigans: these libs are added after common_libs
	"""
	env.Append (LIBS=['blender_blenkernel_blc',
			'soundsystem'])

def winblenderres(env):
	"""
	build the windows icon resource file
	"""
	if sys.platform == 'win32':
		env.RES(['source/icons/winblender.rc'])

def system_libs(env):
	"""
	System libraries: Python, SDL, PNG, JPEG, Gettext, OpenAL, Carbon
	"""
	env.Append (LIBS=['blender_python'])
	env.Append (LIBS=user_options_dict['PYTHON_LIBRARY'])
	env.Append (LIBPATH=user_options_dict['PYTHON_LIBPATH'])
	env.Append (LINKFLAGS=user_options_dict['PYTHON_LINKFLAGS'])
	env.Append (LIBS=user_options_dict['SDL_LIBRARY'])
	env.Append (LIBPATH=user_options_dict['SDL_LIBPATH'])
	env.Append (LIBS=user_options_dict['PNG_LIBRARY'])
	env.Append (LIBPATH=user_options_dict['PNG_LIBPATH'])
	env.Append (LIBS=user_options_dict['JPEG_LIBRARY'])
	env.Append (LIBPATH=user_options_dict['JPEG_LIBPATH'])
	env.Append (LIBS=user_options_dict['GETTEXT_LIBRARY'])
	env.Append (LIBPATH=user_options_dict['GETTEXT_LIBPATH'])
	env.Append (LIBS=user_options_dict['Z_LIBRARY'])
	env.Append (LIBPATH=user_options_dict['Z_LIBPATH'])
	if user_options_dict['USE_OPENAL'] == 1:
		env.Append (LIBS=user_options_dict['OPENAL_LIBRARY'])
		env.Append (LIBPATH=user_options_dict['OPENAL_LIBPATH'])
	env.Append (LIBS=user_options_dict['PLATFORM_LIBS'])
	env.Append (LIBPATH=user_options_dict['PLATFORM_LIBPATH'])
	if sys.platform == 'darwin':
		env.Append (LINKFLAGS='-framework')
		env.Append (LINKFLAGS='Carbon')
		env.Append (LINKFLAGS='-framework')
		env.Append (LINKFLAGS='AGL')
		env.Append (LINKFLAGS='-framework')
		env.Append (LINKFLAGS='AudioUnit')
		env.Append (LINKFLAGS='-framework')
		env.Append (LINKFLAGS='AudioToolbox')
		env.Append (LINKFLAGS='-framework')
		env.Append (LINKFLAGS='CoreAudio')
		if user_options_dict['USE_QUICKTIME'] == 1:
			env.Append (LINKFLAGS='-framework')
			env.Append (LINKFLAGS='QuickTime')
	else:
		env.Append (LINKFLAGS=user_options_dict['PLATFORM_LINKFLAGS'])
	env.BuildDir (root_build_dir, '.', duplicate=0)

def buildinfo(env, build_type):
	"""
	Generate a buildinfo object
	"""
	build_date = time.strftime ("%Y-%m-%d")
	build_time = time.strftime ("%H:%M:%S")
	obj = []
	if user_options_dict['USE_BUILDINFO'] == 1:
		if sys.platform=='win32':
			build_info_file = open("source/creator/winbuildinfo.h", 'w')
			build_info_file.write("char *build_date=\"%s\";\n"%build_date)
			build_info_file.write("char *build_time=\"%s\";\n"%build_time)
			build_info_file.write("char *build_platform=\"win32\";\n")
			build_info_file.write("char *build_type=\"%s\";\n"%build_type)
			build_info_file.close()
			env.Append (CPPDEFINES = ['NAN_BUILDINFO', 'BUILD_DATE'])
		else:
			env.Append (CPPDEFINES = ['BUILD_TIME=\'"%s"\''%(build_time),
							'BUILD_DATE=\'"%s"\''%(build_date),
							'BUILD_TYPE=\'"dynamic"\'',
							'NAN_BUILDINFO',
							'BUILD_PLATFORM=\'"%s"\''%(sys.platform)])
		obj = [env.Object (root_build_dir+'source/creator/%s_buildinfo'%build_type,
						[root_build_dir+'source/creator/buildinfo.c'])]
	return obj
	
def cleanCVS():
	"""
	walks the dist dir and removes all CVS dirs
	"""
	
	try:
		import shutil
	except:
		print "no shutil available"
		print "make sure you use python 2.3"
		print
		return 0
	
	startdir = os.getcwd()
	
	for root, dirs, files in os.walk("dist", topdown=False):
		for name in dirs:
			if name in ['CVS']:
				if os.path.isdir(root + "/" + name):
					shutil.rmtree(root + "/" + name)
	
	os.chdir(startdir)
	
	return 1

def preparedist():
	"""
	Prepare a directory for creating either archives or the installer
	"""
	
	try:
		import shutil
		import time
		import stat
	except:
		print "no shutil available"
		print "make sure you use python 2.3"
		print
		return 0
	
	startdir = os.getcwd()
	
	if os.path.isdir("dist") == 0:
		os.makedirs("dist")
	else:
		shutil.rmtree("dist") # make sure we don't get old cruft
		os.makedirs("dist")
	
	# first copy binaries
	
	if sys.platform == 'win32':
		shutil.copy("blender.exe", "dist/blender.exe")
		if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
			shutil.copy("blenderplayer.exe", "dist/blenderplayer.exe")
		shutil.copy("../lib/windows/python/lib/python23.dll", "dist/python23.dll")
		shutil.copy("../lib/windows/sdl/lib/SDL.dll", "dist/SDL.dll")
		shutil.copy("../lib/windows/gettext/lib/gnu_gettext.dll", "dist/gnu_gettext.dll")
	elif sys.platform in ['linux2', 'linux-i386']:
		shutil.copy("blender", "dist/blender")
		if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
			shutil.copy("blenderplayer", "dist/blenderplayer")
	else:
		print "update preparedist() for your platform!"
		return 0
	
	# now copy .blender and necessary extras for it
	if os.path.isdir("dist/.blender"):
		shutil.rmtree("dist/.blender")
	os.chdir("bin")
	shutil.copytree(".blender/", "../dist/.blender")
	os.chdir(startdir)
	if os.path.isdir("dist/.blender/scripts"):
		shutil.rmtree("dist/.blender/scripts")
	if os.path.isdir("dist/.blender/bpydata"):
		shutil.rmtree("dist/.blender/bpydata")
		
	os.makedirs("dist/.blender/bpydata")
	shutil.copy("release/bpydata/readme.txt", "dist/.blender/bpydata/readme.txt")
	shutil.copy("release/bpydata/KUlang.txt", "dist/.blender/bpydata/KUlang.txt")
	
	os.chdir("release")
	shutil.copytree("scripts/", "../dist/.blender/scripts")
	
	# finally copy auxiliaries (readme, license, etc.)
	if sys.platform == 'win32':
		shutil.copy("windows/extra/Help.url", "../dist/Help.url")
		shutil.copy("windows/extra/Python23.zip", "../dist/Python23.zip")
		shutil.copy("windows/extra/zlib.pyd", "../dist/zlib.pyd")
	shutil.copy("text/copyright.txt", "../dist/copyright.txt")
	shutil.copy("text/blender.html", "../dist/blender.html")
	shutil.copy("text/GPL-license.txt", "../dist/GPL-license.txt")
	shutil.copy("text/Python-license.txt", "../dist/Python-license.txt")
	
	reltext = "release_" + string.join(version.split("."), '') + ".txt"
	shutil.copy("text/" + reltext, "../dist/" + reltext)
	
	os.chdir(startdir)
	
	if cleanCVS()==0:
		return 0
	return 1

def finalisedist(zipname):
	"""
	Fetch the package created and remove temp dir
	"""
	
	try:
		import shutil
	except:
		print "no shutil available"
		print "make sure you use python 2.3"
		print
		return 0
	
	#shutil.copy("dist/" + zipname, zipname)
	#shutil.rmtree("dist")
	
	return 1

def add2arc(arc, file):
	if sys.platform == 'win32':
		arc.write(file)
	else:
		arc.add(file)

		
def appit(target, source, env):
	if sys.platform == 'darwin':
		import shutil
		import commands
		import os.path
						
		target = 'blender' 
		sourceinfo = "source/darwin/%s.app/Contents/Info.plist"%target
		targetinfo = "%s.app/Contents/Info.plist"%target

		cmd = '%s.app'%target
		if os.path.isdir(cmd):
			shutil.rmtree('%s.app'%target)
		shutil.copytree("source/darwin/%s.app"%target, '%s.app'%target)
		cmd = "cat %s | sed s/VERSION/`cat release/VERSION`/ | sed s/DATE/`date +'%%Y-%%b-%%d'`/ > %s"%(sourceinfo,targetinfo)
		commands.getoutput(cmd)
		cmd = 'cp %s %s.app/Contents/MacOS/%s'%(target, target, target)
		commands.getoutput(cmd)
		if  user_options_dict['BUILD_BINARY'] == 'debug':
			print "building debug"
		else :
			cmd = 'strip -u -r %s.app/Contents/MacOS/%s'%(target, target)
			commands.getoutput(cmd)
		cmd = '%s.app/Contents/Resources/'%target
		shutil.copy('bin/.blender/.bfont.ttf', cmd)
		shutil.copy('bin/.blender/.Blanguages', cmd)
		cmd = 'cp -R bin/.blender/locale %s.app/Contents/Resources/'%target
		commands.getoutput(cmd)	
		cmd = 'mkdir %s.app/Contents/MacOS/.blender'%target
		commands.getoutput(cmd)
		cmd = 'cp -R release/bpydata %s.app/Contents/MacOS/.blender'%target
		commands.getoutput(cmd)
		cmd = 'cp -R release/scripts %s.app/Contents/MacOS/.blender/'%target
		commands.getoutput(cmd)
		cmd = 'cp -R release/plugins %s.app/Contents/Resources/'%target 
		commands.getoutput(cmd)
		cmd = 'chmod +x  %s.app/Contents/MacOS/%s'%(target, target)
		commands.getoutput(cmd)
		cmd = 'find %s.app -name CVS -prune -exec rm -rf {} \;'%target
		commands.getoutput(cmd)
		cmd = 'find %s.app -name .DS_Store -exec rm -rf {} \;'%target
		commands.getoutput(cmd)
		
		if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
			target = 'blenderplayer' 
			sourceinfo = "source/darwin/%s.app/Contents/Info.plist"%target
			targetinfo = "%s.app/Contents/Info.plist"%target

			cmd = '%s.app'%target
			if os.path.isdir(cmd):
				shutil.rmtree('%s.app'%target)
			shutil.copytree("source/darwin/%s.app"%target, '%s.app'%target)
			cmd = "cat %s | sed s/VERSION/`cat release/VERSION`/ | sed s/DATE/`date +'%%Y-%%b-%%d'`/ > %s"%(sourceinfo,targetinfo)
			commands.getoutput(cmd)
			cmd = 'cp %s %s.app/Contents/MacOS/%s'%(target, target, target)
			commands.getoutput(cmd)
			if  user_options_dict['BUILD_BINARY'] == 'debug':
				print "building debug player"
			else :
				cmd = 'strip -u -r %s.app/Contents/MacOS/%s'%(target, target)
				commands.getoutput(cmd)
			cmd = '%s.app/Contents/Resources/'%target
			shutil.copy('bin/.blender/.bfont.ttf', cmd)
			shutil.copy('bin/.blender/.Blanguages', cmd)
			cmd = 'cp -R bin/.blender/locale %s.app/Contents/Resources/'%target
			commands.getoutput(cmd)
			cmd = 'cp -R release/bpydata %s.app/Contents/MacOS/.blender'%target
			commands.getoutput(cmd)
			cmd = 'cp -R release/scripts %s.app/Contents/MacOS/.blender/'%target
			commands.getoutput(cmd)
			cmd = 'cp -R release/plugins %s.app/Contents/Resources/'%target 
			commands.getoutput(cmd)
			cmd = 'chmod +x  %s.app/Contents/MacOS/%s'%(target, target)
			commands.getoutput(cmd)
			cmd = 'find %s.app -name CVS -prune -exec rm -rf {} \;'%target
			commands.getoutput(cmd)
			cmd = 'find %s.app -name .DS_Store -exec rm -rf {} \;'%target
			commands.getoutput(cmd)
		
	else:
		print "This target is for the Os X platform only"

def zipit(env, target, source):
	try:
		if sys.platform == 'win32':
			import zipfile
		else:
			import tarfile
	except:
		if sys.platform == 'win32':
			print "no zipfile module found"
		else:
			print "no tarfile module found"
			print "make sure you use python 2.3"
		print
		return
	
	import shutil
	import glob
	import time
	
	startdir = os.getcwd()
	pf=""
	zipext = ""
	zipname = ""
	
	today = time.strftime("%Y%m%d", time.gmtime()) # get time in the form 20040714
	
	if preparedist()==0:
		print "check output for error"
		return
	
	if sys.platform == 'win32':
		zipext += ".zip"
		pf = "windows"
	elif sys.platform == 'linux2' or sys.platform == 'linux-i386':
		zipext += ".tar.gz"
		pf = "linux"
	
	if user_options_dict['BUILD_BINARY'] == 'release':
		blendname = "blender-" + version + "-" + config_guess
	else:
		blendname = "bf_blender_" + pf + "_" + today
	
	zipname = blendname + zipext

	if os.path.isdir(blendname):
		shutil.rmtree(blendname)
	shutil.move(startdir + os.sep + "dist", blendname)

	print
	if sys.platform == 'win32':
		print "Create the zip!"
	elif sys.platform == 'linux2' or sys.platform == 'linux-i386':
		print "Create the tarball!"
	print
	
	if sys.platform == 'win32':
		thezip = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
	else:
		thezip = tarfile.open(zipname, 'w:gz')
	
	for root, dirs, files in os.walk(blendname, topdown=False):
		for name in files:
			if name in [zipname]:
				print "skipping self"
			else:
				file = root + "/" + name
				print "adding: " + file
				add2arc(thezip, file)
	
	thezip.close()
	
	os.chdir(startdir)
	shutil.move(blendname, startdir + os.sep + "dist")
	
	if finalisedist(zipname)==0:
		print "encountered an error in finalisedist"
		print
		return
	
	print
	print "Blender has been successfully packaged"
	print "You can find the file %s in the root source directory"%zipname
	print
	

def printadd(env, target, source):
	"""
	Print warning message if platform hasn't been added to zipit() yet
	"""
	
	print
	print "############"
	print 
	print "Make sure zipit() works for your platform:"
	print "  - binaries to copy (naming?)"
	print "  - possible libraries?"
	print "  - archive format?"
	print
	print "After you've corrected zipit() for your"
	print "platform, be sure to add a proper elif"
	print "at the end of BlenderRelease"
	print
	print "Blender is now ready and can be found in"
	print "root of the source distribution, but it"
	print "hasn't been packaged neatly. Make sure you"
	print "get the right files"
	print
	print "/jesterKing"
	print
	

def noaction(env, target, source):
	print "Empty action"

def DoClean(dir2clean):
	"""
	Do a removal of the root_build_dir the fast way
	"""
	
	import shutil
	print
	print "start the clean"
	dirs = os.listdir(dir2clean)
	for dir in dirs:
		if os.path.isdir(dir2clean + "/" + dir) == 1:
			print "clean dir %s"%(dir2clean+"/" + dir)
			shutil.rmtree(dir2clean+"/" + dir)
	print "done"

def BlenderDefault(target):
	"""
	The default Blender build.
	"""
	def_env = Environment()
	default = def_env.Command('nozip', 'blender$PROGSUFFIX', noaction)
	if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
		def_env.Depends(default, 'blenderplayer$PROGSUFFIX')
	def_env.Alias(".", default)

def donsis(env, target, source):
	"""
	Create a Windows installer with NSIS
	"""
	print
	print "Creating the Windows installer"
	print
	
	startdir = os.getcwd()
	
	if preparedist()==0:
		print "check output for error"
		return
	
	os.chdir("release/windows/installer")
	
	nsis = open("00.sconsblender.nsi", 'r')
	nsis_cnt = str(nsis.read())
	nsis.close()
	
	# do root
	rootlist = []
	rootdir = os.listdir(startdir + "\\dist")
	for rootitem in rootdir:
		if os.path.isdir(startdir + "\\dist\\" + rootitem) == 0:
			rootlist.append("File " + startdir + "\\dist\\" + rootitem)
	rootstring = string.join(rootlist, "\n  ")
	rootstring += "\n\n"
	nsis_cnt = string.replace(nsis_cnt, "[ROOTDIRCONTS]", rootstring)
	
	# do delete items
	delrootlist = []
	for rootitem in rootdir:
		if os.path.isdir(startdir + "\\dist\\" + rootitem) == 0:
			delrootlist.append("Delete $INSTDIR\\" + rootitem)
	delrootstring = string.join(delrootlist, "\n ")
	delrootstring += "\n"
	nsis_cnt = string.replace(nsis_cnt, "[DELROOTDIRCONTS]", delrootstring)
	
	# do scripts
	scriptlist = []
	scriptdir = os.listdir(startdir + "\\dist\\.blender\\scripts")
	for scriptitem in scriptdir:
		if os.path.isdir(startdir + "\\dist\\.blender\\scripts\\" + scriptitem) == 0:
			scriptlist.append("File " + startdir + "\\dist\\.blender\\scripts\\" + scriptitem)
	scriptstring = string.join(scriptlist, "\n  ")
	scriptstring += "\n\n"
	nsis_cnt = string.replace(nsis_cnt, "[SCRIPTCONTS]", scriptstring)
	
	# do bpycontents
	bpydatalist = []
	bpydatadir = os.listdir(startdir + "\\dist\\.blender\\bpydata")
	for bpydataitem in bpydatadir:
		if os.path.isdir(startdir + "\\dist\\.blender\\bpydata\\" + bpydataitem) == 0:
			bpydatalist.append("File " + startdir + "\\dist\\.blender\\bpydata\\" + bpydataitem)
	bpydatastring = string.join(bpydatalist, "\n  ")
	bpydatastring += "\n\n"
	nsis_cnt = string.replace(nsis_cnt, "[BPYCONTS]", bpydatastring)
	
	# do dotblender
	dotblendlist = []
	dotblenddir = os.listdir(startdir+"\\dist\\.blender")
	for dotblenditem in dotblenddir:
		if os.path.isdir(startdir + "\\dist\\.blender\\" + dotblenditem) == 0:
			dotblendlist.append("File " + startdir + "\\dist\\.blender\\" + dotblenditem)
	dotblendstring = string.join(dotblendlist, "\n  ")
	dotblendstring += "\n\n"
	nsis_cnt = string.replace(nsis_cnt, "[DOTBLENDERCONTS]", dotblendstring)
	
	# do language files
	langlist = []
	langfiles = []
	langdir = os.listdir(startdir + "\\dist\\.blender\\locale")
	for langitem in langdir:
		if os.path.isdir(startdir + "\\dist\\.blender\\locale\\" + langitem) == 1:
			langfiles.append("SetOutPath $BLENDERHOME\\.blender\\locale\\" + langitem + "\\LC_MESSAGES")
			langfiles.append("File " + startdir + "\\dist\\.blender\\locale\\" + langitem + "\\LC_MESSAGES\\blender.mo")
	langstring = string.join(langfiles, "\n  ")
	langstring += "\n\n"
	nsis_cnt = string.replace(nsis_cnt, "[LANGUAGECONTS]", langstring)
	
	# var replacements
	nsis_cnt = string.replace(nsis_cnt, "DISTDIR", startdir + "\\dist")
	nsis_cnt = string.replace(nsis_cnt, "SHORTVER", shortversion)
	nsis_cnt = string.replace(nsis_cnt, "VERSION", version)
	
	new_nsis = open("00.blender_tmp.nsi", 'w')
	new_nsis.write(nsis_cnt)
	new_nsis.close()
	
	sys.stdout = os.popen("makensis 00.blender_tmp.nsi", 'w')
	
	os.chdir(startdir)
	
	
def BlenderNSIS(target):
	"""
	Entry for creating Windows installer
	"""
	if sys.platform == 'win32':
		inst_env = Environment()
		nsis_inst = inst_env.Command('nsisinstaller', 'blender$PROGSUFFIX', donsis)
		if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
			inst_env.Depends(nsis_inst, 'blenderplayer$PROGSUFFIX')
		inst_env.Alias("wininst", nsis_inst)
	else:
		print "This target is for the win32 platform only "

def BlenderRelease(target):
	"""
	Make a Release package (tarball, zip, bundle).
	
	target = Name of package to make (string)
	eg: BlenderRelease('blender')
	"""
	
	if sys.platform == 'darwin':
		app_env = Environment()
		Mappit = app_env.Command('appit', appname, appit)
		if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
			app_env.Depends(Mappit, playername)
		app_env.Alias("release", Mappit)
	elif sys.platform in ['win32', 'linux2', 'linux-i386']:
		release_env = Environment()
		releaseit = release_env.Command('blenderrelease', appname, zipit)
		if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
			release_env.Depends(releaseit, playername)
		release_env.Alias("release", releaseit)
	else:
		release_env = Environment()
		releaseit = release_env.Command('blender.tar.gz', appname, printadd)
		if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
			release_env.Depends(releaseit, playername)
		release_env.Alias("release", releaseit)

if enable_clean == 0:

	
	if user_options_dict['BUILD_BLENDER_DYNAMIC'] == 1:
		dy_blender = link_env.Copy ()
		if sys.platform=='win32':
			winblenderres(dy_blender)
		blender_libs(dy_blender)
		common_libs(dy_blender)
		international_libs(dy_blender)
		ketsji_libs(dy_blender)
		system_libs(dy_blender)
		dy_blender.Append (LIBS=user_options_dict['OPENGL_LIBRARY'])
		dy_blender.Append (LIBPATH=user_options_dict['OPENGL_LIBPATH'])
		dy_blender.Append (CPPPATH=user_options_dict['OPENGL_INCLUDE'])
		d_obj = buildinfo(dy_blender, "dynamic")
		if sys.platform == 'win32':
			dy_blender.Program (target='blender',
						source=d_obj + ['source/icons/winblender.res'])
		else:
			if sys.platform == 'cygwin':
				dy_blender.Replace (CC='g++')
			dy_blender.Program (target='blender', source=d_obj)
	
	if user_options_dict['BUILD_BLENDER_STATIC'] == 1:
		st_blender = link_env.Copy ()
		if sys.platform=='win32':
			winblenderres(st_blender)
		blender_libs(st_blender)
		common_libs(st_blender)
		international_libs(st_blender)
		ketsji_libs(st_blender)
		system_libs(st_blender)
		# The next line is to make sure that the LINKFLAGS are appended at the end
		# of the link command. This 'trick' is needed because the GL and GLU static
		# libraries need to be at the end of the command.
		st_blender.Replace(LINKCOM="$LINK -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS $LINKFLAGS")
		s_obj = buildinfo(st_blender, "static")
		st_blender.Append (LINKFLAGS=user_options_dict['OPENGL_STATIC'])
		st_blender.Append (CPPPATH=user_options_dict['OPENGL_INCLUDE'])
		st_blender.Prepend (LIBPATH=['/usr/lib/opengl/xfree/lib'])
		st_blender.Program (target='blenderstatic', source=s_obj)
	
	if sys.platform=='win32':
		if user_options_dict['BUILD_BINARY']=='debug':
			browser = Environment()
			browser_tmp = root_build_dir+'bscmake.tmp'
			browser.Command ('blender.bsc', 'blender$PROGSUFFIX',
				['dir /b/s '+root_build_dir+'*.sbr >'+browser_tmp,
				 'bscmake /nologo /n /oblender.bsc @'+browser_tmp,
				 'del '+browser_tmp])
	
	if user_options_dict['BUILD_BLENDER_PLAYER'] == 1 and user_options_dict['BUILD_GAMEENGINE'] == 1:
		player_blender = link_env.Copy()
		player_libs(player_blender)
		common_libs(player_blender)
		international_libs(player_blender)
		ketsji_libs(player_blender)
		player_libs2(player_blender)
		system_libs(player_blender)
		player_blender.Append (LIBS=user_options_dict['OPENGL_LIBRARY'])
		player_blender.Append (LIBPATH=user_options_dict['OPENGL_LIBPATH'])
		player_blender.Append (CPPPATH=user_options_dict['OPENGL_INCLUDE'])
		d_obj = buildinfo(player_blender, "player")
		if sys.platform == 'win32':
			player_blender.Program (target='blenderplayer',
						source=d_obj + ['source/icons/winblender.res'])
		else:
			if sys.platform == 'cygwin':
				player_blender.Replace (CC='g++')
			player_blender.Program (target='blenderplayer', source=d_obj)
		if sys.platform=='win32':
			if user_options_dict['BUILD_BINARY']=='debug':
				browser = Environment()
				browser_tmp = root_build_dir+'bscmake.tmp'
				browser.Command ('blenderplayer.bsc', 'blenderplayer$PROGSUFFIX',
				['dir /b/s '+root_build_dir+'*.sbr >'+browser_tmp,
				'bscmake /nologo /n /oblenderplayer.bsc @'+browser_tmp,
				'del '+browser_tmp])

	release_target = env.Alias("release", BlenderRelease(appname))
	default_target = env.Alias("default", BlenderDefault(appname))
	wininst_target = env.Alias("winist", BlenderNSIS(appname))
		
else: # only clean target to prevent any building
	clean_target = env.Alias("clean", DoClean(root_build_dir))
	Default("clean")

if enable_clean == 0: # only set up dependencies when not cleaning
	if sys.platform == 'darwin':
		Default("release")
	else:
		Default("default")

	if sys.platform == 'win32':
		if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
			env.Depends(wininst_target, playername)
		env.Depends(wininst_target, appname)
	
	if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
		env.Depends(release_target, playername)
	env.Depends(release_target, appname)
	
	if user_options_dict['BUILD_BLENDER_PLAYER'] == 1:
		env.Depends(default_target, playername)
	env.Depends(default_target, appname)