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

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

Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 14435
Build 14584: arc lint + arc unit
arichardson created this revision.Nov 30 2017, 4:57 PM
brooks accepted this revision.Nov 30 2017, 7:33 PM

Over all the approach seems fine.

usr.bin/find/Makefile
11

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
52

Why is this needed now?

This revision is now accepted and ready to land.Nov 30 2017, 7:33 PM
emaste added a comment.Dec 5 2017, 9:03 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.

arichardson added inline comments.Tue, Jan 16, 7:26 PM
usr.bin/find/Makefile
11

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
52

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.Wed, Jan 17, 2:13 PM
brooks accepted this revision.Wed, Jan 17, 8:23 PM

LGTM

This revision is now accepted and ready to land.Wed, Jan 17, 8:23 PM
imp added a comment.Wed, Jan 17, 10:33 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

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.