wireguard: clean up build order/structure

- Move C++ sources from lib/wireguard to app/wireguard, which require
  Genode include paths (that conflict with linux)
- Rename lib/wireguard_lx_inc_dirs to lib/wireguard, which builds linux
  sources with linux include paths
This commit is contained in:
Christian Helmuth 2024-06-04 17:21:53 +02:00 committed by Norman Feske
parent 2580045a83
commit 791dd38160
11 changed files with 127 additions and 142 deletions

View File

@ -1,3 +1,25 @@
INC_DIR += $(REP_DIR)/src/include/spec/arm_v8
#
# For documentation see $(REP_DIR)/lib/mk/wireguard.inc
#
PRG_TOP_DIR := $(REP_DIR)/src/app/wireguard
PRG_DIR := $(PRG_TOP_DIR)/spec/arm_v8
DDE_LINUX_DIR := $(subst /src/include/lx_kit,,$(call select_from_repositories,src/include/lx_kit))
SRC_C += arch/arm64/kernel/smp.c
SRC_C += arch/arm64/kernel/cpufeature.c
vpath arch/arm64/kernel/cpufeature.c $(PRG_TOP_DIR)/lx_emul/shadow
vpath arch/arm64/kernel/smp.c $(DDE_LINUX_DIR)/src/lib/lx_emul/shadow
SRC_S += arch/arm64/crypto/poly1305-core.S
arch/arm64/crypto/poly1305-core.S:
$(MSG_CONVERT)$@
$(VERBOSE)mkdir -p $(dir $@)
$(VERBOSE)perl $(LX_SRC_DIR)/arch/arm64/crypto/poly1305-armv8.pl > $@
CC_OPT_arch/arm64/crypto/poly1305-core += -Dpoly1305_init=poly1305_init_arm64
include $(REP_DIR)/lib/mk/wireguard.inc

View File

@ -1,26 +0,0 @@
#
# For documentation see $(REP_DIR)/lib/mk/wireguard_lx_inc_dirs.inc .
#
PRG_DIR := $(REP_DIR)/src/app/wireguard/spec/arm_v8
GEN_PRG_DIR := $(PRG_DIR)/../..
DDE_LINUX_DIR := $(subst /src/include/lx_kit,,$(call select_from_repositories,src/include/lx_kit))
SRC_C += arch/arm64/kernel/smp.c
SRC_C += arch/arm64/kernel/cpufeature.c
vpath arch/arm64/kernel/cpufeature.c $(GEN_PRG_DIR)/lx_emul/shadow
vpath arch/arm64/kernel/smp.c $(DDE_LINUX_DIR)/src/lib/lx_emul/shadow
SRC_S += arch/arm64/crypto/poly1305-core.S
arch/arm64/crypto/poly1305-core.S:
$(MSG_CONVERT)$@
$(VERBOSE)mkdir -p $(dir $@)
$(VERBOSE)perl $(LX_SRC_DIR)/arch/arm64/crypto/poly1305-armv8.pl > $@
CC_OPT_arch/arm64/crypto/poly1305-core += -Dpoly1305_init=poly1305_init_arm64
include $(REP_DIR)/lib/mk/wireguard_lx_inc_dirs.inc

View File

@ -1,3 +1,15 @@
INC_DIR += $(REP_DIR)/src/include/spec/x86_64
#
# For documentation see $(REP_DIR)/lib/mk/wireguard.inc
#
PRG_TOP_DIR := $(REP_DIR)/src/app/wireguard
PRG_DIR := $(PRG_TOP_DIR)/spec/x86_64
SRC_S += arch/x86/crypto/poly1305-x86_64-cryptogams.S
arch/x86/crypto/poly1305-x86_64-cryptogams.S:
$(MSG_CONVERT)$@
$(VERBOSE)mkdir -p $(dir $@)
$(VERBOSE)perl $(LX_SRC_DIR)/arch/x86/crypto/poly1305-x86_64-cryptogams.pl > $@
include $(REP_DIR)/lib/mk/wireguard.inc

View File

@ -1,14 +0,0 @@
#
# For documentation see $(REP_DIR)/lib/mk/wireguard_lx_inc_dirs.inc .
#
PRG_DIR := $(REP_DIR)/src/app/wireguard/spec/x86_64
SRC_S += arch/x86/crypto/poly1305-x86_64-cryptogams.S
arch/x86/crypto/poly1305-x86_64-cryptogams.S:
$(MSG_CONVERT)$@
$(VERBOSE)mkdir -p $(dir $@)
$(VERBOSE)perl $(LX_SRC_DIR)/arch/x86/crypto/poly1305-x86_64-cryptogams.pl > $@
include $(REP_DIR)/lib/mk/wireguard_lx_inc_dirs.inc

