summaryrefslogtreecommitdiff
path: root/.Attic/README.old_stage2
blob: eb2a232b4bab66aefb01a530613073f7be1d48ef (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
# old stage 2 based on a broken stage 1, so carefull what to pick
# into the next version..


# generic build
###############

for p in $PACKAGES

	# for ncurses, readline for bash
	# autoreconf needs autotools/m4 and dependencies (crosstool-ng autotools are broken for me)
	# libunistring for gettext
	# libffi for glib2
	bsdtar xf $STAGE1_CHROOT/packages/i486/libffi-3.2.1-2-i486.pkg.tar.gz 
	popd

	cd ..
done

testing:

# common issues
###############


TODOS: in linux package makepkg
https://github.com/libarchive/libarchive/issues/411

https://rubenerd.com/sata-on-qemu/

/usr/libexec/qemu-kvm --enable-kvm -cpu 486 -m 32 -vnc 0.0.0.0:2 \
	-kernel linux/pkg/linux/boot/vmlinuz-linux \
	-append 'root=/dev/hda1 nomodeset init=/etc/rc console=ttyS0 console=tty0' \
	-cdrom /data/isos/arch486.iso -hda /data/libvirt/arch486.qcow2 -nographic

qemu-system-i386 --enable-kvm -cpu 486 -m 32 -cdrom /data/isos/arch486.iso \
	-hda /data/libvirt/arch486.qcow2 -curses -boot d \
	-netdev user,id=net0,net=10.0.0.0/24,host=10.0.0.2,dhcpstart=10.0.0.16,hostfwd=tcp::2222-:22 \
	-device rtl8139,netdev=net0

qemu-system-i386 --enable-kvm -cpu 486 -m 32 \
	-hda /home/cross/arch486.img -curses -boot d \
	-netdev user,id=net0,net=10.0.0.0/24,host=10.0.0.2,dhcpstart=10.0.0.16,hostfwd=tcp::2222-:22 \
	-device rtl8139,netdev=net0

PHASE 2
#######

Test what we can build inside the chroot.
When we get all dependencies right, we go into the real environment (which is
i486 and thus not SMP and slow- ok, we could use distcc, but anyway)

Main problem: we have trouble to run fakeroot in a chroot
fakeroot: nested operation not yet supported
makepkf -F takes care of that (thanks for providing minial fakeroot support)
but pacman also takes an -F parameter
-> INFAKEROOT=1 in /usr/bin/makepkg

As pacman seems to have some trouble, we overwrite the temp packages inside
the chroot and replace the files on the filesystem forcefully:
error: could not register 'temp' database (wrong or NULL argument passed)

In this round don't skip dependencies and tests if possible.

cp pkg/arch-install-scripts/usr/bin/arch-chroot /usr/local/bin/.

arch-chroot /home/cross/i486-root/

# package specific things

# bc
# requires texinfo, is this part of base-devel?
# bootstrap --force
# no /usr/lib32
# ./fbc -c ./libmath.b </dev/null >libmath.h


# libelf 
########
In file included from /usr/include/error.h:52:0,
                 from xmalloc.c:33:
/usr/include/bits/error.h: In function 'error':
/usr/include/bits/error.h:40:5: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]
     __error_noreturn (__status, __errnum, __format, __va_arg_pack ());
     ^~~~~~~~~~~~~~~~
=> -isystem in gcc specfile needed, not -I


