1***********************************************
2Setup Toolchain for Mac OS from Scratch
3***********************************************
4
5:link_to_translation:`zh_CN:[中文]`
6
7Package Manager
8===============
9
10To set up the toolchain from scratch, rather than :doc:`downloading a pre-compiled toolchain<macos-setup>`, you will need to install either the MacPorts_ or Homebrew_ package manager.
11
12MacPorts needs a full XCode installation, while Homebrew only needs XCode command line tools.
13
14    .. _Homebrew: https://brew.sh/
15    .. _MacPorts: https://www.macports.org/install.php
16
17See :ref:`Customized Setup of Toolchain <get-started-customized-setup>` section for some of the reasons why installing the toolchain from scratch may be necessary.
18
19Install Prerequisites
20=====================
21
22- install pip::
23
24    sudo easy_install pip
25
26- install pyserial::
27
28    pip install --user pyserial
29
30- install CMake & Ninja build:
31
32  - If you have Homebrew, you can run::
33
34      brew install cmake ninja dfu-util
35
36  - If you have MacPorts, you can run::
37
38      sudo port install cmake ninja dfu-util
39
40Compile the Toolchain from Source
41=================================
42
43Install dependencies:
44
45  - with MacPorts::
46
47        sudo port install gsed gawk binutils gperf grep gettext wget libtool autoconf automake make
48
49  - with Homebrew::
50
51        brew install gnu-sed gawk binutils gperftools gettext wget help2man libtool autoconf automake make
52
53Create a case-sensitive filesystem image::
54
55    hdiutil create ~/esp/crosstool.dmg -volname "ctng" -size 10g -fs "Case-sensitive HFS+"
56
57Mount it::
58
59    hdiutil mount ~/esp/crosstool.dmg
60
61Create a symlink to your work directory::
62
63    mkdir -p ~/esp
64    ln -s /Volumes/ctng ~/esp/ctng-volume
65
66Go into the newly created directory::
67
68    cd ~/esp/ctng-volume
69
70Download ``crosstool-NG`` and build it:
71
72.. include-build-file:: inc/scratch-build-code.inc
73
74Build the toolchain::
75
76    ./ct-ng {IDF_TARGET_TOOLCHAIN_PREFIX}
77    ./ct-ng build
78    chmod -R u+w builds/{IDF_TARGET_TOOLCHAIN_PREFIX}
79
80Toolchain will be built in ``~/esp/ctng-volume/crosstool-NG/builds/{IDF_TARGET_TOOLCHAIN_PREFIX}``. To use it, you need to add ``~/esp/ctng-volume/crosstool-NG/builds/{IDF_TARGET_TOOLCHAIN_PREFIX}/bin`` to ``PATH`` environment variable.
81
82Next Steps
83==========
84
85To carry on with development environment setup, proceed to :ref:`get-started-get-esp-idf`.