46 lines
1.0 KiB
Makefile

ifeq ($(BUILDROOT),)
$(error BUILDROOT IS NOT SET!)
endif
CC := ${TARGET}-gcc
SRC := $(shell find -type f -name '*.[cS]*')
OBJ := $(patsubst %, %.o, $(basename $(basename $(SRC))))
HDR := $(shell find -type f -name '*.h')
CFLAGS := -Wall -Wextra -pedantic -ffreestanding -mcmodel=large -std=c2x
CFLAGS += -ggdb -O0
ASFLAGS += -ggdb
CPPFLAGS += -nostdinc -I include -I /opt/sysroot/usr/include
LDFLAGS := -nostdlib -r
libmittos.a: $(OBJ)
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
# Automatic dependency tracking
DEP := $(OBJ:.o=.d)
DEPFLAGS = -MT $@ -MMD -MP -MF $*.d
$(OBJ): CPPFLAGS += $(DEPFLAGS)
%.d: ;
DESTDIR ?= $(BUILDROOT)/sysroot
LIBDIR := $(DESTDIR)/usr/lib
INCDIR := $(DESTDIR)/usr/include/mittos
$(LIBDIR)/libmittos.a: libmittos.a
install -D $< $@
$(INCDIR)/%: include/%
mkdir -p $(INCDIR)
install -D $< $@
install: install-headers $(LIBDIR)/libmittos.a
install-headers: $(HDR:./include/%=$(INCDIR)/%)
clean:
rm -rf $(OBJ) $(DEP) libmittos.a
.PHONY: install install-headers
# Include automatic dependency rules
include $(DEP)