Re: Improving build system

Liste des GroupesRevenir à ca embedded 
Sujet : Re: Improving build system
De : pozzugno (at) *nospam* gmail.com (pozz)
Groupes : comp.arch.embedded
Date : 16. May 2025, 14:45:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <1007fgv$3kivm$2@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
Il 14/05/2025 11:03, David Brown ha scritto:
On 13/05/2025 17:57, pozz wrote:
[...]
3.
 Makefiles can be split up.  Use "include" - and remember that you can do so using macros.  In my makefile setups, I have a file "host.mk" that is used to identify the build host, then pull in a file that is specific to the host:
 # This is is for identifying host computer to get the paths right
 ifeq ($(OS),Windows_NT)
   # We are on a Windows machine
   host_os := windows
   host := $(COMPUTERNAME)
else
   # Linux machine
   host_os := linux
   host := $(shell hostname)
endif
 ifeq "$(call file-exists,makes/host_$(host).mk)" "1"
   include makes/host_$(host).mk
else
   $(error No host makefile host_$(host).mk found)
endif
 Then I have files like "host_xxx.mk" for a computer named "xxx", containing things like :
 toolchain_path := /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/
 or
 toolchain_path := c:/micros/gcc-arm-none-eabi-10_2020-q4-major/bin/
  All paths to compilers and other build-related programs are specified in these files.  The only things that are taken from the OS path are standard and common programs that do not affect the resulting binary files.
Regarding this point, I tried to set
    toolchain_path := c:\msys64\mingw64\bin
but it doesn't work (a popup error is shown about libwinpthread-1.dll). Even if I call gcc directly from CMD doesn't work for the same reason.
I found the problem disappears if I set the toolchain path in the PATH... but, hey, we were going to put the toolchain path in the makefile to avoid setting the PATH on the command line, but it seems impossible!

Then I have a "commands.mk" file with things like :
 ATDEP := @
 toolchain_prefix := arm-none-eabi-
 CCDEP := $(ATDEP)$(toolchain_path)$(toolchain_prefix)gcc
CC := $(AT)$(CCACHE) $(toolchain_path)$(toolchain_prefix)gcc
LD := $(AT)$(toolchain_path)$(toolchain_prefix)gcc
OBJCOPY := $(AT)$(CCACHE) $(toolchain_path)$(toolchain_prefix)objcopy
OBJDUMP := $(AT)$(CCACHE) $(toolchain_path)$(toolchain_prefix)dump
SIZE := $(AT)$(CCACHE) $(toolchain_path)$(toolchain_prefix)size
  Put CONFIG dependent stuff in "config_full.mk" and similar files.  Put TARGET specific stuff in "target_simulator.mk".  And so on.  It makes it much easier to keep track of things, and you only need a few high-level "ifeq".
  Keep your various makefiles in a separate directory.  Your project makefile is then clear and simple - much of it will be comments about usage (parameters like CONFIG).
  4.
 Generate dependency files, using the same compiler and the same include flags and -D flags as you have for the normal compilation, but with flags like -MM -MP -MT and -MF to make .d dependency files.  Include them all in the makefile, using "-include" so that your makefile does not stop before they are generated.
  5.
 Keep your build directories neat, separate from all source directories, and mirroring the tree structure of the source files.  So if you have a file "src/gui/main_window.c", and you are building with CONFIG=FULL TARGET=embedded, the object file generated should go in something akin to "builds/FULL/embedded/obj/src/gui/main_window.o".  I like to have separate parts for obj (.o files), dep (.d files), and bin (linked binaries, map files, etc.).  You could also mix .d and .o files in the same directory if you prefer.
 This means you can happily do incremental builds for all your configurations and targets, and don't risk mixing object files from different setups.
  6.
 Learn to use submakes.  When you use plain "make" (or, more realistically, "make -j") to build multiple configurations, have each configuration spawned off in a separate submake.  Then you don't need to track multiple copies of your "TARGET" macro in the same build - each submake has just one target, and one config.
  

Date Sujet#  Auteur
13 May 25 * Improving build system19pozz
13 May 25 +- Re: Improving build system1Nicolas Paul Colin de Glocester
14 May 25 +* Re: Improving build system16David Brown
14 May 25 i+* Re: Improving build system11pozz
15 May 25 ii+* Re: Improving build system4Nicolas Paul Colin de Glocester
15 May 25 iii`* Re: Improving build system3David Brown
16 May 25 iii `* Re: Improving build system2Nicolas Paul Colin de Glocester
16 May 25 iii  `- Re: Improving build system1David Brown
15 May 25 ii`* Re: Improving build system6David Brown
15 May 25 ii `* Re: Improving build system5pozz
16 May 25 ii  `* Re: Improving build system4David Brown
16 May 25 ii   `* Re: Improving build system3pozz
16 May 25 ii    `* Re: Improving build system2David Brown
16 May 25 ii     `- Re: Improving build system1pozz
15 May 25 i+- Re: Improving build system1David Brown
16 May 25 i`* Re: Improving build system3pozz
16 May 25 i `* Re: Improving build system2David Brown
17 May 25 i  `- Re: Improving build system1pozz
14 May 25 `- Re: Improving build system1Stefan Reuther

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal