In hindsight, config/ was not the best choice of names.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
--- /dev/null
+ROOT := $(abspath $(CURDIR)/../..)
+DESTDIR ?= $(ROOT)/dist/
+CC = gcc
+
+PV_ENVIRONMENTS := pv64 pv32
+HVM_ENVIRONMENTS := hvm64 hvm32
+ALL_ENVIRONMENTS := $(PV_ENVIRONMENTS) $(HVM_ENVIRONMENTS)
+
+pv64_arch := x86_64
+pv32_arch := x86_32
+hvm64_arch := x86_64
+hvm32_arch := x86_32
+
+COMMON_FLAGS := -pipe -I$(ROOT)/include -MMD -MP
+
+COMMON_AFLAGS := $(COMMON_FLAGS) -D__ASSEMBLY__
+COMMON_CFLAGS := $(COMMON_FLAGS) -Wall -Wextra -Werror -std=gnu99 -Wstrict-prototypes -O3 -g
+COMMON_CFLAGS += -fno-common -fno-asynchronous-unwind-tables -fno-strict-aliasing
+COMMON_CFLAGS += -fno-stack-protector -ffreestanding
+COMMON_CFLAGS += -mno-red-zone -mno-sse
+
+COMMON_AFLAGS-x86_32 := -m32
+COMMON_AFLAGS-x86_64 := -m64
+
+COMMON_CFLAGS-x86_32 := -m32
+COMMON_CFLAGS-x86_64 := -m64
+
+head-pv64 := $(ROOT)/arch/x86/boot/head_pv64.o
+head-pv32 := $(ROOT)/arch/x86/boot/head_pv32.o
+head-hvm64 := $(ROOT)/arch/x86/boot/head_hvm64.o
+head-hvm32 := $(ROOT)/arch/x86/boot/head_hvm32.o
+
+defcfg-pv := $(ROOT)/config/default-pv.cfg.in
+defcfg-hvm := $(ROOT)/config/default-hvm.cfg.in
+
+defcfg-pv64 := $(defcfg-pv)
+defcfg-pv32 := $(defcfg-pv)
+defcfg-hvm64 := $(defcfg-hvm)
+defcfg-hvm32 := $(defcfg-hvm)
+
+obj-perarch :=
+obj-perenv :=
+include $(ROOT)/build/files.mk
+
+# Run once per environment to set up some common bits & pieces
+define PERENV_setup
+
+AFLAGS_$($(1)_arch) := $$(COMMON_AFLAGS) $$(COMMON_AFLAGS-$($(1)_arch))
+CFLAGS_$($(1)_arch) := $$(COMMON_CFLAGS) $$(COMMON_CFLAGS-$($(1)_arch))
+
+AFLAGS_$(1) := $$(AFLAGS_$($(1)_arch)) $$(COMMON_AFLAGS-$(1)) -DCONFIG_ENV_$(1) -include arch/x86/config.h
+CFLAGS_$(1) := $$(CFLAGS_$($(1)_arch)) $$(COMMON_CFLAGS-$(1)) -DCONFIG_ENV_$(1) -include arch/x86/config.h
+
+link-$(1) := $(ROOT)/arch/x86/link-$(1).lds
+
+LDFLAGS_$(1) := -T $$(link-$(1))
+
+# Needs to pick up test-provided obj-perenv and obj-perarch
+DEPS-$(1) = $(head-$(1)) \
+ $$(obj-perarch:%.o=%-$($(1)_arch).o) \
+ $$(obj-$(1):%.o=%-$(1).o) $$(obj-perenv:%.o=%-$(1).o)
+
+# Generate head with approprate flags
+ifneq ($(findstring $(1),$(PV_ENVIRONMENTS)),)
+# PV guests generate head_pv64.o and head_pv32.o from head_pv.S
+%/head_$(1).o: %/head_pv.S
+ $$(CC) $$(AFLAGS_$(1)) -c $$< -o $$@
+endif
+ifneq ($(findstring $(1),$(HVM_ENVIRONMENTS)),)
+# HVM guests generate head_hvm64.o and head_hvm32.o from head_hvm.S
+%/head_$(1).o: %/head_hvm.S
+ $$(CC) $$(AFLAGS_$(1)) -c $$< -o $$@
+endif
+
+# Generate .lds with approprate flags
+%/link-$(1).lds: %/link.lds.S
+ $$(CC) -E $$(AFLAGS_$(1)) -P -C $$< -o $$@
+
+# Generate a per-arch .o from .S
+%-$($(1)_arch).o: %.S
+ $$(CC) $$(AFLAGS_$($(1)_arch)) -c $$< -o $$@
+
+# Generate a per-arch .o from .c
+%-$($(1)_arch).o: %.c
+ $$(CC) $$(CFLAGS_$($(1)_arch)) -c $$< -o $$@
+
+# Generate a per-env .o from .S
+%-$(1).o: %.S
+ $$(CC) $$(AFLAGS_$(1)) -c $$< -o $$@
+
+# Generate a per-env .o from .c
+%-$(1).o: %.c
+ $$(CC) $$(CFLAGS_$(1)) -c $$< -o $$@
+
+endef
+
+$(foreach env,$(ALL_ENVIRONMENTS),$(eval $(call PERENV_setup,$(env))))
+
--- /dev/null
+# Files compiled and linked for different architectures and environments
+#
+# obj-perarch get compiled once per architecture
+# obj-perenv get get compiled once for each environment
+# obj-$(env) are objects unique to a specific environment
+
+obj-perarch += $(ROOT)/common/console.o
+obj-perarch += $(ROOT)/common/lib.o
+obj-perarch += $(ROOT)/common/libc/string.o
+obj-perarch += $(ROOT)/common/libc/vsnprintf.o
+obj-perarch += $(ROOT)/common/report.o
+obj-perarch += $(ROOT)/common/setup.o
+
+obj-perenv += $(ROOT)/arch/x86/desc.o
+obj-perenv += $(ROOT)/arch/x86/setup.o
+obj-perenv += $(ROOT)/arch/x86/traps.o
+
+# Always link hypercall_page.S last as it is a page of data replaced by the hyperisor
+obj-perenv += $(ROOT)/arch/x86/hypercall_page.o
+
+# HVM specific objects
+obj-hvm += $(ROOT)/arch/x86/hvm_pagetables.o
+
+obj-hvm32 += $(obj-hvm)
+obj-hvm64 += $(obj-hvm)
--- /dev/null
+
+# Sanity checking of expected parameters
+
+ifeq ($(NAME),)
+$(error NAME should be specified)
+endif
+
+ifeq ($(TEST-ENVS),)
+$(error TEST-ENVS should not be empty)
+endif
+
+ifneq ($(filter-out $(ALL_ENVIRONMENTS),$(TEST-ENVS)),)
+$(error Unrecognised environments '$(filter-out $(ALL_ENVIRONMENTS),$(TEST-ENVS))')
+endif
+
+.PHONY: build
+build: $(foreach env,$(TEST-ENVS),test-$(env)-$(NAME) test-$(env)-$(NAME).cfg)
+
+.PHONY: install install-each-env
+install: install-each-env
+
+define PERENV_build
+
+ifneq ($(1),hvm64)
+# Generic link line for most environments
+test-$(1)-$(NAME): $$(DEPS-$(1)) $$(link-$(1))
+ $$(LD) $$(LDFLAGS_$(1)) $$(DEPS-$(1)) -o $$@
+else
+# hvm64 needs linking normally, then converting to elf32-x86-64
+test-$(1)-$(NAME): $$(DEPS-$(1)) $$(link-$(1))
+ $$(LD) $$(LDFLAGS_$(1)) $$(DEPS-$(1)) -o $$@.tmp
+ objcopy $$@.tmp -O elf32-x86-64 $$@
+ rm -f $$@.tmp
+endif
+
+cfg-$(1) ?= $(defcfg-$(1))
+
+test-$(1)-$(NAME).cfg: $$(cfg-$(1))
+ sed -e "s/@@NAME@@/$$(NAME)/g" \
+ -e "s/@@ENV@@/$(1)/g" \
+ < $$< > $$@
+
+-include $$(link-$(1):%.lds=%.d)
+-include $$(DEPS-$(1):%.o=%.d)
+
+.PHONY: install-$(1) install-$(1).cfg
+install-$(1): test-$(1)-$(NAME)
+ @mkdir -p $(DESTDIR)
+ install -m775 -p $$< $(DESTDIR)
+
+install-$(1).cfg: test-$(1)-$(NAME).cfg
+ @mkdir -p $(DESTDIR)
+ install -m664 -p $$< $(DESTDIR)
+
+install-each-env: install-$(1) install-$(1).cfg
+
+endef
+$(foreach env,$(TEST-ENVS),$(eval $(call PERENV_build,$(env))))
+
+.PHONY: clean
+clean:
+ find $(ROOT) \( -name "*.o" -o -name "*.d" \) -delete
+ rm -f $(foreach env,$(TEST-ENVS),test-$(env)-$(NAME) test-$(env)-$(NAME).cfg)
+
+.PHONY: %var
+%var:
+ @echo "$* = $($*)"
+++ /dev/null
-ROOT := $(abspath $(CURDIR)/../..)
-DESTDIR ?= $(ROOT)/dist/
-CC = gcc
-
-PV_ENVIRONMENTS := pv64 pv32
-HVM_ENVIRONMENTS := hvm64 hvm32
-ALL_ENVIRONMENTS := $(PV_ENVIRONMENTS) $(HVM_ENVIRONMENTS)
-
-pv64_arch := x86_64
-pv32_arch := x86_32
-hvm64_arch := x86_64
-hvm32_arch := x86_32
-
-COMMON_FLAGS := -pipe -I$(ROOT)/include -MMD -MP
-
-COMMON_AFLAGS := $(COMMON_FLAGS) -D__ASSEMBLY__
-COMMON_CFLAGS := $(COMMON_FLAGS) -Wall -Wextra -Werror -std=gnu99 -Wstrict-prototypes -O3 -g
-COMMON_CFLAGS += -fno-common -fno-asynchronous-unwind-tables -fno-strict-aliasing
-COMMON_CFLAGS += -fno-stack-protector -ffreestanding
-COMMON_CFLAGS += -mno-red-zone -mno-sse
-
-COMMON_AFLAGS-x86_32 := -m32
-COMMON_AFLAGS-x86_64 := -m64
-
-COMMON_CFLAGS-x86_32 := -m32
-COMMON_CFLAGS-x86_64 := -m64
-
-head-pv64 := $(ROOT)/arch/x86/boot/head_pv64.o
-head-pv32 := $(ROOT)/arch/x86/boot/head_pv32.o
-head-hvm64 := $(ROOT)/arch/x86/boot/head_hvm64.o
-head-hvm32 := $(ROOT)/arch/x86/boot/head_hvm32.o
-
-defcfg-pv := $(ROOT)/config/default-pv.cfg.in
-defcfg-hvm := $(ROOT)/config/default-hvm.cfg.in
-
-defcfg-pv64 := $(defcfg-pv)
-defcfg-pv32 := $(defcfg-pv)
-defcfg-hvm64 := $(defcfg-hvm)
-defcfg-hvm32 := $(defcfg-hvm)
-
-obj-perarch :=
-obj-perenv :=
-include $(ROOT)/config/files.mk
-
-# Run once per environment to set up some common bits & pieces
-define PERENV_setup
-
-AFLAGS_$($(1)_arch) := $$(COMMON_AFLAGS) $$(COMMON_AFLAGS-$($(1)_arch))
-CFLAGS_$($(1)_arch) := $$(COMMON_CFLAGS) $$(COMMON_CFLAGS-$($(1)_arch))
-
-AFLAGS_$(1) := $$(AFLAGS_$($(1)_arch)) $$(COMMON_AFLAGS-$(1)) -DCONFIG_ENV_$(1) -include arch/x86/config.h
-CFLAGS_$(1) := $$(CFLAGS_$($(1)_arch)) $$(COMMON_CFLAGS-$(1)) -DCONFIG_ENV_$(1) -include arch/x86/config.h
-
-link-$(1) := $(ROOT)/arch/x86/link-$(1).lds
-
-LDFLAGS_$(1) := -T $$(link-$(1))
-
-# Needs to pick up test-provided obj-perenv and obj-perarch
-DEPS-$(1) = $(head-$(1)) \
- $$(obj-perarch:%.o=%-$($(1)_arch).o) \
- $$(obj-$(1):%.o=%-$(1).o) $$(obj-perenv:%.o=%-$(1).o)
-
-# Generate head with approprate flags
-ifneq ($(findstring $(1),$(PV_ENVIRONMENTS)),)
-# PV guests generate head_pv64.o and head_pv32.o from head_pv.S
-%/head_$(1).o: %/head_pv.S
- $$(CC) $$(AFLAGS_$(1)) -c $$< -o $$@
-endif
-ifneq ($(findstring $(1),$(HVM_ENVIRONMENTS)),)
-# HVM guests generate head_hvm64.o and head_hvm32.o from head_hvm.S
-%/head_$(1).o: %/head_hvm.S
- $$(CC) $$(AFLAGS_$(1)) -c $$< -o $$@
-endif
-
-# Generate .lds with approprate flags
-%/link-$(1).lds: %/link.lds.S
- $$(CC) -E $$(AFLAGS_$(1)) -P -C $$< -o $$@
-
-# Generate a per-arch .o from .S
-%-$($(1)_arch).o: %.S
- $$(CC) $$(AFLAGS_$($(1)_arch)) -c $$< -o $$@
-
-# Generate a per-arch .o from .c
-%-$($(1)_arch).o: %.c
- $$(CC) $$(CFLAGS_$($(1)_arch)) -c $$< -o $$@
-
-# Generate a per-env .o from .S
-%-$(1).o: %.S
- $$(CC) $$(AFLAGS_$(1)) -c $$< -o $$@
-
-# Generate a per-env .o from .c
-%-$(1).o: %.c
- $$(CC) $$(CFLAGS_$(1)) -c $$< -o $$@
-
-endef
-
-$(foreach env,$(ALL_ENVIRONMENTS),$(eval $(call PERENV_setup,$(env))))
-
+++ /dev/null
-# Files compiled and linked for different architectures and environments
-#
-# obj-perarch get compiled once per architecture
-# obj-perenv get get compiled once for each environment
-# obj-$(env) are objects unique to a specific environment
-
-obj-perarch += $(ROOT)/common/console.o
-obj-perarch += $(ROOT)/common/lib.o
-obj-perarch += $(ROOT)/common/libc/string.o
-obj-perarch += $(ROOT)/common/libc/vsnprintf.o
-obj-perarch += $(ROOT)/common/report.o
-obj-perarch += $(ROOT)/common/setup.o
-
-obj-perenv += $(ROOT)/arch/x86/desc.o
-obj-perenv += $(ROOT)/arch/x86/setup.o
-obj-perenv += $(ROOT)/arch/x86/traps.o
-
-# Always link hypercall_page.S last as it is a page of data replaced by the hyperisor
-obj-perenv += $(ROOT)/arch/x86/hypercall_page.o
-
-# HVM specific objects
-obj-hvm += $(ROOT)/arch/x86/hvm_pagetables.o
-
-obj-hvm32 += $(obj-hvm)
-obj-hvm64 += $(obj-hvm)
+++ /dev/null
-
-# Sanity checking of expected parameters
-
-ifeq ($(NAME),)
-$(error NAME should be specified)
-endif
-
-ifeq ($(TEST-ENVS),)
-$(error TEST-ENVS should not be empty)
-endif
-
-ifneq ($(filter-out $(ALL_ENVIRONMENTS),$(TEST-ENVS)),)
-$(error Unrecognised environments '$(filter-out $(ALL_ENVIRONMENTS),$(TEST-ENVS))')
-endif
-
-.PHONY: build
-build: $(foreach env,$(TEST-ENVS),test-$(env)-$(NAME) test-$(env)-$(NAME).cfg)
-
-.PHONY: install install-each-env
-install: install-each-env
-
-define PERENV_build
-
-ifneq ($(1),hvm64)
-# Generic link line for most environments
-test-$(1)-$(NAME): $$(DEPS-$(1)) $$(link-$(1))
- $$(LD) $$(LDFLAGS_$(1)) $$(DEPS-$(1)) -o $$@
-else
-# hvm64 needs linking normally, then converting to elf32-x86-64
-test-$(1)-$(NAME): $$(DEPS-$(1)) $$(link-$(1))
- $$(LD) $$(LDFLAGS_$(1)) $$(DEPS-$(1)) -o $$@.tmp
- objcopy $$@.tmp -O elf32-x86-64 $$@
- rm -f $$@.tmp
-endif
-
-cfg-$(1) ?= $(defcfg-$(1))
-
-test-$(1)-$(NAME).cfg: $$(cfg-$(1))
- sed -e "s/@@NAME@@/$$(NAME)/g" \
- -e "s/@@ENV@@/$(1)/g" \
- < $$< > $$@
-
--include $$(link-$(1):%.lds=%.d)
--include $$(DEPS-$(1):%.o=%.d)
-
-.PHONY: install-$(1) install-$(1).cfg
-install-$(1): test-$(1)-$(NAME)
- @mkdir -p $(DESTDIR)
- install -m775 -p $$< $(DESTDIR)
-
-install-$(1).cfg: test-$(1)-$(NAME).cfg
- @mkdir -p $(DESTDIR)
- install -m664 -p $$< $(DESTDIR)
-
-install-each-env: install-$(1) install-$(1).cfg
-
-endef
-$(foreach env,$(TEST-ENVS),$(eval $(call PERENV_build,$(env))))
-
-.PHONY: clean
-clean:
- find $(ROOT) \( -name "*.o" -o -name "*.d" \) -delete
- rm -f $(foreach env,$(TEST-ENVS),test-$(env)-$(NAME) test-$(env)-$(NAME).cfg)
-
-.PHONY: %var
-%var:
- @echo "$* = $($*)"
ROOT := $(abspath $(CURDIR)/../..)
-include $(ROOT)/config/common.mk
+include $(ROOT)/build/common.mk
NAME := example
TEST-ENVS := $(ALL_ENVIRONMENTS)
obj-perenv += main.o
-include $(ROOT)/config/gen.mk
+include $(ROOT)/build/gen.mk