开发者

Correct way to call some make targets depending on the value of environment variable?

开发者 https://www.devze.com 2023-01-22 22:43 出处:网络
I should create several packages of our application using make(on AIX). Content of packages should be different depending on one environ开发者_运维问答ment variable.

I should create several packages of our application using make(on AIX).

Content of packages should be different depending on one environ开发者_运维问答ment 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?


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:

ifeq ($(WITH_CPP),Y)
  INSTALLATION_OBJECTS += $(CPP_OBJECTS)
endif

Or if the way to include the c++ parts is by building a separate target:

ifeq ($(WITH_CPP),Y)
  installation-package: cpp-part
endif

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.


An alternative approach is to make the C++ parts of your package depend on some phony target:

cxx: cxx-part-1 cxx-part-2
.PHONY: cxx

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 use autoconf or automake to split out the configuration step from the build step.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号