View File

@ -1,39 +1,58 @@
LIBS += base net jitterentropy wireguard_lx_inc_dirs
#
# This library is for avoiding clashes between Linux and Genode includes.
# If we were to compile all the *.c files of this library directly with the
# WireGuard library, there would be only one INC_DIR applied to *.cc files as
# well as to *.c files. Some Genode headers, however, (e.g. 'net/udp.h' or
# 'net/dhcp.h') exist with the same include identifier in both Linux and
# Genode, and we would have the problem that we want the Linux variant in *.c
# files and the Genode variant in *.cc files. Therefore, we create two
# dedicated INC_DIR settings through separate libraries.
#
#VIRT_LINUX_INCLUDE_DIR := $(call select_from_repositories,src/include/virt_linux)
SRC_C += $(notdir $(wildcard $(PRG_DIR)/generated_dummies.c))
SRC_C += dummies.c
SRC_C += lx_emul.c
SRC_C += wireguard.c
SRC_C += genode_c_api_arch.c
DDE_LINUX_DIR := $(subst /src/include/lx_kit,,$(call select_from_repositories,src/include/lx_kit))
vpath wireguard.c $(PRG_TOP_DIR)/genode_c_api
vpath %.c $(PRG_TOP_DIR)
vpath %.c $(PRG_DIR)
MUSL_TM_DIR = $(call select_from_repositories,src/lib/musl_tm)
INC_DIR += $(PRG_DIR)
INC_DIR += $(PRG_TOP_DIR)
INC_DIR += $(REP_DIR)/src/app/wireguard
INC_DIR += $(DDE_LINUX_DIR)/src/include/virt_linux
INC_DIR += $(DDE_LINUX_DIR)/src/include
INC_DIR += $(MUSL_TM_DIR)
LIBS += virt_lx_emul virt_linux_generated
ifeq ($(filter-out $(SPECS),x86_64),)
SPEC_ARCH := x86_64
endif
ifeq ($(filter-out $(SPECS),arm_v8),)
SPEC_ARCH := arm_v8
endif
#
# Some local files include linux headers that expect the KBUILD_* symbols to
# be defined. However, the lx_emul mechanism for adding the definitions doesn't
# apply to these files, which is why we have to do it manually.
#
INC_DIR += $(DDE_LINUX_DIR)/src/include/spec/$(SPEC_ARCH)
WG_KBUILD_DEFS := -DKBUILD_MODFILE='"wireguard"' \
-DKBUILD_BASENAME='"wireguard"' \
-DKBUILD_MODNAME='"wireguard"'
SRC_C += tm_to_secs.c
CC_OPT_wireguard += $(WG_KBUILD_DEFS)
CC_OPT_lx_emul += $(WG_KBUILD_DEFS)
SRC_CC += arp_cache.cc
SRC_CC += arp_waiter.cc
SRC_CC += base64.cc
SRC_CC += config_model.cc
SRC_CC += dhcp_client.cc
SRC_CC += ipv4_address_prefix.cc
SRC_CC += ipv4_config.cc
SRC_CC += lx_emul/random.cc
SRC_CC += main.cc
SRC_CC += nic_connection.cc
SRC_CC += uplink_connection.cc
#
# The lx_emul Makefiles have a generic mechanism for defining the
# KBUILD_MODFILE, KBUILD_BASENAME, and KBUILD_MODNAME for each Linux
# compilation unit to be unique. However, some WireGuard units expect
# KBUILD_MODNAME to be the same for all WireGuard units. Therefore, we
# let a target-specific variable override the CC_OPT_* variable for those
# units.
#
vpath tm_to_secs.c $(MUSL_TM_DIR)
vpath %.cc $(REP_DIR)/src/app/wireguard
vpath %.cc $(DDE_LINUX_DIR)/src/lib
OBJECTS_TO_FIX_CC_OPT_FOR := \
drivers/net/wireguard/device.o \
drivers/net/wireguard/netlink.o
define FIX_OBJECT_CC_OPT =
$(1): override CC_OPT_$(1:%.o=%) = $(WG_KBUILD_DEFS)
endef
$(foreach OBJECT,$(OBJECTS_TO_FIX_CC_OPT_FOR), \
$(eval $(call FIX_OBJECT_CC_OPT,$(OBJECT))))

View File

