Makefile 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # The toolchain definitions
  2. CC = cc
  3. SPARSE = sparse
  4. V = @ # Verbose build: make V=1
  5. C = 0 # Sparsechecker build: make C=1
  6. Q = $(V:1=)
  7. QUIET_CC = $(Q:@=@echo ' CC '$@;)$(CC)
  8. QUIET_DEPEND = $(Q:@=@echo ' DEPEND '$@;)$(CC)
  9. ifeq ($(C),1)
  10. QUIET_SPARSE = $(Q:@=@echo ' SPARSE '$@;)$(SPARSE)
  11. else
  12. QUIET_SPARSE = @/bin/true
  13. endif
  14. PREFIX ?= /usr/local
  15. CFLAGS ?= -Os -fomit-frame-pointer
  16. CFLAGS += -std=c99 -Wall -pedantic -D_BSD_SOURCE
  17. LDFLAGS ?=
  18. SRCS = morse_encoder.c
  19. BIN = morse_encoder
  20. .SUFFIXES:
  21. .PHONY: all install clean distclean
  22. .DEFAULT_GOAL := all
  23. DEPS = $(sort $(patsubst %.c,dep/%.d,$(1)))
  24. OBJS = $(sort $(patsubst %.c,obj/%.o,$(1)))
  25. # Generate dependencies
  26. $(call DEPS,$(SRCS)): dep/%.d: %.c
  27. @mkdir -p $(dir $@)
  28. $(QUIET_DEPEND) -o $@.tmp -MM -MG -MT "$@ $(patsubst dep/%.d,obj/%.o,$@)" $(CFLAGS) $< && mv -f $@.tmp $@
  29. -include $(call DEPS,$(SRCS))
  30. # Generate object files
  31. $(call OBJS,$(SRCS)): obj/%.o:
  32. @mkdir -p $(dir $@)
  33. $(QUIET_SPARSE) $(SPARSEFLAGS) $<
  34. $(QUIET_CC) -o $@ -c $(CFLAGS) $<
  35. all: $(BIN)
  36. $(BIN): $(call OBJS,$(SRCS))
  37. $(QUIET_CC) $(CFLAGS) -o $(BIN) $(call OBJS,$(SRCS)) $(LDFLAGS)
  38. clean:
  39. -rm -Rf obj dep *.orig *.rej *~
  40. distclean: clean
  41. -rm -f $(BIN)