freebsd-ports/Mk/Uses/qmake.mk
Raphael Kubo da Costa 8ceb79f0fe Make sure ${WRKSRC}/lib is passed before /usr/local/lib when linking.
This is another shot at fixing the linkage problems that have plagued our
users particularly when upgrading from Qt 5.x to 5.(x+1). Quick recap: in
Qt5, qmake will by default pass QMAKE_LIBDIR to the linker before other
directories such as ${WRKSRC}/lib, which is where the port's libraries are
built. When a user is upgrading Qt, we can end up with the following linker
line:
  c++ -o SomeBinary -lfoo1 -L/usr/local/lib -L${WRKSRC}/lib -lfoo2 -lfoo3
If libfoo2.so is being built by the port and an older version is currently
installed on the system, /usr/local/lib/libfoo2.so will be picked up instead
of the newly-built ${WRKSRC}/lib/libfoo2.so. At best things just work, at
worst SomeBinary needs some new symbol that is not present in the old
libfoo2.so and linking fails. Case in point: bug 198720.

The previous approach, adopted when fixing bug 194088, was to stop setting
QMAKE_{INC,LIB}DIR in the FreeBSD mkspecs and set the CPATH and LIBRARY_PATH
environment variables in Uses/qmake.mk. This way we just did not pass
-L/usr/local/lib to the linker at all and things mostly worked. However,
people using Qt to build their own software without the ports tree were out
of luck, as they would then need need to deal with passing
/usr/local/{include,lib} to the compiler/linker themselves (bug 195105). Not
only that, but if a dependency mentioned /usr/local/lib we would still have
problems anyway (in bug 198720, the GStreamer pkg-config files contain
-L/usr/local/lib, for example).

We now solve the issue by setting the QMAKE_LIBDIR_FLAGS variable in
.qmake.cache to ${WRKSRC}/lib instead. qmake appends the value of
QMAKE_LIBDIR to QMAKE_LIBDIR_FLAGS, so we are always sure -L${WRKSRC}/lib
will come before -L/usr/local/lib in the linker options. Moreover, qmake is
smart enough to automatically call sed(1) and remove references to
${WRKSRC}/lib from .prl and .pc files when installing them.

PR:		194088
PR:		195105
PR:		198720
MFH:		2015Q4
2015-12-28 18:51:41 +00:00

114 lines
3.1 KiB
Makefile

# $FreeBSD$
#
# Provide support for qmake-based projects
#
# Feature: qmake
# Usage: USES=qmake or USES=qmake:ARGS
# Must be used along with 'USE_QT*=#'
# Valid ARGS: norecursive outsource
# ARGS description:
# norecursive Don't pass -recursive argument to qmake binary
# outsource Perform an out-of-source build
#
#
# Variables for ports:
# QMAKE_ENV - Environment passed to qmake.
# Default: ${CONFIGURE_ENV}
# QMAKE_ARGS - Arguments passed to qmake.
# Default: see below
# QMAKE_SOURCE_PATH - Path to qmake project files.
# Default: ${WRKSRC} if out-of-source build is
# requested, empty otherwise.
#
# User defined variables:
# QMAKE_VERBOSE - Enable verbose configure output.
#
# MAINTAINER: kde@FreeBSD.org
.if !defined(_INCLUDE_USES_QMAKE_MK)
_INCLUDE_USES_QMAKE_MK= yes
# _QT_VERSION is defined in bsd.qt.mk, only if a correct Qt version was selected
# via USE_QT*.
.if empty(_QT_VERSION)
IGNORE= 'USES+= qmake' must be accompanied with 'USE_QT[${_QT_SUPPORTED:S/ //g}]= #'
.endif
# _env is a private argument used only by bsd.qt.mk to get variables and custom
# targets (currently, only qmake-configure), without qmake being added to the
# configure stage.
_VALID_ARGS= norecursive outsource _env
.for arg in ${qmake_ARGS}
. if empty(_VALID_ARGS:M${arg})
IGNORE= Incorrect 'USES+= qmake' usage: argument '${arg}' is not recognized
. endif
.endfor
.if ! ${qmake_ARGS:M_env}
USE_QT${_QT_VERSION:R:R}+= qmake_build
.endif
# QMAKESPEC belongs to bsd.qt.mk.
QMAKE_ENV?= ${CONFIGURE_ENV}
QMAKE_ARGS+= -spec ${QMAKESPEC} \
QMAKE_CC="${CC}" QMAKE_CXX="${CXX}" \
QMAKE_LINK_C="${CC}" QMAKE_LINK_C_SHLIB="${CC}" \
QMAKE_LINK="${CXX}" QMAKE_LINK_SHLIB="${CXX}" \
QMAKE_CFLAGS="${CFLAGS}" \
QMAKE_CXXFLAGS="${CXXFLAGS}" \
QMAKE_LFLAGS="${LDFLAGS}" \
QMAKE_LIBS="${LIBS}" \
QMAKE_CFLAGS_DEBUG="" \
QMAKE_CFLAGS_RELEASE="" \
QMAKE_CXXFLAGS_DEBUG="" \
QMAKE_CXXFLAGS_RELEASE="" \
PREFIX="${PREFIX}"
.if defined(WITH_DEBUG)
QMAKE_ARGS+= CONFIG+="debug" \
CONFIG-="release"
.else
QMAKE_ARGS+= CONFIG+="release" \
CONFIG-="debug separate_debug_info"
.endif # defined(WITH_DEBUG)
# We set -recursive by default to keep qmake from running in the build stage.
.if ! ${qmake_ARGS:Mnorecursive}
QMAKE_ARGS+= -recursive
.endif
.if defined(QMAKE_VERBOSE)
QMAKE_ARGS+= -d
.endif
# _QMAKE_WRKSRC (and _QMAKE, below) are needed to abstract the qmake target and
# use it for both qtbase and USES=qmake ports. They are private, not supposed to
# be used anywhere else.
_QMAKE_WRKSRC?= ${CONFIGURE_WRKSRC}
.if ${qmake_ARGS:Moutsource}
CONFIGURE_WRKSRC= ${WRKDIR}/.build
BUILD_WRKSRC= ${CONFIGURE_WRKSRC}
INSTALL_WRKSRC= ${BUILD_WRKSRC}
QMAKE_SOURCE_PATH?= ${WRKSRC}
.else
QMAKE_SOURCE_PATH?= # empty
.endif
.if ! ${qmake_ARGS:M_env}
DESTDIRNAME= INSTALL_ROOT
.endif
# Define a custom target to make it usable by bsd.qt.mk for internal Qt
# configuration.
qmake-configure:
@${MKDIR} ${_QMAKE_WRKSRC}
@cd ${_QMAKE_WRKSRC} && \
${SETENV} ${QMAKE_ENV} ${_QMAKE} ${QMAKE_ARGS} ${QMAKE_SOURCE_PATH}
.if !target(do-configure) && ! ${qmake_ARGS:M_env}
do-configure: qmake-configure
@${DO_NADA}
.endif
.endif # !defined(_INCLUDE_USES_QMAKE_MK)