-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmuddle_build_toolchain.py
executable file
·1562 lines (1270 loc) · 65 KB
/
muddle_build_toolchain.py
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
#! /usr/bin/env python
"""
muddle_build_toolchain.py
This script invokes a bunch of commands to build a toolchain from a
CodeSourcery source package.
It is not formally a part of muddle because you normally want to
build toolchains separately from your build, under controlled
conditions.
muddle_build_toolchain.py relies on a configuration file, like
those in examples/toolchains .
Usage: muddle_build_toolchain.py [config file] <[stage]>
Patches are from whole package directories so given:
binutils-notworking
binutils-working
do
diff -urN binutils-notworking binutils-working > my.patch
Switches:
--help Print out this help.
"""
import sys
import os
import re
import xml.dom
import xml.dom.minidom
import muddled
import muddled.xmlconfig as xmlconfig
# Should we run just the stage specified, or from the stage
# specified?
gStageExact = False
class GiveUp(Exception):
pass
def unpack_bz2(srcdir,filename,tmpdir):
rv = os.chdir(tmpdir)
if rv:
raise GiveUp("Cannot change directory to %s"%tmpdir)
full_filename = os.path.join(srcdir,filename)
rv = run_command("bzip2 -dc %s | tar xvf - "%full_filename)
if rv:
raise GiveUp("Can't unpack %s - %d"%(filename, rv))
def archive_exists(config,pkg):
return config.exists("/toolchain/sources/%s/archive"%pkg)
def query_archive(config, pkg):
return config.query_string("/toolchain/sources/%s/archive"%pkg)
def query_dir(config,pkg):
return config.query_string("/toolchain/sources/%s/dir"%pkg)
def restore_env(saved):
os.environ = saved
def set_env(k,v):
os.environ[k] = v
def append_env(k,v):
if (k in os.environ):
os.environ[k] = "%s:%s"%(os.environ[k], v)
else:
os.environ[k] = v
def prepend_env(k,v):
if (k in os.environ):
os.environ[k] = "%s:%s"%(v,os.environ[k])
else:
os.environ[k] = v
def run_command(cmd):
print "%s\n"%cmd
return os.system(cmd)
def do_configure(actual_dir,opts):
rv = os.chdir(actual_dir)
if rv:
raise GiveUp,"Cannot change dir to %s"%actual_dir
rv = run_command("./configure %s"%opts)
if rv:
raise GiveUp,"Cannot configure - %d"%rv
def do_ext_configure(actual_dir,config_dir,opts):
"""
Change directory to actual_dir, and run config_dir/configure with opts
"""
rv = os.chdir(actual_dir)
if rv:
raise GiveUp,"Cannot change dir to %s"%actual_dir
rv = run_command("%s/configure %s"%(config_dir,opts))
if rv:
raise GiveUp,"Cannot configure - %d"%rv
def do_make(actual_dir, opts, tgt):
rv = os.chdir(actual_dir)
if rv:
raise GiveUp, "Cannot change dir to %s"%actual_dir
rv = run_command("make %s %s"%(opts, tgt))
if rv:
raise GiveUp, "[%s] Cannot make %s - %d"%(actual_dir,tgt,rv)
def build_gnu(base_dir,package_dir,config_options, make_opts):
actual_dir = os.path.join(base_dir, package_dir)
do_configure(actual_dir, config_options)
do_make(actual_dir, make_opts, "all")
do_make(actual_dir, make_opts, "install")
def run_stage(this_one,specd):
global gStageExact
if (gStageExact and this_one == specd):
print "> Run stage %d (%d) OK. \n"%(this_one, specd)
return True
elif ((not gStageExact) and this_one >= specd):
print "> Run stage %d (%d) OK. \n"%(this_one, specd)
return True;
else:
print "> Run stage %d (%d) Bad - Don't run.\n"%(this_one, specd)
return False
def clean_build_dir(root,dir):
clean_dir(os.path.join(root,dir))
def clean_dir(dname):
os.system("rm -rf %s"%(dname))
def rename(in_dir, src, dst, force = True):
if force:
clean_dir(os.path.join(in_dir, dst))
print "%s: Renaming %s to %s (force = %s)"%(in_dir, src, dst, force)
os.rename(os.path.join(in_dir, src), \
os.path.join(in_dir, dst))
def patch(config, dst_dir, dst_pkg, patch_dir, patch_name):
i = 0;
while True:
key_name = "/toolchain/sources/%s/patch%d"%(patch_name,i)
if (config.exists(key_name)):
patch_name = config.query_string(key_name)
print "> Patching %s with %s .."%(patch_name, key_name)
os.chdir(os.path.join(dst_dir, dst_pkg))
rv = run_command("patch -p1 < %s"%(os.path.join(patch_dir,patch_name)))
if rv:
raise GiveUp, "Cannot patch package %s with patch %s"%\
(dst_pkg, patch_name)
i = i + 1
else:
break
def copy_dir_into(src_dir,dst_dir):
rv=os.system("mkdir -p %s"%dst_dir)
if rv:
print "Could not create destination directory: got error %s"%rv
rv=os.system("cp -a %s %s"%(os.path.join(src_dir,"*"), dst_dir))
if rv:
print "Could not copy files: got error %s"%rv
def make_writable(dir):
os.system("chmod -R u+w %s"%dir)
def make_dir(dir):
os.system("mkdir -p %s"%dir)
def copy_file(src_file, dst_file):
os.system("cp %s %s"%(src_file,dst_file))
def move_file(src_file,dst_file):
print "Moving %s -> %s "%(src_file,dst_file)
os.system("mv %s %s"%(src_file, dst_file))
def do_unlink(src_file):
print "Unlink %s"%src_file
os.system("rm -f %s"%src_file)
def build_dir_list(src_dir):
dir_contents=os.listdir(src_dir)
dirs=[]
for name in dir_contents:
if not os.path.isfile(os.path.join(src_dir,name)):
dirs.append(name)
return dirs
def build_file_list(src_dir):
dir_contents=os.listdir(src_dir)
files=[]
for name in dir_contents:
if os.path.isfile(os.path.join(src_dir,name)):
files.append(name)
return files
def do_glibc_build(config, src_dir,install_baremetal,host_tools, \
pkgversion, bugurl, \
glibc_src_base, glibc_build_base, \
variant, cflags, current_stage, specd_start, \
doc_dir):
"""Build glibc itself - args are the same as do_glibc_headers
doc_dir Documentation dir into which we'll copy the generated docs.
"""
old_env = os.environ
# We've already unpacked whatever glibc we were going to use, so
# just reuse what's already there.csdac
glibc_src_dir = os.path.join(glibc_src_base, variant)
glibc_build_dir = os.path.join(glibc_build_base, variant)
host_arch = config.query_string("/toolchain/host-arch");
target = config.query_string("/toolchain/bare-metal-target")
if (run_stage(current_stage, specd_start)):
saved_env = os.environ
set_env("CC", "%s %s"%(os.path.join(host_tools, "bin", \
"%s-gcc"%target),
cflags))
set_env("CXX", "%s %s"%(os.path.join(host_tools, "bin",
"%s-g++"%target),
cflags))
set_env("CFLAGS", "-g -O2")
set_env("AR", os.path.join(host_tools, "bin", \
"%s-ar"%target))
set_env("RANLIB", \
os.path.join(host_tools, "bin",\
"%s-ranlib"%target))
make_dir(glibc_build_dir)
linux_version = config.query_string("/toolchain/sources/linux/version")
do_ext_configure(glibc_build_dir, glibc_src_dir, \
"--prefix=/usr " + \
("--with-headers=%s "%\
(os.path.join(install_baremetal, "libc", "usr", "include"))) +\
("--build=%s "%(host_arch)) + \
("--host=%s "%target) +\
"--disable-profile " +\
"--without-gd " + \
"--without-cvs " + \
"--enable-add-ons " +\
("--enable-kernel=%s "%linux_version) +\
("--with-pkgversion=%s "%pkgversion) +\
("--with-bugurl=%s "%bugurl))
if (variant == "default"):
install_root = os.path.join(install_baremetal, "libc")
else:
install_root = os.path.join(install_baremetal, "libc", \
variant)
current_stage = current_stage + 1
# 068/184 et seq.
if (run_stage(current_stage, specd_start)):
do_make(glibc_build_dir, "-j4", "all")
do_make(glibc_build_dir, "install_root=%s"%(os.path.join(install_baremetal, "libc")),\
"install")
current_stage = current_stage + 1
if (run_stage(current_stage, specd_start)):
copy_dir_into(os.path.join(glibc_build_dir, "manual", "libc"), \
os.path.join(doc_dir, "html"))
make_dir(os.path.join(doc_dir, "pdf"))
copy_file(os.path.join(glibc_build_dir, "manual", "libc.pdf"), \
os.path.join(doc_dir, "pdf", "libc.pdf"))
# Now we want to remove a whole bunchof libraries.
libc_install_dir = os.path.join(install_baremetal, "libc")
do_unlink(os.path.join(libc_install_dir, "usr", "libexec", "pt_chown"))
clean_dir(os.path.join(libc_install_dir, "usr", "lib", "libc_pic"))
for i in ("libBrokenLocale_pic", "libanl_pic", "libc_pic", "libcidn_pic", \
"libcrypt_pic", "libdl_pic", "libm_pic", "libnsl_pic", \
"libnss_compat_pic", "libnss_dns_pic", "libnss_files_pic", \
"libnss_hesiod_pic", "libnss_nis_pic", "libnss_nisplus_pic", \
"libresolv_pic", "librt_pic", "libthread_db_pic", \
"libutil_pic"):
do_unlink(os.path.join(libc_install_dir, "usr", "lib", i + ".a"))
do_unlink(os.path.join(libc_install_dir, "usr", "lib", i + ".map"))
tgt_bindir = os.path.join(libc_install_dir, "usr", "lib", "bin")
make_dir(tgt_bindir)
for i in ("ldconfig", "sln"):
move_file(os.path.join(libc_install_dir, "sbin", i), \
os.path.join(tgt_bindir, i))
for i in ("catchsegv", "gencat", "getconf", "getent", "iconv", "ldd", \
"locale", "localedef", "mtrace", "pcprofiledump", \
"rpcgen", "sprof", "tzselect", "xtrace"):
move_file(os.path.join(libc_install_dir, "usr", "bin", i), \
os.path.join(tgt_bindir, i))
for i in ("iconvconfig", "nscd", "rpcinfo", "zdump", "zic"):
move_file(os.path.join(libc_install_dir, "usr", "sbin", i), \
os.path.join(tgt_bindir, i))
current_stage = current_stage + 1
return current_stage
def do_glibc_headers(config, src_dir, install_baremetal, host_tools, \
pkgversion, bugurl, \
first_build, header_dir, \
variant_dir, cflags, current_stage, specd_start):
"""Builds a glibc and installs headers and crt0 etc.
first_build is where the glibc goes (typically tmp_host_dir/glibc-first)
header_dir is where headers will be installed (host_obj/glibc-headers-x)
variant_dir the variant directory - default/ armv4t etc.
cflags the flags passed to gcc when building glibc
stage current stage.
start_stage Stage to start at.
Returns the next stage.
"""
glibc_first_dir = first_build
glibc_header_dir = header_dir
host_arch = config.query_string("/toolchain/host-arch");
old_env = os.environ
bare_metal_target = config.query_string("/toolchain/bare-metal-target")
# [054/184]
# Let's go for glibc0.
if (run_stage(current_stage, specd_start)):
make_dir(glibc_first_dir)
unpack_bz2(src_dir, query_archive(config, "glibc"), glibc_first_dir)
rename(glibc_first_dir, query_dir(config, "glibc"), variant_dir)
if (archive_exists(config,"glibc-ports")):
unpack_bz2(src_dir, query_archive(config, "glibc-ports"), glibc_first_dir)
rename(glibc_first_dir, query_dir(config, "glibc-ports"), \
os.path.join(variant_dir, "ports"), force = True)
make_writable(glibc_first_dir)
default_dir = os.path.join(glibc_first_dir, variant_dir)
glibc_header_default = os.path.join(glibc_header_dir, variant_dir)
current_stage = current_stage + 1
if (run_stage(current_stage,specd_start)):
saved_env = os.environ
set_env("CC", "%s %s"%(os.path.join(host_tools, "bin", \
"%s-gcc"%bare_metal_target),
cflags))
set_env("CXX", "%s %s"%(os.path.join(host_tools, "bin",
"%s-g++"%bare_metal_target),
cflags))
set_env("CFLAGS", "-g -O2")
set_env("AR", os.path.join(host_tools, "bin", \
"%s-ar"%bare_metal_target))
set_env("RANLIB", \
os.path.join(host_tools, "bin",\
"%s-ranlib"%bare_metal_target))
make_dir(glibc_header_dir)
make_dir(glibc_header_default)
do_ext_configure(glibc_header_default, default_dir,\
"--prefix=/usr " + \
"--with-headers=%s "%\
(os.path.join(install_baremetal, "libc", "usr","include")) +\
("--build=%s"%(host_arch)) + \
" --host=%s "%bare_metal_target + \
"--disable-profile " + \
"--without-gd " + \
"--without-cvs " + \
"--enable-add-ons " + \
"--enable-kernel=2.6.14 " + \
"--with-pkgversion=%s "%pkgversion + \
"--with-bugurl=%s "%bugurl)
# Work out the install dir .
if (variant_dir == "default"):
install_root = os.path.join(install_baremetal, "libc")
else:
install_root = os.path.join(install_baremetal, "libc", \
variant_dir)
current_stage = current_stage + 1
if (run_stage(current_stage, specd_start)):
do_make(glibc_header_default, \
"install_root=%s "%install_root + \
"install-bootstrap-headers=yes ",\
"install-headers")
do_make(glibc_header_default, "", "csu/subdir_lib")
make_dir(os.path.join(install_root, "usr", "lib"))
for i in ("crt1.o", "crti.o", "crtn.o"):
copy_file(os.path.join(glibc_header_default, "csu", i), \
os.path.join(install_root,"usr",\
"lib",i))
os.system("%s %s -o %s -nostdlib -nostartfiles -shared -x c /dev/null"%\
(os.path.join(host_tools, "bin", \
"arm-none-linux-gnueabi-gcc"), \
cflags, \
os.path.join(install_root, \
"usr", "lib", \
"libc.so")))
current_stage = current_stage + 1
os.environ = old_env
return current_stage
def do_localedef(build_dir, test_dir, src, charset, dest):
rv=os.chdir(build_dir)
if rv:
raise GiveUp, "Cannot change to dir %s"%build_dir
# rv=run_command("./localedef --quiet -c --little-endian --uint32-align=4 " + \
# ("-i glibc/localedata/locales/%s "%src) + \
# ("-f glibc/localedata/charmaps/%s "%charset) + \
# ("little4/usr/lib/locale/test/%s"%dest))
rv=run_command("./localedef --quiet -c --little-endian --uint32-align=4 " + \
("-i glibc/localedata/locales/%s "%src) + \
("-f glibc/localedata/charmaps/%s "%charset) + \
(test_dir+"/%s"%dest))
if rv:
raise GiveUp, "Cannot run command %d"%rv
def build_glibc(config, build_stage, stage):
"""
Build a toolchain with glibc
"""
doc_target = config.query_string("/toolchain/doc-target")
tmp_dir = "/tmp/muddle-toolchain-tmp"
tmp_host_dir = os.path.join(tmp_dir, "host")
gcc_final_dir = os.path.join( tmp_host_dir, "gcc-final")
src_dir = config.query_string("/toolchain/src-dir")
unpacked_gcc = os.path.join(tmp_host_dir, query_dir(config, "gcc"))
bare_metal_target = config.query_string("/toolchain/bare-metal-target")
pkgversion = config.query_string("/toolchain/version")
bugurl = config.query_string("/toolchain/bugurl")
host_arch = config.query_string("/toolchain/host-arch");
dest_dir = config.query_string("/toolchain/dest-dir")
dest_dir_none = os.path.join(dest_dir,
config.query_string("/toolchain/bare-metal-target"),
"libc")
support_tools = os.path.join(dest_dir, "support-tools")
patch_dir = config.query_string("/toolchain/patch-dir")
host_tools = os.path.join(dest_dir, "host-tools")
host_obj = os.path.join(tmp_dir, "host-obj")
install_baremetal = os.path.join(host_tools, \
bare_metal_target)
default_arch = config.query_string("/toolchain/arch")
default_opts = config.query_string("/toolchain/opts")
variants = config.query_hashlist("/toolchain/variant", [ "arch", "opts"])
doc_dir = os.path.join(host_tools, "share", "doc", doc_target)
tools_install_options = \
("prefix=%s exec_prefix=%s libdir=%s" +\
" htmldir=%s pdfdir=%s infodir=%s mandir=%s datadir=%s")%\
(host_tools,\
host_tools,\
os.path.join(host_tools,"lib"),\
os.path.join(host_tools,\
"share/doc/%s/html"%(doc_target)),\
os.path.join(host_tools,\
"share/doc/%s/pdf"%(doc_target)),\
os.path.join(host_tools,\
"share/doc/%s/info"%(doc_target)),\
os.path.join(host_tools,\
"share/doc/%s/man"%(doc_target)),\
os.path.join(host_tools,\
"share"))
# Task [046/184]
linux_srcdir = os.path.join(tmp_host_dir,
query_dir(config, "linux"))
linux_tmp_hdrdir = os.path.join(host_obj, \
"tmp-linux-headers")
if (run_stage(build_stage,stage)):
make_dir(os.path.join(install_baremetal,"libc/usr/include"))
make_dir(os.path.join(install_baremetal,"libc/usr/include/bits"))
make_dir(os.path.join(install_baremetal,"libc/usr/include/gnu"))
unpack_bz2(src_dir, query_archive(config,"linux"), tmp_host_dir)
clean_dir(linux_tmp_hdrdir)
print "In %s"%(linux_srcdir)
do_make(linux_srcdir, "", \
("ARCH=arm CROSS_COMPILE=%s INSTALL_HDR_PATH=%s "+\
"headers_install")%\
(os.path.join(host_tools,"bin/%s-"%bare_metal_target),\
linux_tmp_hdrdir))
for i in ("linux", "asm", "asm-generic", "mtd", "rdma", \
"sound", "video"):
copy_dir_into(os.path.join(linux_tmp_hdrdir, "include", i),\
os.path.join(install_baremetal, "libc", "usr",\
"include", i))
build_stage = build_stage + 1
libc_sysroot = os.path.join(install_baremetal, "libc")
for i in variants:
make_dir(os.path.join(install_baremetal, "libc", i["arch"]))
make_dir(os.path.join(install_baremetal, "libc", i["arch"]))
set_env("AR_FOR_TARGET", "%s-ar"%(bare_metal_target))
set_env("NM_FOR_TARGET", "%s-nm"%(bare_metal_target))
set_env("OBJDUMP_FOR_TARGET", "%s-objdump"%(bare_metal_target))
set_env("STRIP_FOR_TARGET", "%s-strip"%(bare_metal_target))
gcc_first_dir = os.path.join(tmp_host_dir, "gcc-first")
unpacked_gcc = os.path.join(tmp_host_dir, query_dir(config, "gcc"))
# Task [047/184]
if (run_stage(build_stage,stage)):
clean_dir(gcc_first_dir)
make_dir(gcc_first_dir)
# Make sure we don't use stdlib for the first gcc.
specs= "%{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables} %{O2:%{!fno-remove-local-statics: -fremove-local-statics}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: -fremove-local-statics}}}"
stdcxx="-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm"
# C++ does not get built for the first gcc, for obvious
# reasons (we'll try to link against our unwind lib, which uses
# glibc, before we're ready)
do_ext_configure(gcc_first_dir, unpacked_gcc, \
( ("--build=%s --host=%s "%(host_arch,host_arch)) +\
("--target=%s "%(bare_metal_target)) +\
"--enable-threads "+\
"--disable-libmudflap "+\
"--disable-libssp "+\
"--disable-libstdcxx-pch " +\
"--enable-symvers=gnu " +\
"--with-gnu-as " +\
"--with-gnu-ld " +\
("--with-arch=%s "%(default_arch)) + \
"--enable-languages=c "+\
"--enable-shared "+\
"--disable-lto " +\
"--enable-symvers=gnu "+\
"--enable-__cxa_atexit " +\
("--with-pkgversion=\"%s\" "%pkgversion) +\
("--with-bugurl=\"%s\" "%bugurl) +\
"--disable-nls " +\
("--prefix=%s "%dest_dir) +\
"--disable-shared " +\
"--disable-threads "+\
"--disable-libssp " +\
"--disable-libgomp " +\
"--without-headers " +\
"--with-newlib " +\
"--disable-decimal-float "+\
"--disable-libffi " +\
"--enable-languages=c "+\
("'--with-specs=%s' "%(specs)) + \
("'--with-host-libstdcxx=%s' "%(stdcxx)) + \
("--with-sysroot=%s "%dest_dir_none) +\
("--with-build-sysroot=%s "%\
(os.path.join(install_baremetal, "libc"))) +\
("--with-gmp=%s "%support_tools) +\
("--with-mpfr=%s "%support_tools) +\
("--with-ppl=%s "%support_tools) +\
"--disable-libgomp "+\
"--enable-poison-system-directories " +\
("--with-build-time-tools=%s"%\
(os.path.join(install_baremetal, "bin"))))\
)
do_make(gcc_first_dir, \
("LD_FLAGS_FOR_TARGET=--sysroot=%s "%libc_sysroot) +\
("CPPFLAGS_FOR_TARGET=--sysroot=%s "%libc_sysroot) +\
("build_tooldir=%s"%install_baremetal), "all")
do_make(gcc_first_dir, \
tools_install_options, "install")
clean_dir(os.path.join(host_tools, "include"))
do_unlink(os.path.join(host_tools, "lib/libiberty.a"))
do_unlink(os.path.join(host_tools, "bin/%s-gccbug"%bare_metal_target))
build_stage = build_stage + 1
glibc_first_dir = os.path.join(tmp_host_dir, "glibc-first")
glibc_header_dir = os.path.join(host_obj, "glibc-headers-x")
# [054/184]
# We build three glibcs - default/, armv4t/ and thumb2/
#os.environ = saved2_env
# Next is 057/184
print "Building glibc0 (ARM) @ stage 8 (specd %d)"%stage
build_stage = do_glibc_headers(config, \
src_dir, install_baremetal, \
host_tools,\
pkgversion, bugurl, \
glibc_first_dir, \
glibc_header_dir, \
"default", default_opts, build_stage, stage)
for var in variants:
arch = var["arch"]
opts = var["opts"]
print "Building glibc (%s) @ stage %d"%(arch,build_stage)
build_stage = do_glibc_headers(config, \
src_dir, install_baremetal, \
host_tools,\
pkgversion, bugurl, \
glibc_first_dir, \
glibc_header_dir, \
arch, \
opts,\
build_stage, \
stage)
gcc_second_dir = os.path.join(tmp_host_dir, "gcc-second")
print "Building our second gcc at stage %d, in %s"%(build_stage,gcc_second_dir)
# [063/184]
if run_stage(build_stage, stage):
clean_dir(gcc_second_dir)
make_dir(gcc_second_dir)
saved_env = os.environ
set_env("CC_FOR_BUILD", "gcc")
set_env("CC", "gcc")
set_env("AR", "ar")
set_env("RANLIB", "ranlib")
append_env("PATH", os.path.join(tmp_host_dir, "bin"))
append_env("LD_LIBRARY_PATH", os.path.join(tmp_host_dir, "lib"))
do_ext_configure(gcc_second_dir, unpacked_gcc, \
("--build=%s --host=%s "%(host_arch,host_arch)) + \
("--target=%s "%bare_metal_target) +\
"--enable-threads "+\
"--disable-libmudflap "+\
"--disable-libssp "+\
"--disable-libstdcxx-pch "+\
"--with-gnu-as " +\
"--with-gnu-ld " +\
"--enable-languages=c,c++ " +\
"--enable-shared " +\
"--enable-symvers=gnu " +\
"--enable-__cxa_atexit " +\
"--with-pkgversion=\"%s\" "%pkgversion + \
"--with-bugurl=\"%s\" "%bugurl + \
"--disable-nls " +\
("--prefix=%s "%dest_dir) +\
"--enable-languages=c " +\
"--disable-libffi " +\
("--with-sysroot=%s "%\
os.path.join(dest_dir, bare_metal_target, "libc")) +\
"--with-build-sysroot=%s "%libc_sysroot +\
"--with-gmp=%s "%support_tools +\
"--with-mpfr=%s "%support_tools +\
"--disable-libgomp " +\
"--enable-poison-system-directories " +\
("--with-build-time-tools=%s"% \
os.path.join(install_baremetal, "bin")))
do_make(gcc_second_dir,
("LDFLAGS_FOR_TARGET=--sysroot=%s "%(os.path.join(install_baremetal, "libc"))) +
("CPPFLAGS_FOR_TARGET=--sysroot=%s "%(os.path.join(install_baremetal, "libc"))) +
("build_tooldir=--sysroot=%s"%install_baremetal), "all")
do_make(gcc_second_dir,
tools_install_options,
"install")
clean_dir(os.path.join(host_tools, "include"))
do_unlink(os.path.join(host_tools, "lib/libiberty.a"))
do_unlink(os.path.join(host_tools, "bin/%s-gccbug"%bare_metal_target))
os.environ = saved_env;
glibc_second_src = os.path.join(tmp_host_dir, "glibc-first")
glibc_second_build = os.path.join(tmp_host_dir, "glibc-second-build")
build_stage = build_stage + 1
# [067/184] second stage glibc build.
print "Second stage glibc @ %d"%build_stage
build_stage = do_glibc_build(config, src_dir, install_baremetal, \
host_tools,\
pkgversion, bugurl, \
glibc_second_src, \
glibc_second_build, \
"default", default_opts, build_stage, stage,\
doc_dir)
for i in variants:
arch = var["arch"]
opts = var["opts"]
print "Second stage glibc for %s @ %d"%(arch, build_stage)
build_stage = do_glibc_build(config, src_dir, install_baremetal, \
host_tools,\
pkgversion, bugurl, \
glibc_second_src, \
glibc_second_build, \
arch, opts, build_stage,stage, \
doc_dir)
print "Building locale definitions @ %d"%build_stage
locale_build_dir = os.path.join(tmp_host_dir,
query_dir(config, "glibc-localedef"))
locale_install_dir = os.path.join(locale_build_dir, "install_test_locales")
locale_little4_dir = os.path.join(locale_install_dir, "little4")
locale_test_dir = os.path.join(locale_little4_dir, "usr", "lib", "locale", "test")
if run_stage(build_stage, stage):
#[076/184]
clean_dir(locale_build_dir)
unpack_bz2(src_dir, query_archive(config, "glibc-localedef"), tmp_host_dir)
saved_env = os.environ
set_env("CC_FOR_BUILD", "gcc")
set_env("CC", "gcc")
set_env("AR", "ar")
set_env("RANLIB", "ranlib")
append_env("PATH", os.path.join(tmp_host_dir, "bin"))
append_env("LD_LIBRARY_PATH", os.path.join(tmp_host_dir, "lib"))
print "local build dir is %s"%locale_build_dir
print "glibc_second_src is %s"%(os.path.join(glibc_second_src, "default"))
do_configure(locale_build_dir, \
"--prefix=/usr " +\
"--with-glibc=%s"%(os.path.join(glibc_second_src, "default")))
do_make(locale_build_dir, "-j4", "all")
#start of #[077/184]
locale_opts = config.query_string("/toolchain/sources/glibc-localedef/options")
do_make(locale_build_dir, "install_root=%s "%(locale_little4_dir) + \
("'LOCALEDEF_OPTS=%s'"%locale_opts),
"install-locales")
os.environ = saved_env
build_stage = build_stage + 1
print "Creating test locales @ %d"%build_stage
if (run_stage(build_stage, stage)):
print "default build"
make_dir(locale_test_dir)
print "locale test dir is %s"%locale_test_dir
print "locale build dir is %s"%locale_build_dir
f = open(os.path.join(locale_test_dir, "README"),"w")
f.write("The locales in this directory are used by the GLIBC test harness\n")
f.close()
set_env("I18NPATH", os.path.join(glibc_second_src, "localedata"))
set_env("GCONV_PATH", "iconvdata")
# do_localedef(locale_build_dir, locale_test_dir, "de_DE", "ISO-8859-1", "de_DE.ISO-8859-1")
for lang in ["de_DE", "en_US", "da_DK", "sv_SE", "fr_FR", "nb_NO", "nn_NO"]:
do_localedef( locale_build_dir, locale_test_dir, lang, "ISO-8859-1", lang+".ISO-8859-1" )
for lang in ["de_DE", "en_US", "ja_JP", "tr_TR", "cs_CZ", "fa_IR", "fr_FR"]:
do_localedef( locale_build_dir, locale_test_dir, lang, "UTF-8", lang+".UTF-8")
do_localedef( locale_build_dir, locale_test_dir, "hr_HR", "ISO-8859-2", "hr_HR.ISO-8859-2" )
do_localedef( locale_build_dir, locale_test_dir, "en_US", "ANSI_X3.4-1968", "en_US.ANSI_X3.4-1968" )
do_localedef( locale_build_dir, locale_test_dir, "ja_JP", "EUC-JP", "ja_JP.EUC-JP" )
do_localedef( locale_build_dir, locale_test_dir, "ja_JP", "SHIFT_JIS", "ja_JP.SHIFT_JIS" )
do_localedef( locale_build_dir, locale_test_dir, "vi_VN", "TCVN5712-1", "vi_VN.TCVN5712-1" )
do_localedef( locale_build_dir, locale_test_dir, "zh_TW", "EUC-TW", "zh_TW.EUC-TW" )
copy_dir_into( locale_little4_dir, os.path.join( host_tools, bare_metal_target, "libc") )
build_stage = build_stage + 1
if (run_stage(build_stage, stage)):
#Stage 29: Start of #[078/184]
#for each directory in locale_little4_dir/usr/lib/locale,
#create a directory with subdirectory "LC_MESSAGES" in
#host_tools/arm-none-linux-gnueabi/libc/armv4t/usr/lib/locale
#and create links from targets to sources for all files
for var in variants:
arch = var["arch"]
opts = var["opts"]
print "Relocating locales for variant %s"%(arch)
locale_definitions_base_dir=os.path.join(locale_little4_dir,"usr","lib","locale")
dir_list=build_dir_list(locale_definitions_base_dir)
test_dir_list=build_dir_list(os.path.join(locale_definitions_base_dir,"test"))
for name in dir_list:
if name!="test":
#create directory
locale_definitions_target_dir=os.path.join(host_tools,
bare_metal_target,"libc",
arch,"usr","lib","locale",name)
print locale_definitions_target_dir
print os.path.join(locale_definitions_base_dir, name)
make_dir(locale_definitions_target_dir)
#get a list of all files in the directory
file_list=build_file_list(os.path.join(locale_definitions_base_dir, name))
#link files
for filename in file_list:
src_file=os.path.join( locale_definitions_base_dir,name, filename )
target_file=os.path.join(locale_definitions_target_dir, filename)
try:
os.link(src_file, target_file)
except:
#do_unlink(target_file)
os.system("rm -f %s"%target_file)
os.link(src_file, target_file)
#do the same for the subdirectory LC_MESSAGES
locale_definitions_target_dir=os.path.join(host_tools,
bare_metal_target,
"libc",arch,
"usr","lib","locale",
name,"LC_MESSAGES")
make_dir(locale_definitions_target_dir)
#get a list of all files in the directory
file_list=build_file_list(os.path.join(locale_definitions_base_dir,
name, "LC_MESSAGES"))
#link files
for filename in file_list:
src_file=os.path.join( locale_definitions_base_dir,name,
"LC_MESSAGES", filename )
target_file=os.path.join(locale_definitions_target_dir, filename)
try:
os.link(src_file, target_file)
except:
#do_unlink(target_file)
os.system("rm -f %s"%target_file)
os.link(src_file, target_file)
else:
#create test directory
locale_definitions_target_dir=os.path.join(host_tools,bare_metal_target,
"libc",arch,"usr","lib",
"locale","test")
make_dir(locale_definitions_target_dir)
for testname in test_dir_list:
#create test subdirectories
locale_definitions_target_dir=os.path.join(host_tools,
bare_metal_target,
"libc",arch,
"usr","lib","locale",
"test",testname)
make_dir(locale_definitions_target_dir)
print locale_definitions_target_dir
print os.path.join(locale_definitions_base_dir, "test", testname)
#get directory contents
file_list=build_file_list(os.path.join(locale_definitions_base_dir, "test", testname))
#link files
for filename in file_list:
src_file=os.path.join( locale_definitions_base_dir, "test",
testname, filename )
target_file=os.path.join(locale_definitions_target_dir, filename)
try:
os.link(src_file, target_file)
except:
do_unlink(target_file)
os.link(src_file, target_file)
#do the same for the subdirectory LC_MESSAGES
locale_definitions_target_dir=os.path.join(host_tools,
bare_metal_target,
"libc",arch,
"usr","lib","locale",
"test",testname,"LC_MESSAGES")
make_dir(locale_definitions_target_dir)
#get directory contents
file_list=build_file_list(os.path.join(locale_definitions_base_dir,
"test", testname, "LC_MESSAGES"))
#link files
for filename in file_list:
src_file=os.path.join( locale_definitions_base_dir, "test", testname, "LC_MESSAGES", filename )
target_file=os.path.join(locale_definitions_target_dir, filename)
try:
os.link(src_file, target_file)
except:
do_unlink(target_file)
os.link(src_file, target_file)
build_stage = build_stage + 1
if (run_stage(build_stage, stage)):
#Stage 31
#[080/184]
#run configuration for the final gcc build
clean_dir(gcc_final_dir)
make_dir(gcc_final_dir)
#gcc has already been unpacked, so skip straight to the configuration
do_ext_configure(gcc_final_dir, unpacked_gcc, \
("--build=%s --host=%s "%(host_arch,host_arch)) + \
("--target=%s "%bare_metal_target) +\
"--enable-threads "+\
"--disable-libmudflap "+\
"--disable-libssp "+\
"--disable-libstdcxx-pch "+\
"--with-gnu-as " +\
"--with-gnu-ld " +\
"--enable-languages=c,c++ " +\
"--enable-shared " +\
"--enable-symvers=gnu " +\
"--enable-__cxa_atexit " +\
"--with-pkgversion=\"%s\" "%pkgversion + \
"--with-bugurl=\"%s\" "%bugurl + \
"--disable-nls " +\
("--prefix=%s "%dest_dir) +\
("--with-sysroot=%s "%\
os.path.join(dest_dir, bare_metal_target, "libc")) +\
"--with-build-sysroot=%s "%libc_sysroot +\
("--with-gmp=%s "%support_tools) +\
("--with-mpfr=%s "%support_tools) +\
"--disable-libgomp " +\
"--enable-poison-system-directories " +\
("--with-build-time-tools=%s"% \
os.path.join(install_baremetal, "bin")))
#[081/184]: the final gcc build
do_make(gcc_final_dir,
("LDFLAGS_FOR_TARGET=--sysroot=%s "%(os.path.join(install_baremetal, "libc"))) +
("CPPFLAGS_FOR_TARGET=--sysroot=%s "%(os.path.join(install_baremetal, "libc"))) +
("build_tooldir=--sysroot=%s"%install_baremetal), "all")
#[082/184]: install the final gcc build
do_make(gcc_final_dir, tools_install_options, "install")
#[083/184]: postinstall the final gcc build
clean_dir(os.path.join(host_tools, "include"))
do_unlink(os.path.join(host_tools, "lib/libiberty.a"))
for var in variants:
arch = var["arch"]
do_unlink(os.path.join(host_tools, "lib/%s/libiberty.a"%arch))
do_unlink(os.path.join(host_tools, "bin/%s-gccbug"%bare_metal_target))
build_stage = build_stage + 1
return build_stage
def build_none(config, build_stage, stage):
"""
Build a toolchain without a library at all.
"""
doc_target = config.query_string("/toolchain/doc-target")
tmp_dir = "/tmp/muddle-toolchain-tmp"
tmp_host_dir = os.path.join(tmp_dir, "host")
gcc_final_dir = os.path.join( tmp_host_dir, "gcc-final")
src_dir = config.query_string("/toolchain/src-dir")
unpacked_gcc = os.path.join(tmp_host_dir, query_dir(config, "gcc"))
if (config.exists("/toolchain/bare-metal-target")):
bare_metal_target = config.query_string("/toolchain/bare-metal-target")
else:
bare_metal_target = None
pkgversion = config.query_string("/toolchain/version")
bugurl = config.query_string("/toolchain/bugurl")
dest_dir = config.query_string("/toolchain/dest-dir")
patch_dir = config.query_string("/toolchain/patch-dir")
host_tools = os.path.join(dest_dir, "host-tools")
support_tools = os.path.join(dest_dir, "support-tools")
host_obj = os.path.join(tmp_dir, "host-obj")
if (bare_metal_target is not None):