如何从Makefile中读取文件?

发布于 2024-09-14 23:57:32 字数 363 浏览 2 评论 0原文

我正在使用 GNU Make 构建一个多目录项目。 我的问题是如何使用单个 makefile 来构建多个设备? 例如,我的应用程序必须在各种 X、Y、Z 移动设备上运行,每个移动设备具有不同的属性,如屏幕尺寸、键盘类型、平台版本等。我必须传递 make -f; <目标名称>。这里的 targetname 可以是设备名称和型号,如 Samsung CorbyPlus,但我的 makefile 必须转到 samsung 的特定目录名并打开定义了所有上述属性的 .txt 文件等。我必须在构建时阅读所有这些内容,并通过一些宏/定义/标志访问我的代码。

谁能建议如何做到这一点?如果能满足我的要求,更好的解决方案将不胜感激。

I am using GNU Make to build a multiple-directory project.
My question is how can I use single makefile to build multiple devices?
e.g. My application has to run on various X,Y,Z mobile devices each having different properties like screensize, keyboard type, platform version etc. I have to pass make -f <makefilename> <targetname>. Here targetname can be device name and model like Samsung CorbyPlus, but my makefile has to go to particular dirname of samsung and open the .txt file or so where all above properties are defined. I have to read all of them during build time and access in my code through some macros/defines/flags.

Can anyone suggest how to do this? Even better solution for my requirement will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅气称霸 2024-09-21 23:57:32

我建议使用配置 makefile。例如,假设您有多个设备及其配置:

config_device1.mk

OPTION1=yes
OPTION2=0

config_device2.mk

OPTION1=no
OPTION2=1

然后您可以使用从命令行传递的特殊参数有条件地将它们包含到基本 makefile 中(< strong>ma​​ke -f makefile DEVICE=dev_type1)并使用配置文件中的选项并处理它们:

ma​​kefile

ifeq ($(DEVICE),dev_type1)
include $(CONFIG_PATH)/config_device1.mk
endif

ifeq ($(DEVICE),dev_type2)
include $(CONFIG_PATH)/config_device1.mk
endif

ifeq ($(OPTION1),yes)
CFLAGS += -DBUILD_OPTION1     
endif

CFLAGS += -DBUILD_OPTION2=$(OPTION2)

顺便说一句,从长远来看(如果你现在没有时间限制)它是最好使用一些现有的构建系统,阅读其手册并坚持其方法。

I'd suggest using configuration makefiles. For example, suppose you have several device with its configurations:

config_device1.mk

OPTION1=yes
OPTION2=0

config_device2.mk

OPTION1=no
OPTION2=1

Then you can conditionally include them into base makefile using special parameter passed from command line (make -f makefile DEVICE=dev_type1) and use options from configuration files and process them:

makefile

ifeq ($(DEVICE),dev_type1)
include $(CONFIG_PATH)/config_device1.mk
endif

ifeq ($(DEVICE),dev_type2)
include $(CONFIG_PATH)/config_device1.mk
endif

ifeq ($(OPTION1),yes)
CFLAGS += -DBUILD_OPTION1     
endif

CFLAGS += -DBUILD_OPTION2=$(OPTION2)

BTW, for a long perspective (if you don't have time constraints now) it's better to use some of existing build system, read its manual and stick to its methodology.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文