Include additional directories to Makefile

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
SuomyNonaPatri
Level 1
Level 1
10 sign-ins 5 questions asked 5 sign-ins

I'm currently working with the Infineon XMC4700 uC and have recently started to programm small "libraries" for for certain hardware components. For that reason, I createded a directory for each project and placed the corresponding files to it to test each component in a separate main.c file. As long as the .h and .c files are located in the same directory as the actual main.c file I know what I have to change in my Makefile.

However, for reasons of clarity and comprehensibility I'd like to place all headers in a "src" directory and all .c-files in a directory "inc". For example, the current directory looks like this

~/EigeneProgramme/XMC4700/ShiftRegister
|_build
|_inc
| |_ project.h
|_src
| |_ project.c
|_main.c
|_Makefile
However, if I do this, the program does no longer compile. My first approach was to extend the VPATH variable to show the compiler the path to the required files.

The code below shows the declaration of certain variables in the currently used Makefile.

CROSS_COMPILE=arm-none-eabi

CC = $(CROSS_COMPILE)-gcc
LD = $(CROSS_COMPILE)-gcc --specs=nosys.specs
AR = $(CROSS_COMPILE)-ar
AS = $(CROSS_COMPILE)-as
OC = $(CROSS_COMPILE)-objcopy
OD = $(CROSS_COMPILE)-objdump
SZ = $(CROSS_COMPILE)-size
ifeq ($(GDB_QUIET),true)
DB = $(CROSS_COMPILE)-gdb -quiet
else
DB = $(CROSS_COMPILE)-gdb
endif

BUILDDIR = build
LIB_BUILDDIR = lib_build
USB_LIBDIR = $(XMC_LIBDIR)/ThirdPartyLibraries/USBlib/USB

XMC_SERIES=4700
XMC_PACKAGE=F100
XMC_SIZE=2048

VPATH += $(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/BasicMathFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/CommonTables:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/ComplexMathFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/ControllerFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/FastMathFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/FilteringFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/MatrixFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/StatisticsFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/SupportFunctions:$(XMC_LIBDIR)/CMSIS/DSP_Lib/Source/TransformFunctions:$(XMC_LIBDIR)/CMSIS/Infineon/XMC$(XMC_SERIES)_series/Source:$(XMC_LIBDIR)/CMSIS/RTOS/RTX/SRC:$(XMC_LIBDIR)/CMSIS/RTOS/RTX/SRC/ARM:$(XMC_LIBDIR)/CMSIS/RTOS/RTX/Templates:$(XMC_LIBDIR)/CMSIS/RTOS/RTX/UserCodeTemplates:$(XMC_LIBDIR)/ThirdPartyLibraries/Newlib:$(XMC_LIBDIR)/XMCLib/src:$(USB_LIBDIR)/Class/Common:$(USB_LIBDIR)/Class/Device:$(USB_LIBDIR)/Common:$(USB_LIBDIR)/Core:$(USB_LIBDIR)/Core/XMC4000

CFLAGS = -I$(XMC_LIBDIR)/CMSIS/Include/
CFLAGS += -I$(XMC_LIBDIR)/CMSIS/Infineon/XMC$(XMC_SERIES)_series/Include/
CFLAGS += -I$(XMC_LIBDIR)/XMCLib/inc/
CFLAGS += -I$(USB_LIBDIR)
CFLAGS += -I$(USB_LIBDIR)/Class
CFLAGS += -I$(USB_LIBDIR)/Class/Common
CFLAGS += -I$(USB_LIBDIR)/Class/Device
CFLAGS += -I$(USB_LIBDIR)/Common
CFLAGS += -I$(USB_LIBDIR)/Core
CFLAGS += -I$(USB_LIBDIR)/Core/XMC4000
CFLAGS += -DXMC$(XMC_SERIES)_$(XMC_PACKAGE)x$(XMC_SIZE)
CFLAGS += -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mthumb
CFLAGS += -g3 -gdwarf-2
CFLAGS += -c
CFLAGS += -Wa,-adhlns="$@.lst"
SFLAGS = $(CFLAGS)
CFLAGS +=$(SCFLAGS)
SFLAGS += -Wall
CFLAGS += -Wall
CFLAGS += -ffunction-sections
SFLAGS += -x assembler-with-cpp
LFLAGS = -T$(BUILDDIR)/$(LD_NAME).ld -nostartfiles
LFLAGS += -L$(XMC_LIBDIR)/CMSIS/Lib/GCC/
LFLAGS += -Wl,-Map,"$@.map"
LFLAGS += -mcpu=cortex-m4 -mthumb
LFLAGS += -g3 -gdwarf-2

LIBSRCS += startup_XMC$(XMC_SERIES).c system_XMC$(XMC_SERIES).c
LIBSRCS += syscalls.c


OBJS = $(patsubst %.c,$(BUILDDIR)/%.o,$(SRCS))
LIBOBJS = $(patsubst %.c,$(LIB_BUILDDIR)/%.o,$(LIBSRCS))

Unfortunately, I'm not very experienced with Makefiles. For that reason, I'm struggling to adjust the Makefile to compile the program.

So could somebody provide a solution how to adujust the above shown snipped of my current voojio shagle Makefile to compile the program?

0 Likes
1 Solution
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @SuomyNonaPatri,

In DAVE4 we use the CDT Managed Build System but it can be disabled deselecting the checkbox below.

ncbs_0-1651550152299.png

 

See also the tutorial at  https://mcuoneclipse.com/2017/07/22/tutorial-makefile-projects-with-eclipse/  on how to use your own Makefiles.

Regards,
Nikhil

 

View solution in original post

0 Likes
2 Replies
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @SuomyNonaPatri,

Are you trying to edit the makefile of the DAVE project? The makefile is automatically generated and should not be edited.

Regards,
Nikhil

0 Likes
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @SuomyNonaPatri,

In DAVE4 we use the CDT Managed Build System but it can be disabled deselecting the checkbox below.

ncbs_0-1651550152299.png

 

See also the tutorial at  https://mcuoneclipse.com/2017/07/22/tutorial-makefile-projects-with-eclipse/  on how to use your own Makefiles.

Regards,
Nikhil

 

0 Likes