# # Makefile # # Copyright (C) 2016 Aleksandar Andrejevic # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # DEBUG = yes # Compilers and tools CC = i686-elf-gcc ASM = nasm AR = i686-elf-ar # Directories SRCDIR = src OBJDIR = obj DEPDIR = dep # Flags CFLAGS = -Wall -Werror -ffreestanding -nostdlib -fPIC -I .. ASMFLAGS = -felf ifeq ($(DEBUG), yes) CFLAGS += -g else CFLAGS += -O3 endif # Input and output files SOURCES = $(wildcard $(SRCDIR)/*.c) SOURCES += $(wildcard $(SRCDIR)/*.asm) DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d) OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES))) .PHONY: all clean all: $(WRAPPERS) $(OBJDIR) $(DEPDIR) libmlsys.a -include $(DEPENDS) $(OBJDIR): mkdir -p $(OBJDIR) $(DEPDIR): mkdir -p $(DEPDIR) $(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile mkdir -p $(dir $@) mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d)) $(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $< $(OBJDIR)/%.o: $(SRCDIR)/%.asm Makefile $(ASM) $(ASMFLAGS) -o $@ $< libmlsys.a: $(OBJECTS) $(AR) rcs $@ $^ clean: rm -f libmlsys.a find $(OBJDIR) -name \*.o -delete find $(DEPDIR) -name \*.d -delete