Bug 263880 - make clean, cleandir doesn't clean /usr/obj
Summary: make clean, cleandir doesn't clean /usr/obj
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2022-05-09 13:48 UTC by Jonathan Vasquez
Modified: 2022-05-13 20:06 UTC (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Vasquez 2022-05-09 13:48:54 UTC

Apologies if this is not a bug and just a lack of understanding on my part, but looking at build(7), the description for 'clean' says:

"Remove any files created during the build process."

and the description for 'cleandir' mentions removing the 'canonical object directory if it exists or perform actions equivalent to 'make clean cleandepend'.

In my testing, I noticed that if I do a 'make clean' or 'make cleandir' (even if I run cleandir twice), it doesn't actually clean up my /usr/obj directory. Only a 'make cleanworld' cleans it:

root@leslie:/usr/src # find /usr/obj

A quick test I did was the following:

-- I originally did the touch on /usr/obj but I noticed that the cleanworld command only cleans up stuff under the particular architecture rather than a flat out nuking of /usr/obj. I'm guessing this is possibly to support a cross building workflow.

root@leslie:/usr/src # touch /usr/obj/usr/src/amd64.amd64/lol
root@leslie:/usr/src # ls -l /usr/obj/usr/src/amd64.amd64/
total 1
-rw-r--r--  1 root  wheel  0 May  9 09:43 lol

root@leslie:/usr/src # make cleanworld
(cd /usr/obj/usr/src/amd64.amd64/ && rm -rf *)
chflags -R 0 /usr/obj/usr/src/amd64.amd64/
(cd /usr/obj/usr/src/amd64.amd64/ && rm -rf *)

root@leslie:/usr/src # ls -l /usr/obj/usr/src/amd64.amd64/
total 0


My expectation for a 'make clean' in /usr/src would be that all of the build files created are cleaned up (including /usr/obj).

root@leslie:/usr/src # touch /usr/obj/usr/src/amd64.amd64/lol
root@leslie:/usr/src # ls -l /usr/obj/usr/src/amd64.amd64/
total 1
-rw-r--r--  1 root  wheel  0 May  9 09:44 lol

root@leslie:/usr/src # make cleandir


root@leslie:/usr/src # ls -l /usr/obj/usr/src/amd64.amd64/
total 1
-rw-r--r--  1 root  wheel  0 May  9 09:44 lol


Another related note (which I'll need confirmation for) is if /usr/obj is even re-used during subsequent builds. The handbook mentions that /usr/obj can speed up subsequent builds, but I've noticed that the first thing a build does is pretty much to cleanworld before rebuilding. That kinda defeats the purpose of re-using those objects. There's this old link (seems forked by someone) where in the past it mentioned /usr/obj is not used afterwards so it could be deleted, but I'm not sure if behavior in FreeBSD changed from that time of that post:

Comment 1 Ed Maste freebsd_committer 2022-05-09 18:33:49 UTC
To confirm, do you mean that directories are left behind under /usr/obj, but objects are otherwise cleaned up?
Comment 2 Jonathan Vasquez 2022-05-09 18:45:41 UTC
Hey Ed,

That seems to be case. I went ahead and made a backup of my /usr/src and /usr/obj so that I can clean them and show you the following. The below is after today's build of 13.1-STABLE. I ran a 'make clean' for the purpose of this example:

root@leslie:/usr # du -sh obj
6.6G    obj
root@leslie:/usr # du -sh src
2.2G    src

root@leslie:/usr # du -sh obj
3.4G    obj
root@leslie:/usr # du -sh src
2.2G    src

Is 'make clean' suppose to still leave stuff behind given the man page description? I'm not sure if that's intended. I do know that when building the Linux kernel, if you do a 'make clean', it does clean up a bunch of stuff but only leaves a minimum amount of left over files in order to allow people to still be able to build kernel modules that are outside the tree (You can actually reduce it even further if you know what files to keep, but that's neither here nor there). A 'make distclean' would pretty much wipe everything it built, and would nuke your kernel config as well, essentially bringing you back to a pristine source tree as if you just had extracted it from kernel.org.

So with that context, is 'make clean' on FreeBSD suppose to leave that much stuff behind? If so, what's the purpose for it (kernel module building (i.e drm-kmod?). Is there an equivalent on FreeBSD to pretty much completely clean out the tree and any build output etc? At the moment I would think doing the following would get me back to a vanilla state:

# cd /usr/src
# make clean cleanworld
# git reset --hard HEAD
# git clean -dfx
# rm -rf /usr/obj/*

Thank you,
Comment 3 Jonathan Vasquez 2022-05-13 18:40:48 UTC
Since I reported this, I've discovered the "NO_CLEAN" option (-DNO_CLEAN) which seems to answer my previous question regarding /usr/obj and speeding up the builds as mentioned in the docs. I think the man page could use a little bit of clarification, and also the handbook. I'll submit a patch to the handbook for:

https://docs.freebsd.org/en/books/handbook/cutting-edge/#makeworld ( Performing a Clean Build)

to note that the build system does an automatic cleaning at the start of every build unless this option is specific. Although I do also know that user may need to be careful when rebuilding with artifacts in /usr/obj since I've noticed in weird instances it could lead to some weirdness during runtime of those newly compiled binaries (at least in other OSes, I'm not sure how much I should worry about that in FreeBSD though.. especially if also using ccache).

Comment 4 Jonathan Vasquez 2022-05-13 18:44:54 UTC
I forgot to mention, and also the src.conf - WITHOUT_CLEAN option. Seems to be preferred based on the output of make when using the -DNO_CLEAN option (and based on the Makefile.inc1 documentation. I'll make sure to include this in the handbook patch.