# 
# libxml2
# go without icu for now, icu needs C++
# also, python bindings and git are not really needed
sed -i 's@^depends\(.*\)@#depends\1@g' libxml2/PKGBUILD
sed -i 's@^makedepends\(.*\)@#makedepends\1@g' libxml2/PKGBUILD
build()
{
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0 /g' libtool
  make
}
sed -i 's@--with-icu@@' libxml2/PKGBUILD
# dito package
# really, what is it with people!
# take: ftp://xmlsoft.org/libxml2/libxml2-2.9.7.tar.gz
#source=(git+https://git.gnome.org/browse/libxml2#commit=$_commit
# no tests, c++ tests would fail
./configure: line 13042: syntax error near unexpected token `Z,zlib,'
./configure: line 13042: `    PKG_CHECK_MODULES(Z,zlib,'
==> ERROR: A failure occurred in build().
    Aborting...
-> zlib probing needs pkg-config, which is it's own disaster, so disable
zlib for now.
=> hack out the broken PKG_CHECK_MODULES out of configure!
-> same trick for LZMA (equally broken) and ICU
-> disable testing for now, either it takes long or it hangs

# libgcrypt
# download location broken, download by hand, adapt PKGBUILD

# libxslt: same disaster as libxml2
# no python, no check

# kmod: circular dependency on linux-headers, let's build
# linux/linux-headers correctly outside the chroot and install
# them here (at least linux-headers)
# gtk-doc draws in Gnome bullshit again
sed -i 's@^makedepends\(.*\)@#makedepends\1@g' kmod/PKGBUILD

# inetutils:
# disable checks

# iroute2
# trying with iptables, as iptables draws in tons of things
sed -i 's@^makedepends\(.*\)@#makedepends\1@g' iproute2/PKGBUILD
sed -i 's@^depends\(.*\)@#depends\1@g' iproute2/PKGBUILD

# bison
# --nocheck: fails miserably to compile tests (C++ missing?)

# linux-headers: fails hapilly and has tons of weird stuff in it
install: failed to access ‘/home/cross/build/linux/pkg/linux-headers/usr/lib/modules/4.13.13-1/build’: No such file or directory
_package-headers()
=>  mkdir -p "${_builddir}" everywhere, the problem is install -D on Centos, obviously broken!

# kmod
configure: error: The pkg-config script could not be found or is too old.  Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.

Alternatively, you may set the environment variables liblzma_CFLAGS
and liblzma_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

To get pkg-config, see <http://pkg-config.freedesktop.org/>.
See `config.log' for more details
==> ERROR: A failure occurred in build().
    Aborting...
=> let's try to set lzma ourselves or disable it, get around pkg-config probing
# no pkg-config, no docu, try to work around
sed -i 's@--enable-gtk-doc@--disable-gtk-doc@g' kmod/PKGBUILD
sed -i 's@./configure@liblzma_CFLAGS=-I/usr/include liblzma_LIBS=-llzma ./configure@g' kmod/PKGBUILD
sed -i 's@./configure@zlib_CFLAGS=-I/usr/include zlib_LIBS=-lz ./configure@g' kmod/PKGBUILD
=> ok heck: linking errors
sed -i 's@--with-xz@--without-xz@g' kmod/PKGBUILD
sed -i 's@--with-zlib@--without-zlib@g' kmod/PKGBUILD

# libidn
# --nocheck, testing hangs

# iputils
# remove git again
# no docu, hack out manually 
sed -i 's@^makedepends\(.*\)@#makedepends\1@g' iptuils/PKGBUILD

# perl-error
# no checks, needs perl test-pod
sed -i 's@^checkdepends\(.*\)@#checkdepends\1@g' perl-error/PKGBUILD


# shadow
# git treatment again.
# no docu
# --disable-man

# tar:
# checking whether mknod can create fifo without root privileges... configure: error: in `/build/tar/src/tar-1.29':
# configure: error: you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)
# See `config.log' for more details
=> oh, please, bugger off!
sed -i 's@./configure@FORCE_UNSAFE_CONFIGURE=1 ./configure@g' tar/PKGBUILD

#TODO:

#TODO: libldap keyutils krb5 they end in circlejerk with systemd!
# we will solve that later by building a non-systemd version and then bootstrapping first systemd

# for now we don't rebuild ca-certificates, we had to copy them funilly anyway, and it's
# just a bunch of certs. So, in phase 3 or 4 then..

# curl
######
# curl needs asciidoc and p11-kit, don't build them, use them from the host
sed -i 's@makedepends\(.*\)@#makedepends\1@g' curl/PKGBUILD
# build with minimal features, enough to make pacman download packages
sed -i 's@depends\(.*\)@depends=('ca-certificates' 'openssl' 'zlib')@g' curl/PKGBUILD
# zsh, perl is used to create a completion file for curl and zsh?
sed -i 's@--with-gssapi@--with-gssapi --without-zsh-functions-dir@g' curl/PKGBUILD

# pacman
########
# pacman's tests mostly fail on non-Archlinux, so skip them
# asciidoc is a makedepend, we can use the one on the host
sed -i 's@makedepends\(.*\)@#makedepends\1@g' pacman/PKGBUILD
sed -i 's@checkdepends\(.*\)@#checkdepends\1@g' pacman/PKGBUILD
# minimal dependencies, we don't sign anything yet
sed -i "s/'gpgme'//g" pacman/PKGBUILD
sed -i "s/'pacman-mirrorlist'//g" pacman/PKGBUILD
sed -i "s/'archlinux-keyring'//g" pacman/PKGBUILD
# we need pkg-config, otherwise pacman find libarchive in the wrong
# place, but pkg-config needs glib2 and glib2 is built using meson (urgh!)
# when we take the host version, lets patch the host pkgconfig file to
# use the sysroot of the toolchain
# we simply set LIBARCHIVE_CFLAGS and LIBARCHIVE_LIBS to get rid of pkg-config probing
sed -i 's@./configure@LIBARCHIVE_CFLAGS=-I/usr/include LIBARCHIVE_LIBS=-larchive ./configure@g' pacman/PKGBUILD
# --nocheck still, as we don't have python yet
# and of course :-)
sed -i 's/exit 1 # \$E_USER_ABORT/# exit 1 # $E_USER_ABORT/g' /home/cross/i486-root/usr/bin/makepkg
# TODO
install: cannot stat '/build/pacman/src/pacman.conf.i486': No such file or directory
==> ERROR: A failure occurred in package().
    Aborting...
=> use the /etc/pacman-i486.conf from the chroot as pacman.conf.i486 (we still have the temp
   repo and we force the Architecture)
sed -i "s/686)/486)/g" pacman/PKGBUILD
sed -i 's/mycarch="i686"/mycarch="i486")/g' pacman/PKGBUILD
sed -i 's/mychost="i686-pc-linux-gnu"/mychost="i486-pc-linux-gnu"/g' pacman/PKGBUILD
sed -i 's/myflags="-march=i686"/myflags=-march=i486/g' pacman/PKGBUILD

# gmp
#####
# no C++
sed -i 's@--enable-cxx@--disable-cxx@g' gmp/PKGBUILD

# gawk
######
# we don't have a valid locale yet, disable NLS
# and disable testing
sed -i 's@./configure@./configure --disable-nls@g' PKGBUILD

# openssh
#########
# package suffers from featuritis
# remove ldns and kerberos5 support, keep libedit (as it's easy to build)
# ssh => not good, openssl <> unbound <> openssl cycle and mess
sed -i 's@^makedepends\(.*\)@#makedepends\1@g' PKGBUILD
sed -i 's@^depends\(.*\)@#depends\1@g' PKGBUILD
sed -i 's@--with-ldns@--without-ldns@g' PKGBUILD
sed -i 's@--with-kerberos5=/usr@--without-kerberos5@g' PKGBUILD
#ln: failed to create symbolic link '/build/openssh/pkg/openssh/usr/share/man/man1/slogin.1.gz': No such file or directory
sed -i 's@\(ln -sf ssh.1.gz.*\)@#\1@g' PKGBUILD

# git
#####
# manual PKGBUILD fix
#make: pkg-config: Command not found
#make: pkg-config: Command not found
#make: Leaving directory '/build/git/src/git-2.15.0/contrib/subtree'

# tcl
#####
# disable tests: cynical, disable unit tests of a software needed for testing

# dejagnu
#########
# has hard-wired AC_PROG_CXX in configure, remove internal C++ tests
sed -i '/.\/configure/ i \  sed -i "s@AC_PROG_CXX@#AC_PROG_CXX@" configure.ac' dejagnu/PKGBUILD
sed -i '/configure.ac/ a \  sed -i "s@\\(unit_SOURCES.*\\)@#\\1@g" Makefile.am' dejagnu/PKGBUILD
sed -i '/configure.ac/ a \  sed -i "s@\\(check_PROGRAMS*\\)@#\\1@g" Makefile.am' dejagnu/PKGBUILD
sed -i '/Makefile.am/ a \  autoreconf' dejagnu/PKGBUILD

# wget
######
# no gnutls, no libpsl
sed -i 's@^depends\(.*\)@#depends\1@g' PKGBUILD
sed -i 's@--enable-nls@--disable-nls@g' PKGBUILD
sed -i 's@--with-ssl=gnutls@--with-ssl=openssl@g' PKGBUILD
sed -i '/.\/configure/ a \    --without-libpsl \\' PKGBUILD
# work around pkg-config
sed -i 's@./configure@OPENSSL_CFLAGS=-I/usr/include OPENSSL_LIBS="-lssl lcrypto" ./configure@g' PKGBUILD
# needs myriads of perl modules for testing => --nocheck
sed -i 's@^checkdepends\(.*\)@#checkdepends\1@g' PKGBUILD

# binutils
##########
# risky, risky
sed -i 's/glibc>=2.26/glib/g' binutils/PKGBUILD
# this is in gold, so let's disable gold! We don't have C++ (yet), so this should not matter..
sed -i 's@--enable-gold@--disable-gold@g' binutils/PKGBUILD

# libunwind
###########
# no TeX, no docu
sed -i 's@^makedepends\(.*\)@#makedepends\1@g' libunwind/PKGBUILD


# TODO: gcc
#####
TODO:
sed -i 's@^makedepends\(.*\)@#makedepends\1@g' binutils/PKGBUILD
sed -i 's@^checkdepends\(.*\)@#checkdepends\1@g' binutils/PKGBUILD
sed -i 's@^depends\(.*\)@#depends\1@g' binutils/PKGBUILD

# gcc
#####
# no gcc-ada and doxygen
sed -i '/makedepend/ s/gcc-ada //g' gcc/PKGBUILD
sed -i '/makedepend/ s/doxygen //g' gcc/PKGBUILD
# avoid huge git checkouts
sed -i 's@git+https://gcc.gnu.org/git/gcc.git.*@ftp://ftp.mpi-sb.mpg.de/pub/gnu/mirror/gcc.gnu.org/pub/gcc/releases/${pkgname}-${pkgver}/${pkgname}-${pkgver}.tar.gz@' gcc/PKGBUILD
sed -i 's@cd gcc$@cd ${pkgname}-${pkgver}@g' gcc/PKGBUILD
sed -i 's@$srcdir/gcc/configure@$srcdir/${pkgname}-${pkgver}/configure@g' gcc/PKGBUILD
# we don't have a working C++ compiler right now, be must bootstrap
# doesn't work, we need c++ sind 4.8!
#sed -i '/--enable-shared/ a \      --enable-bootstrap \\' gcc/PKGBUILD
# remove ADA, we don't have (and will most likely never have a GNAT binary to
# bootstrap ADA itself), on the other hand, there is nothing using ADA anyway.
# at least not in packages/community
sed -i '/pkgname/ s/gcc-ada//g' gcc/PKGBUILD
sed -i '/enable-languages/ s/ada//g' gcc/PKGBUILD
# send bugs to the right place
sed -i 's@https://bugs.archlinux.org/@https://bugs.archlinux32.org/@g' gcc/PKGBUILD
# so, I don't know what GNU people call bootstrapping, but this definitely isn't for C!
/usr/include/c++/7.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
=> let's try to fix the C++ compiler then..
# this is really really dangerous, let's hope, it works
=> find /usr/include/c++/7.2.0 -type f -exec sed -i 's/#include_next/#include/g' {} \;
# /build/gcc/src/gcc-7.2.0/libgo/testsuite/gotest: line 624: 28445 Killed                  ./a.out -test.short -test.timeout=${timeout}s "$@"
=> ok, enough, go without testing
==> Starting package_gcc-go()...
make: *** i486-pc-linux-gnu/libgo: No such file or directory.  Stop.
==> ERROR: A failure occurred in package_gcc-go().
    Aborting...
=> fails, oh well, nobody needs go :-)



