Makefile 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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: test_format test_dirs test_files test_seek test_truncate \
  36. test_entries test_interspersed test_alloc test_paths test_attrs \
  37. test_move test_orphan test_corrupt
  38. @rm test.c
  39. test_%: tests/test_%.sh
  40. ifdef QUIET
  41. @./$< | sed -n '/^[-=]/p'
  42. else
  43. ./$<
  44. endif
  45. -include $(DEP)
  46. lfs: $(OBJ)
  47. $(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
  48. %.a: $(OBJ)
  49. $(AR) rcs $@ $^
  50. %.o: %.c
  51. $(CC) -c -MMD $(CFLAGS) $< -o $@
  52. %.s: %.c
  53. $(CC) -S $(CFLAGS) $< -o $@
  54. clean:
  55. rm -f $(TARGET)
  56. rm -f $(OBJ)
  57. rm -f $(DEP)
  58. rm -f $(ASM)