MayaPosch / Nodate

A light-weight framework for STM32 and other architectures written in C++.
GNU Lesser General Public License v3.0
137 stars 18 forks source link

Build with gprbuild #5

Closed Fabien-Chouteau closed 4 years ago

Fabien-Chouteau commented 4 years ago

Hi Maya,

There only this one CPP file in the project? https://github.com/MayaPosch/Nodate/blob/9440750e420aab7631007c629d557d8e358565c3/arch/stm32/Makefile.ada#L76

MayaPosch commented 4 years ago

Yes, that file is used with the CMSIS headers together with the preprocessor. It provides the data arrays that are used in the Ada code (via Interfaces.C).

Fabien-Chouteau commented 4 years ago

As I said on twitter, I would first make a static library from the cpp code:

CPPSTATICLIB=libstm32cpp.a

$(CPPSTATICLIB): $(CPPOBJECTS)
    ar ru $@ $^
    ranlib $@

and then call gprbuild to build the Ada application that uses the cpp lib:


$(APPFOLDER)/bin/$(OUTPUT).elf: $(CPPSTATICLIB)
    gprbuild -P my_project.gpr

my_project.gpr:

project My_Project is
    for Languages use ("Ada");
    for Source_Dirs use (...)
    for Target use "arm-eabi";
    for Runtime ("Ada") use "zfp-cortex-m4f";
    [...]
    package Linker is
      for Switches ("Ada") use ("-lstm32cpp");
   end Linker;

Something like that.

Note that you can most likely also compile the cpp file with gprbuild and don't need the Makefile at all.

MayaPosch commented 4 years ago

I would very much prefer it to not have to dynamically create project files just to keep gprbuild happy.

I'm still exploring ways to make cross-compiling with GNAT work, but so far it basically seems needlessly complicated compared to doing the same with any other language.

I nearly got things working using the local toolchain's gnatmake. Gnatlink still errors out with ELF relocation issues, presumably due to toolchain issues.

I'm more tempted to take this even more low-level with just arm-eabi-gcc and no gnatmake, gprbuild or any such poorly documented abstractions. At this point I'm severely frustrated with using those tools and how they do not really fix issues, but just create new, interesting ones.

Fabien-Chouteau commented 4 years ago

I would very much prefer it to not have to dynamically create project files just to keep gprbuild happy.

The project file is always the same, not dynamic.

I'm still exploring ways to make cross-compiling with GNAT work, but so far it basically seems needlessly complicated compared to doing the same with any other language.

Which other languages for instance?