]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
inmates: Build library archive and link it implicitly
authorJan Kiszka <jan.kiszka@siemens.com>
Sat, 9 May 2015 14:57:08 +0000 (16:57 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Fri, 15 May 2015 07:14:00 +0000 (09:14 +0200)
Kbuild already comes with support for building lib.a archives from a set
of objects. Use this to build inmate libraries for x86, here in 64 and
32-bit form, and for ARM. Link against the correct libraries implicitly
so that the demos no longer have to state their dependencies explicitly.

This will also allow to use the inmate libraries from different folders
than demos because the library objects are now only built once.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
.gitignore
inmates/Makefile
inmates/demos/arm/Makefile
inmates/demos/x86/Makefile
inmates/lib/arm/Makefile [new file with mode: 0644]
inmates/lib/arm/Makefile.lib
inmates/lib/x86/Makefile [new file with mode: 0644]
inmates/lib/x86/Makefile.lib

index 14b28e5a4b968bf34b05f0f4361fd1f152c25520..a3af93a8e68bd84c68aad5394bb9ce1e09f4fc60 100644 (file)
@@ -1,4 +1,4 @@
-*.o
+*.[oa]
 *.mod.[co]
 *.cmd
 *.bin
index cf1d124f8bed777339cc7bd8852f66018821c860..012627a33f4174764ec5b2981a9eefbe5fa67044 100644 (file)
@@ -30,4 +30,7 @@ endif
 OBJCOPYFLAGS := -O binary
 LDFLAGS += -T
 
-subdir-y := demos/$(SRCARCH)
+subdir-y := lib/$(SRCARCH) demos/$(SRCARCH)
+
+# demos depend on the library
+$(obj)/demos/$(SRCARCH): $(obj)/lib/$(SRCARCH)
index 020deae6b9634795595acf482818d4e5f8b4d2f6..b0fda4edc6894ef095dde5ff9f7feed4ac4fda58 100644 (file)
 
 include $(INMATES_LIB)/Makefile.lib
 
-LIBDIR := ../../lib/arm
-
 INMATES := gic-demo.bin uart-demo.bin
 
-gic-demo-y := gic-demo.o \
-       $(addprefix $(LIBDIR)/,header.o printk.o gic.o $(DRIVERS))
-
-uart-demo-y := uart-demo.o \
-       $(addprefix $(LIBDIR)/,header.o printk.o $(DRIVERS))
+gic-demo-y     := gic-demo.o
+uart-demo-y    := uart-demo.o
 
 $(eval $(call DECLARE_TARGETS,$(INMATES)))
index 2a96bd9848485c658cc9bef79d4fa20bc42fa286..110501f0e7e5c54bc7a848cd7b1e0a218a2f94a5 100644 (file)
 
 include $(INMATES_LIB)/Makefile.lib
 
-LIBDIR := ../../lib/x86
-
 INMATES := tiny-demo.bin apic-demo.bin ioapic-demo.bin 32-bit-demo.bin \
        pci-demo.bin e1000-demo.bin ivshmem-demo.bin
 
-tiny-demo-y := tiny-demo.o \
-       $(LIBDIR)/header.o $(LIBDIR)/printk.o $(LIBDIR)/timing.o
-
-apic-demo-y := apic-demo.o \
-       $(LIBDIR)/header.o $(LIBDIR)/printk.o $(LIBDIR)/timing.o \
-       $(LIBDIR)/int.o
-
-ioapic-demo-y := ioapic-demo.o \
-       $(LIBDIR)/header.o $(LIBDIR)/printk.o $(LIBDIR)/mem.o \
-       $(LIBDIR)/int.o $(LIBDIR)/ioapic.o
+tiny-demo-y    := tiny-demo.o
+apic-demo-y    := apic-demo.o
+ioapic-demo-y  := ioapic-demo.o
+pci-demo-y     := pci-demo.o
+e1000-demo-y   := e1000-demo.o
+ivshmem-demo-y := ivshmem-demo.o
 
 $(eval $(call DECLARE_32_BIT,32-bit-demo))
-32-bit-demo-y := 32-bit-demo.o \
-       $(LIBDIR)/header-32.o $(LIBDIR)/printk-32.o
-
-pci-demo-y := pci-demo.o \
-       $(LIBDIR)/header.o $(LIBDIR)/printk.o $(LIBDIR)/mem.o \
-       $(LIBDIR)/int.o $(LIBDIR)/pci.o $(LIBDIR)/timing.o
-
-e1000-demo-y := e1000-demo.o \
-       $(LIBDIR)/header.o $(LIBDIR)/printk.o $(LIBDIR)/mem.o \
-       $(LIBDIR)/pci.o $(LIBDIR)/timing.o
-
-ivshmem-demo-y := ivshmem-demo.o \
-       $(LIBDIR)/header.o $(LIBDIR)/printk.o $(LIBDIR)/mem.o \
-       $(LIBDIR)/int.o $(LIBDIR)/pci.o $(LIBDIR)/timing.o
+32-bit-demo-y  := 32-bit-demo.o
 
 $(eval $(call DECLARE_TARGETS,$(INMATES)))
diff --git a/inmates/lib/arm/Makefile b/inmates/lib/arm/Makefile
new file mode 100644 (file)
index 0000000..8478a49
--- /dev/null
@@ -0,0 +1,22 @@
+#
+# Jailhouse, a Linux-based partitioning hypervisor
+#
+# Copyright (c) Siemens AG, 2015
+#
+# Authors:
+#  Jan Kiszka <jan.kiszka@siemens.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+
+include $(INMATES_LIB)/Makefile.lib
+
+always := lib.a
+
+lib-y                          := header.o gic.o printk.o
+lib-$(CONFIG_ARM_GIC)          += gic-v2.o
+lib-$(CONFIG_ARM_GIC_V3)       += gic-v3.o
+lib-$(CONFIG_SERIAL_AMBA_PL011)        += uart-pl011.o
+lib-$(CONFIG_SERIAL_8250_DW)   += uart-8250-dw.o
+lib-$(CONFIG_SERIAL_TEGRA)     += uart-tegra.o
index 0393d8a1a2712d422db826b2443ef80c3d5b01d8..9510ff88cd7a66e7e3e67f029fa58dad84a30522 100644 (file)
@@ -31,14 +31,7 @@ mach-$(CONFIG_MACH_VEXPRESS)         := vexpress
 mach-$(CONFIG_MACH_SUN7I)              := sun7i
 mach-$(CONFIG_MACH_TEGRA124)           := tegra124
 
-gic-$(CONFIG_ARM_GIC)                  := gic-v2.o
-gic-$(CONFIG_ARM_GIC_V3)               := gic-v3.o
-uart-$(CONFIG_SERIAL_AMBA_PL011)       := uart-pl011.o
-uart-$(CONFIG_SERIAL_8250_DW)          := uart-8250-dw.o
-uart-$(CONFIG_SERIAL_TEGRA)            := uart-tegra.o
-
 MACHINE                                        := mach-$(mach-y)
-DRIVERS                                        := $(gic-y) $(uart-y)
 KBUILD_CFLAGS                          += -I$(INMATES_LIB)/include/$(MACHINE)
 KBUILD_AFLAGS                          += -I$(INMATES_LIB)/include/$(MACHINE)
 
@@ -46,7 +39,8 @@ KBUILD_AFLAGS                         += -I$(INMATES_LIB)/include/$(MACHINE)
 .SECONDARY: $(addprefix $(obj)/,$(targets))
 
 .SECONDEXPANSION:
-$(obj)/%-linked.o: $(INMATES_LIB)/inmate.lds $$(addprefix $$(obj)/,$$($$*-y))
+$(obj)/%-linked.o: $(INMATES_LIB)/inmate.lds $$(addprefix $$(obj)/,$$($$*-y)) \
+                  $(INMATES_LIB)/lib.a
        $(call if_changed,ld)
 
 $(obj)/%.bin: $(obj)/%-linked.o
diff --git a/inmates/lib/x86/Makefile b/inmates/lib/x86/Makefile
new file mode 100644 (file)
index 0000000..dda825e
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# Jailhouse, a Linux-based partitioning hypervisor
+#
+# Copyright (c) Siemens AG, 2015
+#
+# Authors:
+#  Jan Kiszka <jan.kiszka@siemens.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+
+always := lib.a lib32.a
+
+TARGETS := header.o hypercall.o ioapic.o printk.o
+TARGETS_64_ONLY := int.o mem.o pci.o timing.o
+
+lib-y := $(TARGETS) $(TARGETS_64_ONLY)
+
+lib32-y := $(addprefix $(obj)/,$(TARGETS:.o=-32.o))
+
+quiet_cmd_link_archive32 = AR      $@
+cmd_link_archive32 = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib32-y)
+
+$(obj)/lib32.a: $(lib32-y)
+       $(call if_changed,link_archive32)
+
+AFLAGS_header-32.o := -m32
+targets += header-32.o
+
+$(obj)/%-32.o: c_flags += -m32
+$(obj)/%-32.o: $(src)/%.c
+       $(call if_changed_rule,cc_o_c)
index 6088f97d79fae449724e89f04ffd657eaae8a2a2..3679614a0b0da93383c6242d5277743f8709a96a 100644 (file)
@@ -23,9 +23,10 @@ endef
 # prevent deleting intermediate files which would cause rebuilds
 .SECONDARY: $(addprefix $(obj)/,$(targets))
 
-# obj/NAME-linked.o: ... obj/$(NAME-y)
+# obj/NAME-linked.o: ... obj/$(NAME-y) lib/lib[32].a
 .SECONDEXPANSION:
-$(obj)/%-linked.o: $(INMATES_LIB)/inmate.lds $$(addprefix $$(obj)/,$$($$*-y))
+$(obj)/%-linked.o: $(INMATES_LIB)/inmate.lds $$(addprefix $$(obj)/,$$($$*-y)) \
+                  $(INMATES_LIB)/$$(if $$($$*_32),lib32.a,lib.a)
        $(call if_changed,ld)
 
 $(obj)/%.bin: $(obj)/%-linked.o
@@ -35,10 +36,5 @@ $(obj)/%.bin: $(obj)/%-linked.o
 define DECLARE_32_BIT =
  CFLAGS_$(1).o := -m32
  LDFLAGS_$(1)-linked.o := /dev/null -m elf_i386 -T
+ $(1)_32 := y
 endef
-
-AFLAGS_header-32.o := -m32
-
-$(obj)/%-32.o: c_flags += -m32
-$(obj)/%-32.o: $(obj)/%.c
-       $(call if_changed_rule,cc_o_c)