ifeq ($(SYMBOLS_DIR),)
	SYMBOLS_DIR = $(REP_DIR)/lib/symbols
endif

LD_SCRIPT_SO = $(BASE_DIR)/src/ld/genode_rel.ld

: |> ^ CONVERT %o^ sed \
	-e "s/^\(\w\+\) D \(\w\+\)\$/.data; .global \1; .type \1,%%object; .size \1,\2; \1:/p" \
	-e "s/^\(\w\+\) V/.data; .weak \1; .type \1,%%object; \1:/p" \
	-e "s/^\(\w\+\) T/.text; .global \1; .type \1,%%function; \1:/p" \
	-e "s/^\(\w\+\) R \(\w\+\)\$/.section .rodata; .global \1; .type \1,%%object; .size \1,\2; \1:/p" \
	-e "s/^\(\w\+\) W/.text; .weak \1; .type \1,%%function; \1:/p" \
	-e "s/^\(\w\+\) B \(\w\+\)\$/.bss; .global \1; .type \1,%%object; .size \1,\2; \1:/p" \
	-e "s/^\(\w\+\) U/.text; .global \1; $(ASM_SYM_DEPENDENCY)/p" \
	$(SYMBOLS_DIR)/%d > %o |> $(LOCAL_LIB_PREFIX)/%d.symbols.s {asm}

: {asm} |> ^ ASSEMBLE %o^ $(CC) -c %f -o %o \
	|> $(LOCAL_LIB_PREFIX)/%b.o {obj}

!merge = |> ^ MERGE %o^ $(LD) \
	-o %o \
	-shared --eh-frame-hdr $(LD_OPT) \
	-T $(LD_SCRIPT_SO) \
	--whole-archive --start-group \
	$(LIB_SO_DEPS) %f \
	--end-group --no-whole-archive \
|>

: {obj} |> !merge |> $(LOCAL_LIB_PREFIX)/arm64/%d.lib.so  <artifacts>
: {obj} |> !merge |> $(LOCAL_LIB_PREFIX)/x86_32/%d.lib.so <artifacts>
: {obj} |> !merge |> $(LOCAL_LIB_PREFIX)/x86_64/%d.lib.so <artifacts>
