I am currently trying to develop C libraries and project templates for the STM8 microcontroller using the SDCC OS compiler. My target is a (nearly) NOOB-compatible setup similar to Arduino - but with make+shellscripts instead of an IDE (there are limits to my ambition...)
Currently I am struggling with make to auto-detect dependencies. In Arduino the user only includes the relevant headers, e.g. "#include LCD-lib", and the build mechanism automatically detects dependency and links the respective libs. No need to manually add it to an IDE or the Makefile.
I love the simplicity of that, but so far I have failed miserably in creating a respective Makefile. Basically here's what the Makefile should achieve:
- scan the *.c files in the project root for included headers. Note that these files are located in a different lib folder
- add all included headers and (if exist) the corresponding C-files to the build process
- to minimize compile time and size, unused C files in the lib folder must be skipped during build
I am confident that make can do all the above - but not at my level of experience with make... :-(
Here's the folder structure I have in mind:
├── Library
│ ├── Base
│ │ ├── general STM8 sources and headers
│ ├── STM8S_Discovery
│ │ └── board specific sources and headers
│ └── User
│ └── optional user library sources and headers
├── Projects
│ ├── Examples (to be filled)
│ │ └── Basic_Project
│ │ ├── compile_upload.sh --> double-click to build and upload
│ │ ├── config.h
│ │ ├── main.c
│ │ └── Makefile --> should detect dependencies in ./*.c and ./*.h
│ └── User_Projects (still empty)
└── Tools
├── programmer.py --> for programming (already works from make)
└── terminal.py --> for serial terminal (already works from make)
I know it's a lot to ask, but a convenient Makefile is my main blocking point. Any help is highly appreciated!!! Thanks a lot in advance!
Regards, Georg Icking-Konert
thanks again for your support!
Following the above advice I wrote a small python script, which uses the gcc (or actually sdcc) dependency generator. The below script scans all project .c files for #included headers using gcc. The respective header files are then searched in the project and library folders. If a corresponding .c file exist (same path and name as header), it is added to the Makefile. This process is repeated until no more new headers are found.
The result is a Makefile which only builds modules which are #included modules in the project .c files - just as in the Arduino IDE. It may not be elegant but the job :-)
Lines 95-106 in the script are compiler and project specific, and have to be adapted accordingly. Have fun and thanks again!
Note: I realize that this answer doesn't meet all of your requirements, in fact this approach still requires you to list the names of relevant Arduino Libraries that you use in your project, as well as a list of paths to directories that should be included in the project. However, this solution is the closest to your requirements that I could think of and it might still help someone else reading this question down the road.
I use Arduino Makefile for this:
.pde/.ino
extension containingsetup()
and `loop() methods.c/.cpp/.h/.hpp
filesadd a project Makefile that sets project-refined settings in this sub-directory, e.g.:
compile and run using
make all
,make upload
,make monitor
, etc.Ensure that you have picocom installed on your Unix/Linux machine (or equivalent) as console serial monitor. On MAC-OS, you can use screen by setting the
MON_CMD
variable accordingly.Makefile.master:
The original Makefile.master was written by
Alan Burlison
and modified byMatthieu Weber
, and can be found here.I made some changes so that it fits my configuration, in particular I've added these lines of code:
and subsequently removed
-g
option from defaultC/CXX _FLAGS
entries in Makefile.master. In this way symbol information is not added on release code, and only when code is compiled withDEBUG=1
the code shielded byfinds its way into the binary, thus resulting smaller release executables.
Here you can find my own version of the Makefile.master:
Use Example:
Given a dir-tree like follows:
You could place
Makefile.master
withinProjects
, then assuming that:Library/Base
andLibrary/User
for this projectthen you would add the following
Makefile
intoBasic Project
:Note that
common.h
should be automatically detected because it is located in.
, and there should be no need to add the latter toINC_DIRS
.Final Note: last time I tested this configuration I was using version
1.0.5
of Arduino source code, and it was working flawlessly.You can find a discussion, along with a sample implementation, of an automatic dependency generation method for GNU make here. You don't say you're using GNU make so I'm just assuming.
I don't know if that's sufficient for you or not; it wasn't clear from your statements about your requirements.
first of all thanks a lot to all for the fast and substantial support! I should've asked much earlier...
Now back to my (no longer an) issue. I now understand that I actually asked 2 different questions:
I understand the 2nd is much more difficult to achieve from within make...!? But Patrick's Makefile makes the manual configuration very convenient. So that's ok for me :-)
[add timeslip...] Ok, having pondered some more, would the following work / make sense?
Does that somehow make sense...? Thanks again and have a nice day, wherever you are!
Regards, Georg Icking-Konert