multiple directory project

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi guys,

im having trouble configuring my makefile to suite my project structure. I have this current project structure and compiling the code just works fine.

MyProject (my project folder)
   - makefile  (my makefile)
   - Source  (my source folder)
        - main.c
        - somefile.c
   - Include  (my include folder)
        - main.h
        - someinclude.h

my makefile has these lines (i modified some lines just cause i wanted it look that way, aesthectics purposes though :twisted: ):

# Target file name (without extension).
TARGET = main

# List C source files here. (C dependencies are automatically generated.)
SOURCE = \
../Source\Application\$(TARGET).c \
../Source\Bios\Bios.c \
../Source\Bios\Mega16\Vectors.c \
../Source\Interface\Display\Lcd.c \
../Source\Memory\Eeprom\Eeprom.c


#jay: added 10192008; remove "../" from source file
SRC = $(subst ../,,$(SOURCE))


# List any extra directories to look for include files here.
#     Each directory must be seperated by a space.
#     Use forward slashes for directory separators.
#     For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = \
../Include\Application \
../Include\Bios \
../Include\Common \
../Include\Interface\Communication \
../Include\Interface\Display \
../Include\Memory\Eeprom


#---------------- Compiler Options C ----------------
#  -g*:          generate debugging information
#  -O*:          optimization level
#  -f...:        tuning, see GCC manual and avr-libc documentation
#  -Wall...:     warning level
#  -Wa,...:      tell GCC to pass this to the assembler.
#    -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(subst ../,,$(EXTRAINCDIRS)))
CFLAGS += $(CSTANDARD)

The above configuration just works fine.

Now, i wanted to move the makefile to a different folder (having this new directory structure)

MyProject  (my project folder)
   - Source  (my source folder)
        - main.c
        - somefile.c
   - Include  (my include folder)
        - main.h
        - someinclude.h
   - Project  (my project sub-folder)
        - makefile  (my makefile)

I want all generated files of make be inside "Project" folder and not in "MyProject" folder, but invoking make results to:

> "make.exe" all
make.exe: *** No rule to make target `all'. Stop.

> Process Exit Code: 2
> Time Taken: 00:00

I think the problem is how make is able to determine the current directory of my makefile. Initially, my makefile can see my main.c because i specified that it is in its current directory + Source\Application.

By moving the makefile inside "Project" folder, it won't be able to see my main.c since current directory of my makefile is ..\Project and Source\Application is not inside "Project" folder.

Any ideas on how i'll resolve this issue? I think i'll have to do some shell commands just to set my directory up (back to MyProject folder).

Im new to makefiles and gcc, pardon me.

Thanks for the help.

-jay

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jay warren wrote:
Any ideas on how i'll resolve this issue?
I have implemented similarly unconventional directory structures before using VPATH. It may or may not be useful for this particular situation. You may also need to make changes in the compiler/linker options to get the .o, .elf, etc. files to end up where you want them.

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the input, dkinzer.

I've actually used VPATH on my first project directory structure, it worked though.

I'm trying to avoid using VPATH so as to avoid editing too many lines in the makefile. I'd like to edit the source and include files only as much as possible in my future projects, and avoid any constant declarations. With this, I can freely move my project file (maintaining the structure) from any directory without editing my makefile.