OSX Toolchain

by jzaun on Tue Feb 28, 2012 7:20 pm

I'm trying to compile gcc and have it installed into a specific directory. I've got things partially working but am running into some issues. I've posted up at stackoverflow so I'll just like to it there rather than have a huge post here too...

http://stackoverflow.com/questions/9477 ... rom-source

Any help would be much appreciated.
jzaun
 
Posts: 3
Joined: Tue Feb 28, 2012 6:20 pm

Re: OSX Toolchain

by westfw on Tue Feb 28, 2012 9:36 pm

I did this recently. It helped a lot to first install (using fink commander) a "native" x86 version of gcc; this seems to avoid a lot of problems with random library incompatibilities I was having. (fink installs in /sw/ I put cross compilers in /sw/cross, using mostly the tutorial posted here with -prefix=/sw/cross )
(There was some more info here: viewtopic.php?f=24&t=26112 )

Your stackoverflow post seems to be gone. What sort of problems are you having...
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: OSX Toolchain

by jzaun on Tue Feb 28, 2012 10:54 pm

Hi westfw & thanks for the reply.

I worked out the install & removed the stack post as noone had replied yet. I think I have a working install script, at least it all compiled. I have yet to test anything with it though. I had to remove the CC="cc --no-cpp-precomp" bit from the gcc make command to get it to compile, so who knows.

The idea is that is downloads and installs everything into a user directory without root. I'm hoping to setup a working self-contained build area that doesn't install/effect anything else on the system. I'm new to the avr world in general, just got a Axon2 and want to play with it on my mac.

I looked at the other options and they all seem to install the avr tool chain all over the place on the system, I'm trying very hard to avoid that. Any comments on the script would be welcomed.

Code: Select all
#!/bin/bash

# Cleanup
rm -rf build
rm -rf binutils
rm -rf gmp
rm -rf mpfr
rm -rf mpc
rm -rf gcc
rm -rf gccobj
rm -rf lib-avr
rm -rf avrdude
rm -rf simulavr

# Download binutils
echo "Downloading binutils"
echo -e "\033]0;Downloading binutils\007"
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.gz
tar -xzvf binutils-2.22.tar.gz >> ./unpack.log 2>&1
rm -rf binutils-2.22.tar.gz >> ./unpack.log 2>&1
mv binutils-2.22 binutils >> ./unpack.log 2>&1

# Download gmp
echo "Downloading gmp"
echo -e "\033]0;Downloading gmp\007"
curl -O ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.4.tar.bz2
tar -xzvf gmp-5.0.4.tar.bz2 >> ./unpack.log 2>&1
rm -rf gmp-5.0.4.tar.bz2 >> ./unpack.log 2>&1
mv gmp-5.0.4 gmp >> ./unpack.log 2>&1

# Download mpfr
echo "Downloading mpfr"
echo -e "\033]0;Downloading mpfr\007"
curl -O http://www.mpfr.org/mpfr-current/mpfr-3.1.0.tar.gz
tar -xzvf mpfr-3.1.0.tar.gz >> ./unpack.log 2>&1
rm -rf mpfr-3.1.0.tar.gz >> ./unpack.log 2>&1
mv mpfr-3.1.0 mpfr >> ./unpack.log 2>&1

# Download mpc
echo "Downloading mpc"
echo -e "\033]0;Downloading mpc\007"
curl -O http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz
tar -xzvf mpc-0.9.tar.gz >> ./unpack.log 2>&1
rm -rf mpc-0.9.tar.gz >> ./unpack.log 2>&1
mv mpc-0.9 mpc >> ./unpack.log 2>&1

# Download gcc
echo "Downloading gcc"
echo -e "\033]0;Downloading gcc\007"
curl -O http://www.netgull.com/gcc/releases/gcc-4.6.2/gcc-4.6.2.tar.bz2
tar -xzvf gcc-4.6.2.tar.bz2 >> ./unpack.log 2>&1
rm -rf gcc-4.6.2.tar.bz2 >> ./unpack.log 2>&1
mv gcc-4.6.2 gcc >> ./unpack.log 2>&1

# Download lib-avr
echo "Downloading lib-avr"
echo -e "\033]0;Downloading lib-avr\007"
curl -O http://savannah.spinellicreations.com/avr-libc/avr-libc-1.8.0.tar.bz2
tar -xzvf avr-libc-1.8.0.tar.bz2 >> ./unpack.log 2>&1
rm -rf avr-libc-1.8.0.tar.bz2 >> ./unpack.log 2>&1
mv avr-libc-1.8.0 lib-avr >> ./unpack.log 2>&1

# Download avrdude
echo "Downloading avrdude"
echo -e "\033]0;Downloading avrdude\007"
curl -O http://gnu.mirrors.pair.com/savannah/savannah/avrdude/avrdude-5.11svn-20111019.tar.gz
tar -xzvf avrdude-5.11svn-20111019.tar.gz >> ./unpack.log 2>&1
rm -rf avrdude-5.11svn-20111019.tar.gz >> ./unpack.log 2>&1
mv avrdude-5.11svn-20111019 avrdude >> ./unpack.log 2>&1


# Make the build directory
rm -f ./unpack.log
mkdir build

