Makefile 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. # Settings
  20. DEBUG = yes
  21. ACPICA = yes
  22. # Compilers and tools
  23. CC = i686-elf-gcc
  24. ASM = nasm
  25. LINK = i686-elf-ld
  26. # Directories
  27. SRCDIR = src
  28. OBJDIR = obj
  29. DEPDIR = dep
  30. LIBGCC_DIR = $(shell $(CC) -print-file-name=)
  31. # Flags
  32. CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I include
  33. ASMFLAGS = -felf
  34. LDFLAGS = -T link.ld -L $(LIBGCC_DIR) -lgcc
  35. ifeq ($(DEBUG), yes)
  36. CFLAGS += -g
  37. else
  38. CFLAGS += -O3
  39. endif
  40. # Input and output files
  41. SOURCES = $(wildcard $(SRCDIR)/*.c)
  42. SOURCES += $(wildcard $(SRCDIR)/exec/*.c)
  43. SOURCES += $(shell find $(SRCDIR)/drivers -type f -name \*.c)
  44. SOURCES += $(wildcard $(SRCDIR)/*.asm)
  45. ifeq ($(ACPICA), yes)
  46. CFLAGS += -I include/acpica -D ACPICA
  47. SOURCES += $(shell find $(SRCDIR)/acpica -type f -name \*.c)
  48. endif
  49. DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
  50. OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
  51. .PHONY: all clean
  52. all: $(OBJDIR) $(DEPDIR) monolithium
  53. clean:
  54. find $(OBJDIR) -name \*.o -delete
  55. find $(DEPDIR) -name \*.d -delete
  56. rm monolithium
  57. -include $(DEPENDS)
  58. $(OBJDIR):
  59. mkdir -p $(OBJDIR)
  60. $(DEPDIR):
  61. mkdir -p $(DEPDIR)
  62. $(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
  63. mkdir -p $(dir $@)
  64. mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
  65. $(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
  66. $(OBJDIR)/%.o: $(SRCDIR)/%.asm
  67. mkdir -p $(dir $@)
  68. $(ASM) $(ASMFLAGS) -o $@ $<
  69. monolithium: $(OBJDIR)/boot/boot.o $(OBJECTS)
  70. $(LINK) -o $@ $(OBJECTS) $(LDFLAGS)