all_hosts = Skeleton Linux Linux-SGX FreeBSD

ifeq ($(PAL_HOST),)
SYS := $(shell gcc -dumpmachine)
ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux)
PAL_HOST := Linux
else ifeq ($(findstring freebsd,$(SYS)),freebsd)
PAL_HOST := FreeBSD
else
$(error Unsupported platform: $(SYS))
endif
endif

# Set SGX=1 to build Graphene for SGX
ifeq ($(SGX)$(SGX_RUN),11)
	$(error "Do not use SGX=1 and SGX_RUN=1 at the same time")
endif
ifeq ($(SGX)$(SGX_RUN),1)
	PAL_HOST := $(patsubst %-SGX,%,$(PAL_HOST))-SGX
endif

ifeq ($(findstring $(PAL_HOST),$(all_hosts)),)
$(error Unsupported platform: $(PAL_HOST))
endif

export PAL_HOST
export PAL_HOST_MACRO = $(shell echo $(PAL_HOST) | tr '[:lower:]' '[:upper:]' | tr '-' '_')

.DEFAULT_GOAL := all
.PHONY: print_host
print_host:
	@echo $(PAL_HOST)
