#       $NetBSD: Makefile.nbincludes,v 1.13 2025/03/29 23:37:00 tsutsui Exp $

include <bsd.hostinit.mk>

_ARCHDIR:=      ${.PARSEDIR}/../sys/arch
_INCDIR:=       ${.PARSEDIR}/../include
_SYSDIR:=       ${.PARSEDIR}/../sys/sys
_UFSDIR:=       ${.PARSEDIR}/../sys/ufs
_FSDIR:=        ${.PARSEDIR}/../sys/fs
_SUBDIR!=       cd ${_ARCHDIR} && ${MAKE} -V SUBDIR

if make(depend) || make(all) || make(dependall) || make(install)
# There's no need to run these commands for "make cleandir" or "make obj",
# and TOOL_SED will not yet have been built.
_UFS_INCS!=     cd ${_UFSDIR} && find ffs ufs -name '*.h'
_FS_INCS!=      cd ${_FSDIR} && find cd9660 -name '*.h'
_FS_INCS+=      unicode.h
_ARCH_INCS!=    ${TOOL_SED} -e 's/^\#.*//' ${.PARSEDIR}/headerlist 2> /dev/null || true
endif

_ARCH_INCS+=    ews4800mips/include/pdinfo.h ews4800mips/include/vtoc.h

# for sh3/include/elf_machdep.h
for sh3mach in dreamcast evbsh3 hpcsh landisk mmeye sh3
_ARCH_INCS+=    ${sh3mach}/include/endian_machdep.h
endfor

_INCS=          disktab.h
_SYSINCS=       bootblock.h \
               disklabel.h disklabel_acorn.h disklabel_gpt.h disklabel_rdb.h \
               dkbad.h \
               exec_elf.h exec_ecoff.h

HOST_CPPFLAGS+= -I${TOOLDIR}/include -I${TOOLDIR}/include/nbinclude

beforedepend:
       ${HOST_INSTALL_DIR} ${TOOLDIR}/include/nbinclude
       ${HOST_INSTALL_DIR} ${TOOLDIR}/include/nbinclude/sys
       ${HOST_INSTALL_DIR} ${TOOLDIR}/include/nbinclude/ufs
       ${HOST_INSTALL_DIR} ${TOOLDIR}/include/nbinclude/fs
       ${HOST_INSTALL_DIR} ${TOOLDIR}/include/nbinclude/fs/cd9660
       cd ${_ARCHDIR} && \
           ${TOOL_PAX} -s /include\\/// -rw ${_ARCH_INCS} \
           ${TOOLDIR}/include/nbinclude
       cd ${_INCDIR} && \
           ${TOOL_PAX} -rw ${_INCS} ${TOOLDIR}/include/nbinclude
       cd ${_SYSDIR} && \
           ${TOOL_PAX} -rw ${_SYSINCS} ${TOOLDIR}/include/nbinclude/sys
       cd ${_UFSDIR} && \
           ${TOOL_PAX} -rw ${_UFS_INCS} ${TOOLDIR}/include/nbinclude/ufs
       cd ${_FSDIR} && \
           ${TOOL_PAX} -rw ${_FS_INCS} ${TOOLDIR}/include/nbinclude/fs
       cd ${TOOLDIR}/include/nbinclude && rm -f machine && \
           ${HOST_INSTALL_SYMLINK} ${MACHINE} machine