Makefile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 rambd/*.c filebd/*.c)
  9. OBJ := $(SRC:.c=.o)
  10. DEP := $(SRC:.c=.d)
  11. ASM := $(SRC:.c=.s)
  12. TEST := $(patsubst tests/%.sh,%,$(wildcard tests/test_*))
  13. SHELL = /bin/bash -o pipefail
  14. ifdef DEBUG
  15. override CFLAGS += -O0 -g3
  16. else
  17. override CFLAGS += -Os
  18. endif
  19. ifdef WORD
  20. override CFLAGS += -m$(WORD)
  21. endif
  22. ifdef TRACE
  23. override CFLAGS += -DLFS_YES_TRACE
  24. endif
  25. override CFLAGS += -I.
  26. override CFLAGS += -std=c99 -Wall -pedantic
  27. override CFLAGS += -Wextra -Wshadow -Wjump-misses-init -Wundef
  28. # Remove missing-field-initializers because of GCC bug
  29. override CFLAGS += -Wno-missing-field-initializers
  30. all: $(TARGET)
  31. asm: $(ASM)
  32. size: $(OBJ)
  33. $(SIZE) -t $^
  34. .SUFFIXES:
  35. test: \
  36. test_format \
  37. test_dirs \
  38. test_files \
  39. test_seek \
  40. test_truncate \
  41. test_entries \
  42. test_interspersed \
  43. test_alloc \
  44. test_paths \
  45. test_attrs \
  46. test_move \
  47. test_orphan \
  48. test_relocations \
  49. test_corrupt
  50. @rm test.c
  51. test_%: tests/test_%.sh
  52. ifdef QUIET
  53. @./$< | sed -nu '/^[-=]/p'
  54. else
  55. ./$<
  56. endif
  57. test_:
  58. ./scripts/test_.py $(TFLAGS)
  59. -include $(DEP)
  60. %?:
  61. @echo '$($*)'
  62. lfs: $(OBJ)
  63. $(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
  64. %.a: $(OBJ)
  65. $(AR) rcs $@ $^
  66. %.o: %.c
  67. $(CC) -c -MMD $(CFLAGS) $< -o $@
  68. %.s: %.c
  69. $(CC) -S $(CFLAGS) $< -o $@
  70. clean:
  71. rm -f $(TARGET)
  72. rm -f $(OBJ)
  73. rm -f $(DEP)
  74. rm -f $(ASM)
  75. rm -f tests_/test_*.toml.*