如何组织大量的头文件包括makefile中的路径?

时间:2015-07-20 14:31:17

标签: c gcc makefile

我对makefile很新,我必须为大型项目编写一个makefile,用gnu​​ gcc编译器编译项目。

源文件的相关头文件组织在不同的子目录中,如下所示:

D:\MyProject\SubProject1\Modules\APP\StateManager\Include
D:\MyProject\Tools\
D:\MyProject\Common\Public
D:\MyProject\Function\Modules\FSW\Public
D:\MyProject\SubProject1\Modules\Version\Include
D:\MyProject\SubProject1\Modules\APP\AC\Include
D:\MyProject\SubProject1\Modules\APP\DBDTmanager\Public
D:\MyProject\SubProject1\Modules\APP\Diag\Include\
D:\MyProject\SubProject1\Modules\APP\FunTTT\Include
D:\MyProject\SubProject1\Modules\Basis_SW\Adc\Include
D:\MyProject\SubProject1\Modules\Basis_SW\Func2\Include
D:\MyProject\SubProject1\Modules\Basis_SW\Stubs\Include
D:\MyProject\SubProject1\Modules\Basis_SW\DTC\Include
D:\MyProject\SubProject1\Modules\Basis_SW\Generated\Include
D:\MyProject\SubProject1\Modules\Basis_SW\Generated_BSM\Include
D:\MyProject\SubProject1\Modules\Basis_SW\Functions\Include
D:\MyProject\SubProject1\Modules\BistTests\Include
D:\MyProject\SubProject1\Modules\BistTests\Include\WatchDog\Include
D:\MyProject\App\ssw\common\Public
D:\MyProject\Bit\Modules\Timer\Include

知道如何以“清晰”和“可监督”的方式在makefile中定义包含?

任何建议的Thx!

2 个答案:

答案 0 :(得分:1)

假设您在此处没有任何其他要求,并且只是希望以相当简洁的方式将所有这些条目纳入您的CFLAGS值,您可以执行以下操作:

PROJDIR := D:\MyProject
SUBPROJDIR := $(PROJDIR)\SubProject1\Modules

CFLAGS += -I$(PROJDIR)\SubProject1\Modules\APP\StateManager\Include
CFLAGS += -I$(PROJDIR)\Tools\
CFLAGS += -I$(PROJDIR)\Common\Public
CFLAGS += -I$(PROJDIR)\Function\Modules\FSW\Public
CFLAGS += -I$(SUBPROJDIR)\Version\Include
CFLAGS += -I$(SUBPROJDIR)\APP\AC\Include
CFLAGS += -I$(SUBPROJDIR)\APP\DBDTmanager\Public
CFLAGS += -I$(SUBPROJDIR)\APP\Diag\Include\
CFLAGS += -I$(SUBPROJDIR)\APP\FunTTT\Include
CFLAGS += -I$(SUBPROJDIR)\Basis_SW\Adc\Include
CFLAGS += -I$(SUBPROJDIR)\Basis_SW\Func2\Include
CFLAGS += -I$(SUBPROJDIR)\Basis_SW\Stubs\Include
CFLAGS += -I$(SUBPROJDIR)\Basis_SW\DTC\Include
CFLAGS += -I$(SUBPROJDIR)\Basis_SW\Generated\Include
CFLAGS += -I$(SUBPROJDIR)\Basis_SW\Generated_BSM\Include
CFLAGS += -I$(SUBPROJDIR)\Basis_SW\Functions\Include
CFLAGS += -I$(SUBPROJDIR)\BistTests\Include
CFLAGS += -I$(SUBPROJDIR)\BistTests\Include\WatchDog\Include
CFLAGS += -I$(PROJDIR)\App\ssw\common\Public
CFLAGS += -I$(PROJDIR)\Bit\Modules\Timer\Include

答案 1 :(得分:0)

使用此

INC=-I<header-path-1>  -I<header-path-2> -I<header-path3>

PS:它们都是以空格分隔的