Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to put src files in a subfolder #267

Open
mgcrea opened this issue Sep 17, 2014 · 9 comments · May be fixed by #406
Open

Ability to put src files in a subfolder #267

mgcrea opened this issue Sep 17, 2014 · 9 comments · May be fixed by #406
Labels

Comments

@mgcrea
Copy link

mgcrea commented Sep 17, 2014

I'd like to put all my src files (.ino, .h, etc.) in a src subfolder. Is there a way to achieve that?

@ladislas
Copy link
Contributor

Can you show us a directory structure like the one you'd like to have?

@mgcrea
Copy link
Author

mgcrea commented Sep 17, 2014

@ladislas

I'd love to have some PROJECT_SRC_DIR var that I could set like:

  • PROJECT_SRC_DIR = $(realpath $(PROJECT_DIR)/src)

Expected structure:

$ tree -L 2
.
├── Makefile
├── build
│   └── uno
├── lib
│   └── Firmata
├── make
│   ├── Arduino.mk
│   ├── CONTRIBUTING.md
│   ├── Common.mk
│   ├── HISTORY.md
│   ├── README.md
│   ├── ard-reset-arduino.1
│   ├── arduino-mk-vars.md
│   ├── bin
│   ├── chipKIT.mk
│   ├── examples
│   ├── licence.txt
│   ├── packaging
│   ├── script
│   └── tests
└── src
    ├── app.h
    └── app.ino

$ cat Makefile 
# Arduino Make file. Refer to /~https://github.com/sudar/Arduino-Makefile
# /~https://github.com/WeAreLeka/moti/blob/dev/Makefile-OSX.mk

PROJECT_DIR   = $(shell pwd)
ARDMK_DIR     = $(realpath $(PROJECT_DIR)/make)
ARDUINO_DIR   = /Applications/Arduino.app/Contents/Resources/Java
AVR_TOOLS_DIR = /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr
AVRDUDE_CONF  = /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf
USER_LIB_PATH = $(realpath $(PROJECT_DIR)/lib)
MONITOR_PORT  = /dev/cu.usbmodem*
BOARD_TAG     = uno

include $(ARDMK_DIR)/Arduino.mk

@sej7278
Copy link
Collaborator

sej7278 commented Sep 18, 2014

this is kind of how 1.5 libraries work:

/~https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#source-code

which just got backported to 1.0.6:

arduino/Arduino@5672402

but its not for ino sketches, just libraries.

the tree structure above seems odd as you're mixing ino files with header files in the same directory, which should really be in an includes or lib directory.

@ladislas
Copy link
Contributor

@mgcrea If you put your Makefile into your src folder, it should work.

That's what I do here. (note: the Makefile is missing here because I cp it on each machine as I work on Linux as well as on OSX)

I have different directories into my src/ because I need to have different apps and behaviors. But if I put everything from moti/ to src/, it works as well.

Why would you like to keep your Makefile out of src/?

@mgcrea
Copy link
Author

mgcrea commented Sep 18, 2014

@ladislas, I'm coming from a JS background where you usually have a Gruntfile.js or gulpfile.js build config on the root, and alway the source files in src or app. Feels clumsy to have to cd to a subdir to start a build on a project.

@sej7278 my app.h file is only used by the app.ino for forward declaration, would be strange to put it n a lib folder. To me it should live in the src folder, maybe in src/headers or src/includes. Would that be fine?

@ladislas
Copy link
Contributor

@mgcrea I know what you mean. But as a little advice I'd say "don't try to c++ the way you js".

They are two different languages made for different things and the directory structure might change from what you're used to with js.

but if your want to do what you try to do, you can put a Makefile in src/ and one in your root and include the one from src/ into the one from source. so that when you call make from root, you'll build your project.

@marbru
Copy link

marbru commented Oct 4, 2015

Sorry for resurrecting this, but I too think this would be a super useful feature. I have my arduino code inside an src folder, but when working I always stay on my root to call git commands, and it's a bit of a pain to keep switching to the src dir to compile...

What I did as a hacky workaround is to have both my Makefile + this tiny shell script on my root:

#!/bin/bash

SRC_DIR=src

cp Makefile $SRC_DIR
cd $SRC_DIR
make $1
rm Makefile
cd ..

Ugly? very. But it does the trick...

@birgersp
Copy link

@marbru Why copy the makefile into src? Why not just load the makefile with make -f ../Makefile?

@crystalline
Copy link

I have to build a project with lots of subdirectories (see /~https://github.com/repetier/Repetier-Firmware ), so I replaced lines

LOCAL_C_SRCS    ?= $(wildcard *.c)
LOCAL_CPP_SRCS  ?= $(wildcard *.cpp)

with

LOCAL_C_SRCS    ?= $(shell find . -type f -name '*.c' | tr '\n' ' ')
LOCAL_CPP_SRCS  ?= $(shell find . -type f -name '*.cpp' | tr '\n' ' ')

This finds all .c and .cpp files recursively in all subdirectories.
Obviously this will work only for unix-like OSes, but it works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants