<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://miosix.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Building_GCC_from_sources</id>
	<title>Building GCC from sources - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://miosix.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Building_GCC_from_sources"/>
	<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Building_GCC_from_sources&amp;action=history"/>
	<updated>2026-04-15T00:41:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>https://miosix.org/wiki/index.php?title=Building_GCC_from_sources&amp;diff=304&amp;oldid=prev</id>
		<title>Daniele.cattaneo: Create the page by mostly copy-pasting and adapting text from the macOS getting started guide.</title>
		<link rel="alternate" type="text/html" href="https://miosix.org/wiki/index.php?title=Building_GCC_from_sources&amp;diff=304&amp;oldid=prev"/>
		<updated>2023-06-11T13:57:13Z</updated>

		<summary type="html">&lt;p&gt;Create the page by mostly copy-pasting and adapting text from the macOS getting started guide.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;ATTENTION&amp;#039;&amp;#039;&amp;#039;: This page is still a WIP. Usual disclaimers about not taking responsibility for your system disruption applies.&lt;br /&gt;
&lt;br /&gt;
The Miosix repository contains a set of scripts which are used to build the&lt;br /&gt;
toolchain from sources. These scripts perform the entire building process&lt;br /&gt;
automatically, from downloading the dependencies, to compiling them, to&lt;br /&gt;
finally packaging them.&lt;br /&gt;
&lt;br /&gt;
The steps required to use these scripts are similar for all three operating&lt;br /&gt;
systems supported by the toolchain (macOS, Windows, Linux), but some platform-specific&lt;br /&gt;
steps are also required.&lt;br /&gt;
&lt;br /&gt;
== Before you begin ==&lt;br /&gt;
&lt;br /&gt;
Building the Miosix toolchain can be time-consuming and stressful for system&lt;br /&gt;
resources. Make sure the system you intend to build the toolchain on has at&lt;br /&gt;
least the following system requirements:&lt;br /&gt;
&lt;br /&gt;
* 4 GB of RAM&lt;br /&gt;
* 4 CPU cores&lt;br /&gt;
* 10 GB of free disk space&lt;br /&gt;
&lt;br /&gt;
Any reasonably modern system will be able to meet these requirements. However&lt;br /&gt;
notice that the only truly necessary requirement is the free disk space for&lt;br /&gt;
the build products. Other requirements can be ignored if you are willing to&lt;br /&gt;
spend quite some time waiting out for the compilation to end.&lt;br /&gt;
&lt;br /&gt;
== System dependencies installation ==&lt;br /&gt;
&lt;br /&gt;
=== Linux ===&lt;br /&gt;
&lt;br /&gt;
TODO&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&lt;br /&gt;
TODO&lt;br /&gt;
&lt;br /&gt;
=== macOS ===&lt;br /&gt;
&lt;br /&gt;
==== Install the Command Line Tools ====&lt;br /&gt;
&lt;br /&gt;
Install the Command Line Tools by running the following command in terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
xcode-select --install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command line tools provide &amp;lt;code&amp;gt;clang&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;clang++&amp;lt;/code&amp;gt;,&lt;br /&gt;
&amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;bison&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;flex&amp;lt;/code&amp;gt; and headers for the C&lt;br /&gt;
standard library, the C++ STL, and more tools required for building the&lt;br /&gt;
toolchain.&lt;br /&gt;
&lt;br /&gt;
It is not necessary to also install Xcode to build the Miosix toolchain, the&lt;br /&gt;
Command Line Tools suffice.&lt;br /&gt;
&lt;br /&gt;
It is recommended to run the command even if the Command Line Tools were already&lt;br /&gt;
installed on your system, since the Command Line Tools installation may have&lt;br /&gt;
been messed up by upgrading from a previous release.&lt;br /&gt;
&lt;br /&gt;
==== Check the installed packages ====&lt;br /&gt;
&lt;br /&gt;
If everything went as supposed, running from terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cc -v&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
should return some text including:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Apple clang version 14.0.3 (clang-1403.0.22.14.1)&lt;br /&gt;
Target: x86_64-apple-darwin22.5.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Toolchain Sources Download ==&lt;br /&gt;
&lt;br /&gt;
=== Download the Miosix git repository ===&lt;br /&gt;
&lt;br /&gt;
From a terminal, cd to a folder of your choice, making sure that the path from&lt;br /&gt;
root to it doesn&amp;#039;t contain spaces or special characters. Then run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone https://miosix.org/git-public/miosix-kernel.git&lt;br /&gt;
cd miosix-kernel&lt;br /&gt;
git fetch origin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
To select the development version of the kernel&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git checkout -b testing origin/testing&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note that currently, the &amp;#039;&amp;#039;master&amp;#039;&amp;#039; branch contains the stable kernel,&lt;br /&gt;
the &amp;#039;&amp;#039;testing&amp;#039;&amp;#039; branch contains the current development version, and the&lt;br /&gt;
&amp;#039;&amp;#039;unstable&amp;#039;&amp;#039; branch contains experimental commits that implement more radical&lt;br /&gt;
restructuring of the code.&lt;br /&gt;
&lt;br /&gt;
Usually the &amp;#039;&amp;#039;testing&amp;#039;&amp;#039; branch contains the latest updates made, especially&lt;br /&gt;
support packages for new boards, so its advised to use the code contained in&lt;br /&gt;
this branch.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;macOS only:&amp;#039;&amp;#039;&amp;#039; If you are building for macOS, use the &amp;#039;&amp;#039;unstable&amp;#039;&amp;#039; branch&lt;br /&gt;
instead, because it is the one where the patches to the compilation scripts for&lt;br /&gt;
macOS support are currently located. Just replace &amp;lt;code&amp;gt;testing&amp;lt;/code&amp;gt; with&lt;br /&gt;
&amp;lt;code&amp;gt;unstable&amp;lt;/code&amp;gt; in the commands shown above.&lt;br /&gt;
&lt;br /&gt;
Make sure the path to your current working directory does not contain spaces,&lt;br /&gt;
or compiling will fail! You can check the path to the current working directory&lt;br /&gt;
by running the command &amp;lt;code&amp;gt;pwd&amp;lt;/code&amp;gt;. For example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/home/foo/temp                          OK&lt;br /&gt;
/home/foo/directory with spaces/temp    NO!!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now move to the compiler directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cd miosix-kernel/miosix/_tools/compiler/gcc-9.2.0-mp3.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run the script for downloading the sources ===&lt;br /&gt;
&lt;br /&gt;
At this point you need to run the dependencies download script. From terminal,&lt;br /&gt;
run &amp;lt;code&amp;gt;sh download.sh&amp;lt;/code&amp;gt; from the folder where you performed the&lt;br /&gt;
&amp;lt;code&amp;gt;git clone&amp;lt;/code&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
If you want to build a redistributable package, you should also run the&lt;br /&gt;
command &amp;lt;code&amp;gt;sh installers/additional-download.sh&amp;lt;/code&amp;gt;. Do &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; change&lt;br /&gt;
the working directory to &amp;lt;code&amp;gt;installers&amp;lt;/code&amp;gt; before running this command!&lt;br /&gt;
&lt;br /&gt;
== Toolchain install script configuration ==&lt;br /&gt;
&lt;br /&gt;
The Miosix toolchain install script supports compiling the toolchain in three&lt;br /&gt;
different ways:&lt;br /&gt;
1. Non-redistributable, local install&lt;br /&gt;
2. Non-redistributable, global install&lt;br /&gt;
3. Redistributable (installable package), global install&lt;br /&gt;
&lt;br /&gt;
The default configuration of the script compiles the toolchain as&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;non-redistributable, with local install&amp;#039;&amp;#039;&amp;#039;. &amp;#039;&amp;#039;&amp;#039;If this is OK for you, skip to the next section.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
If you want a different configuration, edit the install script located at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
miosix-kernel/miosix/_tools/compiler/gcc-9.2.0-mp3.1/install-script.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the beginning of the script, the following lines of code (or similar ones)&lt;br /&gt;
should appear:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Uncomment if installing globally on this system&lt;br /&gt;
PREFIX=/opt/arm-miosix-eabi&lt;br /&gt;
DESTDIR=&lt;br /&gt;
SUDO=sudo&lt;br /&gt;
# Uncomment if installing locally on this system, sudo isn&amp;#039;t necessary&lt;br /&gt;
#PREFIX=`pwd`/gcc/arm-miosix-eabi&lt;br /&gt;
#DESTDIR=&lt;br /&gt;
#SUDO=&lt;br /&gt;
# Uncomment for producing a package for redistribution. The prefix is set to the&lt;br /&gt;
# final install directory, but when this script does &amp;quot;make install&amp;quot; files are&lt;br /&gt;
# copied with $DESTDIR as prefix. When doing a redistibutable build you also&lt;br /&gt;
# have to specify HOST or (on Mac OS), BUILD, see below.&lt;br /&gt;
#PREFIX=/opt/arm-miosix-eabi&lt;br /&gt;
#DESTDIR=`pwd`/dist&lt;br /&gt;
#SUDO=&lt;br /&gt;
&lt;br /&gt;
# Uncomment if targeting a local install. This will use -march= -mtune= flags&lt;br /&gt;
# to optimize for your processor, but the code won&amp;#039;t be portable to other&lt;br /&gt;
# architectures, so don&amp;#039;t distribute it&lt;br /&gt;
BUILD=&lt;br /&gt;
HOST=&lt;br /&gt;
# Uncomment if targeting linux 64 bit (distributable)&lt;br /&gt;
#BUILD=&lt;br /&gt;
#HOST=x86_64-linux-gnu&lt;br /&gt;
# Uncomment if targeting windows 64 bit (distributable)&lt;br /&gt;
# you have to run this script from Linux anyway (see canadian cross compiling)&lt;br /&gt;
#BUILD=&lt;br /&gt;
#HOST=x86_64-w64-mingw32&lt;br /&gt;
# Uncomment if targeting macOS 64 bit Intel (distributable), compiling on Linux&lt;br /&gt;
# Must first install the osxcross toolchain&lt;br /&gt;
#BUILD=&lt;br /&gt;
#HOST=x86_64-apple-darwin18&lt;br /&gt;
# Uncomment if targeting macOS 64 bit Intel (distributable), compiling on macOS&lt;br /&gt;
# The script must be run under macOS and without canadian cross compiling&lt;br /&gt;
# because it confuses autotools&amp;#039;s configuration scripts. Instead we set the&lt;br /&gt;
# compiler options for macOS minimum version and architecture in order to be&lt;br /&gt;
# able to deploy the binaries on older machines and OS versions. We also must&lt;br /&gt;
# force --build and --host to specify a x86_64 cpu to avoid&lt;br /&gt;
# architecture-dependent code.&lt;br /&gt;
#BUILD=x86_64-apple-darwin17 # No macs exist with a cpu older than a Core 2&lt;br /&gt;
#HOST=&lt;br /&gt;
#export CFLAGS=&amp;#039;-mmacos-version-min=10.13 -O3&amp;#039;&lt;br /&gt;
#export CXXFLAGS=&amp;#039;-mmacos-version-min=10.13 -O3&amp;#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The comments in the source should be sufficiently self-explanatory. Just&lt;br /&gt;
un-comment the appropriate section depending on the kind of installation you&lt;br /&gt;
want to perform by removing the hash (&amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt;) characters at the&lt;br /&gt;
beginning of the appropriate lines of code.&lt;br /&gt;
&lt;br /&gt;
Remember to also &amp;#039;&amp;#039;&amp;#039;comment&amp;#039;&amp;#039;&amp;#039; any line of code in this section that is&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; related to the option you want to choose.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Warning about redistributable packages:&amp;#039;&amp;#039;&amp;#039; The &amp;#039;&amp;#039;&amp;#039;redistributable&amp;#039;&amp;#039;&amp;#039; options&lt;br /&gt;
are used to build the installable packages that are available on the&lt;br /&gt;
[[Miosix Toolchain]] page. If you want to build the toolchain just for yourself,&lt;br /&gt;
do not build a redistributable package. Additionally, to build a redistributable&lt;br /&gt;
package you must have built and installed the toolchain &amp;#039;&amp;#039;&amp;#039;at least once&amp;#039;&amp;#039;&amp;#039; as a&lt;br /&gt;
non-redistributable global install.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Linux only:&amp;#039;&amp;#039;&amp;#039; By default, in global install mode, the script installs the&lt;br /&gt;
toolchain in &amp;lt;code&amp;gt;/opt/arm-miosix-eabi&amp;lt;/code&amp;gt;, but it also creates symlinks&lt;br /&gt;
to most tools of interest in &amp;lt;code&amp;gt;/usr/bin&amp;lt;/code&amp;gt;. If you do not want to&lt;br /&gt;
pollute &amp;lt;code&amp;gt;/usr/bin&amp;lt;/code&amp;gt; with stuff not installed by your package manager&lt;br /&gt;
(APT, pacman, ...) comment the following line in the script:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$SUDO ln -s $DESTDIR$PREFIX/bin/* /usr/bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
After this modification you will also need to manually add&lt;br /&gt;
&amp;lt;code&amp;gt;/opt/arm-miosix-eabi/bin&amp;lt;/code&amp;gt; to your &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt; variable&lt;br /&gt;
to access the toolchain from your shell, for example by modifying your shell&lt;br /&gt;
profile setup script (&amp;lt;code&amp;gt;.profile&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;.bashrc&amp;lt;/code&amp;gt; or another&lt;br /&gt;
file depending on your shell).&lt;br /&gt;
&lt;br /&gt;
== Toolchain compilation and installation ==&lt;br /&gt;
&lt;br /&gt;
We can now finally run the compilation script. From terminal, run: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sh install-script.sh -j`nproc`&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;macOS only:&amp;#039;&amp;#039;&amp;#039; macOS does not ship with the &amp;lt;code&amp;gt;nproc&amp;lt;/code&amp;gt; tool by&lt;br /&gt;
default, used by the command above to automatically detect the number of CPUs&lt;br /&gt;
(or CPU cores) available on your system. In case you have not installed this&lt;br /&gt;
tool manually yourself via a third-party package manager (such as&lt;br /&gt;
[https://brew.sh Homebrew] or [https://www.macports.org MacPorts]) just replace&lt;br /&gt;
&amp;lt;code&amp;gt;`nproc`&amp;lt;/code&amp;gt; in the command above with the number of CPUs you have&lt;br /&gt;
available.&lt;br /&gt;
&lt;br /&gt;
The install script will print out progress information as it runs.&lt;br /&gt;
At the end, if everything worked correctly, and if you kept the default&lt;br /&gt;
configuration (non-redistributable, local install) you&amp;#039;ll find the toolchain at:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
miosix-kernel/miosix/_tools/compiler/gcc-9.2.0-mp3.1/gcc/arm-miosix-eabi/bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you selected a global install instead, by default the toolchain will be&lt;br /&gt;
installed here:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
/opt/arm-miosix-eabi/bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;macOS only:&amp;#039;&amp;#039;&amp;#039; Now you need to add the toolchain to your path. Edit the shell&lt;br /&gt;
profile script (&amp;lt;code&amp;gt;~/.profile&amp;lt;/code&amp;gt;) and add the following lines:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#arm-miosix-eabi&lt;br /&gt;
export PATH={my-folder-of-choice-path}/miosix-kernel/miosix/_tools/compiler/gcc-9.2.0-mp3.1/gcc/arm-miosix-eabi/bin:$PATH&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where you must replace {my-folder-of-choice-path} with the path of the folder&lt;br /&gt;
where you run the git clone command.&lt;br /&gt;
Then run from terminal:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
source .bash_profile&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
in order to reload the bash profile script.&lt;br /&gt;
&lt;br /&gt;
== Cleanup ==&lt;br /&gt;
&lt;br /&gt;
In order to remove temporary and log files run from the terminal:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sh cleanup.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This script will remove log files and temporary files created during the&lt;br /&gt;
installation process, but will keep the downloaded files, so that it will be&lt;br /&gt;
possible to run install-script.sh again without the need for redownloading&lt;br /&gt;
anything.&lt;/div&gt;</summary>
		<author><name>Daniele.cattaneo</name></author>
	</entry>
</feed>