Makefile.libc 2.12 KB
# Makefile for building libc

#include $(TOP)/Makefile.tools

# library specific compilation flags
CFLAGS=-ffreestanding -ffunction-sections -fdata-sections -Wno-unknown-pragmas $(LIBFLAGS)

all: $(LIBFILE) $(DSTDIR)/../include
	@echo "NEWLIB (C/M) library is prepared"

# ------------------------------------------------------------------------------
# libc: from newlib
# build with configure/make
NEWLIB_SRCPATH=$(abspath ./newlib/newlib)
#C_SRCPATH=$(abspath ./newlib/newlib/libc)
#M_SRCPATH=$(abspath ./newlib/newlib/libm)
SRCPATH=$(abspath ./newlib/newlib/$(LIB))
NEWLIB_DSTDIR=$(DSTDIR)/../../newlib/$(ARCHID)


$(NEWLIB_DSTDIR):
	mkdir -p $(NEWLIB_DSTDIR)

$(DSTDIR):
	mkdir -p $(DSTDIR)

# run building
$(DSTDIR)/libc.a: $(DSTDIR) $(NEWLIB_DSTDIR) $(NEWLIB_DSTDIR)/libc.a
	cp $(NEWLIB_DSTDIR)/libc.a $@

$(DSTDIR)/libm.a: $(DSTDIR) $(NEWLIB_DSTDIR) $(NEWLIB_DSTDIR)/libm.a
	cp $(NEWLIB_DSTDIR)/libm.a $@

$(NEWLIB_DSTDIR)/libc.a: $(NEWLIB_DSTDIR)/Makefile
	(cd $(NEWLIB_DSTDIR); AR_FLAGS=r make;)

$(NEWLIB_DSTDIR)/libm.a: $(NEWLIB_DSTDIR)/Makefile
	(cd $(NEWLIB_DSTDIR); AR_FLAGS=r make;)

# run configure
$(NEWLIB_DSTDIR)/Makefile: $(NEWLIB_SRCPATH)/configure
	(cd $(NEWLIB_DSTDIR); CC=$(CC) CFLAGS="$(CCARCH) $(CFLAGS) -I$(SRCPATH)/include -I$(SRCPATH)/../libc/machine/riscv --sysroot=$(NEWLIB_DSTDIR)/sysroot64" RANLIB=$(RANLIB) AR=$(AR) $(NEWLIB_SRCPATH)/configure --build=$(TOOLCHAIN) --prefix=$(NEWLIB_DSTDIR)/sysroot64 --disable-newlib-fno-builtin --enable-silent-rules --enable-newlib-nano-malloc;)
#  --enable-newlib-nano-formatted-io
# --disable-newlib-io-float --enable-newlib-nano-malloc --enable-newlib-nano-formatted-io 
#  -Werror


# run preparing copy of directory 'include' (libc)
ifeq ($(LIB),libc)

$(DSTDIR)/../include: $(SRCPATH)
	cp -r $(SRCPATH)/include $(DSTDIR)/../include
	cp $(SRCPATH)/machine/riscv/sys/*.h $(DSTDIR)/../include/sys

endif

ifeq ($(LIB),libm)			# run copying include (libm)

$(DSTDIR)/../include:
	mkdir -p $@
	cp $(SRCPATH)/machine/riscv/*.h $@

endif

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