Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions tools/lkl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,9 @@ export CFLAGS += -I$(OUTPUT)/include -Iinclude -Wall -g -O2 -Wextra \

include Targets

# Expand targets to output location and suffix but preserve special
# targets (e.g. .WAIT)
# $1 - targets
# $2 - suffix
expand-targets = $(foreach t,$(1),$(if $(filter .%,$(t)),$(t),$(OUTPUT)$(t)$(2)))

TARGETS := $(call expand-targets,$(progs-y),$(EXESUF))
TARGETS += $(call expand-targets,$(tests-y),$(EXESUF))
TARGETS += $(call expand-targets,$(libs-y),$(SOSUF))
TARGETS := $(progs-y:%=$(OUTPUT)%$(EXESUF))
TARGETS := $(tests-y:%=$(OUTPUT)%$(EXESUF))
TARGETS += $(libs-y:%=$(OUTPUT)%$(SOSUF))
all: $(TARGETS)

# this workaround is for FreeBSD
Expand All @@ -87,25 +81,29 @@ $(OUTPUT)lib/lkl.o: bin/stat $(DOT_CONFIG)
$(MAKE) -C ../.. ARCH=lkl $(KOPT)
$(MAKE) -C ../.. ARCH=lkl $(KOPT) install INSTALL_PATH=$(OUTPUT)

# rules to link libs
# rules to link hijack libs
$(OUTPUT)%$(SOSUF): LDFLAGS += -shared
$(OUTPUT)%$(SOSUF): $(OUTPUT)%-in.o $(OUTPUT)liblkl.a
$(OUTPUT)%$(SOSUF): $(priv-libs-y:%=$(OUTPUT)%-in.o) $(OUTPUT)%-in.o $(OUTPUT)liblkl.a
$(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y)

# liblkl is special
$(OUTPUT)liblkl$(SOSUF): $(OUTPUT)%-in.o $(OUTPUT)lib/lkl.o
$(OUTPUT)lib/liblkl$(SOSUF): $(OUTPUT)lib/liblkl-in.o $(OUTPUT)lib/lkl.o
$(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y)

$(OUTPUT)liblkl.a: $(OUTPUT)lib/liblkl-in.o $(OUTPUT)lib/lkl.o
$(QUIET_AR)$(AR) -rc $@ $^

# rule to link programs
$(OUTPUT)%$(EXESUF): $(OUTPUT)%-in.o $(OUTPUT)liblkl.a
$(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y)

# tests use a common private lib
$(tests-y:%=$(OUTPUT)%$(EXESUF)): $(tests-priv-y:%=$(OUTPUT)%-in.o)

# rule to build objects
$(OUTPUT)%-in.o: $(OUTPUT)lib/lkl.o FORCE
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*)


$(OUTPUT)cpfromfs$(EXESUF): cptofs$(EXESUF)
$(Q)if ! [ -e $@ ]; then ln -s $< $@; fi

Expand Down Expand Up @@ -181,7 +179,7 @@ libraries_install: $(libs-y:%=$(OUTPUT)%$(SOSUF)) $(OUTPUT)liblkl.a
install -d $(DESTDIR)$(LIBDIR) ; \
install -m 644 $^ $(DESTDIR)$(LIBDIR)

programs_install: $(call expand-targets,$(progs-y),$(EXESUF))
programs_install: $(progs-y:%=$(OUTPUT)%$(EXESUF))
$(call QUIET_INSTALL, programs) \
install -d $(DESTDIR)$(BINDIR) ; \
install -m 755 $^ $(DESTDIR)$(BINDIR)
Expand All @@ -197,4 +195,3 @@ FORCE: ;
.PHONY: headers_install libraries_install programs_install install
.NOTPARALLEL : lib/lkl.o
.SECONDARY:
.WAIT:
8 changes: 4 additions & 4 deletions tools/lkl/Targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
libs-y += lib/liblkl

ifneq ($(LKL_HOST_CONFIG_BSD),y)
priv-libs-$(LKL_HOST_CONFIG_POSIX) += lib/hijack/libhijack-priv
libs-$(LKL_HOST_CONFIG_POSIX) += lib/hijack/liblkl-hijack
libs-$(LKL_HOST_CONFIG_POSIX) += lib/hijack/liblkl-zpoline
endif
Expand All @@ -26,11 +27,10 @@ LDLIBS_cptofs-y := -larchive
LDLIBS_cptofs-$(LKL_HOST_CONFIG_NEEDS_LARGP) += -largp

# tools/build/Makefile.build does not support parallel builds when
# objects are shared between build objects so keep the test that uses
# the most common object first and insert a build barrier to avoid
# rebuilding common objects
# objects are shared between build objects so use tests-common-in.o
# as a tests build prerequisite which gets linked into each binary.
tests-priv-y := tests/tests-common
tests-y := tests/disk
tests-y += .WAIT
tests-y += tests/boot
tests-y += tests/disk-vfio-pci
tests-y += tests/net-test
Expand Down
13 changes: 5 additions & 8 deletions tools/lkl/lib/hijack/Build
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
libhijack-priv-y += hijack.o
libhijack-priv-y += init.o
libhijack-priv-y += xlate.o
libhijack-priv-y += dbg_handler.o

liblkl-hijack-y += preload.o
liblkl-hijack-y += hijack.o
liblkl-hijack-y += init.o
liblkl-hijack-y += xlate.o
liblkl-hijack-y += dbg_handler.o

liblkl-zpoline-y += zpoline.o
liblkl-zpoline-y += hijack.o
liblkl-zpoline-y += init.o
liblkl-zpoline-y += xlate.o
liblkl-zpoline-y += dbg_handler.o

# -std=gnu23/c23 fails due to HOST_CALL (*host_##name)()
CFLAGS_hijack.o += -std=gnu11
13 changes: 7 additions & 6 deletions tools/lkl/tests/Build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
boot-y += boot.o test.o
disk-y += disk.o cla.o test.o
disk-vfio-pci-y += disk-vfio-pci.o cla.o test.o
net-test-y += net-test.o cla.o test.o
config-y += config.o test.o
test-dlmopen-y += test-dlmopen.o test.o
tests-common-y += cla.o test.o
boot-y += boot.o
disk-y += disk.o
disk-vfio-pci-y += disk-vfio-pci.o
net-test-y += net-test.o
config-y += config.o
test-dlmopen-y += test-dlmopen.o
Loading