#	mobile/userland -- the NetBSD programs of the phone
#
# docs/NETBSD-USERLAND.md (the plan), docs/PORTING-USERLAND.md (how to port
# one program).  Run through ../tools/mxmake.sh; from mobile/ that is
#     make userland [PROG=cat]
#
# The steps, in order:
#   mx-dirs    lay down the destdir hierarchy (mk/mx.dist) with nbmtree --
#              NetBSD's install(1) creates no directories; build.sh's
#              distrib-dirs does the same with src/etc/mtree/NetBSD.dist
#   mx-compat  src/tools/compat (libnbcompat) for the phone, uninstalled, in
#              its object directory; every port links it
#   mx-lib     lib/mxlinux (libmxlinux): the NetBSD interfaces glibc lacks,
#              NetBSD's own sources where they run; every port links it
#   the ports  every directory here with a Makefile, except mk/ -- found, not
#              listed, so two agents adding two ports never edit one file;
#              PROG=<dir> builds one

.include <bsd.own.mk>

.if defined(PROG) && !empty(PROG)
MX_PORTS=	${PROG}
.else
MX_PORTS!=	cd ${.CURDIR} && ls -d */Makefile 2>/dev/null | \
		    sed -e 's,/Makefile$$,,' -e '/^mk$$/d'
.endif

all: mx-dirs mx-compat mx-lib mx-ports

mx-dirs: .PHONY
	mkdir -p ${MX_DESTDIR}
	${TOOL_MTREE} -N ${NETBSDSRCDIR}/etc -deU -f ${.CURDIR}/mk/mx.dist \
	    -p ${MX_DESTDIR} >/dev/null

mx-compat: .PHONY
	cd ${NETBSDSRCDIR}/tools/compat && ${MAKE} obj && ${MAKE} dependall

mx-lib: .PHONY mx-compat
	cd ${.CURDIR}/lib/mxlinux && ${MAKE} obj && ${MAKE} dependall

mx-ports: .PHONY mx-dirs mx-compat mx-lib
.for p in ${MX_PORTS}
	@echo "===> userland ${p}"
	cd ${.CURDIR}/${p} && ${MAKE} obj && ${MAKE} dependall && ${MAKE} install
.endfor

clean cleandir: .PHONY
.for p in ${MX_PORTS}
	cd ${.CURDIR}/${p} && ${MAKE} ${.TARGET}
.endfor
