tags:

views:

24

answers:

2

I should create several packages of our application using make(on AIX).
Content of packages should be different depending on one environment variable.
Somethink 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?

+1  A: 

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.

Beta
Agreed, with caveats: You're using GNUisms in a question that doesn't necessarily deal with GNUmake (the OP mentions AIX). I suggest that a better solution is to use `automake` (or at least `autoconf`). Then the user can choose to build the C++ part with `--enable-cxx` (or similar, look up the `AC_ARG_ENABLE` macro) and the appropriate changes to the build process can be made using `AM_CONDITIONAL` (or some similar mechanism for non-`automake`).
Jack Kelly
@Jack Kelly: You're right, I was thinking in terms of GNUMake. GNUMake supports AIX, but AIX has its own default Make, with which I am not familiar.
Beta
A: 

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.

Jack Kelly
Maybe I misunderstand this. It seems that 1) the behavior will not depend on the environmental variable, 2) the C++ parts will be included if they exist, whether or not they are wanted, and 3) there is some confusion between making an installation package and *installing* something.
Beta
I'm trying to describe something like how the O'Caml build system works. Basically, if you want the native code compilers, you have to run `make opt` at some point before `make install`. The fact that this doesn't depend on envvars is fine: they were a suggested mechanism, not the one that must be used. Both methods have their faults, because they're not obviously repeatable.
Jack Kelly