July 26, 2017

Compile the GNU MPFR Library for ARM Cortex M7

In a previous post,  I described how to compile GMP (GNU MP) for Cortex M4 (eg: stm32f4) target on a Mac. I thought I would follow up and describe the steps required to build MPFR for cortex-m7 target on Mac. These steps should work just as well on Linux also.

MPFR library is a C library for multiple-precision floating-point computations. From their web site, it is described as follows.

The main goal of MPFR is to provide a library for multiple-precision floating-point computation which is both efficient and has a well-defined semantics

It is quite a popular library, cited by many publications and is definitely a worthwhile addition to your toolbox. So, lets see how to cross compile this library on Mac for the cortex m7 target.

One thing to note is that MPFR depends on GMP, so 2 downloads will be required. Also it is assumed I assume you already have GNU ARM Embedded Toolchain installed and working

Create a directory and download GMP and MPFR

mkdir arm_f7_builds
cd arm_f7_builds
curl -O
curl -O
tar -xf gmp-6.1.2.tar.bz2
tar -xf mpfr-3.1.5.tar.bz2

Build GMP and install.

mkdir tools
cd gmp-6.1.2
mkdir build_stm32f7
cd build_stm32f7/
export PATH=/Users/frank/opt/gcc-arm-none-eabi-6-2017-q1-update/bin/:$PATH
../configure CC=arm-none-eabi-gcc CFLAGS="-nostartfiles --specs=nosys.specs -mcpu=cortex-m7"  --host=arm-none-eabi  \
   --disable-assembly --prefix=/Users/frank/arm_f7_builds/tools/
make install
cd ../..

Build MPFR and install. Notice how we point to the location where we just installed GMP.

cd mpfr-3.1.5
mkdir build_stm32f7
cd build_stm32f7/
../configure CC=arm-none-eabi-gcc CFLAGS="-nostartfiles --specs=nosys.specs -mcpu=cortex-m7"   --host=arm-none-eabi  \
  --prefix=/Users/frank/arm_f7_builds/tools/ --with-gmp-include=/Users/frank/arm_f7_builds/tools/include/  \
make install
cd ../..

Lets examine the resulting directory structure.

tree tools/

✔ ~/arm_f7_builds
16:32 $ tree tools/
├── include
│   ├── gmp.h
│   ├── mpf2mpfr.h
│   └── mpfr.h
├── lib
│   ├── libgmp.a
│   ├──
│   ├── libmpfr.a
│   └──
└── share
├── doc
│   └── mpfr
│   ├── AUTHORS
│   ├── BUGS
│   ├── COPYING
│   ├── FAQ.html
│   ├── NEWS
│   ├── TODO
│   └── examples
│   ├── ReadMe
│   ├── divworst.c
│   ├── rndo-add.c
│   ├── sample.c
│   └── version.c
└── info
├── dir

Great, we can see both the static libraries (libgmp.a and libmpfr.a) and the header files (gmp.h and mpfr.h) are available.

In a follow up article, I will use show how to use the static MPFR library in a demo project for a Cortex M7 board (eg: STM32F7 Discovery Board).