SUBDIRS :=

# SUBDIRS += ./public
SUBDIRS += ./protocol
SUBDIRS += ./system


define make_subdir
	@for subdir in $(SUBDIRS); do \
		if [ -f "$$subdir/makefile" ]; then \
			(cd "$$subdir" && make -f makefile $1) || exit 1; \
		fi; \
	done
endef

# 默认目标
.PHONY: all
all:
	$(call make_subdir,all)

# 测试目标
.PHONY: test
test:
	$(call make_subdir,test)

# 清理目标
.PHONY: clean
clean:
	@echo "make: removing targets and objects"
	$(call make_subdir,clean)

# 重新构建
.PHONY: rebuild
rebuild: clean all

# 显示帮助
.PHONY: help
help:
	@echo "Available targets:"
	@echo "  all     - Build all using both Makefile and Makefile_a"
	@echo "  test    - Run tests"
	@echo "  clean   - Clean all"
	@echo "  rebuild - Clean and rebuild"
	@echo "  help    - Show this help"