Skip to content

Instantly share code, notes, and snippets.

@leoncamel
Created June 16, 2012 19:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoncamel/2942254 to your computer and use it in GitHub Desktop.
Save leoncamel/2942254 to your computer and use it in GitHub Desktop.
build gcc on mac lion
#!/bin/sh
# TODO:
# 1: Could not find the frame base for "main(int, char**)".
# gdb ./hello
# GNU gdb (GDB) 7.4
# Copyright (C) 2012 Free Software Foundation, Inc.
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
# This is free software: you are free to change and redistribute it.
# There is NO WARRANTY, to the extent permitted by law. Type "show copying"
# and "show warranty" for details.
# This GDB was configured as "x86_64-apple-darwin11.4.0".
# For bug reporting instructions, please see:
# <http://www.gnu.org/software/gdb/bugs/>...
# Reading symbols from /Users/leoncamel/tmp/test-gdb/hello...done.
# (gdb) b main
# Breakpoint 1 at 0x100000ea0: file main.cpp, line 78.
# (gdb) run
# Starting program: /Users/leoncamel/tmp/test-gdb/hello
# Breakpoint 1, main (argc=<optimized out>, argv=<optimized out>) at main.cpp:78
# 78 {
# (gdb) n
# 79 Test t1;
# (gdb)
# 80 cout << endl;
# (gdb)
# 81 cout << testfun(1, 2) << endl;
# (gdb) print t1
# Could not find the frame base for "main(int, char**)".
# (gdb)
set -x
VERSION=4.7.1
#PREFIX=/usr/gcc-$(VERSION)
PREFIX=$HOME/bin/gcc-$VERSION/
#LANGUAGES=c,c++,fortran
LANGUAGES=c,c++
MAKE=make
# Or
# MAKE='make -j 4' # to compile using four cores
export CC='/usr/bin/llvm-gcc'
export CXX='/usr/bin/llvm-g++'
export CFLAGS='-Os -msse4'
## https://trac.macports.org/ticket/27237
export CXXFLAGS='-U_GLIBCXX_DEBUG -U_GLIBCXX_DEBUG_PEDANTIC -Os -msse4'
# Prerequisites
#brew install gmp
#brew install mpfr
#brew install libmpc
# Download & install the latest GCC
mkdir -p $PREFIX
# temp directory
TEMPDIR=temp-gcc
if [ ! -d $TEMPDIR ] ; then
mkdir $TEMPDIR
fi
cd $TEMPDIR
# download gcc package
PKGSUFFIX=tar.bz2
wget -c http://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.$PKGSUFFIX
tar xfz gcc-$VERSION.$PKGSUFFIX
# rm gcc-$VERSION.$PKGSUFFIX
cd gcc-$VERSION
mkdir build
cd build
../configure \
--prefix=$PREFIX \
--with-gmp=$(brew --prefix gmp) \
--with-mpfr=$(brew --prefix mpfr) \
--with-mpc=$(brew --prefix libmpc) \
--program-suffix=-$VERSION \
--enable-languages=$LANGUAGES \
--with-system-zlib \
--enable-stage1-checking \
--enable-plugin \
--enable-lto \
--enable-threads \
--disable-debug \
--disable-multilib
# make && make install
$MAKE bootstrap
make install
# strip debug symbols
# reference :
# [1] http://stackoverflow.com/questions/3353722/how-do-i-debug-c0x-programs-in-macports-gcc-4-5
# [2] http://gcc.gnu.org/ml/gcc/2008-10/msg00083.html
strip -S $PREFIX/lib/libstdc++.6.dylib
strip -S $PREFIX/lib/libgcc_s.1.dylib
# Uncomment for cleanup …
# cd ../../..
# rm -r temp-gcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment