简体   繁体   English

在 Makefile 中包含其他目录

[英]Include additional directories to Makefile

I'm a student and I'm currently working with the Infineon XMC4700 uC and have recently started to programm small "libraries" for for certain hardware components.我是一名学生,目前正在使用 Infineon XMC4700 uC,最近开始为某些硬件组件编写小型“库”。 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.出于这个原因,我为每个项目创建了一个目录,并将相应的文件放入其中,以在单独的 main.c 文件中测试每个组件。 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.只要 .h 和 .c 文件与实际的 main.c 文件位于同一目录中,我就知道我必须在我的 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".但是,为了清晰和易于理解,我想将所有标题放在“src”目录中,将所有 .c 文件放在目录“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.我的第一种方法是扩展 VPATH 变量以向编译器显示所需文件的路径。

The code below shows the declaration of certain variables in the currently used Makefile.下面的代码显示了当前使用的 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.不幸的是,我对 Makefile 不是很有经验。 For that reason, I'm struggling to adjust the Makefile to compile the program.出于这个原因,我正在努力调整 Makefile 来编译程序。

So could somebody provide a solution how to adujust the above shown snipped of my current Makefile to compile the program?那么有人可以提供一个解决方案如何调整上面显示的我当前 Makefile 的片段来编译程序吗?

Best regards此致

RadbaldMeyer拉德巴尔德迈耶

You should add a -I_inc in the CFLAGS .您应该在CFLAGS添加-I_inc

CFLAGS += -I_inc

VPATH is for another usage, mostly used to generate object files in a directory different from source files. VPATH是另一种用法,主要用于在与源文件不同的目录中生成目标文件。 In this case, in _build .在这种情况下,在_build When GNU Make try to build the binaries files, let's say _build\\project.o , it will search for all the project.c in the VPATH list of directories.当 GNU Make 尝试构建二进制文件时,比如说_build\\project.o ,它会在 VPATH 目录列表中搜索所有project.c It will then compile the first project.c found and generate the corresponding project.o .然后它会编译找到的第一个project.c并生成相应的project.o

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM