Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By ficeto
#9769 Here is the script I have been using to build the toolchain (C++ is added to this one also)
I used it a week ago ;)
Code: Select all#!/bin/bash
set -e -u

InstallBase=`pwd`
BrewHome=/brew2/local
BrewTools="gnu-sed binutils gawk automake libtool bash"
BrewToolsExtra="https://raw.github.com/Homebrew/homebrew-dupes/master/grep.rb"
ImageName=CrossToolNG
ImageNameExt=${ImageName}.sparseimage
CrossToolVersion=crosstool-NG
ToolChainName=xtensa-lx106-elf

function buildBrewDepends(){
    if [ ! -d "$BrewHome" ]
    then
      echo "If asked, enter your sudo password to create the $BrewHome folder"
      sudo mkdir -p "$BrewHome"
      sudo chown -R $USER "$BrewHome"
      curl -Lsf http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C$BrewHome
    fi
    echo "Updating HomeBrew tools..."
    $BrewHome/bin/brew update
    $BrewHome/bin/brew upgrade
    set +e
    $BrewHome/bin/brew install $BrewTools && true
    $BrewHome/bin/brew install $BrewToolsExtra && true
    set -e
}

function createCaseSensitiveVolume(){
    echo "Creating sparse volume mounted on /Volumes/${ImageName}..."
    ImageNameExt=${ImageName}.sparseimage
    diskutil umount force /Volumes/${ImageName} && true
    rm -f ${ImageNameExt} && true
    hdiutil create ${ImageName} -volname ${ImageName} -type SPARSE -size 8g -fs HFSX
    hdiutil mount ${ImageNameExt}
    cd /Volumes/$ImageName
}

function downloadCrossTool(){
    echo "Downloading crosstool-ng..."
    git clone -b lx106-g++ git://github.com/jcmvbkbc/crosstool-NG.git
}

function patchCrosstool(){
    cd $CrossToolVersion
    echo "Patching crosstool-ng..."
    sed -i .bak '6i\
#include <stddef.h>' kconfig/zconf.y
}

function buildCrosstool(){
    echo "Configuring crosstool-ng..."
    ./bootstrap && ./configure --prefix=`pwd` --enable-local \
   --with-objcopy=$BrewHome/bin/gobjcopyi       \
   --with-objdump=$BrewHome/bin/gobjdump        \
   --with-ranlib=$BrewHome/bin/granlib          \
   --with-readelf=$BrewHome/bin/greadelf        \
   --with-libtool=$BrewHome/bin/glibtool        \
   --with-libtoolize=$BrewHome/bin/glibtoolize  \
   --with-sed=$BrewHome/bin/gsed                \
   --with-awk=$BrewHome/bin/gawk                \
   --with-grep=$BrewHome/bin/ggrep                \
   --with-automake=$BrewHome/bin/automake       \
   --with-bash=$BrewHome/bin/bash               \
   CFLAGS="-std=c99 -Doffsetof=__builtin_offsetof"  && make && make install
}

function buildToolchain(){
    echo "Selecting $ToolChainName..."
    ulimit -n 1024
    PATH=$BrewHome/bin:$PATH ./ct-ng $ToolChainName
    echo "Building $ToolChainName..."
    PATH=$BrewHome/bin:$PATH ./ct-ng build && cp -r builds/$ToolChainName $InstallBase/$ToolChainName
    cd $InstallBase
    diskutil umount force /Volumes/${ImageName} && true
    rm -f ${ImageNameExt} && true
    echo "DONE! Check for folder called $ToolChainName containing the toolchain"
}

buildBrewDepends
createCaseSensitiveVolume
downloadCrossTool
patchCrosstool
buildCrosstool
buildToolchain
User avatar
By Sven
#15672 I am using your script , but i'got this error than i am execute it:
Cloning into 'crosstool-NG'...
remote: Counting objects: 25674, done.
remote: Total 25674 (delta 0), reused 0 (delta 0), pack-reused 25674
Receiving objects: 100% (25674/25674), 14.89 MiB | 1.41 MiB/s, done.
Resolving deltas: 100% (14498/14498), done.
Checking connectivity... done
Patching crosstool-ng...
sed: -e expression #1, char 1: unknown command: `.'

Patching works now, changed line sed sed -i. bak '6i\
#include <stddef.h>' kconfig/zconf.y

to sed -i.bak '6i\#include <stddef.h>' kconfig/zconf.y

after install:
[INFO ] Installing pass-2 core C compiler

it show me that /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstddef:46:9: error: no member named 'ptrdiff_t' in the global namespace
[ERROR] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstddef:46:9: error: no member named 'ptrdiff_t' in the global namespace
[ERROR] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstddef:46:9: error: no member named 'ptrdiff_t' in the global namespace
[ERROR] :13: error: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stringunknown type name 'ptrdiff_t'
[ERROR] 13: error: unknown type name 'ptrdiff_t'
[ERROR] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:429:56: error: unknown type name 'ptrdiff_t'
[ERROR] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:429:56: error: unknown type name 'ptrdiff_t'
[ERROR] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:402:13: error: unknown type name 'ptrdiff_t'
[ERROR] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:745:66:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:745 error:: unknown type name 'ptrdiff_t'66:

