简体   繁体   English

makefile与OS相关的编译器

[英]makefile with OS dependent compiler

I have a set of C programs that are generally compiled using gcc in a makefile, but OSX Mavericks now uses clang. 我有一组C程序,通常在makefile中使用gcc编译,但OSX Mavericks现在使用clang。 What is a good way to test for existing compilers in a makefile and use the appropriate one? 在makefile中测试现有编译器并使用适当的编译器的好方法是什么? Moreover, I would also like to use architecture-dependent optimization flags (eg, for gcc on Linux, I would use -O3, but on OSX I would use -fast; for clang on OSX I would use -Ofast). 此外,我还想使用依赖于体系结构的优化标志(例如,对于Linux上的gcc,我会使用-O3,但是在OSX上我会使用-fast;对于OSX上的clang我会使用-Ofast)。

Kindest thanks, 最诚挚的谢谢,

Ryan 瑞安

If you are compiling on MacOS X and Linux then you can put the following in your makefile: 如果您正在MacOS X和Linux上进行编译,那么您可以将以下内容放在makefile中:

UNAME := $(shell uname)

ifeq ($(UNAME), Darwin)
CFLAGS = -Ofast
endif

ifeq ($(UNAME), Linux)
CFLAGS = -O3
endif

# etc

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

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