2022-11-12 21:04:47 +02:00
|
|
|
DEFAULT_HOST!=../default-host.sh
|
|
|
|
HOST?=DEFAULT_HOST
|
|
|
|
HOSTARCH!=../target-triplet-to-arch.sh $(HOST)
|
|
|
|
|
|
|
|
CFLAGS?=-O2 -g
|
|
|
|
CPPFLAGS?=
|
|
|
|
LDFLAGS?=
|
|
|
|
LIBS?=
|
|
|
|
|
|
|
|
DESTDIR?=
|
|
|
|
PREFIX?=/usr/local
|
|
|
|
EXEC_PREFIX?=$(PREFIX)
|
|
|
|
INCLUDEDIR?=$(PREFIX)/include
|
|
|
|
LIBDIR?=$(EXEC_PREFIX)/lib
|
|
|
|
|
2023-01-13 00:04:15 +02:00
|
|
|
CFLAGS:=$(CFLAGS) -D__is_libc -Iinclude -ffreestanding -Wall -Wextra -Werror=return-type
|
2022-12-03 18:15:10 +02:00
|
|
|
CPPFLAGS:=$(CPPFLAGS)
|
2022-12-13 00:51:57 +02:00
|
|
|
LIBK_CFLAGS:=$(CFLAGS) -D__is_libk
|
|
|
|
LIBK_CPPFLAGS:=$(CPPFLAGS)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
ARCHDIR=arch/$(HOSTARCH)
|
|
|
|
|
|
|
|
include $(ARCHDIR)/make.config
|
|
|
|
|
|
|
|
CFLAGS:=$(CFLAGS) $(ARCH_CFLAGS)
|
|
|
|
CPPFLAGS:=$(CPPFLAGS) $(ARCH_CPPFLAGS)
|
|
|
|
LIBK_CFLAGS:=$(LIBK_CFLAGS) $(KERNEL_ARCH_CFLAGS)
|
|
|
|
LIBK_CPPFLAGS:=$(LIBK_CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS)
|
|
|
|
|
2022-12-03 18:15:10 +02:00
|
|
|
BUILDDIR=$(abspath build)
|
|
|
|
|
2022-11-12 21:04:47 +02:00
|
|
|
FREEOBJS=\
|
|
|
|
$(ARCH_FREEOBJS) \
|
|
|
|
stdio/printf.o \
|
|
|
|
stdio/putchar.o \
|
|
|
|
stdio/puts.o \
|
|
|
|
stdlib/abort.o \
|
|
|
|
string/memcmp.o \
|
|
|
|
string/memcpy.o \
|
|
|
|
string/memmove.o \
|
|
|
|
string/memset.o \
|
2022-11-12 23:47:06 +02:00
|
|
|
string/strcpy.o \
|
2022-11-12 21:04:47 +02:00
|
|
|
string/strlen.o \
|
2022-11-12 23:47:06 +02:00
|
|
|
string/strncpy.o \
|
2022-11-15 21:42:14 +02:00
|
|
|
string/strstr.o \
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
HOSTEDOBJS=\
|
|
|
|
$(ARCH_HOSTEDOBJS) \
|
|
|
|
|
|
|
|
OBJS=\
|
|
|
|
$(FREEOBJS) \
|
|
|
|
$(HOSTEDOBJS) \
|
|
|
|
|
|
|
|
LIBK_OBJS=$(FREEOBJS:.o=.libk.o)
|
|
|
|
|
|
|
|
#BINARIES=libc.a libk.a # Not ready for libc yet.
|
|
|
|
BINARIES=libk.a
|
|
|
|
|
2022-12-03 18:15:10 +02:00
|
|
|
.PHONY: all always clean install install-headers install-libs
|
2022-11-14 00:27:11 +02:00
|
|
|
.SUFFIXES: .o .libk.o .cpp .S
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
all: $(BINARIES)
|
|
|
|
|
2022-12-03 18:15:10 +02:00
|
|
|
libc.a: always $(OBJS)
|
|
|
|
cd $(BUILDDIR) && $(AR) rcs $@ $(OBJS)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
2022-12-03 18:15:10 +02:00
|
|
|
libk.a: always $(LIBK_OBJS)
|
|
|
|
cd $(BUILDDIR) && $(AR) rcs $@ $(LIBK_OBJS)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
2022-11-14 00:27:11 +02:00
|
|
|
.cpp.o:
|
2022-12-03 18:15:10 +02:00
|
|
|
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
.S.o:
|
2022-12-03 18:15:10 +02:00
|
|
|
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(CFLAGS) $(CPPFLAGS)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
2022-11-14 00:27:11 +02:00
|
|
|
.cpp.libk.o:
|
2022-12-03 18:15:10 +02:00
|
|
|
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
.S.libk.o:
|
2022-12-03 18:15:10 +02:00
|
|
|
$(CXX) -MD -c $< -o $(BUILDDIR)/$@ $(LIBK_CFLAGS) $(LIBK_CPPFLAGS)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
clean:
|
2022-12-03 18:15:10 +02:00
|
|
|
rm -rf $(BUILDDIR)
|
|
|
|
|
|
|
|
always:
|
|
|
|
mkdir -p $(BUILDDIR)/stdio
|
|
|
|
mkdir -p $(BUILDDIR)/stdlib
|
|
|
|
mkdir -p $(BUILDDIR)/string
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
install: install-headers install-libs
|
|
|
|
|
|
|
|
install-headers:
|
|
|
|
mkdir -p $(DESTDIR)$(INCLUDEDIR)
|
|
|
|
cp -R --preserve=timestamps include/. $(DESTDIR)$(INCLUDEDIR)/.
|
|
|
|
|
|
|
|
install-libs: $(BINARIES)
|
|
|
|
mkdir -p $(DESTDIR)$(LIBDIR)
|
2022-12-03 18:15:10 +02:00
|
|
|
cp $(BUILDDIR)/$(BINARIES) $(DESTDIR)$(LIBDIR)
|
2022-11-12 21:04:47 +02:00
|
|
|
|
|
|
|
-include $(OBJS:.o=.d)
|
|
|
|
-include $(LIBK_OBJS:.o=.d)
|