如何使用 Jam make 工具构建项目的不同版本?
我有一个 C++ 项目,它编译为不同的版本,包括发布版本、调试版本、共享库和可执行文件,每个版本都有不同的编译器标志。 我正在尝试使用 Jam 作为 Make 的替代品,因为它看起来是一个更简单的系统。
Jam有这个能力吗? 主要问题是它总是将 .o 文件放在与源文件相同的文件夹中,因此在构建多个版本时会覆盖它们。
更新
我找到了一个似乎有效的解决方案。 使用此文件,我可以构建库或可执行文件的调试和发布配置。
构建发布库的命令:
jam -s config=lib -s release=1
如果您仅输入 jam
,它将构建调试可执行文件。 这是 Jam 文件:
FILES =
main.cpp
;
BASENAME = steve ;
OBJ = obj ;
if $(release)
{
OBJ = $(OBJ)r ;
}
else
{
DEFINES += DEBUG ;
OBJ = $(OBJ)d ;
}
if $(config) = lib
{
OBJ = $(OBJ)_lib ;
OUTFILE = lib$(BASENAME).so ;
DEFINES += SHARED_LIBRARY ;
LINKFLAGS +=
-shared -Wl,-soname,$(OUTFILE) -fvisibility=hidden -fPICS
;
}
else
{
OUTFILE = $(BASENAME) ;
}
LOCATE_TARGET = $(OBJ) ;
MkDir $(LOCATE_TARGET) ;
Main $(OUTFILE) : $(FILES) ;
I have a C++ project that compiles to different versions, including release, debug, shared library, and executable, with different compiler flags for each. I am trying out Jam as an alternative to Make, because it looks like a simpler system.
Is Jam capable of this? The main problem is that it always places the .o files into the same folder as the source file, so it overwrites them when building multiple versions.
Update
I found a solution that seems to work. Using this file, I can build debug and release configurations of a library or executable.
Command to build release library:
jam -s config=lib -s release=1
If you only type jam
, it builds the debug executable. Here is the Jamfile:
FILES =
main.cpp
;
BASENAME = steve ;
OBJ = obj ;
if $(release)
{
OBJ = $(OBJ)r ;
}
else
{
DEFINES += DEBUG ;
OBJ = $(OBJ)d ;
}
if $(config) = lib
{
OBJ = $(OBJ)_lib ;
OUTFILE = lib$(BASENAME).so ;
DEFINES += SHARED_LIBRARY ;
LINKFLAGS +=
-shared -Wl,-soname,$(OUTFILE) -fvisibility=hidden -fPICS
;
}
else
{
OUTFILE = $(BASENAME) ;
}
LOCATE_TARGET = $(OBJ) ;
MkDir $(LOCATE_TARGET) ;
Main $(OUTFILE) : $(FILES) ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不熟悉 Perforce 的 Jam,但是 bjam 允许这样做 - 并且这很简单。
bjam
不会将中间文件放在与源相同的目录中; 它根据您正在构建的项目类型创建 debug/release/static/shared 目录。例如,如果您想要构建库的发布和调试版本,并且想要静态构建它:
bjam
确实有一些怪癖,但我们发现它非常有效。 目前,我们使用(几乎)相同的构建脚本来构建我们的系统,其中使用 msvc(8.0 和 9.0)、x86 上的 gcc 4.3、ARM 上的 gcc 3.4 和 PowerPC 上的 gcc 4.3。 很不错。I'm not familiar with Perforce's Jam however bjam allows this - and it's trivially easy.
bjam
does not place the intermediate files in the same directory as the source; it creates debug/release/static/shared directories depending on the type of project you're building.For example if you wanted to build release and debug version of a library and you wanted to build it statically:
bjam
does have some quirks but we've found it very effective. Currently we're using (almost) identical build scripts to build our system using msvc (8.0 and 9.0), gcc 4.3 on x86, gcc 3.4 on ARM and gcc 4.3 for the PowerPC. Very nice.是的,它有这个能力。 它被称为“变体”,boost.build 预定义了“调试”和“发布”。 还可以添加您自己的“功能”并定义它们
因为链接不兼容会将生成的目标文件放入不同的子目录中:
feature magic : off on : 传播复合 ;
feature.compose on:USE_MAGIC;
我发现维护共存变体的简便性是其最强大的功能之一
升压.构建。 此外,维护项目层次结构(例如,应用程序
需要库); 这是在文件级别完成的,而不是通过递归到目录中来完成的,从而使并行构建非常高效。
Yes, it's capable of this. It's called 'variants', boost.build comes with 'debug' and 'release' predefined. It's also possible to add 'features' of your own, defining them
as link-incompatible will put generated object files into different subdirectories:
feature magic : off on : propagated composite ;
feature.compose on : USE_MAGIC ;
I find the ease of maintaining co-existing variants is one of the strongest features of
boost.build. Also, it's very easy to maintain project hierarchies (e.g., application
requiring libraries); this is done on the file level, not by recursing into directories, making parallel builds very efficient.
构建系统的普及很重要,因为这意味着组织中更多的人(以及未来的员工)可能了解它并能够支持它。
我会说不要这样做。 不要使用果酱。 无论如何,除了 boost 之外还有人使用它吗? 例如,我认为 Ant 是一个更流行的系统,而且我发现它更容易学习。 帮您的组织一个忙,不要碰果酱。
The popularity of the build system is important, because it means more people in your organization (and future employees) are likely to know it and be able to support it.
I would say don't do it. Don't use Jam. Does anyone but boost use it, anyway? I think Ant, for example, is a much more popular system and I find it easier to learn. Do your organization a favor and don't touch jam.