only c language
no checkdepdns, makedepnds

why the hell, I switched off c++, so wy are still cpp probes being done!?
/lib/cpp hardcoded, seriosly!!
# in prepare()
ln -s ../bin/cpp /home/cross/x-tools/i486-unknown-linux-gnu/lib/cpp
find . -name configure -exec sed -i 's@/lib/cpp@/home/cross/x-tools/i486-unknown-linux-gnu/bin/cpp@g' {} \;

since 4.8 gcc is written in C++, fine. so we have to have a crosstool-ng C++ or
=> we add C++ to the crosstool-ng toolchain, easier and more secure

 included from /home/cross/build/gcc/src/gcc-7.2.0/gcc/genmddeps.c:19:0:
/home/cross/build/gcc/src/gcc-7.2.0/gcc/system.h:540:34: error: declaration of C function ‘const cha
r* strsignal(int)’ conflicts with
 extern const char *strsignal (int);
                                  ^
In file included from /usr/include/c++/4.8.2/cstring:42:0,
                 from /home/cross/build/gcc/src/gcc-7.2.0/gcc/system.h:235,
                 from /home/cross/build/gcc/src/gcc-7.2.0/gcc/genmddeps.c:19:
/usr/include/string.h:562:14: error: previous declaration ‘char* strsignal(int)’ here
 extern char *strsignal (int __sig) __THROW;             ^
