I've been working on a program called RoboJournal for some time now and I'm trying to simplify the creation of source packages for Debian. When a user builds the program on Linux, qmake sets the install path to /usr/local/bin (which is as it should be for user-compiled programs) However, this causes problems when I create the Debian source package since all packaged executables are supposed to install to /usr/bin.
The easiest way to fix this problem is to edit the install path manually before making the source package but I would prefer to keep the codebase the same (having multiple variants of the codebase with the same version number always causes problems eventually).
It would be great if the package maintainer could just run something like qmake --package robojournal.pro
to create a makefile with the correct install path for packaging purposes. Meanwhile, omitting the --package
argument would still allow users to create a regular build.
Can this (or something similar) be done? I've checked the qmake documentation but I’ve found nothing on configuring a project file to allow qmake to accept custom Unix-style arguments.
You can achieve what you need by using the CONFIG variable. Anything can be added to the CONFIG variable and each of the options specified in the CONFIG variable can be used as a scope condition:
package {
message(Creating a makefile with the correct install path for packaging purposes...)
} else {
message(Creating a regular build...)
}
This provides you with a convenient way to customize project files and fine-tune the generated Makefiles. See Configuration and Scopes.
The list of values held by CONFIG can be extended on the command line. You can run qmake with or without "CONFIG+=package":
qmake "CONFIG+=package" robojournal.pro
qmake robojournal.pro
See Makefile Mode Options.
By default qmake
produces empty install
and unistall
targets unless you instruct qmake
to do install explicitly.
For example, the project file
TEMPLATE = app
TARGET = test
DEPENDPATH += .
INCLUDEPATH += .
SOURCES += main.cpp
results in the following Makefile (only install part is shown to save the space)
####### Install
install: FORCE
uninstall: FORCE
FORCE:
Then the following rule in Qt project file will specify installation path
unix {
target.path = /usr/bin/
INSTALLS += target
}
Now Makefile has changed
####### Install
install_target: first FORCE
@$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/usr/bin/ || $(MKDIR) $(INSTALL_ROOT)/usr/bin/
-$(INSTALL_PROGRAM) "$(QMAKE_TARGET)" "$(INSTALL_ROOT)/usr/bin/$(QMAKE_TARGET)"
uninstall_target: FORCE
-$(DEL_FILE) "$(INSTALL_ROOT)/usr/bin/$(QMAKE_TARGET)"
-$(DEL_DIR) $(INSTALL_ROOT)/usr/bin/
install: install_target FORCE
uninstall: uninstall_target FORCE
FORCE:
This is the part from robojournal.pro:
target.path = /usr/local/bin
INSTALLS += target shortcut icon shortcut-deb icon-deb
End users will highly unlikely to compile application. And even those who will compile it like me, won't install it, because it can be launched from build directory. Thus, it's safe to replace /usr/local/bin with /usr/bin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With