[Qt-interest] setting makefile variable from .pro file
Pete Black
theblackpeter at gmail.com
Wed Feb 4 22:05:39 CET 2009
andrew.m.goth at l-3com.com wrote:
> Pete Black wrote:
>> Anyone know a good way to set an environment variable used in
>> the qmake generated makefile from the .pro file?
>
> If you want to override the definition of one the variables in the
> Makefile, you can try prefixing its name with "QMAKE_". For example,
> here's how I link to the NSPR library:
>
> QMAKE_CXXFLAGS += $(shell nspr-config --cflags nspr)
> QMAKE_LFLAGS += $(shell nspr-config --libs nspr)
>
> I use += instead of = or := because I want to augment CXXFLAGS and
> LFLAGS, not replace them outright.
>
> By the way, make variables are not environment variables, but they can
> be overridden from the environment or from arguments to make, as in each
> of the following examples:
>
> $ export INSTALL_ROOT=/usr/local; make
> $ env INSTALL_ROOT=/usr/local make
> $ INSTALL_ROOT=/usr/local make
> $ make INSTALL_ROOT=/usr/local
> $ make INSTALL_ROOT:=/usr/local
> $ make INSTALL_ROOT+=/usr/local
>
> If the variable was not an environment variable to begin with, it will
> not be exported to make's child process environments. But if it was an
> environment variable or was overridden by one of the arguments to make,
> it will be exported. Precedence rules apply; see below for examples:
>
> $ cat Makefile
> TEST:=1
> all:
> @echo TEST=$$TEST
> $ make
> TEST=
> $ TEST=2 make
> TEST=1
> $ make TEST=2
> TEST=2
> $ TEST=0 make TEST=2
> TEST=2
> $ TEST=0 make TEST+=2
> TEST=0 2
>
> Adding a "QMAKE_" prefix does not work for variables that aren't in the
> qmake-generated Makefile to begin with, such as INSTALL_ROOT. Perhaps
> you were thinking of INSTALL_DIR? That can be set directly from the PRO
> file.
Thanks for the response. Right, I'm guessing the "QMAKE_" prefix covers
the variables defined at the top of the make and those documented[1] of
course. And INSTALL_ROOT, as you mention is not one of them.
> So please tell us, what would this environment variable do? What are
> you really trying to accomplish?
Basically I'm looking for something similar to "./configure --prefix".
Looking at the generated make file INSTALL_ROOT is prefixed to every
installation path. For instance, I have:
install_target: first FORCE
@$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/usr/local/bin/ || $(MKDIR)
$(INSTALL_ROOT)/usr/local/bin/ -$(INSTALL_PROGRAM)
...
However, INSTALL_DIR doesn't seem to be used. So what I would like to do
is to have a default value for INSTALL_ROOT, say "/usr/local" and then I
can just specify the "top" directory structure for the install targets
in the .pro file. That would give a lot more flexibility when installing
and one would just need to override INSTALL_ROOT to get the files to the
desired location.
Here are a few useful and possible locations for the bin folder based on
different INSTALL_ROOT and target.path = /bin:
INSTALL_ROOT="/usr/local" -> "/usr/local/bin"
INSTALL_ROOT="/usr" -> "/usr/bin"
INSTALL_ROOT="$HOME" -> "$HOME/bin"
Now if I could just set INSTALL_ROOT in the .pro file in a nice way
(that is, without having to create a custom make rule) everything would
be great. Another approach would be to prefix target.path et al in the
.pro file with another variable, but then what's the point of having
INSTALL_ROOT in the makefile which would be a much more elegant solution?
Any ideas are welcome.
[1]http://doc.trolltech.com/qmake-variable-reference.html
More information about the Qt-interest-old
mailing list