RREE / build-avr-ada-toolchain

Scripts for Building the AVR-Ada Toolchain
MIT License
7 stars 6 forks source link

Dockerfile for encapsulation of the toolchain #5

Open arcadien opened 4 years ago

arcadien commented 4 years ago

It would be great to have a Docker image containing a functional ada-avr toolchain.

arcadien commented 4 years ago

I'm working on it on a devel branch. I open a pull request as soon as i can build something functional. Setup

Issue(s) to solve:

RREE commented 4 years ago

Salut Aurélien,

it's good that you started to develop a Docker image as I have the slightest idea how to do that.

When you get the error in avr-libc, do you try to compile it directly or as part of my build script? I typically work on different Debian systems and never had problems compiling avr-libc. It is also not really needed as you can simply install it ($ sudo apt install avr-libc). That is probably not the latest version, but still good enough for AVR-Ada.

If you get the error when compiling avr-libc yourself, have a look at the build script. You have to carefully follow the steps:

  1. ./bootstrap
  2. ./configure --build=./config.guess --host=avr --prefix=
  3. make
  4. make install

BTW, you also don't need to compile avrdude. You can install it from the Debian repository, too.

bon courage Rolf

Am 18.02.2020 um 22:32 schrieb Aurélien Labrosse:

I'm working on it on a devel branch https://github.com/arcadien/build-avr-ada-toolchain/tree/devel. I open a pull request as soon as i can build something functional. Setup

  • I'm using Ubuntu 19.04 as base, where GCC 9 is available.
  • I'm using host (Ubuntu) libs: isl, gmp, mpc, mpfr

Issue(s) to solve:

  • avr-libc does not compile. For now, it seems i need to have a system avr-gcc installed to compile avr-libc. If I use the freshly compiled avr-gcc, i have the |configure: error: cannot compute suffix of object files: cannot compile| error.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/RREE/build-avr-ada-toolchain/issues/5?email_source=notifications&email_token=AABK7OPOQMUOOJJXXCJPXULRDRHV3A5CNFSM4KXMRD32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMFGWTA#issuecomment-587885388, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABK7OM36UUIEKYU2MQVPH3RDRHV3ANCNFSM4KXMRD3Q.

arcadien commented 4 years ago

Thanks for these information. I"m now close, i just have to find a way to install various gpr files from Avr-Ada to the /opt/ folder.

letsbyteit commented 3 years ago

I'm currently taking the same approach as @arcadien: Putting the toolchain into a Docker-image for ease of development.

At this point, I don't know the version matching of everything well enough, to make it work. I took this repo of @RREE and forked it for the following reason here: https://github.com/letsbyteit/build-avr-ada-toolchain The main problem for a dockerization was that the build-script is intended to be a "single installer". Which means, the Dockerfile may have basically looked like RUN build-avr-ada.sh. This is nice in general, but for such long running tasks, Docker lets us profit from layering. Which means, every RUN command is layered and can be cached for future runs. This saves time, when gcc was compiled successfully but the RTS failed after gcc compilation. By splitting the main script in a quick-and-dirty way into several scripts, I can retry a lot more often.

The Dockerfile I came up with looks currently as following:

FROM debian:bullseye-slim

# Update sources
RUN apt-get update

# Install general basics
RUN apt install -y git wget

# Install compilation toolchain, GCC 9 by default
RUN apt install -y build-essential gcc gcc-9 gnat-9 g++-9
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 100

# Install dependencies
RUN apt install -y libisl-dev libgmp-dev libmpc-dev bison flex gprbuild

# Get Install & Setup Package from Repo
RUN git clone https://github.com/letsbyteit/build-avr-ada-toolchain.git

# Build avr-ada
# Clean-up build-dir and download additional deps
RUN cd build-avr-ada-toolchain && ./download.sh
# Build binutils
RUN cd build-avr-ada-toolchain && ./build_binutils.sh
# Compile gcc...
RUN cd build-avr-ada-toolchain && ./build_gcc.sh || cat  /build-avr-ada-toolchain/build/step22_gcc_gcc_obj.log
# Compile avr-libc
RUN cd build-avr-ada-toolchain && ./build_libc.sh || cat /build-avr-ada-toolchain/build/step31_libc_conf.log
# Compile the RTS for avr-ada
RUN cd build-avr-ada-toolchain && ./build_avradarts.sh
# Finally, make the avr-ada
RUN cd build-avr-ada-toolchain && ./build_avr_ada.sh || cat /build-avr-ada-toolchain/build/step14_avrada_libs.log

