Luna/libs/libc/Makefile

74 lines
1.8 KiB
Makefile
Raw Normal View History

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
CFLAGS := -Wall -Wextra -Werror -Os -nostdlib -fno-omit-frame-pointer
2022-10-02 15:01:30 +00:00
CXXFLAGS := -fno-rtti -fno-exceptions
ASMFLAGS := -felf64
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-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))
$(LIBC_OBJ)/%.cpp.o: $(LIBC_SRC)/%.cpp
@mkdir -p $(@D)
2022-10-02 15:01:30 +00:00
$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $^
$(LIBC_OBJ)/%.c.o: $(LIBC_SRC)/%.c
@mkdir -p $(@D)
2022-10-02 15:01:30 +00:00
$(CC) $(CFLAGS) -o $@ -c $^
$(LIBC_OBJ)/%.asm.o: $(LIBC_SRC)/%.asm
@mkdir -p $(@D)
2022-10-02 15:01:30 +00:00
$(ASM) $(ASMFLAGS) -o $@ $^
2022-10-02 15:01:30 +00:00
$(LIBC_BIN)/libc.a: $(OBJS)
@mkdir -p $(@D)
2022-10-02 15:01:30 +00:00
$(AR) rcs $@ $(OBJS)
$(LIBC_BIN)/crt0.o: $(LIBC_DIR)/crt0.asm
@mkdir -p $(@D)
2022-10-02 15:01:30 +00:00
$(ASM) $(ASMFLAGS) -o $@ $^
$(LIBC_BIN)/crti.o: $(LIBC_DIR)/crti.asm
@mkdir -p $(@D)
2022-10-02 15:01:30 +00:00
$(ASM) $(ASMFLAGS) -o $@ $^
$(LIBC_BIN)/crtn.o: $(LIBC_DIR)/crtn.asm
@mkdir -p $(@D)
2022-10-02 15:01:30 +00:00
$(ASM) $(ASMFLAGS) -o $@ $^
build: $(LIBC_BIN)/crt0.o $(LIBC_BIN)/crti.o $(LIBC_BIN)/crtn.o $(LIBC_BIN)/libc.a
2022-10-02 15:01:30 +00:00
$(DESTDIR)/libc.a: $(LIBC_BIN)/libc.a
@mkdir -p $(@D)
cp $^ $@
2022-10-02 15:01:30 +00:00
$(DESTDIR)/crt0.o: $(LIBC_BIN)/crt0.o
@mkdir -p $(@D)
cp $^ $@
2022-10-02 15:01:30 +00:00
$(DESTDIR)/crti.o: $(LIBC_BIN)/crti.o
@mkdir -p $(@D)
cp $^ $@
2022-10-02 15:01:30 +00:00
$(DESTDIR)/crtn.o: $(LIBC_BIN)/crtn.o
@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
clean:
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