In file included from ./bconfig.h:5:0,
=> so, we get to an end here, c++ is taken from the host while cross-compiling?!
-> remove glibc-devel on the host!
-> draw the g++ link, autoconf fails in gcc in funny ways (not finding uint64_t)
-> carefull, we build a gcc over a crossng-gcc, not sure, this is supported..
-> aha. if mpfr, mpc and gmp are not installed and taken from sysroot but from i486-root
   some pathes get messed up.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82590
https://www.mail-archive.com/gcc-bugs@gcc.gnu.org/msg550065.html
https://gcc.gnu.org/bugzilla/show_bug.cgi?format=multiple&id=54692

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65863
-> huh?
https://gcc.gnu.org/ml/gcc-help/2016-06/msg00016.html
- > yes, this is the inicatition I needed, mpfr, gmp and mpc point to a weird location

The stage one compiler doesn't find the shared library, o well:
/home/cross/build/gcc/src/gcc-build/./gcc/cc1: error while loading shared libraries: libmpc.so.3: cannot open shared object file: No such file or directory
-> export LD_LIBRARY_PATH=/home/cross/x-tools/i486-unknown-linux-gnu/i486-unknown-linux-gnu/sysroot/usr/lib

And it never ends:
In file included from /home/cross/build/gcc/src/gcc-7.2.0/libgcc/libgcc2.c:27:0:
/home/cross/build/gcc/src/gcc-7.2.0/libgcc/../gcc/tsystem.h:87:10: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
          ^~~~~~~~~