I am using MacOS X 10.10.3 , Xcode 6.3.1 and command line tools
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0

Any idea.
Remove ptrdiff_t in the source file has no effect.
User avatar
By ulumu
#15745 I modified the script above, give it a try. A Disk Image named "ESPDISK" will be showing up in the desktop, and contains the ESP toolchain when all compiling finished.

Code: Select all#!/bin/bash
set -e -u

InstallBase=~/Desktop
BrewHome=/usr/local
BrewToolsExtra="https://raw.github.com/Homebrew/homebrew-dupes/master/grep.rb"
ImageName=ESPDISK
ImageNameDMG=${InstallBase}/${ImageName}.dmg

# --------------------------
# Install Homebrew tarball
# and obtain required tools
# --------------------------
function createHomeBrew(){
    if [ ! -d "$BrewHome" ]
    then
      echo "If asked, enter your sudo password to create the $BrewHome folder"
      sudo mkdir -p "$BrewHome"
      sudo chown -R $USER "$BrewHome"
      curl -Lsf http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C$BrewHome
    fi
    echo "+--------------------------------------------------------+"
    echo "|                Updating HomeBrew tools                 |"
    echo "+--------------------------------------------------------+"
    $BrewHome/bin/brew update
    $BrewHome/bin/brew upgrade
    set +e
    $BrewHome/bin/brew install gnu-sed --with-default-names && true
    $BrewHome/bin/brew tap homebrew/dupes && true
    $BrewHome/bin/brew install gperf && true
    $BrewHome/bin/brew install grep && true
    $BrewHome/bin/brew install autoconf && true
    $BrewHome/bin/brew install binutils && true
    $BrewHome/bin/brew install gawk && true
    $BrewHome/bin/brew install libtool && true
    $BrewHome/bin/brew install $BrewToolsExtra && true
    $BrewHome/bin/brew link --overwrite gawk
    $BrewHome/bin/brew doctor && true
    set -e
}

# ------------------------------------
# Create a Case Sensitive Volume
# Necessary for the esp sdk toolchain
# to work properly in OSX
# ------------------------------------
function createCaseSensitiveVolume(){
    echo "+--------------------------------------------------------+"
    echo "|      Creating volume mounted on /Volumes/$ImageName     |"
    echo "+--------------------------------------------------------+"
    cd ${InstallBase}
    diskutil umount force /Volumes/${ImageName} && true
    rm -f ${ImageNameDMG}
    hdiutil create ${ImageNameDMG} -volname ${ImageName} -size 10g -fs "Case-sensitive HFS+"
    hdiutil mount ${ImageNameDMG}
    cd /Volumes/${ImageName}
}

# -------------------------------
# Download esp-open-sdk from GIT
# and place it inside the Volume
# -------------------------------
function downloadEspOpenSdk(){
    echo "+--------------------------------------------------------+"
    echo "|            Downloading ESP-open-sdk...                 |"
    echo "+--------------------------------------------------------+"
    cd /Volumes/${ImageName}
    git clone https://github.com/pfalcon/esp-open-sdk.git
    cd esp-open-sdk
}

# ------------------------------------
# Patching config file to use AR tool
# from the toolchain and not from OSX
# ------------------------------------
function patchXtensaConfigFile(){
    echo "+--------------------------------------------------------+"
    echo "|              Patching ESP-open-sdk...                  |"
    echo "+--------------------------------------------------------+"
    sed -i.bak '19i\
AM_PROG_AR' lx106-hal/configure.ac
}

# ---------------------------------------
# Just build the Xtensa Cross toolchain
# so it will generate all configure file
# ---------------------------------------
function buildCrosstoolNG(){
    echo "+--------------------------------------------------------+"
    echo "|              Configuring ESP-open-sdk...               |"
    echo "+--------------------------------------------------------+"
    make toolchain && true
}

# ----------------------------------
# Final build to merge ESP sdk with
# Xtensa cross toolchain
# ----------------------------------
function buildEspSdk(){
    echo "+--------------------------------------------------------+"
    echo "|                 Building ESP Open SDK                  |"
    echo "+--------------------------------------------------------+"
    ulimit -n 1024
    make STANDALONE=y
    cd /Volumes
    export PATH=/Volumes/${ImageName}/esp-open-sdk/xtensa-lx106-elf/bin:$PATH
    echo "+--------------------------------------------------------+"
    echo "|   DONE! Check for folder called $ImageName             |"
    echo "+--------------------------------------------------------+"
}


createHomeBrew
createCaseSensitiveVolume
downloadEspOpenSdk
buildCrosstoolNG
patchXtensaConfigFile
buildEspSdk