Notes on the various things to get my CFLAGS used _________________________________________________ For my "default" CFLAGS I use "-O2 -march=native" but where a package defaults to -O3 I now try to use that. The great benefit of using -march=native when checking if my flags are being used, is that no package will ever default to that - so if I can see it in the logs, I know my flags were used. However, if a configure script produces a summary report showing the flags it will use, but runs non-verbose make commands, that is good enough for me. For many of the seds, I actually conditionalize them to only run if CFLAGS are set, i.e test -z "$CFLAGS" || sed ... 0. There is no compilation in this package! 1. No action necessary, make is verbose and shows my flags are used. 2. Many packages run make in non-verbose mode. Use 'make V=1' to see the details. 3. (bzip2-1.0.6) - the default flags are '-O2 -g' so use sed: sed -i "s/-O2 -g/${CFLAGS}/" Makefile Makefile-libbz2_so 4. I discovered that a sed was needed (now in the book) to make this version recognize that gcc-8 understood -DFORTIFY_SOURCE=2. With that added, to get my flags used by perl itself, and also by any modules which do C compilation, I needed an extra argument in configure: -D"optimize=$CFLAGS" 5. For Python3, which defaults to -g -O3, if I am setting CFLAGS I use sed to strip the -g : sed -i '/OPT=/s/-g //' configure and then I remove any -O value from my CFLAGS. Some modules definitely compile and use the flags I passed to Python 6. I'm using bc-1.1.4 (a fork, not yet in LFS). When I was watching one of the builds I realised there were messages on the screen during the tests (a breakage). I had not noticed that before, the test log just ends abruptly and I had assumed that was normal. 7. gmp-6.1.2 : If I'm using my own CFLAGS, I use its "build for the host" configure, if I'm not setting them I use the fsf configure. 8. libcap-2.27 : If I'm using my own CFLAGS I use seds to remove the -g and to replace -O2 with my flags: sed -i -e 's/^DEBUG =.*/DEBUG =/' \ -e "s/-O2/${CFLAGS}/" Make.Rules 9. Many perl modules do not do any compilation, but those that do all seem to use the flags I passed to perl. 10. Adding --verbose shows my CXXFLAGS are used 11. Some python modules, most of which use setup.py, are not at all verbose and give no indication of how (or if) they are running compiles. But I remove any -O? from my CFLAGS so that any compile with pick up Python's own -O3 : i.e. sed 's/-O. //' 12. grub: I don't think I'm likely to actually install a new bootloader when building variants which might break things, so I've decided to not pass my flags to this package. 13. sysklogd-1.5.1 : by default this only uses my CFLAGS for pidfile.c, the rest is compiled as -O3 without my flags. So, I use a sed: sed -i "s/-O3/$CFLAGS &/" Makefile 14. sqlite-3.28.0 : I put my CFLAGS at the front of the defines. 15. Python-2.7.16 : this is not quite the same as Python3, it defaults to -g -O3 but puts any CFLAGS in front of that, so sed out the -g : sed -i '/OPT=/s/-g //' configure 16. traceroute-2.1.0 uses -O2, use sed to add my own CFLAGS after that: sed -i "s/# CFLAGS +=/CFLAGS += $CFLAGS/" Make.defines 17. Some packages default to -O3, but if CFLAGS are supplied they will either use those to replace the -O3, or to follow it. For CFLAGS (and similarly for CXXFLAGS): CFLAGS=$(echo $CFLAGS | sed 's/-O./-O3/') 18. fortune-mod-1.99.1 uses -O2 and ignores CFLAGS. Use a sed: sed -i "s/-O2/$CFLAGS/" Makefile 19. pciutils-3.6.2 ignores my CFLAGS and uses -O2. Use a sed: sed -i "s/OPT=.*/OPT=${CFLAGS}/" Makefile 20. postfix-3.4.5 make makefiles DEBUG= OPT="${CFLAGS}" 21. unzip60 and zip30 default to using (just) -O3 First 'make flags' which is part of the normal run. Then use a sed to put own CFLAGS in front of -O3: sed -i "s/-O3/$CFLAGS &/g" flags Then run 'make'. 22. fcron-3.2.1 by default uses my CFLAGS but follows with -O2. Instead, configure --with-cflags="$CFLAGS" 23. libuv_v1.28.0 In configue add cc_cv_cflags__g=no 24. Packages which use cmake: I use -DCMAKE_BUILD_TYPE=RELEASE which ensures that my own CFLAGS are followed by the package's -O3, but I follow that with make VERBOSE=1 (or ninja -v where the book uses ninja with cmake, e.f. tiff). 25. lsof_4.91 : another odd variation: LSOF_CFGF="$CFLAGS" ./Configure -n linux 26. For meson packages (except xorg-proto, which does not do any compilation) I use -Dbuildtype=release which specifies -O3 but then puts my CFLAGS after it. For these packages, I remove any -O? from the CFLAGS, i.e. sed 's/-O. //' 27. xsnow-1.42 : exceptionally, I will mention that to build this I use a sed from the late Andy Benton: sed -i 's# /usr[^ ]*.h##g;/^ *\\$/d;s#X11R6/##' Makefile and to get it to use my CFLAGS instead of -O2 : sed -i "/CDEBUGFLAGS =/s/-O2/$CFLAGS/" Makefile 28. I use functions to modify CFLAGS for packages, e.g. to remove my optimizations. For libvorbis, where I remove any -O? so that the package's own -O3 will be used, my reduced flags (-march=native) were followed by my full flags (-O2 -march=native) although building without scripts worked correctly. In the end. after modifying the CFLAGS I now copy them to an extra variable, unset CFLAGS, reload from the extra variable. But only for this package. 29. For anything using rust, there are few options to put in RUSTFLAGS for tuning. The optimization level (equivalent to -On in CFLAGS) can be passed as '-C opt-level=n' and machine micro-architecture (like -march=) can be passed as '-Ctarget-cpu='. Note that whenever you set RUSTFLAGS in your environment, you must export them. HOWEVER, please note that at one time I had accidentally changed my bash function which strips eveything except -march= and converts that to -target-cpu= (I was merging various similar functions) and removed the export. When I tracked that down, tested, and rebuilt rust and its program I found that the build times increased by a few percent. Maybe it slows things down, or maybe this is the normal "I find rust programs have very variable compile times". 30. rustc-1.32.0 : To get full details, pass '-vv' to the x.py script, i.e. ./x.py build -vv --exclude ... The default optimization level is 2. 31. librsvg-2.44.13 : For the parts using gcc, my CFLAGS are picked up instead of its default of '-g -O2'. To see what happens in the rust parts, use 'make V=1'. That shows that it uses '-C opt-level=3 -C debuginfo=2', and if you pass any RUSTFLAGS to it, those go later and so can override the opt-level. So, for the rust part I let it use its optimization and convert my -march= to -Ctarget-cpu= if I have set it. 32. cbindgen-0.8.3 : Using --verbose, we can see that the --release switch enables '-C opt-level=3. Again, I let rust use its own opt-level and merely add -Ctarget-cpu if I have set that. 33. firefox-67.0 : For the C and CXX parts, with a verbose build my flags were picked up and then followed by its own flags (sometimes -O2, in other places -O3). For the rust part, for consistency with the other rust packages I am at the moment only putting '-C target-cpu=' in my RUSTFLAGS (if I have set -march in my CFLAGS). To pass your own RUSTFLAGS, add the following to mozconfig: export RUSTFLAGS="$RUSTFLAGS" 34. My flags are picked up, but the package applies -O3 after them. 35. Exceptionally, poppler-0.75.0 uses -O2 for release builds, and picks up user-supplied CFLAGS after this. 36. gsettings-desktop-schemas only does one pice of conventional compiling, and for that it uses -O1 but with my -march=native. 37. mupdf-1.14.0 : by default, this passes -O2 after any user-specified flags. Override that, if any optimizations are set, with : sed -i 's/-O2 //' Makerules 38. A few packagage developers still think that -O9 is the maximum optimization (for gcc, anything greater than 3 is treated as -O3). 39. boost_1_70_0 will by default use -O3, so I remove any -O values from my CXXFLAGS. To get a verbose build, use -d+2 and to use the remaining CXXFLAGS pass them as cxxflags="-foo -bar" i.e. ./b2 stage cxxflags="$CXXFLAGS" -jN threading=multi link=shared -d+2 Update: b2 does not like any -D defines in the CXXFLAGS, and it loses its lunch if the string starts with a space. 40. a52dec-0.7.4 : This accepts my -march=native but appears to drop my -O2 of its own accord, and add a -O3 after the inserted -fPIC. 41. Some packages, such as libmad, put the CFLAGS in the log in reverse order: I added --O2 -march=native' but it used '-march=native -O2'. 42. Some C packages ignore my CFLAGS. For these, the solution is to use: CFLAGS="$CFLAGS" ./configure ... 43. rtmpdump-2.4_p20161210 ignores CFLAGS and uses -O2. Use a sed: sed -i "s/-O2/$CFLAGS/" Makefile librtmp/Makefile 44. audacious-3.10.1, and the plugins, are "unconventional": they do use supplied CFLAGS and CXXFLAGS, but to discover that you need to look at buildsys.mk after running configure. 45. xine-lib-1.2.9 defaults to -g -O3, but will replace the -O3 by the supplied CFLAGS: I remove -O? from my flags and remove the -g with a sed : sed -i 's/-g $CFLAGS/$CFLAGS/' configure 46. flvstreamer-2.1c1 defaults to using -O2 and ignoring CFLAGS. Fix it with a sed: sed -i "s/^OPT=-O2/OPT=$CFLAGS/" Makefile 47. exo-0.12.4 and sox-14.4.2 default to -g -O2 and ignore my CFLAGS. I use a sed: -i "s/-g -O2/$CFLAGS/" configure 48. Qt5 defaults to not using supplied CFLAGS or CXXFLAGS. It can be told to use the CFLAGS (and will copy those to its CXXFLAGS) - these will then be used by everything qmake builds. To do this, run: sed -i -e "s|^\(QMAKE_CFLAGS_RELEASE.*\)|\1 ${CFLAGS}|" \ qtbase/mkspecs/common/gcc-base.conf 49. qtwebwengine invokes ninja from make. For a verbose build of the package (but not of the initial build-tool) 'make VERBOSE=1'. 50. glew-2.1.0 needs a sed to replace its default -O2 with the user's CFLAGS: sed -i "/POPT/s/-O2/$CFLAGS/" config/Makefile.linux 51. asymptote-2.49 does not find the flags unless they are exported. In addition, if the CXXFLAGS are not found, they are set to -std=c++11 So: export CFLAGS export CXXFLAGS="$CXXFLAGS -std=c++11" 52. libnotify-0.7.8 - I had initially omitted -v from the ninja invocation. Upon investigating a warning in a later build, I noticed this, added it for a manual test, and was surprised to find that it did NOT use my CFLAGS in that build (and no-longer produced the warning from CPP. The official meson docs say: $ CFLAGS=-fsomething LDFLAGS=-Wl,--linker-flag meson Using that form for this package clearly works. 2019-05-31 - - - end - - -