#!/usr/bin/perl
# -*- mode: cperl; coding: utf-8; -*-
use strict;
use warnings;
use utf8;
use lib "/h/hamren/src/post/lib", "."; my $rval = do "common.pm" || die "$0: common.pm failed ($!) [$@]"; #--- Single-line common initializer
#--- End of header
my $pro = tt(".pro");
post(
header(),
p("A problem with boiling spaghetti is that it easily boils over. ",
"There are various tricks to try and measures to take, but it is still a process prone to accidents. "),
p("Time for some lateral thinking. ",
"Don't boil the pasta. ",
"Keep the temperature below boiling point, and it will no longer boil over. ",
"There is nothing magical about 100 °C; ",
"95 °C will do just as well. ",
"This not only solves the problem, it removes it."),
h2("Custom rules in Qt makefiles"),
p("Qt makefiles are typically generated from $pro files using «qmake». ",
"Sadly, there seems to be no supported way of adding custom rules to the generated makefile. ",
"One way to overcome this would be to patch the makefile after it has been generated, but then we must make sure to do that every time."),
p("Here is where some lateral pasta thinking comes into play. ",
"Let's not modify the generated makefile. ",
"Instead, write a separate makefile with the additional rules, and include the generated makefile: "),
source_code(<<'EOF'),
first: The first rule in the generated makefile.
... some makefile stuff ...
include Makefile
... some more makefile stuff ...
EOF
p("Since «qmake» generates «Makefile» (capitalized) by default, I use the name «makefile» (lowercase), ",
"and make use of the rule that (GNU) «make» looks for «makefile» before it looks for «Makefile»."),
p("Here are some rules that I put into my «makefile»:"),
source_code(<<'EOF'),
clean: deletei386
deletei386:
rm -rf i386
dirs: i386/gcc/obj/.d i386/gcc/moc/.d i386/gcc/bin/.d
%.d:
mkdir -p $(@D)
touch $@
EOF
p("The first two rules adds the deletion of the «i386/» subdirectory to the «clean:» target. ",
"The next two rules adds a target «dirs:» for making the directories that I use for building. "),
p("The very first rule of my «makefile» actually looks like this:"),
source_code(<<'EOF'),
first: dirs
EOF
p("This makes a plain «make» command without arguments build the «dirs:» directories. "),
p("There is another thing that «qmake» can't do: use different compiler options for different object files. ",
"But rules can be put in «makefile» to solve this:"),
source_code(<<'EOF'),
i386/gcc/obj/qrc_yamaha.o: CXXFLAGS += -Wno-error=unused-variable
i386/gcc/obj/qrc_yamaha.o: CXXFLAGS += -Wno-unused-variable
EOF
p("Here I solve the problem of warnings (which I turn into fatal errors) about unused variables. ",
"The source file is automatically generated by «qrc» (the Qt Resource Compiler), so I have no no control over it. ",
"Since I do no want to turn the warnings off for my own source code, the solution is to selectively disable them for this file."),
footer()
);