Makefile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 -I .. -I ../crt/include
  33. ASMFLAGS = -felf
  34. LDFLAGS = -T link.ld -L $(LIBGCC_DIR) -L ../crt -lgcc -lmlcrt
  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)/memory/*.c)
  43. SOURCES += $(wildcard $(SRCDIR)/exec/*.c)
  44. SOURCES += $(shell find $(SRCDIR)/drivers -type f -name \*.c)
  45. SOURCES += $(wildcard $(SRCDIR)/*.asm)
  46. ifeq ($(ACPICA), yes)
  47. CFLAGS += -I include/acpica -D ACPICA
  48. SOURCES += $(shell find $(SRCDIR)/acpica -type f -name \*.c)
  49. endif
  50. DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
  51. OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
  52. .PHONY: all clean
  53. all: $(OBJDIR) $(DEPDIR) monolithium
  54. clean:
  55. find $(OBJDIR) -name \*.o -delete
  56. find $(DEPDIR) -name \*.d -delete
  57. rm -f monolithium
  58. -include $(DEPENDS)
  59. $(OBJDIR):
  60. mkdir -p $(OBJDIR)
  61. $(DEPDIR):
  62. mkdir -p $(DEPDIR)
  63. $(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
  64. mkdir -p $(dir $@)
  65. mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
  66. $(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
  67. $(OBJDIR)/%.o: $(SRCDIR)/%.asm
  68. mkdir -p $(dir $@)
  69. $(ASM) $(ASMFLAGS) -o $@ $<
  70. monolithium: $(OBJDIR)/boot/boot.o $(OBJECTS)
  71. $(LINK) -o $@ $(OBJECTS) $(LDFLAGS)