Makefile 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # Makefile
  3. #
  4. # Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. DEBUG = yes
  20. # Compilers and tools
  21. CC = i686-elf-gcc
  22. ASM = nasm
  23. AR = i686-elf-ar
  24. # Directories
  25. SRCDIR = src
  26. OBJDIR = obj
  27. DEPDIR = dep
  28. # Flags
  29. CFLAGS = -Wall -Werror -ffreestanding -nostdlib -fPIC -I ..
  30. ASMFLAGS = -felf
  31. ifeq ($(DEBUG), yes)
  32. CFLAGS += -g
  33. else
  34. CFLAGS += -O3
  35. endif
  36. # Input and output files
  37. SOURCES = $(wildcard $(SRCDIR)/*.c)
  38. SOURCES += $(wildcard $(SRCDIR)/*.asm)
  39. DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
  40. OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
  41. .PHONY: all clean
  42. all: $(WRAPPERS) $(OBJDIR) $(DEPDIR) libmlsys.a
  43. -include $(DEPENDS)
  44. $(OBJDIR):
  45. mkdir -p $(OBJDIR)
  46. $(DEPDIR):
  47. mkdir -p $(DEPDIR)
  48. $(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
  49. mkdir -p $(dir $@)
  50. mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
  51. $(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
  52. $(OBJDIR)/%.o: $(SRCDIR)/%.asm Makefile
  53. $(ASM) $(ASMFLAGS) -o $@ $<
  54. libmlsys.a: $(OBJECTS)
  55. $(AR) rcs $@ $^
  56. clean:
  57. rm -f libmlsys.a
  58. find $(OBJDIR) -name \*.o -delete
  59. find $(DEPDIR) -name \*.d -delete