Page MenuHomeFreeBSD

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

Authored by arichardson on Nov 30 2017, 4:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 20, 12:44 AM
Unknown Object (File)
Tue, Nov 19, 10:22 PM
Unknown Object (File)
Sat, Nov 9, 1:58 PM
Unknown Object (File)
Thu, Nov 7, 7:22 PM
Unknown Object (File)
Thu, Nov 7, 5:16 PM
Unknown Object (File)
Thu, Nov 7, 1:08 PM
Unknown Object (File)
Fri, Nov 1, 7:48 AM
Unknown Object (File)
Oct 4 2024, 11:30 PM
Subscribers

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

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 13200
Build 13441: arc lint + arc unit

Event Timeline

Over all the approach seems fine.

usr.bin/find/Makefile
9

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

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

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

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
52–66

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 ↗(On Diff #38942)

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 ↗(On Diff #38942)

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

head/usr.bin/find/find.h
40 ↗(On Diff #38942)

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 ↗(On Diff #38942)

It truly does!

head/usr.bin/find/option.c
70 ↗(On Diff #38942)

Thanks for testing, will commit shortly.

head/usr.bin/find/find.h
40 ↗(On Diff #38942)

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 ↗(On Diff #38942)

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 ↗(On Diff #38942)

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 ↗(On Diff #38942)

#ifdef __FreeBSD__ sounds fine to me