Makefile 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. TARGET = lfs.a
  2. ifneq ($(wildcard test.c main.c),)
  3. override TARGET = lfs
  4. endif
  5. CC ?= gcc
  6. AR ?= ar
  7. SIZE ?= size
  8. SRC += $(wildcard *.c bd/*.c)
  9. OBJ := $(SRC:.c=.o)
  10. DEP := $(SRC:.c=.d)
  11. ASM := $(SRC:.c=.s)
  12. ifdef DEBUG
  13. override CFLAGS += -O0 -g3
  14. else
  15. override CFLAGS += -Os
  16. endif
  17. ifdef WORD
  18. override CFLAGS += -m$(WORD)
  19. endif
  20. ifdef TRACE
  21. override CFLAGS += -DLFS_YES_TRACE
  22. endif
  23. override CFLAGS += -I.
  24. override CFLAGS += -std=c99 -Wall -pedantic
  25. override CFLAGS += -Wextra -Wshadow -Wjump-misses-init -Wundef
  26. # Remove missing-field-initializers because of GCC bug
  27. override CFLAGS += -Wno-missing-field-initializers
  28. ifdef VERBOSE
  29. override TFLAGS += -v
  30. endif
  31. all: $(TARGET)
  32. asm: $(ASM)
  33. size: $(OBJ)
  34. $(SIZE) -t $^
  35. test:
  36. ./scripts/test.py $(TFLAGS)
  37. .SECONDEXPANSION:
  38. test%: tests/test$$(firstword $$(subst \#, ,%)).toml
  39. ./scripts/test.py $@ $(TFLAGS)
  40. -include $(DEP)
  41. lfs: $(OBJ)
  42. $(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
  43. %.a: $(OBJ)
  44. $(AR) rcs $@ $^
  45. %.o: %.c
  46. $(CC) -c -MMD $(CFLAGS) $< -o $@
  47. %.s: %.c
  48. $(CC) -S $(CFLAGS) $< -o $@
  49. clean:
  50. rm -f $(TARGET)
  51. rm -f $(OBJ)
  52. rm -f $(DEP)
  53. rm -f $(ASM)
  54. rm -f tests/*.toml.*