LIBC_DIR := $(LUNA_ROOT)/libs/libc LIBC_SRC := $(LIBC_DIR)/src LIBC_OBJ := $(LIBC_DIR)/lib LIBC_BIN := $(LIBC_DIR)/bin DESTDIR ?= $(LUNA_BASE)/usr/lib CFLAGS := -Os -nostdlib -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 CXXFLAGS := -fno-rtti -fno-exceptions -Wsign-promo -Wstrict-null-sentinel -Wctor-dtor-privacy ASMFLAGS := -felf64 rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d)) CXX_SRC = $(call rwildcard,$(LIBC_SRC),*.cpp) C_SRC = $(call rwildcard,$(LIBC_SRC),*.c) ASM_SRC = $(call rwildcard,$(LIBC_SRC),*.asm) 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) $(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $^ $(LIBC_OBJ)/%.c.o: $(LIBC_SRC)/%.c @mkdir -p $(@D) $(CC) $(CFLAGS) -o $@ -c $^ $(LIBC_OBJ)/%.asm.o: $(LIBC_SRC)/%.asm @mkdir -p $(@D) $(ASM) $(ASMFLAGS) -o $@ $^ $(LIBC_BIN)/libc.a: $(OBJS) @mkdir -p $(@D) $(AR) rcs $@ $(OBJS) $(LIBC_BIN)/crt0.o: $(LIBC_DIR)/crt0.asm @mkdir -p $(@D) $(ASM) $(ASMFLAGS) -o $@ $^ $(LIBC_BIN)/crti.o: $(LIBC_DIR)/crti.asm @mkdir -p $(@D) $(ASM) $(ASMFLAGS) -o $@ $^ $(LIBC_BIN)/crtn.o: $(LIBC_DIR)/crtn.asm @mkdir -p $(@D) $(ASM) $(ASMFLAGS) -o $@ $^ build: $(LIBC_BIN)/crt0.o $(LIBC_BIN)/crti.o $(LIBC_BIN)/crtn.o $(LIBC_BIN)/libc.a $(DESTDIR)/libc.a: $(LIBC_BIN)/libc.a @mkdir -p $(@D) cp $^ $@ $(DESTDIR)/crt0.o: $(LIBC_BIN)/crt0.o @mkdir -p $(@D) cp $^ $@ $(DESTDIR)/crti.o: $(LIBC_BIN)/crti.o @mkdir -p $(@D) cp $^ $@ $(DESTDIR)/crtn.o: $(LIBC_BIN)/crtn.o @mkdir -p $(@D) cp $^ $@ install: $(DESTDIR)/libc.a $(DESTDIR)/crt0.o $(DESTDIR)/crti.o $(DESTDIR)/crtn.o clean: rm -rf $(LIBC_OBJ)/* rm -rf $(LIBC_BIN)/* rm -f $(DESTDIR)/libc.a rm -f $(DESTDIR)/crt*.o