# Clean apt caches
RUN apt-get clean

# TODO: Clean up build artifacts after finishing

My versions.inc file:

# -*- mode: shell-script -*-
#
# versions of the different source packages
#

VER_BINUTILS=2.32
VER_GCC=9.2.0
VER_MPFR=4.1.0
VER_MPC=1.1.0
VER_GMP=6.1.2
VER_LIBC=2.0.0
VER_AVRADA=1.2.2
VER_AVRDUDE=6.3

FILE_BINUTILS="binutils-$VER_BINUTILS"
FILE_GCC="gcc-$VER_GCC"
FILE_MPFR="mpfr-$VER_MPFR"
FILE_MPC="mpc-$VER_MPC"
FILE_GMP="gmp-$VER_GMP"
FILE_LIBC="avr-libc-$VER_LIBC"
FILE_AVRADA="avr-ada-$VER_AVRADA"
FILE_AVRDUDE="avrdude-$VER_AVRDUDE"

BINUTILS_TAR="binutils-$VER_BINUTILS.tar.bz2"
BINUTILS_X="j"
BINUTILS_MIRROR=ftp://sourceware.org/pub/binutils/releases

GCC_TAR="gcc-$VER_GCC.tar.xz"
GCC_X=J
GCC_MIRROR="ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-$VER_GCC"

MPFR_TAR="mpfr-$VER_MPFR.tar.xz"
MPFR_X=J
MPFR_MIRROR="https://www.mpfr.org/mpfr-current"

MPC_TAR="mpc-$VER_MPC.tar.gz"
MPC_X=z
MPC_MIRROR="https://ftp.gnu.org/gnu/mpc"

GMP_TAR="gmp-$VER_GMP.tar.xz"
GMP_X=J
GMP_MIRROR="https://gmplib.org/download/gmp"

LIBC_TAR="avr-libc-$VER_LIBC.tar.bz2"
LIBC_X=j
LIBC_MIRROR="http://download.savannah.gnu.org/releases/avr-libc"

AVRDUDE_TAR="avrdude-$VER_AVRDUDE.tar.gz"
AVRDUDE_X=z
AVRDUDE_MIRROR="http://download.savannah.gnu.org/releases/avrdude"

AVRADA_TAR="avr-ada-$VER_AVRADA.tar.bz2"
AVRADA_X=j
AVRADA_MIRROR="https://downloads.sourceforge.net/project/avr-ada/avr-ada/Source%20Dist"

This works until making the AVR-Ada libraries. There is a mismatch with the structure of the rts directories, I guess. I'm seeking help into getting this final step to work. For me, building such toolchains is new and I don't speak Makefile yet. :)

Running the last action of my scripts goes as following:

./build_avr_ada.sh 
DIR = /opt
--------------------------------------------------------------
GCC AVR-Ada build script: all output is saved in log files
--------------------------------------------------------------

Found native compiler gcc-9
mkdir: cannot create directory '/build-avr-ada-toolchain/build': File exists

--------------------------------------------------------------
2021-08-26_19:19:33  Building AVR-Ada libraries
--------------------------------------------------------------