@ -1,60 +0,0 @@
#
# This library is for avoiding clashes between Linux and Genode includes.
# If we were to compile all the *.c files of this library directly with the
# WireGuard library, there would be only one INC_DIR applied to *.cc files as
# well as to *.c files. Some Genode headers, however, (e.g. 'net/udp.h' or
# 'net/dhcp.h') exist with the same include identifier in both Linux and
# Genode, and we would have the problem that we want the Linux variant in *.c
# files and the Genode variant in *.cc files. Therefore, we create two
# dedicated INC_DIR settings through separate libraries.
#
GEN_PRG_DIR := $(PRG_DIR)/../..
SRC_C += $(notdir $(wildcard $(PRG_DIR)/generated_dummies.c))
SRC_C += dummies.c
SRC_C += lx_emul.c
SRC_C += wireguard.c
SRC_C += genode_c_api_arch.c
vpath wireguard.c $(GEN_PRG_DIR)/genode_c_api
vpath %.c $(PRG_DIR)
vpath %.c $(GEN_PRG_DIR)
INC_DIR += $(PRG_DIR)
INC_DIR += $(GEN_PRG_DIR)
LIBS += virt_lx_emul virt_linux_generated
#
# Some local files include linux headers that expect the KBUILD_* symbols to
# be defined. However, the lx_emul mechanism for adding the definitions doesn't
# apply to these files, which is why we have to do it manually.
#
WG_KBUILD_DEFS := -DKBUILD_MODFILE='"wireguard"' \
-DKBUILD_BASENAME='"wireguard"' \
-DKBUILD_MODNAME='"wireguard"'
CC_OPT_wireguard += $(WG_KBUILD_DEFS)
CC_OPT_lx_emul += $(WG_KBUILD_DEFS)
#
# The lx_emul Makefiles have a generic mechanism for defining the
# KBUILD_MODFILE, KBUILD_BASENAME, and KBUILD_MODNAME for each Linux
# compilation unit to be unique. However, some WireGuard units expect
# KBUILD_MODNAME to be the same for all WireGuard units. Therefore, we
# let a target-specific variable override the CC_OPT_* variable for those
# units.
#
OBJECTS_TO_FIX_CC_OPT_FOR := \
drivers/net/wireguard/device.o \
drivers/net/wireguard/netlink.o
define FIX_OBJECT_CC_OPT =
$(1): override CC_OPT_$(1:%.o=%) = $(WG_KBUILD_DEFS)
endef
$(foreach OBJECT,$(OBJECTS_TO_FIX_CC_OPT_FOR), \
$(eval $(call FIX_OBJECT_CC_OPT,$(OBJECT))))

View File

@ -1,11 +1,8 @@
MIRRORED_FROM_REP_DIR := \
lib/import/import-wireguard.mk \
lib/mk/spec/arm_v8/wireguard.mk \
lib/mk/spec/arm_v8/wireguard_lx_inc_dirs.mk \
lib/mk/spec/x86_64/wireguard.mk \
lib/mk/spec/x86_64/wireguard_lx_inc_dirs.mk \
lib/mk/wireguard.inc \
lib/mk/wireguard_lx_inc_dirs.inc \
src/app/wireguard \
content: $(MIRRORED_FROM_REP_DIR)

View File

@ -0,0 +1,5 @@
REQUIRES := arm_v8
INC_DIR += $(DDE_LINUX_DIR)/src/include/spec/arm_v8
include $(PRG_DIR)/../../target.inc

View File

@ -0,0 +1,5 @@
REQUIRES := x86_64
INC_DIR += $(DDE_LINUX_DIR)/src/include/spec/x86_64
include $(PRG_DIR)/../../target.inc

View File

@ -0,0 +1,32 @@
TARGET = wireguard
LIBS += base net jitterentropy wireguard
DDE_LINUX_DIR := $(subst /src/include/lx_kit,,$(call select_from_repositories,src/include/lx_kit))
MUSL_TM_DIR = $(call select_from_repositories,src/lib/musl_tm)
INC_DIR += $(PRG_DIR)/../..
INC_DIR += $(DDE_LINUX_DIR)/src/include/virt_linux
INC_DIR += $(DDE_LINUX_DIR)/src/include
INC_DIR += $(MUSL_TM_DIR)
SRC_C += tm_to_secs.c
SRC_CC += arp_cache.cc
SRC_CC += arp_waiter.cc
SRC_CC += base64.cc
SRC_CC += config_model.cc
SRC_CC += dhcp_client.cc
SRC_CC += ipv4_address_prefix.cc
SRC_CC += ipv4_config.cc
SRC_CC += lx_emul/random.cc
SRC_CC += main.cc
SRC_CC += nic_connection.cc
SRC_CC += uplink_connection.cc
vpath tm_to_secs.c $(MUSL_TM_DIR)
vpath %.cc $(REP_DIR)/src/app/wireguard
vpath %.cc $(DDE_LINUX_DIR)/src/lib
CONFIG_XSD := ../../config.xsd

View File

@ -1,7 +0,0 @@
TARGET = wireguard
SRC_CC += dummy.cc
LIBS += wireguard
CONFIG_XSD := config.xsd