# ******************************************************************************
# Makefile: Builds all the test apps using nested makefiles
# Sealevel Systems, Inc.
# Dec 2025 - July 2026
# ******************************************************************************

APPDIR  ?= /usr/bin
MAN1DIR ?= /usr/share/man/man1
INCLUDE ?= $(shell pwd)/../driver/inc

CC      ?= /usr/bin/gcc
MKDIR   ?= /bin/mkdir
CP      ?= /bin/cp
RM      ?= /bin/rm
CHMOD   ?= /bin/chmod

## ============================================================================

# Run a nested make in all subdirs that have a Makefile.
# Any test app that isn't up to date will get (re)built.

# Get a list of all subdirs that have a Makefile of their own
SUBDIRS := $(sort $(dir $(wildcard */Makefile)))

.PHONY: all $(SUBDIRS)

all: $(SUBDIRS)

$(SUBDIRS):
	@echo "Building $@ .. "
	$(MAKE) -C $@ all


install:
	@for n in $(SUBDIRS); do $(MAKE) -s -C $$n install || exit 1; done

uninstall:
	@for n in $(SUBDIRS); do $(MAKE) -s -C $$n uninstall || exit 1; done

# Removes all temp build outputs like .o files. Executables are left alone.
clean:
	echo "Cleaning all"
	for dir in $(SUBDIRS); do \
		$(MAKE) -C $$dir clean; \
	done

# Removes all build outputs including executables
clobber:
	echo "Cleaning all"
	for dir in $(SUBDIRS); do \
		$(MAKE) -C $$dir clobber; \
	done