compilation terminated.
make[2]: *** [Makefile:491: _muldi3.o] Error 1
-> https://gcc.gnu.org/ml/gcc-help/2012-04/msg00088.html
-> so, let's try giving it a --with-sysroot to the crosstool-ng dirs
-> and this means also it got past stage 1 compilers :-)

/home/cross/x-tools/i486-unknown-linux-gnu/lib/gcc/i486-unknown-linux-gnu/4.9.4/../../../../i486-unknown-linux-gnu/bin/ld: /home/cross/build/gcc/src/gcc-build/./gcc/liblto_plugin.so: error loading plugin: /home/cross/build/gcc/src/gcc-build/./gcc/liblto_plugin.so: wrong ELF class: ELFCLASS32
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:982: libgcc_s.so] Error 1
=> for now, remove LTO stuff in PKGBUILD

make: *** i486-unknown-linux-gnu/libstdc++-v3/doc: No such file or directory.  Stop.
==> ERROR: A failure occurred in build().
    Aborting...
=> remove the PKGBUILD line #  make -C $CHOST/libstdc++-v3/doc DESTDIR="$pkgdir" doc-install-man
libstdc++-v3/
=> # make documentation
  #make -C $CHOST/libstdc++-v3/doc doc-man-doxygen

install: failed to access ‘/home/cross/build/gcc/pkg/gcc/usr/lib/gcc/i486-unknown-linux-gnu/7.2.0/’: No such file or directory
=> gcc auto-probed itself into i486-pc-linux-gnu, so the installed files are there
CHOST="i486-pc-linux-gnu"    
make: Leaving directory '/home/cross/build/gcc/src/gcc-build/gcc'
install: failed to access ‘/home/cross/build/gcc/pkg/gcc/usr/lib/gcc/i486-unknown-linux-gnu/7.2.0/’: No such file or directory
=> sweet, let's try a symlink

_libdir=usr/lib/gcc/$CHOST/$pkgver
=> hard-code: to _libdir=usr/lib/gcc/i486-pc-linux-gnu/$pkgver
=> nope, now others break
this is hardly the ArchLinux way: vanilla and upstream

again CHOST set to  i486-pc-linux-gnu
=> this package is a disaster!
=> we have a mess with two CHOSTS, one for crosstool-ng (unknown) and
   one for our chroot

# remove traces of ADA
  rm "$pkgdir"/usr/share/info/{gccgo,gfortran.info}

