Makefile 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. CC := gcc
  2. INSTALL := install
  3. CFLAGS += -g -O2 -flto -Wall
  4. LDFLAGS :=
  5. LIBS := -lX11 -lXi
  6. DESTDIR :=
  7. PREFIX := /usr/local
  8. CFLAGS += -DPREFIX=$(PREFIX)
  9. BIN = execonkp
  10. SRCS = main.c
  11. V = @ # Verbose build: make V=1
  12. Q = $(V:1=)
  13. QUIET_CC = $(Q:@=@echo ' CC '$@;)$(CC)
  14. QUIET_DEPEND = $(Q:@=@echo ' DEPEND '$@;)$(CC)
  15. DEPS = $(patsubst %.c,dep/%.d,$(1))
  16. OBJS = $(patsubst %.c,obj/%.o,$(1))
  17. .SUFFIXES:
  18. .PHONY: all install clean
  19. .DEFAULT_GOAL := all
  20. # Generate dependencies
  21. $(call DEPS,$(SRCS)): dep/%.d: %.c
  22. @mkdir -p $(dir $@)
  23. $(QUIET_DEPEND) -o $@.tmp -MM -MT "$@ $(patsubst dep/%.d,obj/%.o,$@)" $(CFLAGS) $< && mv -f $@.tmp $@
  24. -include $(call DEPS,$(SRCS))
  25. # Generate object files
  26. $(call OBJS,$(SRCS)): obj/%.o:
  27. @mkdir -p $(dir $@)
  28. $(QUIET_CC) -o $@ -c $(CFLAGS) $<
  29. all: $(BIN)
  30. $(BIN): $(call OBJS,$(SRCS))
  31. $(QUIET_CC) $(CFLAGS) -o $(BIN) $(LDFLAGS) $(LIBS) $(call OBJS,$(SRCS))
  32. clean:
  33. rm -Rf dep obj core *~ $(BIN)
  34. install: $(BIN)
  35. $(INSTALL) -d -m755 $(DESTDIR)$(PREFIX)/bin/
  36. $(INSTALL) -m755 $(BIN) $(DESTDIR)$(PREFIX)/bin/