| 1 | DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) |
| 2 | DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH) |
| 3 | DEB_HOST_ARCH_BITS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_BITS) |
| 4 | |
| 5 | prefix?=/usr |
| 6 | exec_prefix?=$(prefix) |
| 7 | DESTDIR?= |
| 8 | libexecdir?=$(exec_prefix)/libexec |
| 9 | archlibexecdir?=$(exec_prefix)/libexec/$(DEB_HOST_MULTIARCH) |
| 10 | INSTALL?=install |
| 11 | |
| 12 | uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) |
| 13 | |
| 14 | ISAS_ARCH_LIST:=$(shell cat isa-list | grep '^Architecture:' | cut -d ':' -f2 | sort -u) |
| 15 | ISAS_ARCH_FORUS:=$(call uniq, $(foreach isaarch, $(ISAS_ARCH_LIST), $(shell dpkg-architecture -a $(DEB_HOST_ARCH) -i $(isaarch) && echo $(isaarch)))) |
| 16 | ISAS_ARCH_FORUS_GREP:=$(foreach isa, $(ISAS_ARCH_FORUS), -e '^Architecture:.*[[:space:]]$(isa)') |
| 17 | |
| 18 | ISAS:= $(shell cat isa-list | grep -A1 ^Name | grep -B1 $(ISAS_ARCH_FORUS_GREP) -e 'FakeArchIsEmptySet' | grep ^Name | cut -d ' ' -f2) |
| 19 | |
| 20 | |
| 21 | |
| 22 | TEST_BINARIES = $(foreach isa,$(ISAS),test-$(isa)) |
| 23 | QEMU_BINARIES = $(foreach type,good bad,$(foreach isa,$(ISAS),qemu-$(type)-$(isa))) |
| 24 | TEST_SOURCES = $(foreach isa,$(ISAS),test-$(isa).c) |
| 25 | |
| 26 | GENERATED_FILES += $(foreach isa,$(ISAS),debian/$(isa).docs) |
| 27 | GENERATED_FILES += $(foreach isa,$(ISAS),debian/$(isa).lintian-overrides) |
| 28 | GENERATED_FILES += $(foreach isa,$(ISAS),debian/$(isa).preinst) |
| 29 | GENERATED_FILES += $(foreach isa,$(ISAS),debian/$(isa).templates) |
| 30 | GENERATED_FILES += $(TEST_SOURCES) |
| 31 | ALL_GENERATED_FILES += $(GENERATED_FILES) debian/control |
| 32 | ALL_BINARIES = $(TEST_BINARIES) $(QEMU_BINARIES) |
| 33 | |
| 34 | INPUT_FILES = $(wildcard debian/*.in) |
| 35 | |
| 36 | CFLAGS ?= |
| 37 | CFLAGS += -Wall |
| 38 | CFLAGS += $(shell cat isa-list | sed -e 's/^Name: /Name: test-/' | grep $@ -A3 | grep '^CFLAGS:' | cut -d ' ' -f2-) |
| 39 | |
| 40 | all: $(TEST_BINARIES) |
| 41 | @: |
| 42 | |
| 43 | clean: |
| 44 | rm -f $(GENERATED_FILES) |
| 45 | rm -f $(ALL_BINARIES) |
| 46 | rm -f .last-refresh |
| 47 | |
| 48 | install: |
| 49 | mkdir -p $(DESTDIR)/$(archlibexecdir)/isa-support |
| 50 | for bin in $(TEST_BINARIES); do $(INSTALL) $$bin $(DESTDIR)/$(archlibexecdir)/isa-support; done |
| 51 | for bin in $(QEMU_BINARIES); do if test -e $$bin; then $(INSTALL) $$bin $(DESTDIR)/$(archlibexecdir)/isa-support; fi; done |
| 52 | |
| 53 | check: |
| 54 | ifeq ($(DEB_HOST_ARCH_BITS),64) |
| 55 | set -e ;for isa in $(ISAS); do \ |
| 56 | if test -e qemu-good-$$isa; then \ |
| 57 | echo "Test $$isa"; \ |
| 58 | echo "Test good"; \ |
| 59 | sh ./qemu-good-$$isa ./test-$$isa && echo 'ok'; \ |
| 60 | echo "Test bad"; \ |
| 61 | sh ./qemu-bad-$$isa ./test-$$isa || echo 'ok'; \ |
| 62 | fi; \ |
| 63 | done; |
| 64 | else |
| 65 | echo 'skip in host arch 32 bits' |
| 66 | endif |
| 67 | |
| 68 | refresh: $(ALL_GENERATED_FILES) $(TEST_SOURCES) |
| 69 | @: |
| 70 | |
| 71 | $(GENERATED_FILES): .last-refresh |
| 72 | @: |
| 73 | |
| 74 | .last-refresh: refresh-package $(INPUT_FILES) |
| 75 | ./refresh-package |
| 76 | touch $@ |
| 77 | |
| 78 | .PHONY: all clean refresh |