• Masahiro Yamada's avatar
    kbuild: improve cc-option to clean up all temporary files · ab2cf361
    Masahiro Yamada authored
    BugLink: https://bugs.launchpad.net/bugs/1885932
    
    [ Upstream commit f2f02ebd ]
    
    When cc-option and friends evaluate compiler flags, the temporary file
    $$TMP is created as an output object, and automatically cleaned up.
    The actual file path of $$TMP is .<pid>.tmp, here <pid> is the process
    ID of $(shell ...) invoked from cc-option. (Please note $$$$ is the
    escape sequence of $$).
    
    Such garbage files are cleaned up in most cases, but some compiler flags
    create additional output files.
    
    For example, -gsplit-dwarf creates a .dwo file.
    
    When CONFIG_DEBUG_INFO_SPLIT=y, you will see a bunch of .<pid>.dwo files
    left in the top of build directories. You may not notice them unless you
    do 'ls -a', but the garbage files will increase every time you run 'make'.
    
    This commit changes the temporary object path to .tmp_<pid>/tmp, and
    removes .tmp_<pid> directory when exiting. Separate build artifacts such
    as *.dwo will be cleaned up all together because their file paths are
    usually determined based on the base name of the object.
    
    Another example is -ftest-coverage, which outputs the coverage data into
    <base-name-of-object>.gcno
    Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
    Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
    ab2cf361
Kbuild.include 13.4 KB