Mercurial > hg > aboriginal
changeset 1008:2d5e356580b9
Move sources/native to sources/native-root
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 25 Mar 2010 23:30:20 -0500 |
parents | 48784ae8533e |
children | 6762d6b8d5fc |
files | root-filesystem.sh sources/native-root/bin/getent sources/native-root/etc/group sources/native-root/etc/mdev.conf sources/native-root/etc/passwd sources/native-root/etc/resolv.conf sources/native-root/sbin/init.sh sources/native-root/src/hello.cpp sources/native-root/src/mklfs.sh sources/native-root/src/thread-hello.c sources/native-root/src/thread-hello2.c sources/native/bin/getent sources/native/etc/group sources/native/etc/mdev.conf sources/native/etc/passwd sources/native/etc/resolv.conf sources/native/sbin/init.sh sources/native/src/hello.cpp sources/native/src/mklfs.sh sources/native/src/thread-hello.c sources/native/src/thread-hello2.c |
diffstat | 21 files changed, 446 insertions(+), 446 deletions(-) [+] |
line wrap: on
line diff
--- a/root-filesystem.sh Thu Mar 25 18:54:30 2010 -0500 +++ b/root-filesystem.sh Thu Mar 25 23:30:20 2010 -0500 @@ -30,7 +30,7 @@ # Copy qemu setup script and so on. -cp -r "${SOURCES}/native/." "$STAGE_DIR/" && +cp -r "${SOURCES}/native-root/." "$STAGE_DIR/" && cp "$SRCDIR"/MANIFEST "$STAGE_DIR/src" || dienow # Build busybox and toybox
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/bin/getent Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,31 @@ +#!/bin/sh + +# Copyright 2009 Rob Landley <rob@landley.net>, licensed under GPLv2. + +isnum() +{ + [ ! -z "$(echo $1 | grep '^[0-9]*$')" ] +} + +nocomments() +{ + sed 's/\([^#]*\)#.*/\1/' /etc/$1 +} + +# The world's cheesiest getent implementation + +case "$1" in + passwd|group) + isnum "$2" && + grep -m 1 "[^:]*:[^:]*:$2:" /etc/$1 || + grep -m 1 "^$2:" /etc/$1 + ;; + + hosts|networks|protocols) + nocomments $1 | grep -m 1 -w "$2" + ;; + + services) + nocomments $1 | (isnum "$2" && grep -m 1 "[ ]$2/" || grep -m 1 -w "$2") + ;; +esac
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/etc/group Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,2 @@ +root:x:0: +guest:x:1:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/etc/mdev.conf Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,2 @@ +null 0:0 777 +(zero|random|urandom) 0:0 666
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/etc/passwd Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,2 @@ +root:x:0:0:root:/root:/bin/sh +guest:x:1:1:root:/root:/bin/sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/etc/resolv.conf Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,2 @@ +# This is the default for QEMU +nameserver 10.0.2.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/sbin/init.sh Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,93 @@ +#!/bin/sh + +# Otherwise, building source packages wants things like /bin/bash and +# running the results wants /lib/ld-uClibc.so.0, so set up some directories +# and symlinks to let you easily compile source packages. + +export HOME=/home + +# Populate /dev +mountpoint -q sys || mount -t sysfs sys sys +mountpoint -q dev || mount -t tmpfs -o noatime dev dev +mdev -s + +# Make sure /proc is there +mountpoint -q proc || mount -t proc proc proc + +export PS1='($HOST) \w \$ ' + +# If we're running under qemu, do some more setup +if [ $$ -eq 1 ] +then + + # Note that 10.0.2.2 forwards to 127.0.0.1 on the host. + + # Setup networking for QEMU (needs /proc) + ifconfig eth0 10.0.2.15 + route add default gw 10.0.2.2 + + # If we have no RTC, try rdate instead: + [ "$(date +%s)" -lt 1000 ] && rdate 10.0.2.2 # or time-b.nist.gov + + mount -t tmpfs /tmp /tmp + + # If there's a /dev/hdb or /dev/sdb, mount it on home + + [ -b /dev/hdb ] && HOMEDEV=/dev/hdb + [ -b /dev/sdb ] && HOMEDEV=/dev/sdb + if [ ! -z "$HOMEDEV" ] + then + mount -o noatime $HOMEDEV /home + else + mount -t tmpfs /home /home + fi + cd /home + + [ -b /dev/hdc ] && MNTDEV=/dev/hdc + [ -b /dev/sdc ] && MNTDEV=/dev/sdc + if [ ! -z "$MNTDEV" ] + then + mount -o ro $MNTDEV /mnt + fi + + CONSOLE="$(dmesg | + sed -n '/^Kernel command line:/s@.* console=\(/dev/\)*\([^ ]*\).*@\2@p')" + + if [ -z "$DISTCC_HOSTS" ] + then + echo "Not using distcc." + else + echo "Distcc acceleration enabled." + fi + echo Type exit when done. + + HANDOFF=/bin/ash + if [ -e /mnt/init ] + then + X=xx + echo "Press any key for command line..." + read -t 3 -n 1 X + if [ "$X" == xx ] + then + echo "Running automated build." + HANDOFF=/mnt/init + fi + fi + exec /bin/oneit -c /dev/"$CONSOLE" "$HANDOFF" + +# If we're not PID 1, it's probably a chroot. +else + [ ! -z "$(grep "default for QEMU" /etc/resolv.conf)" ] && + echo "nameserver 4.2.2.1" > /etc/resolv.conf + + # Switch to a shell with command history. + + echo Type exit when done. + /bin/ash + cd / + umount ./dev + umount ./home + umount ./sys + umount ./proc + sync +fi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/src/hello.cpp Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,8 @@ +#include <iostream> +using namespace std; + +int main() +{ + cout << "hello world" << endl; + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/src/mklfs.sh Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,200 @@ +#!/bin/bash + +[ -z "$LFS" ] && LFS=/home/lfs +[ -z "$CPUS" ] && CPUS=1 + +SCRIPTPATH="$(which "$0")" + +echo "LFS chapter 3: Download lfs-packages (grab one big tarball and extract)" + +if [ ! -d "$LFS"/packages/. ] +then + if [ ! -f "$LFS"/lfs-packages-6.3.tar ] + then + mkdir -p "$LFS" && + cd "$LFS" && + wget http://ftp.osuosl.org/pub/lfs/lfs-packages/lfs-packages-6.3.tar || + exit 1 + fi + + mkdir "$LFS"/packages && + cd "$LFS"/packages && + tar xvf ../lfs-packages-6.3.tar +fi + +echo "LFS chapter 4.4: clear environment" + +set +h +umask 022 +export LC_ALL=POSIX +export PATH=/tools/bin:/bin:/usr/bin + +# We can mostly use the FWL /tools tarball as the output of FWL chapter 5, +# except that glibc needs perl to build. So add perl to /tools. + +echo "LFS chapter 5.25: add perl to tools dir" + +if [ ! -f /tools/bin/perl ] +then + cd "$LFS" && + tar xvjf "$LFS"/packages/perl-*.tar.bz2 && + cd perl-5.*/ && + patch -p1 -i "$LFS"/packages/perl-*-libc-2.patch && + sed -i 's/libc\.so\.6/libc.so.0/g' hints/linux.sh && + ./configure.gnu --prefix=/tools -Dstatic_ext='Data/Dumper Fcntl IO POSIX' && + make -j $CPUS perl utilities && + PRIVLIB="$(sed -n 's/^privlib[\t ]*=[\t ]*//p' Makefile)" && + cp -v perl pod/pod2man /tools/bin && + mkdir -p "$PRIVLIB" && + cp -Rv lib/* "$PRIVLIB" && + cd .. && + rm -rf perl-5.*/ + + [ $? -ne 0 ] && exit 1 +fi + +echo "LFS chapter 6.2: setup chroot (plus bind mount /tools into new subdir)." + +if [ "$1" != "--no-chroot" ] +then + mkdir -p "$LFS"/{dev,proc,sys,tools,root/work} && + ln -s /packages "$LFS"/root/work/packages && + mount --bind /tools "$LFS"/tools && + mount -vt proc proc "$LFS"/proc && + mount -vt sysfs sysfs "$LFS"/sys || exit 1 + + # These are allowed to fail (may already exist if script is re-run), but + # must happen before the /dev bind mount to give udev stuff to use. + + mknod -m 600 "$LFS"/dev/console c 5 1 + mknod -m 666 "$LFS"/dev/null c 1 3 + + mount -v --bind /dev "$LFS"/dev || exit 1 + + # These may fail if host's /dev doesn't have pts or shm subdirectories. + + mount -vt devpts devpts "$LFS"/dev/pts + mount -vt tmpfs shm "$LFS"/dev/shm + + echo "LFS chapter 6.4: chroot (tweaked quite a bit)." + + # Perform the chroot, re-running this script with extra argument + # (--no-chroot) and several more environment variables + + cp "$SCRIPTPATH" "$LFS"/mklfs.sh && + chroot "$LFS" /tools/bin/env -i \ + HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ + PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ + UCLIBC_DYNAMIC_LINKER=/tools/lib/ld-uClibc.so.0 \ + UCLIBC_RPATH=/tools/lib LFS="/root/work" CPUS=$CPUS \ + /tools/bin/bash /mklfs.sh --no-chroot + + # The chroot exited. Snapshot return code, clean up mounts, return. + + RETVAL=$? + umount "$LFS"/{dev/{pts,shm},proc,sys,tools} + umount "$LFS"/dev + exit $RETVAL +fi + +# At this point, we've either done the chroot already or we're not doing one. + +echo "LFS chapter 6.5: creating directories" + +mkdir -p /{bin,boot,etc/opt,home,lib,mnt,opt} && +mkdir -p /{media/{floppy,cdrom},sbin,srv,var} && +install -dv -m 0750 /root && +install -dv -m 1777 /tmp /var/tmp && +mkdir -p /usr/{,local/}{bin,include,lib,sbin,src} && +mkdir -p /usr/{,local/}share/{doc,info,locale,man} && +mkdir /usr/{,local/}share/{misc,terminfo,zoneinfo} && +mkdir -p /usr/{,local/}share/man/man{1..8} || exit 1 +for dir in /usr /usr/local; do + ln -s share/{man,doc,info} $dir || exit 1 +done +mkdir /var/{lock,log,mail,run,spool} && +mkdir -p /var/{opt,cache,lib/{misc,locate},local} || exit 1 + +echo "LFS chapter 6.6: symlinks pointing into /tools and general bootstrapping" + +# Note: /etc/mtab is dead, so no touch: symlink /etc/mtab to /proc/mounts + +ln -s /tools/bin/{bash,cat,echo,grep,pwd,stty} /bin && +ln -s /tools/bin/perl /usr/bin && +ln -s /tools/lib/libgcc_s.so{,.1} /usr/lib && +ln -s /tools/lib/libstdc++.so{,.6} /usr/lib && +ln -s bash /bin/sh && +ln -s /proc/mounts /etc/mtab && + +cat > /etc/passwd << "EOF" && +root:x:0:0:root:/root:/bin/bash +nobody:x:99:99:Unprivileged User:/dev/null:/bin/false +EOF + +cat > /etc/group << "EOF" && +root:x:0: +bin:x:1: +sys:x:2: +kmem:x:3: +tty:x:4: +tape:x:5: +daemon:x:6: +floppy:x:7: +disk:x:8: +lp:x:9: +dialout:x:10: +audio:x:11: +video:x:12: +utmp:x:13: +usb:x:14: +cdrom:x:15: +mail:x:34: +nogroup:x:99: +EOF + +touch /var/run/utmp /var/log/{btmp,lastlog,wtmp} && +chgrp utmp /var/run/utmp /var/log/lastlog && +chmod 664 /var/run/utmp /var/log/lastlog || +exit 1 + +echo "LFS chapter 6.7: kernel API headers" + +cd "$LFS" && +tar xvjf "$LFS"/packages/linux-*.tar.bz2 && +cd linux-* && +sed -i '/scsi/d' include/Kbuild && +make -j $CPUS INSTALL_HDR_PATH=/usr headers_install && +cd .. && +rm -rf linux-* || +exit 1 + +echo "LFS 6.8: man pages" + +cd "$LFS" && +tar xvjf "$LFS"/packages/man-pages-*.tar.bz2 && +cd man-pages-* && +make -j $CPUS install && +cd .. && +rm -rf man-pages-* || +exit 1 + +echo "LFS 6.9: glibc" + +cd "$LFS" && +tar xvjf "$LFS"/packages/glibc-[0-9]*.tar.bz2 && +cd glibc-* && +tar xvzf "$LFS"/packages/glibc-libidn-*.tar.gz && +mv glibc-libidn-* libidn && +sed -i '/vi_VN.TCVN/d' localedata/SUPPORTED && +sed -i \ +'s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=/lib/ld-linux.so.2 -o|' \ + scripts/test-installation.pl && +sed -i 's|@BASH@|/bin/bash|' elf/ldd.bash.in && +mkdir ../glibc-build && +cd ../glibc-build && +../glibc-2.5.1/configure --prefix=/usr \ + --disable-profile --enable-add-ons \ + --enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc && +make -j $CPUS + +/tools/bin/ash
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/src/thread-hello.c Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,15 @@ +#define __REENTRANT +#include <pthread.h> +#include <stdio.h> + +void *threadhello(void *unused) +{ + printf("Hello, world!\n"); + return 0; +} + +int main() { + pthread_t thready; + pthread_create(&thready, NULL, &threadhello, NULL); + usleep(10); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native-root/src/thread-hello2.c Thu Mar 25 23:30:20 2010 -0500 @@ -0,0 +1,90 @@ +// Threaded hello world program that uses mutex and event semaphores to pass +// the string to print from one thread to another, and waits for the child +// thread to return a result before exiting the program. + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +// Thread, semaphores, and mailbox +struct thread_info { + pthread_t thread; + pthread_mutex_t wakeup_mutex; + pthread_cond_t wakeup_send, wakeup_receive; + unsigned len; + char *data; +}; + +// Create a new thread with associated resources. +struct thread_info *newthread(void *(*func)(void *)) +{ + struct thread_info *ti = malloc(sizeof(struct thread_info)); + memset(ti, 0, sizeof(struct thread_info)); + + pthread_create(&(ti->thread), NULL, func, ti); + + return ti; +} + +// Send a block of data through mailbox. +void thread_send(struct thread_info *ti, char *data, unsigned len) +{ + pthread_mutex_lock(&(ti->wakeup_mutex)); + // If consumer hasn't consumed yet, wait for them to do so. + if (ti->len) + pthread_cond_wait(&(ti->wakeup_send), &(ti->wakeup_mutex)); + ti->data = data; + ti->len = len; + pthread_cond_signal(&(ti->wakeup_receive)); + pthread_mutex_unlock(&(ti->wakeup_mutex)); +} + +// Receive a block of data through mailbox. +void thread_receive(struct thread_info *ti, char **data, unsigned *len) +{ + pthread_mutex_lock(&(ti->wakeup_mutex)); + if (!ti->len) + pthread_cond_wait(&(ti->wakeup_receive), &(ti->wakeup_mutex)); + *data = ti->data; + *len = ti->len; + // If sender is waiting to send us a second message, wake 'em up. + // Note that "if (ti->len)" be used as an unlocked/nonblocking test for + // pending data, although you still need call this function to read data. + ti->len = 0; + pthread_cond_signal(&(ti->wakeup_send)); + pthread_mutex_unlock(&(ti->wakeup_mutex)); +} + +// Function for new thread to execute. +void *hello_thread(void *thread_data) +{ + struct thread_info *ti = (struct thread_info *)thread_data; + + for (;;) { + unsigned len; + char *data; + + thread_receive(ti, &data, &len); + if (!data) break; + printf("%.*s", len, data); + free(data); + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + void *result; + char *data = strdup("Hello world!\n"); + struct thread_info *ti = newthread(hello_thread); + + // Send one line of text. + thread_send(ti, data, strlen(data)); + // Signal thread to exit and wait for it to do so. + thread_send(ti, NULL, 1); + pthread_join(ti->thread, &result); + + return (long)result; +}
--- a/sources/native/bin/getent Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -#!/bin/sh - -# Copyright 2009 Rob Landley <rob@landley.net>, licensed under GPLv2. - -isnum() -{ - [ ! -z "$(echo $1 | grep '^[0-9]*$')" ] -} - -nocomments() -{ - sed 's/\([^#]*\)#.*/\1/' /etc/$1 -} - -# The world's cheesiest getent implementation - -case "$1" in - passwd|group) - isnum "$2" && - grep -m 1 "[^:]*:[^:]*:$2:" /etc/$1 || - grep -m 1 "^$2:" /etc/$1 - ;; - - hosts|networks|protocols) - nocomments $1 | grep -m 1 -w "$2" - ;; - - services) - nocomments $1 | (isnum "$2" && grep -m 1 "[ ]$2/" || grep -m 1 -w "$2") - ;; -esac
--- a/sources/native/etc/group Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -root:x:0: -guest:x:1:
--- a/sources/native/etc/mdev.conf Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -null 0:0 777 -(zero|random|urandom) 0:0 666
--- a/sources/native/etc/passwd Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -root:x:0:0:root:/root:/bin/sh -guest:x:1:1:root:/root:/bin/sh
--- a/sources/native/etc/resolv.conf Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -# This is the default for QEMU -nameserver 10.0.2.3
--- a/sources/native/sbin/init.sh Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -#!/bin/sh - -# Otherwise, building source packages wants things like /bin/bash and -# running the results wants /lib/ld-uClibc.so.0, so set up some directories -# and symlinks to let you easily compile source packages. - -export HOME=/home - -# Populate /dev -mountpoint -q sys || mount -t sysfs sys sys -mountpoint -q dev || mount -t tmpfs -o noatime dev dev -mdev -s - -# Make sure /proc is there -mountpoint -q proc || mount -t proc proc proc - -export PS1='($HOST) \w \$ ' - -# If we're running under qemu, do some more setup -if [ $$ -eq 1 ] -then - - # Note that 10.0.2.2 forwards to 127.0.0.1 on the host. - - # Setup networking for QEMU (needs /proc) - ifconfig eth0 10.0.2.15 - route add default gw 10.0.2.2 - - # If we have no RTC, try rdate instead: - [ "$(date +%s)" -lt 1000 ] && rdate 10.0.2.2 # or time-b.nist.gov - - mount -t tmpfs /tmp /tmp - - # If there's a /dev/hdb or /dev/sdb, mount it on home - - [ -b /dev/hdb ] && HOMEDEV=/dev/hdb - [ -b /dev/sdb ] && HOMEDEV=/dev/sdb - if [ ! -z "$HOMEDEV" ] - then - mount -o noatime $HOMEDEV /home - else - mount -t tmpfs /home /home - fi - cd /home - - [ -b /dev/hdc ] && MNTDEV=/dev/hdc - [ -b /dev/sdc ] && MNTDEV=/dev/sdc - if [ ! -z "$MNTDEV" ] - then - mount -o ro $MNTDEV /mnt - fi - - CONSOLE="$(dmesg | - sed -n '/^Kernel command line:/s@.* console=\(/dev/\)*\([^ ]*\).*@\2@p')" - - if [ -z "$DISTCC_HOSTS" ] - then - echo "Not using distcc." - else - echo "Distcc acceleration enabled." - fi - echo Type exit when done. - - HANDOFF=/bin/ash - if [ -e /mnt/init ] - then - X=xx - echo "Press any key for command line..." - read -t 3 -n 1 X - if [ "$X" == xx ] - then - echo "Running automated build." - HANDOFF=/mnt/init - fi - fi - exec /bin/oneit -c /dev/"$CONSOLE" "$HANDOFF" - -# If we're not PID 1, it's probably a chroot. -else - [ ! -z "$(grep "default for QEMU" /etc/resolv.conf)" ] && - echo "nameserver 4.2.2.1" > /etc/resolv.conf - - # Switch to a shell with command history. - - echo Type exit when done. - /bin/ash - cd / - umount ./dev - umount ./home - umount ./sys - umount ./proc - sync -fi
--- a/sources/native/src/hello.cpp Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#include <iostream> -using namespace std; - -int main() -{ - cout << "hello world" << endl; - return 0; -}
--- a/sources/native/src/mklfs.sh Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,200 +0,0 @@ -#!/bin/bash - -[ -z "$LFS" ] && LFS=/home/lfs -[ -z "$CPUS" ] && CPUS=1 - -SCRIPTPATH="$(which "$0")" - -echo "LFS chapter 3: Download lfs-packages (grab one big tarball and extract)" - -if [ ! -d "$LFS"/packages/. ] -then - if [ ! -f "$LFS"/lfs-packages-6.3.tar ] - then - mkdir -p "$LFS" && - cd "$LFS" && - wget http://ftp.osuosl.org/pub/lfs/lfs-packages/lfs-packages-6.3.tar || - exit 1 - fi - - mkdir "$LFS"/packages && - cd "$LFS"/packages && - tar xvf ../lfs-packages-6.3.tar -fi - -echo "LFS chapter 4.4: clear environment" - -set +h -umask 022 -export LC_ALL=POSIX -export PATH=/tools/bin:/bin:/usr/bin - -# We can mostly use the FWL /tools tarball as the output of FWL chapter 5, -# except that glibc needs perl to build. So add perl to /tools. - -echo "LFS chapter 5.25: add perl to tools dir" - -if [ ! -f /tools/bin/perl ] -then - cd "$LFS" && - tar xvjf "$LFS"/packages/perl-*.tar.bz2 && - cd perl-5.*/ && - patch -p1 -i "$LFS"/packages/perl-*-libc-2.patch && - sed -i 's/libc\.so\.6/libc.so.0/g' hints/linux.sh && - ./configure.gnu --prefix=/tools -Dstatic_ext='Data/Dumper Fcntl IO POSIX' && - make -j $CPUS perl utilities && - PRIVLIB="$(sed -n 's/^privlib[\t ]*=[\t ]*//p' Makefile)" && - cp -v perl pod/pod2man /tools/bin && - mkdir -p "$PRIVLIB" && - cp -Rv lib/* "$PRIVLIB" && - cd .. && - rm -rf perl-5.*/ - - [ $? -ne 0 ] && exit 1 -fi - -echo "LFS chapter 6.2: setup chroot (plus bind mount /tools into new subdir)." - -if [ "$1" != "--no-chroot" ] -then - mkdir -p "$LFS"/{dev,proc,sys,tools,root/work} && - ln -s /packages "$LFS"/root/work/packages && - mount --bind /tools "$LFS"/tools && - mount -vt proc proc "$LFS"/proc && - mount -vt sysfs sysfs "$LFS"/sys || exit 1 - - # These are allowed to fail (may already exist if script is re-run), but - # must happen before the /dev bind mount to give udev stuff to use. - - mknod -m 600 "$LFS"/dev/console c 5 1 - mknod -m 666 "$LFS"/dev/null c 1 3 - - mount -v --bind /dev "$LFS"/dev || exit 1 - - # These may fail if host's /dev doesn't have pts or shm subdirectories. - - mount -vt devpts devpts "$LFS"/dev/pts - mount -vt tmpfs shm "$LFS"/dev/shm - - echo "LFS chapter 6.4: chroot (tweaked quite a bit)." - - # Perform the chroot, re-running this script with extra argument - # (--no-chroot) and several more environment variables - - cp "$SCRIPTPATH" "$LFS"/mklfs.sh && - chroot "$LFS" /tools/bin/env -i \ - HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ - PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \ - UCLIBC_DYNAMIC_LINKER=/tools/lib/ld-uClibc.so.0 \ - UCLIBC_RPATH=/tools/lib LFS="/root/work" CPUS=$CPUS \ - /tools/bin/bash /mklfs.sh --no-chroot - - # The chroot exited. Snapshot return code, clean up mounts, return. - - RETVAL=$? - umount "$LFS"/{dev/{pts,shm},proc,sys,tools} - umount "$LFS"/dev - exit $RETVAL -fi - -# At this point, we've either done the chroot already or we're not doing one. - -echo "LFS chapter 6.5: creating directories" - -mkdir -p /{bin,boot,etc/opt,home,lib,mnt,opt} && -mkdir -p /{media/{floppy,cdrom},sbin,srv,var} && -install -dv -m 0750 /root && -install -dv -m 1777 /tmp /var/tmp && -mkdir -p /usr/{,local/}{bin,include,lib,sbin,src} && -mkdir -p /usr/{,local/}share/{doc,info,locale,man} && -mkdir /usr/{,local/}share/{misc,terminfo,zoneinfo} && -mkdir -p /usr/{,local/}share/man/man{1..8} || exit 1 -for dir in /usr /usr/local; do - ln -s share/{man,doc,info} $dir || exit 1 -done -mkdir /var/{lock,log,mail,run,spool} && -mkdir -p /var/{opt,cache,lib/{misc,locate},local} || exit 1 - -echo "LFS chapter 6.6: symlinks pointing into /tools and general bootstrapping" - -# Note: /etc/mtab is dead, so no touch: symlink /etc/mtab to /proc/mounts - -ln -s /tools/bin/{bash,cat,echo,grep,pwd,stty} /bin && -ln -s /tools/bin/perl /usr/bin && -ln -s /tools/lib/libgcc_s.so{,.1} /usr/lib && -ln -s /tools/lib/libstdc++.so{,.6} /usr/lib && -ln -s bash /bin/sh && -ln -s /proc/mounts /etc/mtab && - -cat > /etc/passwd << "EOF" && -root:x:0:0:root:/root:/bin/bash -nobody:x:99:99:Unprivileged User:/dev/null:/bin/false -EOF - -cat > /etc/group << "EOF" && -root:x:0: -bin:x:1: -sys:x:2: -kmem:x:3: -tty:x:4: -tape:x:5: -daemon:x:6: -floppy:x:7: -disk:x:8: -lp:x:9: -dialout:x:10: -audio:x:11: -video:x:12: -utmp:x:13: -usb:x:14: -cdrom:x:15: -mail:x:34: -nogroup:x:99: -EOF - -touch /var/run/utmp /var/log/{btmp,lastlog,wtmp} && -chgrp utmp /var/run/utmp /var/log/lastlog && -chmod 664 /var/run/utmp /var/log/lastlog || -exit 1 - -echo "LFS chapter 6.7: kernel API headers" - -cd "$LFS" && -tar xvjf "$LFS"/packages/linux-*.tar.bz2 && -cd linux-* && -sed -i '/scsi/d' include/Kbuild && -make -j $CPUS INSTALL_HDR_PATH=/usr headers_install && -cd .. && -rm -rf linux-* || -exit 1 - -echo "LFS 6.8: man pages" - -cd "$LFS" && -tar xvjf "$LFS"/packages/man-pages-*.tar.bz2 && -cd man-pages-* && -make -j $CPUS install && -cd .. && -rm -rf man-pages-* || -exit 1 - -echo "LFS 6.9: glibc" - -cd "$LFS" && -tar xvjf "$LFS"/packages/glibc-[0-9]*.tar.bz2 && -cd glibc-* && -tar xvzf "$LFS"/packages/glibc-libidn-*.tar.gz && -mv glibc-libidn-* libidn && -sed -i '/vi_VN.TCVN/d' localedata/SUPPORTED && -sed -i \ -'s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=/lib/ld-linux.so.2 -o|' \ - scripts/test-installation.pl && -sed -i 's|@BASH@|/bin/bash|' elf/ldd.bash.in && -mkdir ../glibc-build && -cd ../glibc-build && -../glibc-2.5.1/configure --prefix=/usr \ - --disable-profile --enable-add-ons \ - --enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc && -make -j $CPUS - -/tools/bin/ash
--- a/sources/native/src/thread-hello.c Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -#define __REENTRANT -#include <pthread.h> -#include <stdio.h> - -void *threadhello(void *unused) -{ - printf("Hello, world!\n"); - return 0; -} - -int main() { - pthread_t thready; - pthread_create(&thready, NULL, &threadhello, NULL); - usleep(10); -}
--- a/sources/native/src/thread-hello2.c Thu Mar 25 18:54:30 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -// Threaded hello world program that uses mutex and event semaphores to pass -// the string to print from one thread to another, and waits for the child -// thread to return a result before exiting the program. - -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -// Thread, semaphores, and mailbox -struct thread_info { - pthread_t thread; - pthread_mutex_t wakeup_mutex; - pthread_cond_t wakeup_send, wakeup_receive; - unsigned len; - char *data; -}; - -// Create a new thread with associated resources. -struct thread_info *newthread(void *(*func)(void *)) -{ - struct thread_info *ti = malloc(sizeof(struct thread_info)); - memset(ti, 0, sizeof(struct thread_info)); - - pthread_create(&(ti->thread), NULL, func, ti); - - return ti; -} - -// Send a block of data through mailbox. -void thread_send(struct thread_info *ti, char *data, unsigned len) -{ - pthread_mutex_lock(&(ti->wakeup_mutex)); - // If consumer hasn't consumed yet, wait for them to do so. - if (ti->len) - pthread_cond_wait(&(ti->wakeup_send), &(ti->wakeup_mutex)); - ti->data = data; - ti->len = len; - pthread_cond_signal(&(ti->wakeup_receive)); - pthread_mutex_unlock(&(ti->wakeup_mutex)); -} - -// Receive a block of data through mailbox. -void thread_receive(struct thread_info *ti, char **data, unsigned *len) -{ - pthread_mutex_lock(&(ti->wakeup_mutex)); - if (!ti->len) - pthread_cond_wait(&(ti->wakeup_receive), &(ti->wakeup_mutex)); - *data = ti->data; - *len = ti->len; - // If sender is waiting to send us a second message, wake 'em up. - // Note that "if (ti->len)" be used as an unlocked/nonblocking test for - // pending data, although you still need call this function to read data. - ti->len = 0; - pthread_cond_signal(&(ti->wakeup_send)); - pthread_mutex_unlock(&(ti->wakeup_mutex)); -} - -// Function for new thread to execute. -void *hello_thread(void *thread_data) -{ - struct thread_info *ti = (struct thread_info *)thread_data; - - for (;;) { - unsigned len; - char *data; - - thread_receive(ti, &data, &len); - if (!data) break; - printf("%.*s", len, data); - free(data); - } - - return 0; -} - -int main(int argc, char *argv[]) -{ - void *result; - char *data = strdup("Hello world!\n"); - struct thread_info *ti = newthread(hello_thread); - - // Send one line of text. - thread_send(ti, data, strlen(data)); - // Signal thread to exit and wait for it to do so. - thread_send(ti, NULL, 1); - pthread_join(ti->thread, &result); - - return (long)result; -}