# rm: cannot remove ‘/home/cross/build/gcc/pkg/gcc/usr/share/info/gccgo’: No such file or directory
#  rm "$pkgdir"/usr/share/info/{gccgo,gfortran.info}

/home/cross/x-tools/i486-unknown-linux-gnu/lib/gcc/i486-unknown-linux-gnu/4.9.4/../../../../i486-unknown-linux-gnu/bin/ld: cannot find -lquadmath
collect2: error: ld returned 1 exit status
libtool: install: error: relink `libgfortran.la' with the above command before installing it
make: *** [Makefile:1331: install-toolexeclibLTLIBRARIES] Error 1
make: Leaving directory '/home/cross/build/gcc/src/gcc-build/i486-unknown-linux-gnu/libgfortran'
==> ERROR: A failure occurred in package_gcc-libs().
    Aborting...
=> libquadmath must be retooled before libfortran
=> nope libfortran simply fails to relink => remove it

install: cannot stat ‘/home/cross/build/gcc/src/gcc/COPYING.RUNTIME’: No such file or directory
=> sweet, remove it

error: failed to commit transaction (conflicting files)
gcc: /home/cross/i486-root/usr/lib/libstdc++.a exists in filesystem (owned by gcc-libs)
gcc: /home/cross/i486-root/usr/lib/libstdc++.la exists in filesystem (owned by gcc-libs)
Errors occurred, no packages were upgraded.
=> well, force the package

test.c:1:10: fatal error: stdio.h: No such file or directory


# END TODO: gcc

# glibc
#######
# use 2.25 version, not 2.26. Keep the ABI intact!
# endless loop? gawk -f ../scripts/gen-as-const.awk pthread-pi-defines.sym \
# two reasons: clock and artifacts walk backwards or forward in time
# chroot on server with chroot, hard to have an asynchronous clock?
# or glibc is already installed on the system (where not?), so how the
# hell can it be possibly built!
# => oh, this would be cruel.
# or 3rd reason, we have a glibc shim, maybe this one causes some trouble
# => why?
# or libtool fixing, whatever fixing means (https://forums.gentoo.org/viewtopic-t-496052-start-0.html)
# => nope.
# -isystem /usr/includ ein gcc spec? quite likely!
# ah: old friend:
build/glibc/src/glibc-build/libc.a(dl-sysdep.o): In function `.L18':
dl-sysdep.c:(.text+0x8c): undefined reference to `__memcmp_ia32'
/build/glibc/src/glibc-build/libc.a(dl-sysdep.o): In function `.L87':
dl-sysdep.c:(.text+0x11f): undefined reference to `__memcmp_ia32'
/build/glibc/src/glibc-build/libc.a(dl-sysdep.o): In function `.L19':
dl-sysdep.c:(.text+0x152): undefined reference to `__memcmp_ia32'
/build/glibc/src/glibc-build/libc.a(dl-sysdep.o): In function `.L85':
dl-sysdep.c:(.text+0x19c): undefined reference to `__memcmp_ia32'
dl-sysdep.c:(.text+0x1b7): undefined reference to `__memcmp_ia32'
/build/glibc/src/glibc-build/libc.a(dl-sysdep.o):dl-sysdep.c:(.text+0x202): more undefined references to `__memcmp_ia32' follow
elf/sln
=> USE_MULTIARCH
=> --disable-multi-arch
=> let's test this time, too dangerous to loose the chroot otherwise!
# older 2.25 misses a binutils 2.29 patch:
https://git.busybox.net/buildroot/diff/package/glibc/0005-fix-binutils-2-29-build.patch?id=cf821efbd0b24690b52f379d4a9934a16073762e
{standard input}: Assembler messages:
{standard input}: Error: `loc1@GLIBC_2.0' can't be versioned to common symbol 'loc1'
{standard input}: Error: `loc2@GLIBC_2.0' can't be versioned to common symbol 'loc2'
{standard input}: Error: `locs@GLIBC_2.0' can't be versioned to common symbol 'locs'
make[2]: *** [../o-iterator.mk:9: /build/glibc/src/glibc-build/misc/regexp.os] Error 1

