Makefile.libbuilt 1.25 KB
# Makefile for building 'built' library (built-in llvm functions)

#include $(TOP)/Makefile.tools

# library specific compilation flags
CFLAGS=-ffunction-sections -fdata-sections $(LIBFLAGS)

# ------------------------------------------------------------------------------
# libbuilt: from llvm/builtin


C_SRCPATH:=$(abspath ./builtins)
C_SRCS=$(notdir $(wildcard $(C_SRCPATH)/*.c))

LIBOBJS=$(C_SRCS:%.c=$(DSTDIR)/%.o)

#$(info TEST >>>>)
#$(info $(C_SRCS))
#$(info $(LIBOBJS))
#$(info <<<< TEST)

all: $(DSTDIR)/../include $(DSTDIR)/libbuilt.a
	echo "BUILTIN library is prepared"

# create library
$(DSTDIR)/libbuilt.a: $(LIBOBJS)
	@$(AR) r $@ $(LIBOBJS)

# run preparing copy of directory 'include'
$(DSTDIR)/../include:
	mkdir $@

# compile objects
define GEN_C2O_RULE
$(DSTDIR)/$(cfile:.c=.o) : $(DSTDIR)/$(cfile:.c=.c_S)
	@echo "Assemble $$@ from $$<"
	@$(AS) $(ASARCH) -gdwarf-5 -o $$@ $$<
$(DSTDIR)/$(cfile:.c=.c_S) : $(C_SRCPATH)/$(cfile)
	@echo "Compile '$$<' to '$$@' $(C_SRCPATH)"
	@$(CC) $(CCARCH) $(CFLAGS) -fno-addrsig -I$(C_SRCPATH) -S -o $$@ $$<
endef

$(foreach cfile, $(C_SRCS), \
	$(eval $(GEN_C2O_RULE)) \
)

# ------------------------------------------------------------------------------
clean:
	rm `find $(DSTDIR) -name "*.o"`
	rm `find $(DSTDIR) -name "*.a"`