Page MenuHomeFreeBSD

Allow compiling usr.bin/find on Linux and Mac
ClosedPublic

Authored by arichardson on Nov 30 2017, 4:57 PM.

Details

Summary

When building FreeBSD the makefiles invoke find with various flags such as
-s that aren't supported in the native /usr/bin/find. To fix this I
build the FreeBSD version of find and use that when crossbuilding.

Inserting lots if #ifdefs in the code is rather ugly but I don't see a
better solution.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Over all the approach seems fine.

usr.bin/find/Makefile
9 ↗(On Diff #36009)

I'm waffling about the choice to use #if vs just using #ifdef. Is this the way one does this with cmake?

usr.bin/find/function.c
54 ↗(On Diff #36009)

Why is this needed now?

This revision is now accepted and ready to land.Nov 30 2017, 7:33 PM

I like the intent of this change. It's a bit unfortunate to have the #ifs but I also don't see a better way. Does NetBSD's find do the same thing? What is the #include "nbtool_config.h" for?

I like the intent of this change. It's a bit unfortunate to have the #ifs but I also don't see a better way. Does NetBSD's find do the same thing? What is the #include "nbtool_config.h" for?

I haven't looked at what NetBSD does, I'll have a look tomorrow.
The reason I added the #include "nbtool_config.h" is that many of the other tools that I need to crossbuild already have it so it was easier to do the same for find rather than passing all the -D flags on the command line.
I am currently building all bootstrap tools using https://github.com/arichardson/freebsd-crossbuild and just use CMake to generate nbtool_config.h.
In order to build FreeBSD I still need to run some ugly python code but I'll try to somehow integrate it with the Makefiles in the future.

I've had a look at netbsd and when I create the tools directory with the build.sh script it builds the following binaries;

nbasn1_compile  nbctfconvert  nbgmake         nblex         nbmenuc       nbnroff     nbslc       nbtexindex                x86_64--netbsd-c++        x86_64--netbsd-gcc-ar      x86_64--netbsd-mdsetimage
nbawk           nbctfmerge    nbgpt           nblorder      nbmkcsmapper  nbpax       nbsoelim    nbtic                     x86_64--netbsd-c++filt    x86_64--netbsd-gcc-nm      x86_64--netbsd-nm
nbcap_mkdb      nbcvslatest   nbgroff         nbm4          nbmkdep       nbpaxctl    nbsortinfo  nbtsort                   x86_64--netbsd-cpp        x86_64--netbsd-gcc-ranlib  x86_64--netbsd-objcopy
nbcat           nbdb          nbhexdump       nbmake        nbmkesdb      nbperf      nbstat      nbuudecode                x86_64--netbsd-dbsym      x86_64--netbsd-gcov        x86_64--netbsd-objdump
nbcksum         nbdisklabel   nbhost-mkdep    nbmake-amd64  nbmklocale    nbpic       nbstrfile   nbyacc                    x86_64--netbsd-elfedit    x86_64--netbsd-gcov-dump   x86_64--netbsd-ranlib
nbcompile_et    nbeqn         nbindxbib       nbmakefs      nbmknod       nbpwd_mkdb  nbsunlabel  nbzic                     x86_64--netbsd-fdisk      x86_64--netbsd-gcov-tool   x86_64--netbsd-readelf
nbconfig        nbfile        nbinstallboot   nbmakeinfo    nbmktemp      nbrefer     nbtbl       x86_64--netbsd-addr2line  x86_64--netbsd-g++        x86_64--netbsd-install     x86_64--netbsd-size
nbcrunchgen     nbgenassym    nbinstall-info  nbmakewhatis  nbmsgc        nbrpcgen    nbtexi2dvi  x86_64--netbsd-ar         x86_64--netbsd-gcc        x86_64--netbsd-ld          x86_64--netbsd-strings
nbctags         nbgencat      nbjoin          nbmandoc      nbmtree       nbsed       nbtexi2pdf  x86_64--netbsd-as         x86_64--netbsd-gcc-5.5.0  x86_64--netbsd-ld.bfd      x86_64--netbsd-strip

So it seems the NetBSD build system doesn't need find or plain POSIX find flags are good enough there.

usr.bin/find/Makefile
9 ↗(On Diff #36009)

I did this for consistency with the other files that include nbtool_config.h. It appears to use #define 1/0 for the individual values so they all use #if

usr.bin/find/function.c
54 ↗(On Diff #36009)

I believe on Linux struct statfs is only defined if this header is included but on MacOS it doesn't exist. With this #if it should work on all systems

arichardson added a reviewer: imp.

Avoid nbtool_config.h

This revision now requires review to proceed.Jan 17 2018, 2:13 PM
This revision is now accepted and ready to land.Jan 17 2018, 8:23 PM

This is fine, but I'd like to see us centralize these things so each new tool is easier not a reinvent from scratch effort. libegacy is the right place for this, since we already in place for dealing with older build hosts.

usr.bin/find/find.h
48–62 ↗(On Diff #38087)

This is fine for the moment, but I wonder if we want to expand libegacy (which we use to allow us to upgrade from old FreeBSD versions) to include this sort of stuff when compiling on other systems. That way, build tools could just have a --include fbsd_compat.h added to the build, and missing routines would have a place to build. Let me know if you'd like more details on how we'd planned for this day when we did libegacy. I know NetBSD did their own thing here (hence the nbtool_config.h stuff), but I'm not sure it's a good fit for FreeBSD, unless it's driven under the libegacy bandwagon.

This revision was automatically updated to reflect the committed changes.
phil_krylov.eu added inline comments.
head/usr.bin/find/option.c
70

This is never defined unless you remember to also #include <sys/acl.h>. As a result of this, since FreeBSD 12.0 find -acl is broken.

head/usr.bin/find/option.c
70

Sorry about that. I guess usr.bin/find needs more tests :(

head/usr.bin/find/find.h
40

Does adding the following lines here fix the problem?

#if __has_include(<sys/acl.h>)
#include <sys/acl.h>
#endif
head/usr.bin/find/option.c
70

It truly does!

head/usr.bin/find/option.c
70

Thanks for testing, will commit shortly.

head/usr.bin/find/find.h
40

I don't have my src set up, sorry. But from static analysis,

  • function.c #includes sys/acl.h without any guards, wouldn't that work here as well?
  • unsure if it should go here or in the options.c where actual usage takes place.
head/usr.bin/find/option.c
70

You must have misunderstood, I did not test anything; I was replying to the lack of tests pun.

head/usr.bin/find/option.c
70

has_include isn't supported on all versions of GCC. Specifically, the GCC 6 we still support does not support it. Perhaps use '#ifdef FreeBSD__' to guard the #include instead?

head/usr.bin/find/option.c
70

#ifdef __FreeBSD__ sounds fine to me