Makefile 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. override CFLAGS += -I.
  23. override CFLAGS += -std=c99 -Wall -pedantic
  24. override CFLAGS += -Wextra -Wshadow -Wjump-misses-init
  25. # Remove missing-field-initializers because of GCC bug
  26. override CFLAGS += -Wno-missing-field-initializers
  27. all: $(TARGET)
  28. asm: $(ASM)
  29. size: $(OBJ)
  30. $(SIZE) -t $^
  31. .SUFFIXES:
  32. test: test_format test_dirs test_files test_seek test_truncate \
  33. test_entries test_interspersed test_alloc test_paths test_attrs \
  34. test_move test_orphan test_corrupt
  35. @rm test.c
  36. test_%: tests/test_%.sh
  37. ifdef QUIET
  38. @./$< | sed -n '/^[-=]/p'
  39. else
  40. ./$<
  41. endif
  42. -include $(DEP)
  43. lfs: $(OBJ)
  44. $(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
  45. %.a: $(OBJ)
  46. $(AR) rcs $@ $^
  47. %.o: %.c
  48. $(CC) -c -MMD $(CFLAGS) $< -o $@
  49. %.s: %.c
  50. $(CC) -S $(CFLAGS) $< -o $@
  51. clean:
  52. rm -f $(TARGET)
  53. rm -f $(OBJ)
  54. rm -f $(DEP)
  55. rm -f $(ASM)