根据环境变量的值调用某些 make 目标的正确方法?
我应该使用 make(在 AIX 上)为我们的应用程序创建多个包。
包的内容应该根据一个环境变量而有所不同。
类似于 - 如果环境变量 WITH_CPP 设置为 "Y",则应构建应用程序的 C++ 部分并将其打包到安装包中。
如果环境变量WITH_CPP设置为“N”,则不应构建应用程序的C++部分并将其打包到安装包中。
在 makefile 中处理此类条件的正确方法是什么?
I should create several packages of our application using make(on AIX).
Content of packages should be different depending on one environment variable.
Something like - if environment variable WITH_CPP set to "Y" then c++ part of application should be built and packed to installation package.
If environment variable WITH_CPP set to "N" then c++ part of application should NOT be built and packed to installation package.
What is the correct way to process such conditions in makefiles?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设目标是
installation-package
,并且包含该包的c++部分的方法是将c++对象添加到安装包的对象列表中:或者如果包含c++部分的方法是通过建立一个单独的目标:
这些都是很好的方法,但可能是一件坏事。如果 makefile 的行为取决于环境变量,那么相同的 makefile 将为不同的用户提供不同的结果,这可能会令人头痛。
Suppose the target is
installation-package
, and the way to include the c++ parts of the package is to add c++ objects to a list of objects for the installation package:Or if the way to include the c++ parts is by building a separate target:
These are good ways to do it, but it may be a bad thing to do. If the behavior of the makefile depends on environmental variables, then the same makefile will give different results for different users, which can be a headache.
另一种方法是使包的 C++ 部分依赖于某个虚假目标:
然后,测试(但不依赖)正在构建的包的各个 C++ 部分是否存在,并安装它们(如果存在)。这是可行的,但这是一个非常糟糕的主意,因为依赖图现在必然是不完整的。这也意味着最终用户必须知道运行 make &&使 cxx && sudo make install,或类似的。只需使用
autoconf
或automake
将配置步骤从构建步骤中分离出来。An alternative approach is to make the C++ parts of your package depend on some phony target:
Then, test for (but don't depend on) the existence of the various c++ parts of your package being built and install them if they exist. This is doable, but a really bad idea because the dependency graph is now necessarily incomplete. It also means that the end user must know to run
make && make cxx && sudo make install
, or similar. Just useautoconf
orautomake
to split out the configuration step from the build step.