Makefile 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 -Wshadow -Wunused-parameter
  24. all: $(TARGET)
  25. asm: $(ASM)
  26. size: $(OBJ)
  27. $(SIZE) -t $^
  28. .SUFFIXES:
  29. test: test_format test_dirs test_files test_seek test_truncate \
  30. test_interspersed test_alloc test_paths test_orphan test_move test_corrupt
  31. @rm test.c
  32. test_%: tests/test_%.sh
  33. ifdef QUIET
  34. @./$< | sed -n '/^[-=]/p'
  35. else
  36. ./$<
  37. endif
  38. -include $(DEP)
  39. lfs: $(OBJ)
  40. $(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
  41. %.a: $(OBJ)
  42. $(AR) rcs $@ $^
  43. %.o: %.c
  44. $(CC) -c -MMD $(CFLAGS) $< -o $@
  45. %.s: %.c
  46. $(CC) -S $(CFLAGS) $< -o $@
  47. clean:
  48. rm -f $(TARGET)
  49. rm -f $(OBJ)
  50. rm -f $(DEP)
  51. rm -f $(ASM)