# Install binutils
echo -e "\033]0;Building binutils\007"
cd binutils
./configure --prefix="${PWD}/../build/" --exec-prefix="${PWD}/../build/" --datadir="${PWD}/../build/" --target=avr
make clean
make
make install
cd ..

# Install gmp
echo -e "\033]0;Building gmp\007"
cd gmp
./configure --prefix="${PWD}/../build/" --exec-prefix="${PWD}/../build/" --datadir="${PWD}/../build/"
make clean
make
make install
cd ..

# Install mpfr
echo -e "\033]0;Building mpfr\007"
cd mpfr
./configure --prefix="${PWD}/../build/" --exec-prefix="${PWD}/../build/" --datadir="${PWD}/../build/" --with-gmp="${PWD}/../build/"
make clean
make
make install
cd ..

# Install mpc
echo -e "\033]0;Building mpc\007"
cd mpc
./configure --prefix="${PWD}/../build/" --exec-prefix="${PWD}/../build/" --datadir="${PWD}/../build/" --with-gmp="${PWD}/../build/"
make clean
make
make install
cd ..

# Install gcc
echo -e "\033]0;Building gcc\007"
mkdir gccobj
cd gccobj
../gcc/configure --prefix="${PWD}/../build/" --exec-prefix="${PWD}/../build/" --datadir="${PWD}/../build/" --with-gmp="${PWD}/../build/" --with-mpfr="${PWD}/../build/" --with-mpc="${PWD}/../build/" --target=avr --enable-languages=c --disable-libssp --disable-lto --disable-nls --disable-libgomp --disable-gdbtk --enable-poison-system-directories
make clean
#make CC="cc --no-cpp-precomp" all-gcc
make
make install
cd ..

# Mangle path
export MYOLDPATH=$PATH
export PATH="${PWD}/../build/bin":$MYOLDPATH

# Install lib-avr
echo -e "\033]0;Building lib-avr\007"
cd lib-avr
./configure --prefix="${PWD}/../build/" --exec-prefix="${PWD}/../build/" --datadir="${PWD}/../build/" --host=avr
make
make install
cd ..

# Restore path
export PATH=$MYOLDPATH

# Install avrdude
echo -e "\033]0;Building avrdude\007"
cd avrdude
./configure --prefix="${PWD}/../build/" --exec-prefix="${PWD}/../build/" --datadir="${PWD}/../build/"
make
make install
cd ..

# Cleanup
echo -e "\033]0;\007"
rm -rf binutils
rm -rf gmp
rm -rf mpfr
rm -rf mpc
rm -rf gcc
rm -rf gccobj
rm -rf lib-avr
rm -rf avrdude
rm -rf simulavr
jzaun
 
Posts: 3
Joined: Tue Feb 28, 2012 6:20 pm

Re: OSX Toolchain

by BruceF on Wed Feb 29, 2012 12:28 am

Fink installs everything under /sw (last I used it, anyway), and MacPorts installs its ports only under /opt/local. Delete either of those paths and the corresponding software evaporates instantly, leaving behind only shiny clean bits. The only thing you need to manually manage with either of these systems is your $PATH variable.

There's nothing wrong with building your own toolchain from scratch, but if "they all seem to install the avr tool chain all over the place on the system" is your main concern, I wouldn't be too worried about it. None of these systems is going to mess with /usr/bin/gcc.
- Bruce
BruceF
 
Posts: 205
Joined: Tue May 03, 2011 3:51 pm

Re: OSX Toolchain

by jzaun on Wed Feb 29, 2012 12:53 am

Hi Bruce,
I didn't realize that both those systems were self contained. They are much better off than I had believed, the only issue would be they are not user land (they need root access). I'm trying to have this work all without root as well as be self-contained.
jzaun
 
Posts: 3
Joined: Tue Feb 28, 2012 6:20 pm

Re: OSX Toolchain

by westfw on Wed Feb 29, 2012 2:53 am

Yeah; MacOS has stuff in /usr. Fink installs in /sw. MacPorts installs in /opt/local. Raw builds from a source download (with no other configuration) tend to go into /usr/local.

The problems seem to occur when you install, say, mpfr libraries using fink, but pick up gcc and other libraries from the /usr/ via the Mac defaults. Nothing is exactly wrong, but it can get very confused. So: use as few package managers as possible, install a reasonably complete toolchain, and specify the correct prefix whenever you install something from source... (at least, this is my current theory.)
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: OSX Toolchain

by BruceF on Wed Feb 29, 2012 3:43 am

Mixing package managers is going to end in tears, I'd expect. Pick one and stick with it.

Other than that, I've been good by being careful with $PATH - put /opt/local/bin first if I'm using compilers etc. from MacPorts, or put it last (or even remove it completely) if I'm using OS tools only. You need to understand where your environment variables are coming from to not mess that up, of course. If in doubt: edit your .bashrc (or whatever is defining PATH), quit and restart Terminal, echo $PATH and if it looks right you should be safe.

As for needing root, technically you should be able to get away with not needing root after installing a package manager if you make it's install directory writable by your ordinary user account. "chown -R jzaun /opt/local" or "/sw" should work so long as you don't have any 'sbin' files or something to worry about. I'm not sure how well that aligns with The UNIX Way, though.
- Bruce
BruceF
 
Posts: 205
Joined: Tue May 03, 2011 3:51 pm