Two files with the same name (in subfolders) in Chibi's make system

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
dflogeras
Posts: 234
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Two files with the same name (in subfolders) in Chibi's make system

Post by dflogeras »

Hi, as my project grows, I've structured a few things into sub-folders. The naming I'd prefer would end up with multiple files with the same name, but just adding them via the top-level Makefile ends up with flattened .obj dir clashes.

Is there a recommended way/example of how to do this using .mk files, or other? The AI slop machines generate suggestions that just feel like I'm hacking around and not fully integrating with the way the build system was intended. However, I'm not that proficient in Make to know what is the correct solution.

Thanks for any help,
Dave
User avatar
Giovanni
Site Admin
Posts: 14894
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Two files with the same name (in subfolders) in Chibi's make system

Post by Giovanni »

Hi,

It is would be complex to implement with changes in many places. This is the evaluation:
The ChibiOS makefiles put all object files in one flat directory (build/obj)
and find sources by file name. So source file names must be unique within a
project, even when the files sit in different folders. The kernel and HAL work
the same way, which is why their files carry prefixes such as hal_, ch or
nil. Subfolders are fine; just give the files distinct names, for example
imu/imu_driver.c and baro/baro_driver.c rather than two driver.c.

To integrate a sub-folder cleanly, do what ChibiOS's own components do: give
it a small .mk file that adds its sources and include paths to the shared
lists.

# sensors/sensors.mk
SENSORSSRC = $(SENSORS)/imu/imu_driver.c \
$(SENSORS)/baro/baro_driver.c

SENSORSINC = $(SENSORS)/imu \
$(SENSORS)/baro

# Shared variables
ALLCSRC += $(SENSORSSRC)
ALLINC += $(SENSORSINC)

Then include it in the project Makefile next to the other includes, before
CSRC/INCDIR are defined:

SENSORS := ./sensors
include $(SENSORS)/sensors.mk

The demo Makefiles already contain CSRC = $(ALLCSRC) ... and INCDIR = ...
$(ALLINC) ..., so nothing else needs changing. Compare os/hal/hal.mk,
os/various/shell/shell.mk or any board.mk. You can nest this: a module .mk can
include the .mk files of its sub-modules.
dflogeras
Posts: 234
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: Two files with the same name (in subfolders) in Chibi's make system

Post by dflogeras »

Thanks Giovanni,

I'll keep my files prefixed where necessary then.

Dave
Post Reply