Makefile 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # The toolchain definitions
  2. CC = gcc
  3. INSTALL = install
  4. SPARSE = sparse
  5. V = @ # Verbose build: make V=1
  6. C = 0 # Sparsechecker build: make C=1
  7. Q = $(V:1=)
  8. QUIET_CC = $(Q:@=@echo ' CC '$@;)$(CC)
  9. QUIET_DEPEND = $(Q:@=@echo ' DEPEND '$@;)$(CC)
  10. ifeq ($(C),1)
  11. QUIET_SPARSE = $(Q:@=@echo ' SPARSE '$@;)$(SPARSE)
  12. else
  13. QUIET_SPARSE = @/bin/true
  14. endif
  15. PREFIX ?= /usr/local
  16. CFLAGS = -O2 -Wall -std=c99 -D_GNU_SOURCE -pedantic
  17. LDFLAGS = -lm
  18. SPARSEFLAGS = $(CFLAGS) -D__transparent_union__=__unused__ -D_STRING_ARCH_unaligned=1 \
  19. -D__DBL_MAX__=0.0l \
  20. -Wdeclaration-after-statement -Wdo-while -Wptr-subtraction-blows \
  21. -Wreturn-void -Wshadow -Wtypesign -Wundef
  22. SRCS = main.c es51984.c
  23. BIN = mmmeas
  24. .SUFFIXES:
  25. .PHONY: all install clean distclean
  26. .DEFAULT_GOAL := all
  27. DEPS = $(sort $(patsubst %.c,dep/%.d,$(1)))
  28. OBJS = $(sort $(patsubst %.c,obj/%.o,$(1)))
  29. # Generate dependencies
  30. $(call DEPS,$(SRCS)): dep/%.d: %.c
  31. @mkdir -p $(dir $@)
  32. $(QUIET_DEPEND) -o $@.tmp -MM -MT "$@ $(patsubst dep/%.d,obj/%.o,$@)" $(CFLAGS) $< && mv -f $@.tmp $@
  33. -include $(call DEPS,$(SRCS))
  34. # Generate object files
  35. $(call OBJS,$(SRCS)): obj/%.o:
  36. @mkdir -p $(dir $@)
  37. $(QUIET_SPARSE) $(SPARSEFLAGS) $<
  38. $(QUIET_CC) -o $@ -c $(CFLAGS) $<
  39. all: $(BIN)
  40. $(BIN): $(call OBJS,$(SRCS))
  41. $(QUIET_CC) $(CFLAGS) -o $(BIN) $(call OBJS,$(SRCS)) $(LDFLAGS)
  42. install: all
  43. $(INSTALL) -g 0 -o 0 -m 0755 -t $(PREFIX)/bin/ $(BIN)
  44. clean:
  45. -rm -Rf *~ obj dep
  46. distclean: clean
  47. -rm -f $(BIN)