Makefile 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 emubd/*.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
  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_corrupt
  49. @rm test.c
  50. test_%: tests/test_%.sh
  51. ifdef QUIET
  52. @./$< | sed -n '/^[-=]/p'
  53. else
  54. ./$<
  55. endif
  56. -include $(DEP)
  57. lfs: $(OBJ)
  58. $(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
  59. %.a: $(OBJ)
  60. $(AR) rcs $@ $^
  61. %.o: %.c
  62. $(CC) -c -MMD $(CFLAGS) $< -o $@
  63. %.s: %.c
  64. $(CC) -S $(CFLAGS) $< -o $@
  65. clean:
  66. rm -f $(TARGET)
  67. rm -f $(OBJ)
  68. rm -f $(DEP)
  69. rm -f $(ASM)