Can I store and build two sketches from the same folder?

Hello,

I'm building several Arduino-controlled machines and they all share similar structures and libraries but have different board pinouts and integrate different modules. I would like to be able to store everything in one folder structure so that the shared parts of the code are easy to maintain but still keep, compile and upload independent top levels.

For example, my folder structure looks something like:
machine1_toplevel.ino
machine2_toplevel.ino
src/
src/common_library.h
src/common_library.cpp

Then have a makefile or some other means for calling something like
make upload-machine1
or
make upload-machine2

I see the default build process first concatenates all .ino files in a folder into one file and copiles a sketch. Is there a way to tell the Arduino build utility to not do this?

You can go the folder where the .ino folders are and make your own topic folders like "servo". Then when you want to save a servo sketch, save it in that folder giving it a specific name as to what it does and which board it is for.

You can share youre common code between your ino files just like other libraries.

Go to File -> Preferences and set your Sketchbook location to the top folder for your project. The IDE will automatically create a libraries folder where you can store your common code. When you install additional libraries they will be there as well. All in one location.

{sketchbook folder}
├── libraries
│ └── myClass
│ ├── examples
│ │ └── myClass
│ │ └── myClass.ino
│ ├── keywords.txt
│ ├── library.json
│ ├── library.properties
│ └── src
│ ├── myClass.cpp
│ └── myClass.h
├─── sketch1
│ └── sketch1.ino
└─── sketch2
└── sketch2.ino

Klaus_K:
Go to File -> Preferences and set your Sketchbook location to the top folder for your project.

That's all very well if the OP ever only has one project. But if he had several unrelated projects (as most of us do) she would have to change the Preferences every time s/he switched project.

@r_A_i, If you put your shared code in a .h file and #include it with an absolute file reference you can share code from a .h file located anywhere. I think you should NOT have the shared .h file inside the same folder as your .ino file as you don't want the Arduino IDE to find it of its own accord.

I had a similar requirement to yours a few years ago and I solved it by {A} using the Geany editor rather than the Arduino IDE (that means that my .ino files don't have to be in a folder with the same name) and {B} using this simple Python program to compile and upload code using the Arduino command-line IDE.

I found it very tedious having to use absolute file reference so my Python program converts relative file references to absolute references. The Python code can be called from Geany but can also be used without Geany.

...R