PACKAGES=" \
bzip2 xz flex bc elfutils \
libtool libxml2 libgpg-error libgcrypt libxslt \
docbook-xml docbook-xsl xmlto libcap libtirpc pambase pam inetutils bison iproute2 kmod \
sysfsutils libidn iputils \
expat acl attr lz4 tar libarchive curl pacman \
joe coreutils util-linux pcre grep findutils file diffutils ed patch \
autoconf automake libedit openssh libunwind strace wget \
gmp mpfr gawk libmpc zlib tcl expect dejagnu binutils gcc libtool glibc"
for p in $PACKAGES; do
	asp export $p   
done

for p in $PACKAGES
	cd $p

	sed -i "s/^arch=.*/arch=('i486')/" PKGBUILD

	# for some packages we cannot execute tests (because the dependencies to install in
	# the toolchain environment would be too much)
	# libelf: --nocheck
	# libtool: --nocheck
	# libxml2: --nocheck
	# libxslt: --nocheck
	# inetutils: --nocheck
	# bison: --nocheck
	# pacman: --nocheck
	# util-linux: --nocheck
	# gawk: --nocheck
	# tcl: --nocheck

	makepkg -C --config /etc/makepkg.conf --skipchecksums --skippgpcheck > $p.log 2>&1

	# TODO: 
	# some package break in parallel builds or produce really funky
	# error messages or/and results
	# binutils: use makepkg-noparallel.conf
        # gcc: use makepkg-noparallel.conf for debuging, the real build works fine in parallel
        
	cp -v *.pkg.tar.gz /packages/i486/.

	pacman --noconfirm --config /etc/pacman-i486.conf -U *.pkg.tar.gz 

	# replace all pacman articats and clean caches
	rm -rf /packages/i486/temp* /var/cache/pacman/pkg/*
	repo-add /packages/i486/temp.db.tar.gz /packages/i486/*pkg.tar.gz
	
	#repo-add -n /packages/i486/temp.db.tar.gz /packages/i486/*pkg.tar.gz

	pacman --noconfirm --config /etc/pacman-i486.conf -r / -S $p

	pacman --config /etc/pacman-i486.conf -r / -Q | grep $p
done

# aftermatch for gcc/binutils

#collect2: unable to find ld: this sounds bad, like an archicture mismatch somewhere
#in binutils/gcc
=> this is the cross compiled gcc for i486 inside the chroot, it expects
   its platform dependend stuff in /usr/lib/gcc/i486-unknown-linux-gnu/7.2.0
=> we can temporarily fix this:
ln -s /usr/bin/ld /usr/lib/gcc/i486-unknown-linux-gnu/7.2.0/ld
etc.

# aftermatch for glibc

# bacause pacman cannot set file permissions
chmod u+x /usr/bin/* /lib/*.so*

# kernel headers:
#/usr/include/linux/errno.h missing
#/usr/include/adm/errno.h missing
=> a libarchive compression issue, files missing, because they are in pkg of
  linux-api-headers?!

remove debug packages

error: failed to commit transaction (conflicting files)
/usr/lib/libstdc++.a exists in both 'gcc-libs' and 'gcc'
/usr/lib/libstdc++.la exists in both 'gcc-libs' and 'gcc'
/usr/lib/libblkid.a exists in both 'util-linux' and 'libutil-linux'
/usr/lib/libblkid.la exists in both 'util-linux' and 'libutil-linux'
/usr/lib/libfdisk.a exists in both 'util-linux' and 'libutil-linux'
/usr/lib/libfdisk.la exists in both 'util-linux' and 'libutil-linux'
/usr/lib/libmount.a exists in both 'util-linux' and 'libutil-linux'
/usr/lib/libmount.la exists in both 'util-linux' and 'libutil-linux'
/usr/lib/libsmartcols.a exists in both 'util-linux' and 'libutil-linux'
/usr/lib/libsmartcols.la exists in both 'util-linux' and 'libutil-linux'
/usr/lib/libuuid.a exists in both 'util-linux' and 'libutil-linux'
/usr/lib/libuuid.la exists in both 'util-linux' and 'libutil-linux'
Errors occurred, no packages were upgraded.

=> ok, we loose files and permissions

# in 'real' 486
###############

next round: do those problems persist

error: could not register 'temp' database (wrong or NULL argument passed)

installed binaries have wrong permissions (no execute permission), a pacman issue?
shilly flags? libarchive problem?

git: https helpers
chmod 0777 /usr/lib/git-core/git-remote-*

later: for inside the chroot