mmatuska / mfsbsd

mfsBSD
http://mfsbsd.vx.sk
BSD 2-Clause "Simplified" License
494 stars 137 forks source link

fix: "roothack: No such file or directory" fetal error #142

Closed soobinrho closed 1 year ago

soobinrho commented 1 year ago

What is this issue?

# Error message
Installing roothack ...install: /usr/src/contrib/mfsbsd/work/roothack/roothack: No such file or directory
*** Error code 71

The build process exits with a fetal error as shown above. This error is dependent on where the mfsbsd folder is located, which means this error doesn't happen if it's located in certain places, but it does occur if it's located in, for instance, /usr/src/contrib/mfsbsd.

It's my understanding that the cause of this unexpected behavior stems from the specific way MAKE(1) handles .OBJDIR. According to the documentation,

Its [.OBJDIR] value is determined by trying to chdir to the following directories in order and using the first match:

1. ${MAKEOBJDIRPREFIX}${.CURDIR}

   (Only if `MAKEOBJDIRPREFIX' is set in the environment or on the command line.)

3. ${MAKEOBJDIR}

   (Only if `MAKEOBJDIR' is set in the environment or on the command line.)

4. ${.CURDIR}/obj.${MACHINE}

5. ${.CURDIR}/obj

6. /usr/obj/${.CURDIR}

7. ${.CURDIR}

Normally, .OBJDIR value doesn't matter in a regular mfsBSD build. However, when mfsbsd directory is located at /usr/src/ocntrib/mfsbsd, the value of .OBJDIR comes into play, and in this case, Make is not able to find /usr/src/contrib/mfsbsd/work/roothack/roothack because its .OBJDIR is set to a wrong location. In my case, it was set to /usr/obj/usr/src/${ARCH}/contrib, as opposed to what it should have been, which is /usr/src/contrib/mfsbsd.

Identified Fix

Change in one line of mfsbsd/Makefile (line number 504) fixes this issue. I also submitted a PR.

# BEFORE CHANGE
${_v}cd ${TOOLSDIR}/roothack && env MAKEOBJDIR=${WRKDIR}/roothack make
# AFTER CHANGE
${_v}cd ${TOOLSDIR}/roothack && make MAKEOBJDIR=${WRKDIR}/roothack

How to replicate the issue

Here are the exact command lines that produced this error:

# Prerequisites
cd /usr/src
make buildworld buildkernel -j12

# Clone mfsBSD and import into the FreeBSD vendor-import directory
cd /usr/src/contrib
git clone https://github.com/mmatuska/mfsbsd.git

# Build mfsBSD
cd ./mfsbsd
make all -m"/usr/share/mk" BASE=/usr/obj/usr/src/amd64.amd64/release MAKEOBJDIR=/usr/src/contrib/mfsbsd

#
# By the way, the reason why I used an `-m` flag here is explained at:
# https://wiki.freebsd.org/SummerOfCode2023Projects/IntegrateMfsBSDIntoTheReleaseBuildingTools
#
soobinrho commented 1 year ago

Closing this issue as I've discovered the following passage from /usr/src/share/mk/bsd.obj.mk:

# MAKEOBJDIR    A pathname for the directory where the targets
#       are built.  Note: MAKEOBJDIR is an *environment* variable
#       and works properly only if set as an environment variable,
#       not as a global or command line variable!
#
#       E.g. use `env MAKEOBJDIR=temp-obj make'

Following this fixed the issue completely. The problem was on my code. My bad!