I don't see why you use the word repeating. if each implementation has 1 header and 1 source file each
this is not true, an implementation can have many files. Look at the TFT or Ethernet library:
https://github.com/arduino/Arduino/tree/ide-1.5.x/libraries/Ethernethttps://github.com/arduino/Arduino/tree/ide-1.5.x/libraries/TFTNonetheless there are some maintainers that actually keeps tens of libraries, the time that you save on the development of the tool is time that you put on the back of the library author. With the 1.5 library specification we are focusing to this audience, not the tools developers.
I do not see why you are trying to avoid this. Each and every header file should have something similar to handle multiple inclusions.
IMHO it is also good that you can see (and get guarantee) that this code is only used for a certain platform.
Because, there are a lot of project that uses the same approach, and they don't need these guards, because IMHO are useless. One for all (but you can find a lot more that adopt same structure):
https://github.com/mirrors/linux/tree/master/archNote:
kernel uses the makefile and the GNU GCC tools-chain.If you google "c++ multiplatform" there are a number of forum that suggests the current 1.5 library structure is the "best" way to go:
http://stackoverflow.com/a/3627208/1655275http://stackoverflow.com/a/14592359/1655275these are the first two that are relevant but there are many more.
When a library is added the plugin adds a symbolic link to the root of the library folder at the location [project]/libraries/[libraryname].
It also adds a include link for all languages (C and C++ in V2 and C C++ asm in V1).
The end user needs to add the include to the code himself.
Note I do not have a delete library functionality. A user can delete the link but that will not remove the includes.
Ok, so it links for example:
Project/libraries/Servo -> Arduino-1.0/libraries/Servo
Let's forget about the remove lib functionality for now.
You are right about the variant folder being similar but it is not the same.
Let me first explain how I handle the variant/core
I create 2 symbolic links one with the name [project]/arduino/core and one with [project]/arduino/variant. These link to the appropriate location on disk.
I also create 2 include links to /arduino/core and arduino/variant.
This means that when the user selects another board I may need to update the link location of the link names /arduino/core and arduino/variant.
Link Project/arduino/core -> Arduino/hardware/arduino/avr/cores/arduino
Link Project/arduino/variant -> Arduino/hardware/arduino/avr/variant/leonardo (for example)
Add to build/include path: Project/arduino/core
Add to build/include path: Project/arduino/variant
Note that this solution breaks the symmetry between the "disk situation" and the "eclipse project situation".
The main reason why this works is because arduino only uses
#include "pins_arduino.h"
In other words it relies on the include path to find the file.
When we have a mega; makefile will find it at arduino-1.5.2/hardware/arduino/avr/variants/mega/pins_arduino.h.
The indexer however will find it at [project]/arduino/variant/pins_arduino.h
Understanding this difference is important for the next part.
That's perfectly clear for me until now, it reproduce exactly what Arduino IDE does.
Suppose I do something similar for a library.
I create 2 link locations [project]/libraries/[libname]/lib/arch and [project]/libraries/[libname]/src.
[project]/libraries/[libname]/lib/arch links to ../libraries/[libname]/lib/[arch]
[project]/libraries/[libname]/arch links to ../libraries/[libname]/src
I add [project]/libraries/[libname]/lib/arch and [project]/libraries/[libname]/src. to the include path.
Apart from the maintenance nightmare (There is no delete lib and I don't know how to make one) and apart from the potential performance impact when changing board I expect this to work in all cases for the makefile but not for the indexer.
this is less clear to me, just to clarify, you are saying (supposing a Leonardo board is selected):
Link Project/libraries/Servo/lib/arch -> Arduino-1.5/libraries/Servo/lib/avr
Link Project/libraries/Servo/arch -> Arduino-1.5/libraries/Servo/src
Add to build/include path: Project/libraries/Servo/lib/arch
Add to build/include path: Project/libraries/Servo/arch
but I guess you typo the first link probably you meant:
Link Project/libraries/Servo/lib/arch -> Arduino-1.5/libraries/Servo/arch/avr
Link Project/libraries/Servo/arch -> Arduino-1.5/libraries/Servo/src
Add to build/include path: Project/libraries/Servo/lib/arch
Add to build/include path: Project/libraries/Servo/arch
I still doesn't understand why your links are named lib/arch and arch, instead of arch/avr and src like in the Servo lib, something like that:
Link Project/libraries/Servo/arch/avr -> Arduino-1.5/libraries/Servo/arch/avr
Link Project/libraries/Servo/src -> Arduino-1.5/libraries/Servo/src
Add to build/include path: Project/libraries/Servo/arch/avr
Add to build/include path: Project/libraries/Servo/src
but besides that still I don't see any problem with this setup.
Why you say that the indexer would fail?
But let's go on.
One scenario I think of is the following:
I'm building a board that has a "different" architecture than avr but is very much alike. Some libraries need to change but some are 100% compatible. Suppose this architecture is called "jantje"
Ok
For each library I support I create the folder jantje under [libname]/lib/ where I place my code.
you create for every lib the [libname]/arch/jantje/..... folder, for example Servo/arch/jantje/....
Assume that the Servo lib I need is 100% compatible with the avr lib. What I will do is create 2 files:
Servo.cpp which looks like this
#include ../avr/Servo.cpp
ServoTimers.h which looks like this
#include ../avr/ServoTimers.h
Oh well, I see your point, but since you're providing another architecture (even if is very close to avr), you'll probably do a better job to copy over those file in your private implementation instead of including with the relative path ../avr/.
Proposal: why you don't include the whole library? something like that:
Link Project/libraries/Servo/ -> Arduino-1.5/libraries/Servo/
Add to build/include path: Project/libraries/Servo/arch/avr
Add to build/include path: Project/libraries/Servo/src
note that you link the whole library but you add to the include path only the relevant piece for the selected architecture.
C