I like to have a modern, upgradeable unix layer on my macs. The kind of thing people use homebrew, macports, et al (back to fink) for.
I use gentoo prefix. Usually root-owned in users/shared … I also like to replace the openssh daemon mac os uses.
The process grows in diceyness perhaps. Here goes.
Only ever set it up once (per major os version), then rsync deploy.
I tried bootstrapping normally. Boy. That was a thing. Not recommended.
It was actually easier for me to take my existing 10.7 prefix and upgrade the CHOST on it/rebuild/upgrade. Not, you know, like a lot, but easier (it worked).
Changing the CHOST - Gentoo Wiki was sort of semi-applicable, had some useful info.
clang on Mac OS X was the most critical information nexus.
#!/bin/bash
# this script upgrades a macos 10.7 portage 2.2.10 prefix installation
# into a macos 10.9 portage 2.2.14 prefix installation w/ clang/llvm3.5
# prefix purpose is universal ed25519 ssh (vim, coreutils, etc)
EPREFIX="/Users/Shared/gentoo/"
# user1 is original owner (username) of the prefix, user2 is new
USER1="XXX"
USER2="XXXNew"
if [[ ${SHELL#${EPREFIX}} == ${SHELL} ]] ; then
# Fix weird segfaults due to missing LANG in environment
perl -p -i -e 's/env -i HOME=\$HOME/env -i LANG=\$LANG HOME=\$HOME/' ${EPREFIX}startprefix
echo "Fixed startprefix script"
echo "run ${EPREFIX}startprefix now and rerun fix_gentoo.sh"
exit 0;
fi
perl -p -i -e 's/XXX/XXXNew/g' ${EPREFIX}usr/lib/portage/pym/portage/const_autotool.py
perl -p -i -e 's/XXX/XXXNew/g' ${EPREFIX}usr/share/portage/config/make.globals
echo "Fixed portage user"
# CHOST Changeover
echo "CHOST=\"x86_64-apple-darwin13\"" >> ${EPREFIX}etc/portage/make.conf
# rebuild binutils-apple
emerge -v binutils-apple
ln -s ${EPREFIX}usr/x86_64-apple-darwin13/binutils-bin ${EPREFIX}usr/x86_64-apple-darwin11/binutils-bin
mkdir -p ${EPREFIX}usr/x86_64-apple-darwin11/x86_64-apple-darwin13/lib
ln -s ${EPREFIX}usr/lib/gcc/x86_64-apple-darwin11/4.2.1 ${EPREFIX}usr/x86_64-apple-darwin11/x86_64-apple-darwin13/lib/gcc
#ln -s ${EPREFIX}usr/x86_64-apple-darwin11/gcc-bin ${EPREFIX}usr/x86_64-apple-darwin13/gcc-bin
emerge -v binutils-config
binutils-config 1
env-update
. ${EPREFIX}etc/profile
# rebuild gcc-apple
GCC_BUILDS=0
while true; do
emerge -v gcc-apple
STATUS=$?
if [[ $STATUS == 0 ]]; then
# gcc successfully built
# this was taking about 5 attempts for me
# really dunno what to say about that
break;
else
GCC_BUILDS=$[$GCC_BUILDS + 1];
if [ $GCC_BUILDS -gt 10 ]; then
echo
echo "GCC WOULD NOT BUILD AFTER 10 ATTEMPTS."
echo
exit 1;
fi
fi
done;
rm ${EPREFIX}etc/env.d/04gcc-x86_64-apple-darwin11
rm ${EPREFIX}etc/env.d/gcc/config-x86_64-apple-darwin11
env-update
. ${EPREFIX}etc/profile
# clean up, rebuild 4-5 packs, worked
emerge -v @preserved-rebuild
rm -r ${EPREFIX}usr/x86_64-apple-darwin11
rm -r ${EPREFIX}usr/bin/x86_64-apple-darwin11-*
# full changeover in profile, remove explicit CHOST
eselect profile set 5
perl -p -i -e 's/CHOST="x86_64-apple-darwin13"//' ${EPREFIX}etc/portage/make.conf
env-update
. ${EPREFIX}etc/profile
# rebuild binutils w/ rebuilt gcc
emerge -v binutils-config binutils-apple
. ${EPREFIX}etc/profile
# rebuild gcc w/ rebuilt gcc <== this actually never worked
emerge -v gcc-config
#GCC_BUILDS=0
#while true; do
# emerge -v gcc-apple
# STATUS=$?
# if [[ $STATUS == 0 ]]; then
# # gcc successfully built
# break;
# else
# GCC_BUILDS=$[$GCC_BUILDS + 1];
# if [ $GCC_BUILDS -gt 10 ]; then
# echo
# echo "GCC WOULD NOT REBUILD AFTER 10 ATTEMPTS."
# echo
# exit 1;
# fi
# fi
#done;
# UPDATE PORTAGE TREE
# 1ST PATH IS PATH TO AN UPDATED PORTAGE TREE, IN MY CASE FROM FAILED BOOTSTRAP
rsync -avSH --delete-after --exclude distfiles/ --exclude metadata/ ~XXX/gentoo/usr/portage/ ${EPREFIX}usr/portage/
rsync -avSH /Users/XXX/gentoo/usr/portage/distfiles/ ${EPREFIX}usr/portage/distfiles/
emerge -v dev-libs/libiconv gcc-config binutils-apple
# libffi upgrade needed, can't rebuild gcc now w/o portage upgrade
. ${EPREFIX}etc/profile
emerge -v gmp autoconf-wrapper automake-wrapper
emerge -v mpfr dev-libs/libffi pidof-bsd file less coreutils
hash -r
emerge -v patch
# two-step upgrade to portage 2.2.14(+?)
emerge -v =sys-apps/portage-2.2.10.1-r1
emerge -v portage
emerge -v gcc-apple
. ${EPREFIX}etc/profile
emerge -v ncurses
echo "sys-devel/llvm clang" >> ${EPREFIX}etc/portage/package.use
emerge -v llvm:0/3.4
# get libcxx-apple ebuild
wget https://github.com/fishman/timebomb-gentoo-osx-overlay/archive/master.zip
unzip master.zip
mv timebomb-gentoo-osx-overlay-master/sys-libs/libcxx-apple ${EPREFIX}usr/local/portage/sys-libs/
rm -r timebomb-gentoo-osx-overlay-master
ebuild ${EPREFIX}usr/local/portage/sys-libs/libcxx-apple manifest
emerge -v libcxx-apple
# pulled in a bunch of subversion dep bullshit but fine.
# set up portage environment to use clang(11)
mkdir ${EPREFIX}etc/portage/env
echo "CC=clang
CXX=clang++
CFLAGS=\"${CFLAGS} -stdlib=libstdc++\"
CXXFLAGS=\"${CXXFLAGS} -stdlib=libstdc++\"" > ${EPREFIX}etc/portage/env/clang
echo "CC=clang
CXX=clang++
CFLAGS=\"${CFLAGS}\"
CXXFLAGS=\"${CXXFLAGS} -std=c++11 -stdlib=libstdc++\"
LDFLAGS=\"${LDFLAGS} -stdlib=libc++\"" > ${EPREFIX}etc/portage/env/clang11
# use clang11 for llvm-3.5+ & binutils-apple
echo ">=sys-devel/llvm-3.5 clang11" >> ${EPREFIX}etc/portage/package.env
echo "sys-devel/binutils-apple:6[libcxx] clang11" >> ${EPREFIX}etc/portage/package.env
emerge -v llvm:0/3.5
echo ">=sys-devel/llvm-3.6.0" >> ${EPREFIX}etc/portage/package.mask
# building binutils-apple[libcxx] didn't happen
# strategically rebuild the system
emerge -v binutils-config
emerge -v perl-cleaner perl
perl-cleaner --all -- -v
emerge -v gnuconfig gzip help2man which wget
emerge -v ca-certificates eselect rsync glib:2 pkgconfig
emerge -v python:2.7
emerge -v libxslt gettext debianutils nano grep popt
emerge -v gentoolkit baselayout-prefix
emerge -vu csu libiconv perl-File-Spec automake libtool:2 expat \
perl-ExtUtils-Manifest ExtUtils-Manifest sed make gtk-doc-am
emerge -v dev-perl/libintl-perl
emerge -v openssl
emerge --deselect -v pkgconfig glib:2 perl-cleaner ca-certificates portage python openssl groff \
eselect flex nano popt libxslt gettext libintl-perl Text-Unidecode gtk-doc-am debianutils expat \
libtool:2 perl-ExtUtils-Manifest automake ExtUtils-Manifest help2man perl-File-Spec perl mpfr \
gmp automake-wrapper autoconf-wrapper pax-utils libffi dev-libs/libiconv binutils-config \
gcc-config mime-types zlib ncurses
# bzip won't build w/o FEATURE="allow_broken_install_names", i'm wary, just mask it
echo ">=app-arch/bzip2-1.0.6-r7" >> ${EPREFIX}etc/portage/package.mask
emerge -v nano
emerge -vtuDN --with-bdeps y world
emerge -av --depclean
eclean-dist
# do your upgrade of openssh now, an 1.8 ebuild w/ just --with-pam works w/ password auth on mac os 10.9
# patches would probably help the 4-5 second delay on login, but i'm not worrying about that for now
I installed llvm 3.4/clang & used it to build llvm 3.5/clang, but didn’t actually use it for anything. just might sometime.
Additional SSH specific notes:
OpenSSH6.8p1 prefix ebuild forces -pam, which, I guess makes sense in a prefix context, but I prefer to make the prefix sshd replace the system one, so just replace usewith pam to –with-pam to econf in the ebuild. DNS resolution is one of the more fail-forward things happening on mac os. To prevent a five second delay on logins, add UseDNS no to sshdconfig.
Previous MacOS, like 10.7, had issues that required turning off AcceptEnv LANG LC* in the sshd_config. With 10.9, the behavior is ‘upgraded’ to segfaulting on missing LANG in environment, so AcceptEnv LANG is very much required.
END
follows the bootstrapping. first attempt.
TLDR: it doesn’t go very far, is very challenge, and requires much further research.
Download the newest bootstrap-prefix.sh script
'''
export EPREFIX=/Users/X/gentoo
./bootstrap-prefix.sh
hah yeah right!
'''
set up in ~/gentoo … we’ll have to move/chown after bootstrap because it hates root (and wheel)
apparently the bootstrap process for mac os 10.9 is reaaaaaally terrible. probably 10.8 as well from what i’ve read. the main issues stem from apple removing vital gnu dev components. gcc, automake, autoconf, libtool, readline (replaced w/ an incompatible .h system-accessible). the next issue is determining the proper blend of –std=gnu89 during various stage emerging.
getting through stage1 & 2 was quite difficult, involved path hacking, symlinking bash & perl into future gentoo tree … coaxing things to build by temp moving system includes, adding proper include paths directly to cflags (gentoo/usr/include, gentoo/tmp/usr/include). i mean … grisly.
gcc-apple, for example, requires CC="gcc -std=gnu89″. coreutils, on the other hand, will only build in 99+ mode. try and let as much build in/with/available 99 mode as possible.
CC="gcc -std=gnu89 " emerge --oneshot --nodeps -av gcc-apple
emerge -av system (deselect a bunch of stuff from world)
emerge -av system … goes ok, dies 37 pks in at gmp, –enable-cxx is on. fails super early, during configure, basically w/ no output.
interestingly, ncurses built fine w/ cxx enabled
in the bootstrapped environment, c++ stuff is not so build for some reason, perhaps substantial binary incompatibility due to gcc-apple 4.2. suspect llvm/clang would be ideal? gentoo llvm is at 3.6, apple is based on 3.5
install fsf gcc 4.7, use it (gcc-config, env-update, . gentoo/etc/profile) to build llvm/clang
llvm does not build.
Undefined symbols for architecture x86_64:
"llvm::TargetRegisterInfo::composeSubRegIndexLaneMaskImpl(unsigned int, unsigned int) const", referenced from:
vtable for llvm::TargetRegisterInfo in libLLVMCodeGen.a(TargetRegisterInfo.o)
"llvm::TargetRegisterInfo::composeSubRegIndicesImpl(unsigned int, unsigned int) const", referenced from:
vtable for llvm::TargetRegisterInfo in libLLVMCodeGen.a(TargetRegisterInfo.o)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
/Users/table/gentoo/var/tmp/portage/sys-devel/llvm-3.6.0/work/llvm-3.6.0.src/Makefile.rules:1199: recipe for target '/Users/table/gentoo/var/tmp/portage/sys-devel/llvm-3.6.0/work/llvm-3.6.0.src-.amd64/Release/lib/libLLVM-3.6.dylib' failed
hmm. some things seem to work. it is odd. openssh is def old & shitty on 10.9… still kinda want that real sshd…