2022-10-01 18:59:22 +00:00
|
|
|
LIBC_DIR := $(LUNA_ROOT)/libs/libc
|
|
|
|
LIBC_SRC := $(LIBC_DIR)/src
|
|
|
|
LIBC_OBJ := $(LIBC_DIR)/lib
|
|
|
|
LIBC_BIN := $(LIBC_DIR)/bin
|
|
|
|
|
2022-10-02 15:01:30 +00:00
|
|
|
DESTDIR ?= $(LUNA_BASE)/usr/lib
|
2022-10-01 18:59:22 +00:00
|
|
|
|
2022-11-08 16:39:34 +00:00
|
|
|
CFLAGS := -Os -nostdlib -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -pedantic -Wall -Wextra -Werror -Wfloat-equal -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion
|
2022-10-07 16:19:06 +00:00
|
|
|
CXXFLAGS := -fno-rtti -fno-exceptions -Wsign-promo -Wstrict-null-sentinel -Wctor-dtor-privacy
|
2022-10-02 15:01:30 +00:00
|
|
|
ASMFLAGS := -felf64
|
2022-10-01 18:59:22 +00:00
|
|
|
|
|
|
|
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
|
|
|
|
|
2022-10-02 15:01:30 +00:00
|
|
|
CXX_SRC = $(call rwildcard,$(LIBC_SRC),*.cpp)
|
|
|
|
C_SRC = $(call rwildcard,$(LIBC_SRC),*.c)
|
|
|
|
ASM_SRC = $(call rwildcard,$(LIBC_SRC),*.asm)
|
2022-10-01 18:59:22 +00:00
|
|
|
|
2022-10-02 15:01:30 +00:00
|
|
|
OBJS = $(patsubst $(LIBC_SRC)/%.cpp, $(LIBC_OBJ)/%.cpp.o, $(CXX_SRC))
|
|
|
|
OBJS += $(patsubst $(LIBC_SRC)/%.c, $(LIBC_OBJ)/%.c.o, $(C_SRC))
|
|
|
|
OBJS += $(patsubst $(LIBC_SRC)/%.asm, $(LIBC_OBJ)/%.asm.o, $(ASM_SRC))
|
2022-10-01 18:59:22 +00:00
|
|
|
|
|
|
|
$(LIBC_OBJ)/%.cpp.o: $(LIBC_SRC)/%.cpp
|
|
|
|
@mkdir -p $(@D)
|
2022-10-02 15:01:30 +00:00
|
|
|
$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $^
|
2022-10-01 18:59:22 +00:00
|
|
|
|
|
|
|
$(LIBC_OBJ)/%.c.o: $(LIBC_SRC)/%.c
|
|
|
|
@mkdir -p $(@D)
|
2022-10-02 15:01:30 +00:00
|
|
|
$(CC) $(CFLAGS) -o $@ -c $^
|
2022-10-01 18:59:22 +00:00
|
|
|
|
|
|
|
$(LIBC_OBJ)/%.asm.o: $(LIBC_SRC)/%.asm
|
|
|
|
@mkdir -p $(@D)
|
2022-10-02 15:01:30 +00:00
|
|
|
$(ASM) $(ASMFLAGS) -o $@ $^
|
2022-10-01 18:59:22 +00:00
|
|
|
|
2022-10-02 15:01:30 +00:00
|
|
|
$(LIBC_BIN)/libc.a: $(OBJS)
|
2022-10-01 18:59:22 +00:00
|
|
|
@mkdir -p $(@D)
|
2022-10-02 15:01:30 +00:00
|
|
|
$(AR) rcs $@ $(OBJS)
|
2022-10-01 18:59:22 +00:00
|
|
|
|
|
|
|
$(LIBC_BIN)/crt0.o: $(LIBC_DIR)/crt0.asm
|
|
|
|
@mkdir -p $(@D)
|
2022-10-02 15:01:30 +00:00
|
|
|
$(ASM) $(ASMFLAGS) -o $@ $^
|
2022-10-01 18:59:22 +00:00
|
|
|
|
|
|
|
$(LIBC_BIN)/crti.o: $(LIBC_DIR)/crti.asm
|
|
|
|
@mkdir -p $(@D)
|
2022-10-02 15:01:30 +00:00
|
|
|
$(ASM) $(ASMFLAGS) -o $@ $^
|
2022-10-01 18:59:22 +00:00
|
|
|
|
|
|
|
$(LIBC_BIN)/crtn.o: $(LIBC_DIR)/crtn.asm
|
|
|
|
@mkdir -p $(@D)
|
2022-10-02 15:01:30 +00:00
|
|
|
$(ASM) $(ASMFLAGS) -o $@ $^
|
2022-10-01 18:59:22 +00:00
|
|
|
|
2022-10-02 10:44:32 +00:00
|
|
|
build: $(LIBC_BIN)/crt0.o $(LIBC_BIN)/crti.o $(LIBC_BIN)/crtn.o $(LIBC_BIN)/libc.a
|
2022-10-01 18:59:22 +00:00
|
|
|
|
2022-10-02 15:01:30 +00:00
|
|
|
$(DESTDIR)/libc.a: $(LIBC_BIN)/libc.a
|
2022-10-01 18:59:22 +00:00
|
|
|
@mkdir -p $(@D)
|
|
|
|
cp $^ $@
|
|
|
|
|
2022-10-02 15:01:30 +00:00
|
|
|
$(DESTDIR)/crt0.o: $(LIBC_BIN)/crt0.o
|
2022-10-01 18:59:22 +00:00
|
|
|
@mkdir -p $(@D)
|
|
|
|
cp $^ $@
|
|
|
|
|
2022-10-02 15:01:30 +00:00
|
|
|
$(DESTDIR)/crti.o: $(LIBC_BIN)/crti.o
|
2022-10-01 18:59:22 +00:00
|
|
|
@mkdir -p $(@D)
|
|
|
|
cp $^ $@
|
|
|
|
|
2022-10-02 15:01:30 +00:00
|
|
|
$(DESTDIR)/crtn.o: $(LIBC_BIN)/crtn.o
|
2022-10-01 18:59:22 +00:00
|
|
|
@mkdir -p $(@D)
|
|
|
|
cp $^ $@
|
|
|
|
|
2022-10-02 15:01:30 +00:00
|
|
|
install: $(DESTDIR)/libc.a $(DESTDIR)/crt0.o $(DESTDIR)/crti.o $(DESTDIR)/crtn.o
|
2022-10-01 18:59:22 +00:00
|
|
|
|
2022-10-02 10:44:32 +00:00
|
|
|
clean:
|
2022-10-01 18:59:22 +00:00
|
|
|
rm -rf $(LIBC_OBJ)/*
|
|
|
|
rm -rf $(LIBC_BIN)/*
|
2022-10-02 15:01:30 +00:00
|
|
|
rm -f $(DESTDIR)/libc.a
|
|
|
|
rm -f $(DESTDIR)/crt*.o
|