build AVR-Ada libs ... (log in /build-avr-ada-toolchain/build/step14_avrada_libs.log)

 **** The last command failed :(
Please check the generated log files for errors and warnings.
Exiting..

The according log file looks as following:

make -C avr build_libs
make[1]: Entering directory '/build-avr-ada-toolchain/build/avr-ada-1.2.2/avr'
make -C avr_lib build_libs
make[2]: Entering directory '/build-avr-ada-toolchain/build/avr-ada-1.2.2/avr/avr_lib'
gprbuild -XRTS=/build-avr-ada-toolchain/build/avr-ada-1.2.2/avr/avr_lib/../../gcc-9.2-rts/rts -p -P../avr_lib.gpr -XMCU=attiny2313
make[2]: gprbuild: No such file or directory
make[2]: *** [Makefile:101: attiny2313/lib/libavrada.a] Error 127
make[2]: Leaving directory '/build-avr-ada-toolchain/build/avr-ada-1.2.2/avr/avr_lib'
make[1]: *** [Makefile:81: build_libs] Error 2
make[1]: Leaving directory '/build-avr-ada-toolchain/build/avr-ada-1.2.2/avr'
make: *** [Makefile:118: build_libs] Error 2

Within build-avr-ada-toolchain/build/avr-ada-1.2.2/avr/avr_lib/Makefile I had to change some $(GNATMAKE) to $(GPRBUILD) due to deprecation by GNAT.

The according Makefile file looks like:

###########################################################################
## The AVR-Ada Library is free software;  you can redistribute it and/or ##
## modify it under terms of the  GNU General Public License as published ##
## by  the  Free Software  Foundation;  either  version 2, or  (at  your ##
## option) any later version.  The AVR-Ada Library is distributed in the ##
## hope that it will be useful, but  WITHOUT ANY WARRANTY;  without even ##
## the  implied warranty of MERCHANTABILITY or FITNESS FOR A  PARTICULAR ##
## PURPOSE.  See the GNU General Public License for more details.        ##
###########################################################################

# avr/avr_lib/Makefile builds the AVR-Ada MCUs & Boards

###############################################################
#
#  Top
#
all: build_libs
clean: clean_libs

.PHONY: all clean

###############################################################
#
#  Config
#
../../config:
    $(MAKE) -C ../.. config

include ../../config

###############################################################
#
#  Settings
#
include ../../excldevs.mk

# list of primary devices
PRIMARY_MCU_LIST := attiny2313 atmega8 atmega8u2 atmega168 atmega169 \
   atmega32 atmega328p atmega644p atmega2560

# list of all supported devices
# MCU_LIST = $(filter-out $(excluded_parts), $(shell (ls -d at*)))
MCU_LIST = $(PRIMARY_MCU_LIST)

BOARD_LIST = \
   arduino_uno \
   xbeeimu \
   sparkfun8u2

include boards.mk

# Library to build for each MCU
LIB = libavrada.a
THREAD_LIB = libavr-thread.a

# All libaries
# we build separate libraries for each supported device and each board (why?)
LIB_LIST := $(patsubst %, %/lib/$(LIB), $(MCU_LIST))
THREAD_LIB_LIST := $(patsubst %, %/thread-lib/$(THREAD_LIB), $(MCU_LIST))
BOARD_LIB_LIST := $(patsubst %, board-%/lib/$(LIB), $(BOARD_LIST))

# All part specific registers and definitions
MCU_SPECS := $(patsubst %, %/avr-mcu.ads, $(MCU_LIST))
BOARD_MCU_SPECS := $(patsubst %, board-%/avr-mcu.ads, $(BOARD_LIST))

# Point to our RTS
XRTS = -XRTS=$(CURDIR)/../../gcc-$(major).$(minor)-rts/rts
#XRTS = -XRTS=/build-avr-ada-toolchain/rts/gcc-9/
#XRTS = -XRTS=/build-avr-ada-toolchain/build/avr-ada-rts-gcc-9/

# Location of avr.cgpr if RTS has been installed
INSTALL_CGPR_DIR = $(PREFIX)/share/gpr

###############################################################
#
#  Tools
#
GNATMAKE  = avr-gnatmake
GPRBUILD  = gprbuild
GPRCONFIG = gprconfig
RM        = rm -f
MKDIR     = mkdir
ECHO      = echo

###############################################################
#
#  Build
#
build_libs: stamp-links stamp-libs

# first set the variable MCU
at%/avr-mcu.ads : MCU = $(patsubst %/avr-mcu.ads,%, $@)
at%/lib/$(LIB)  : MCU = $(patsubst %/lib/$(LIB),%, $@)
at%/thread-lib/$(THREAD_LIB): MCU = $(patsubst %/thread-lib/$(THREAD_LIB),%, $@)

at%/lib/$(LIB): stamp-links at%/obj at%/lib ../avr_lib.gpr ../avr_tools.gpr \
   ../mcu.gpr at%/avr-mcu.ads
    $(GPRBUILD) $(XRTS) -p -P../avr_lib.gpr -XMCU=$(MCU)

board-%/lib/$(LIB): stamp-links board-%/obj board-%/lib ../avr_lib.gpr \
   ../mcu.gpr board-%/avr-mcu.ads
    $(GPRBUILD) $(XRTS) -P../avr_lib.gpr -XBOARD=$(BOARD) -XMCU=$(MCU)

local-avr.cgpr: V := $(strip $(major).$(minor).$(patch))
local-avr.cgpr:
    $(GPRCONFIG) --batch --target=avr \
      --config=Asm,$(V) \
      --config=Asm2,$(V) \
      --config=Asm_Cpp,$(V) \
      --config=C,$(V) \
      -o local-avr.cgpr

# rule for building the thread library
at%/thread-lib/$(THREAD_LIB): local-avr.cgpr at%/thread-obj at%/thread-lib \
   ../threads_lib.gpr ../mcu.gpr
    $(GPRBUILD) -p --config=local-avr.cgpr -P../threads_lib.gpr -XMCU=$(MCU)

at%/avr-mcu.ads board-%/avr-mcu.ads:
    $(ECHO) "pragma Style_Checks (Off);"  > $@
    $(ECHO) "with AVR.${MCU};"                    >> $@
    $(ECHO) "package AVR.MCU renames AVR.${MCU};" >> $@

at%/obj:
    $(MKDIR) -p $@

at%/lib:
    $(MKDIR) -p $@

at%/thread-obj:
    $(MKDIR) -p $@

at%/thread-lib:
    $(MKDIR) -p $@

board-%/obj:
    $(MKDIR) -p $@

board-%/lib:
    $(MKDIR) -p $@

stamp-links: $(MCU_SPECS) $(BOARD_MCU_SPECS)
    touch $@

stamp-libs: $(LIB_LIST) $(BOARD_LIB_LIST) $(THREAD_LIB_LIST)
    touch $@

.PHONY: build_libs

# don't delete these intermediate files
.PRECIOUS: at%/avr-mcu.ads at%/lib at%/obj board-%/avr-mcu.ads board-%/lib \
   board-%/obj at%/thread-lib at%/thread-obj

###############################################################
#
#  Clean
#
clean_libs:
    -$(RM) stamp-*
    -$(RM) -r at*/obj at*/lib
    -$(RM) -r at*/thread-obj at*/thread-lib
    -$(RM) -r board-*/obj board-*/lib
    -$(RM) at*/avr-mcu.ads board-*/avr-mcu.ads
    -$(RM) local-avr.cgpr

.PHONY: clean_libs

###############################################################
#
#  Implicit rules
#

# Create assembler files from Ada source files.
%.s : %.adb
    $(GNATMAKE) -f -u -P../avr_lib -XMCU=$(MCU) $< -cargs -S

%.s : %.ads
    $(GNATMAKE) -f -u -P../avr_lib -XMCU=$(MCU) $< -cargs -S

-include $(Makefile_post)

My directory structure looks as following:

tree -L 3 /build-avr-ada-toolchain/
/build-avr-ada-toolchain/
|-- LICENSE
|-- README.md
|-- actions.sh
|-- base.sh
|-- bin
|   |-- config.inc
|   |-- download.sh
|   |-- utilities.inc
|   `-- versions.inc
|-- build
|   |-- avr-ada-1.2.2
|   |   |-- Makefile
|   |   |-- apps
|   |   |-- avr
|   |   |-- config
|   |   |-- configure
|   |   |-- excldevs.mk
|   |   |-- gcc-4.7-rts
|   |   |-- patches
|   |   `-- tools
|   |-- avr-ada-rts-gcc-9
|   |   |-- Makefile
|   |   |-- README.gnatlink_inst
|   |   |-- README.gprconfig
|   |   |-- adainclude
|   |   |-- asm
|   |   |-- rts-avr25
|   |   |-- rts-avr3
|   |   |-- rts-avr31
|   |   |-- rts-avr35
|   |   |-- rts-avr4
|   |   |-- rts-avr5
|   |   |-- rts-avr51
|   |   `-- rts-avr6
|   |-- build.log
|   |-- build.sum
|   |-- step14_avrada_libs.log
|   |-- step62_avrada_rts_make.log
|   |-- step68_avrada_rts_install.log
|   `-- time_run.log
|-- build-avr-ada.sh
|-- build_avr_ada.sh
|-- build_avradarts.sh
|-- build_binutils.sh
|-- build_gcc.sh
|-- build_libc.sh
|-- download.sh
|-- patches
|   |-- avrdude
|   |   `-- 6.3
|   |-- binutils
|   |   |-- 2.15
|   |   |-- 2.16
|   |   |-- 2.17
|   |   |-- 2.18
|   |   |-- 2.19
|   |   |-- 2.20.1
|   |   |-- 2.24
|   |   `-- 2.32
|   `-- gcc
|       |-- 3.4
|       |-- 4.1
|       |-- 4.2.0
|       |-- 4.3.2
|       |-- 4.4.2
|       |-- 4.4.5
|       |-- 4.5.1
|       |-- 4.7.0
|       |-- 4.7.2
|       |-- 4.9.1
|       |-- 4.9.2
|       |-- 8.3.0
|       `-- 9.2.0
|-- rts
|   |-- gcc-8
|   |   |-- Makefile
|   |   |-- README.gnatlink_inst
|   |   |-- README.gprconfig
|   |   |-- adainclude
|   |   `-- asm
|   `-- gcc-9
|       |-- Makefile
|       |-- README.gnatlink_inst
|       |-- README.gprconfig
|       |-- adainclude
|       `-- asm
`-- src
    |-- avr-ada-1.2.2.tar.bz2
    |-- avr-libc-2.0.0.tar.bz2
    |-- avrdude-6.3.tar.gz
    |-- binutils-2.32.tar.bz2
    |-- gcc-9.2.0.tar.xz
    |-- gmp-6.1.2.tar.xz
    |-- mpc-1.1.0.tar.gz
    `-- mpfr-4.1.0.tar.xz

53 directories, 42 files

I tried some fiddling with XRTS path but I'm always stuck with the error:

gprbuild -XRTS=/build-avr-ada-toolchain/build/avr-ada-rts-gcc-9/ -p -P../avr_lib.gpr -XMCU=attiny2313
make[2]: gprbuild: No such file or directory
make[2]: *** [Makefile:101: attiny2313/lib/libavrada.a] Error 127

Maybe someone has any idea what I could possibly try to fix this. My suspicion is that the paths and naming schemes of the rts does not match the structure expected by the Makefile.

I am thankful for any hints.

letsbyteit commented 3 years ago

So, I realized that avr-ada 1.9.0 is somehow available via git main branch on sourceforge. And that this resolved the compatibility issues. Also, I had some PATH problems to resolve and figured that my libc wasn't building at all due to missing automake (I missed this).

My working Dockerfile for this looks now like this (consider this still a WIP, I've not tested it thoroughly):

FROM debian:bullseye-slim

# Update sources
RUN apt-get update

# Install general basics
RUN apt install -y git wget

# Install compilation toolchain, GCC 9 by default
RUN apt install -y build-essential gcc gcc-9 gnat-9 g++-9
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 100

# Install dependencies
RUN apt install -y libisl-dev libgmp-dev libmpc-dev bison flex gprbuild automake

# Get Install & Setup Package from Repo
RUN git clone https://github.com/letsbyteit/build-avr-ada-toolchain.git

# Build avr-ada
# Clean-up build-dir and download additional deps
RUN cd build-avr-ada-toolchain && ./download.sh
RUN cd build-avr-ada-toolchain/build && git clone https://git.code.sf.net/p/avr-ada/code avr-ada
# Build binutils
RUN cd build-avr-ada-toolchain && ./build_binutils.sh
# Compile gcc...
RUN cd build-avr-ada-toolchain && ./build_gcc.sh
# Compile avr-libc
RUN cd build-avr-ada-toolchain && ./build_libc.sh
# Compile the RTS for avr-ada
RUN cd build-avr-ada-toolchain && ./build_avradarts.sh
# Finally, make the avr-ada
RUN ln -s /usr/lib/gprbuild /usr/libexec/gprbuild
RUN cd build-avr-ada-toolchain && ./build_avr_ada.sh
ENV PATH="/opt/avr_92_gnat/bin:$PATH"

# Clean apt caches
RUN apt-get clean

# Remove build files
RUN rm -rf build-avr-ada-toolchain/src/*
RUN rm -rf build-avr-ada-toolchain/build/
# TODO Maybe remove whole /build-avr-ada-toolchain ???