Skip to content

Commit

Permalink
evaluate import-<api-name>.mk files if present
Browse files Browse the repository at this point in the history
If a used API contains an import-<api-name>.mk file, we evalute this in
order to set the include directories appropriately. This relieves us
from most quirks.

genodelabs#81
  • Loading branch information
jschlatow committed Jan 31, 2024
1 parent 313d4c4 commit b18045e
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 44 deletions.
17 changes: 17 additions & 0 deletions share/goa/lib/flags.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
#
set include_dirs { }
foreach api $used_apis {
# look for import-<api_name>.mk file, if present take include dirs from this file
set import_file [glob -nocomplain -directory [file join $depot_dir $api lib import] import-[archive_name $api].mk]
if {[llength $import_file]} {
set cmd "make"
lappend cmd "-f"
lappend cmd [file join $tool_dir mk import_api.mk]
lappend cmd "REPOSITORIES=[file join $depot_dir $api]"
lappend cmd "IMPORT_MK=$import_file"
lappend cmd "TOOL_DIR=$tool_dir"

set dirs [exec {*}$cmd]
lappend include_dirs {*}$dirs

continue
}

# apply include dir convention if there are no import-*.mk files
set dir [file join $depot_dir $api include]

if {$arch == "x86_64"} {
Expand Down
44 changes: 0 additions & 44 deletions share/goa/lib/quirks.tcl
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
##
# Add include search path whenever using the given 'api'
#
# \param api API for which the input-search path must be extended
# \param args include-search path elements relative to the API archive
#
proc append_include_dir_for_api { api args } {

if {[using_api $api]} {
global include_dirs
lappend include_dirs [file join [api_archive_dir $api] {*}$args]
}
}

# C runtime

append_include_dir_for_api libc include libc
append_include_dir_for_api libc include libc-genode

if {$arch == "x86_64"} {
append_include_dir_for_api libc include spec x86 libc
append_include_dir_for_api libc include spec x86_64 libc
}

if {$arch == "arm_v8a"} {
append_include_dir_for_api libc include spec arm_64 libc
}

if {[using_api libc]} {

Expand All @@ -41,20 +14,8 @@ if {[using_api compat-libc]} {
lappend lib_src [file join $compat_libc_dir compat.cc]
}

# Standard C++ library

append_include_dir_for_api stdcxx include stdcxx
append_include_dir_for_api stdcxx include stdcxx std
append_include_dir_for_api stdcxx include stdcxx c_global

if {$arch == "x86_64"} { append_include_dir_for_api stdcxx include spec x86_64 stdcxx }
if {$arch == "arm_v8a"} { append_include_dir_for_api stdcxx include spec arm_64 stdcxx }

# SDL

append_include_dir_for_api sdl include SDL
append_include_dir_for_api sdl_image include SDL

if {[using_api sdl]} {

# CMake's detection of libSDL expects the library named uppercase
Expand All @@ -71,11 +32,6 @@ if {[using_api sdl]} {

# SDL2

append_include_dir_for_api sdl2 include SDL2
append_include_dir_for_api sdl2_mixer include SDL2
append_include_dir_for_api sdl2_image include SDL2
append_include_dir_for_api sdl2_ttf include SDL2

if {[using_api sdl2]} {

# CMake's detection of libSDL expects the library named uppercase
Expand Down
21 changes: 21 additions & 0 deletions share/goa/mk/import_api.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/make -f

ARCH ?= x86_64
REP_DIR ?= $(firstword $(REPOSITORIES))

select_from_repositories = $(firstword $(foreach REP,$(REPOSITORIES),$(wildcard $(REP)/$(1))))
select_from_ports = $(REP_DIR)

# set up SPECS
BASE_DIR := $(TOOL_DIR)
SPECS := $(ARCH)
include $(BASE_DIR)/mk/spec/$(ARCH).mk

include $(IMPORT_MK)

ALL_INC_DIR := $(INC_DIR)
ALL_INC_DIR += $(foreach DIR,$(REP_INC_DIR), $(foreach REP,$(REPOSITORIES),$(REP)/$(DIR)))
ALL_INC_DIR += $(foreach REP,$(REPOSITORIES),$(REP)/include)

include_dirs:
@echo ${ALL_INC_DIR}
4 changes: 4 additions & 0 deletions share/goa/mk/spec/32bit.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#
# 32-bit-specific Genode headers
#
REP_INC_DIR += include/spec/32bit
4 changes: 4 additions & 0 deletions share/goa/mk/spec/64bit.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#
# 64-bit-specific Genode headers
#
REP_INC_DIR += include/spec/64bit
15 changes: 15 additions & 0 deletions share/goa/mk/spec/arm.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# ARM-specific Genode headers
#
REP_INC_DIR += include/spec/arm

SPECS += 32bit

#
# Prevent compiler message
# "note: the mangling of 'va_list' has changed in GCC 4.4"
#
CC_C_OPT += -Wno-psabi
CC_CXX_OPT += -Wno-psabi

include $(BASE_DIR)/mk/spec/32bit.mk
6 changes: 6 additions & 0 deletions share/goa/mk/spec/arm_v6.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SPECS += arm
REP_INC_DIR += include/spec/arm_v6
CC_MARCH ?= -march=armv6k -mfpu=vfp -mfloat-abi=softfp

include $(BASE_DIR)/mk/spec/arm.mk

5 changes: 5 additions & 0 deletions share/goa/mk/spec/arm_v7.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SPECS += arm
REP_INC_DIR += include/spec/arm_v7

include $(BASE_DIR)/mk/spec/arm.mk

5 changes: 5 additions & 0 deletions share/goa/mk/spec/arm_v7a.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SPECS += arm_v7
CC_MARCH ?= -march=armv7-a -mfpu=vfpv3 -mfloat-abi=softfp

include $(BASE_DIR)/mk/spec/arm_v7.mk

7 changes: 7 additions & 0 deletions share/goa/mk/spec/arm_v8a.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SPECS += arm_v8 arm_64 64bit neon
REP_INC_DIR += include/spec/arm_v8
REP_INC_DIR += include/spec/arm_64

CC_MARCH ?= -march=armv8-a

include $(BASE_DIR)/mk/spec/64bit.mk
8 changes: 8 additions & 0 deletions share/goa/mk/spec/riscv.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SPECS += 64bit
REP_INC_DIR += include/spec/riscv

# force soft-float for binutiles
AS_OPT += -march rv64imac -mabi=lp64

include $(BASE_DIR)/mk/spec/64bit.mk

19 changes: 19 additions & 0 deletions share/goa/mk/spec/x86_32.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Specifics for 32-bit x86
#
SPECS += x86 32bit

#
# x86-specific Genode headers
#
REP_INC_DIR += include/spec/x86
REP_INC_DIR += include/spec/x86_32

#
# x86-specific flags
#
CC_MARCH ?= -march=i686 -m32
LD_MARCH ?= -melf_i386
AS_MARCH ?= -march=i686 --32

include $(BASE_DIR)/mk/spec/32bit.mk
23 changes: 23 additions & 0 deletions share/goa/mk/spec/x86_64.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Specifics for 64-bit x86
#
SPECS += x86 64bit

#
# x86-specific Genode headers
#
REP_INC_DIR += include/spec/x86
REP_INC_DIR += include/spec/x86_64

CC_MARCH ?= -m64 -mcmodel=large

#
# Avoid wasting almost 4 MiB by telling the linker that the max page size is
# 4K. Otherwise, the linker would align the text segment to a 4M boundary,
# effectively adding 4M of zeros to each binary.
#
# See http://sourceware.org/ml/binutils/2009-04/msg00099.html
#
LD_MARCH ?= -melf_x86_64

include $(BASE_DIR)/mk/spec/64bit.mk

0 comments on commit b18045e

Please sign in to comment.