如何为 32 位和 64 位创建单个 makefile?
我有一个可以在 Linux (x86_64
) 和 OS X Intel (x86_64
) 上透明工作的 makefile
。这使用 64 位特定的 GCC 选项。
有没有办法调整 makefile,以便我可以构建 32 位和 64 位 OS X PPC(ppc
、ppc64
),而无需维护单独的 arch -特定的makefiles——也许像预处理器指令之类的东西可以在构建之前确定架构?
I have a makefile
that works transparently for Linux (x86_64
) and OS X Intel (x86_64
). This uses 64-bit specific GCC options.
Is there a way to adjust the makefile so that I could build for 32-bit and 64-bit OS X PPC (ppc
, ppc64
) without having to maintain separate, arch-specific makefiles — perhaps something like a pre-processor directive that can determine the architecture before building?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试包含文件。这不是标准 Makefile 语法(Single Unix v3 规范中的语法)的一部分,但受到广泛支持。使用 GNU make,它看起来像这样:
有了这个,您可以拥有一个如下所示的 x86 Makefile:
和一个 PowerPC Makefile:
并且大部分编译规则将位于一个文件中 (
common.mk
) ,在必要时使用$(ARCHFLAGS)
。Try file inclusion. This is not part of the standard Makefile syntax (the one in the Single Unix v3 specification) but is widely supported. With GNU make, this looks like this:
With this, you could have an x86 Makefile like this:
and a PowerPC Makefile:
and the bulk of your compilation rules will be in one file (
common.mk
), using$(ARCHFLAGS)
where necessary.我认为通过使用某种构建系统(例如 cmake 或 GNU 自动工具),您可以通过更少的工作(和痛苦)来实现您的目标。
I think that you would achieve your goals with less work (and pain) by employing some kind of a build system such as cmake or GNU autotools.
实现此目的的一种方法是:
posix
、win32
、win32-gcc
等。我在中小型项目(2 或 3 人编写代码几年),它非常适合。
One way to work this is to:
posix
,win32
,win32-gcc
, etc.I've used this in small-to-medium size projects (2 or 3 persons working on code for a few years), and it fits the bill well.
看看这个:
http://mad-scientist.net/make/multi-arch .html
它有点过时,但我认为有很好的信息可能对您有用。
Have a look at this:
http://mad-scientist.net/make/multi-arch.html
It is somewhat dated but has good info that could be useful for you I suppose.
虽然它没有明确回答 CPP 编译,但我刚刚为汇编语言创建的这个方法可以很容易地适应。
然后,
我将
helloworld-32.s
和helloworld-64.s
添加到项目文件夹中,然后通过在文件夹中运行make
来解决所有问题。Although it doesn't explicitly answer the CPP compilation, this method I've just created for assembly language could be easily adapted to fit.
makefile
I then add
helloworld-32.s
andhelloworld-64.s
to the project folder and everything works out by runningmake
in the folder.