#
# Common make for acpica tools and utilities
#

#
# Get the OS machine architecture. Anything with a "64" in the returned
# string will be treated as a 64-bit OS. Otherwise, the default is 32-bit.
#
ifeq ($(HOST), _FreeBSD)
HARDWARE_NAME := $(shell uname -p)
else
HARDWARE_NAME := $(shell uname -m)
endif

#
# Main rule will only generate versions that are appropriate for the running
# OS, either 64-bit or 32-bit.
#
all:	$(PROGS)
$(PROGS): FORCE
	@cd $(BUILD_DIRECTORY_PATH)/$@; \
	mkdir -p obj; \
	$(MAKE) || exit "$$?"; \
	if [ $(findstring 64,$(HARDWARE_NAME)) ]; then \
		echo "64-bit version of $@:"; \
	else \
		echo "32-bit version of $@:"; \
	fi; \
	ls -al ../bin/$@; \
	echo "";

#
# Simple clean removes all .obj files, but leaves the executables
# in the local bin directory
#
clean:	FORCE
	@for toolname in $(PROGS); do \
		(cd $(BUILD_DIRECTORY_PATH)/$$toolname; \
		if [ -d "obj" ] ; then \
			echo "Removing $$toolname:"; \
			pwd; \
			$(MAKE) clean; \
			rmdir obj; \
			echo ""; \
		fi; \
		); \
	done;

#
# Very clean removes all executables and the local bin directory
#
veryclean:	FORCE
	@for toolname in $(PROGS); do \
		(cd $(BUILD_DIRECTORY_PATH)/$$toolname; \
		if [ -d "obj" ] ; then \
			echo "Removing $$toolname:"; \
			pwd; \
			$(MAKE) clean; \
			rmdir obj; \
			echo ""; \
		fi; \
		); \
		if [ -e "$(BUILD_DIRECTORY_PATH)/bin/$$toolname" ] ; then \
			rm $(BUILD_DIRECTORY_PATH)/bin/$$toolname; \
		fi; \
	done; \
	if [ -d "bin" ] ; then \
		rmdir bin; \
	fi;

#
# Install all tools, either 32-bit or 64-bit as appropriate for the host OS
#
install:	FORCE
	@for toolname in $(PROGS); do \
		(cd $(BUILD_DIRECTORY_PATH)/$$toolname; \
		pwd; \
		$(MAKE) PROG=$$toolname install; \
		if [ $(findstring 64,$(HARDWARE_NAME)) ]; then \
			echo "Installed 64-bit version of $$toolname"; \
		else \
			echo "Installed 32-bit version of $$toolname"; \
		fi; \
		echo ""; \
		); \
	done;

machine:	FORCE
	@echo "Machine architecture: $(HARDWARE_NAME), $(XBITS)";
	@echo "Findstring: $(findstring 64, $(HARDWARE_NAME))";

FORCE:

