Luna/libs/libc/Makefile

85 lines
2.4 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
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
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-11-08 17:03:43 +00:00
@$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $^
@echo " CXX $^"
$(LIBC_OBJ)/%.c.o: $(LIBC_SRC)/%.c
@mkdir -p $(@D)
2022-11-08 17:03:43 +00:00
@$(CC) $(CFLAGS) -o $@ -c $^
@echo " CC $^"
$(LIBC_OBJ)/%.asm.o: $(LIBC_SRC)/%.asm
@mkdir -p $(@D)
2022-11-08 17:03:43 +00:00
@$(ASM) $(ASMFLAGS) -o $@ $^
@echo " ASM $^"
2022-10-02 15:01:30 +00:00
$(LIBC_BIN)/libc.a: $(OBJS)
@mkdir -p $(@D)
2022-11-08 17:03:43 +00:00
@$(AR) rcs $@ $(OBJS)
@echo " AR $@"
$(LIBC_BIN)/crt0.o: $(LIBC_DIR)/crt0.asm
@mkdir -p $(@D)
2022-11-08 17:03:43 +00:00
@$(ASM) $(ASMFLAGS) -o $@ $^
@echo " ASM $^"
$(LIBC_BIN)/crti.o: $(LIBC_DIR)/crti.asm
@mkdir -p $(@D)
2022-11-08 17:03:43 +00:00
@$(ASM) $(ASMFLAGS) -o $@ $^
@echo " ASM $^"
$(LIBC_BIN)/crtn.o: $(LIBC_DIR)/crtn.asm
@mkdir -p $(@D)
2022-11-08 17:03:43 +00:00
@$(ASM) $(ASMFLAGS) -o $@ $^
@echo " ASM $^"
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)
2022-11-08 17:03:43 +00:00
@cp $^ $@
@echo " INSTALL $^"
2022-10-02 15:01:30 +00:00
$(DESTDIR)/crt0.o: $(LIBC_BIN)/crt0.o
@mkdir -p $(@D)
2022-11-08 17:03:43 +00:00
@cp $^ $@
@echo " INSTALL $^"
2022-10-02 15:01:30 +00:00
$(DESTDIR)/crti.o: $(LIBC_BIN)/crti.o
@mkdir -p $(@D)
2022-11-08 17:03:43 +00:00
@cp $^ $@
@echo " INSTALL $^"
2022-10-02 15:01:30 +00:00
$(DESTDIR)/crtn.o: $(LIBC_BIN)/crtn.o
@mkdir -p $(@D)
2022-11-08 17:03:43 +00:00
@cp $^ $@
@echo " INSTALL $^"
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