CC? = cc MAIN = dwmclock SRC = dwmclock.c OBJ = $(SRC:.c=.o) CFLAGS := -std=c99 -Wall -Wextra -pedantic -Os $(shell pkg-config --cflags x11) $(CFLAGS) LDFLAGS := $(shell pkg-config --libs x11) $(LDFLAGS) # install in /usr/local/bin DESTDIR ?= / PREFIX ?= /usr/local # install in ~/.local/bin #DESTDIR ?= ~ #PREFIX ?= /.local include config.mk all: $(SRC) $(MAIN) $(MAIN): $(OBJ) $(CC) $(LDFLAGS) -o $@ $(OBJ) $(MAIN)-print: CFLAGS+=-DPRINT $(MAIN)-print: LDFLAGS= $(MAIN)-print: $(OBJ:.o=-print.o) $(CC) $(LDFLAGS) -o $@ $(OBJ:.o=-print.o) %-print.o: $(CC) -c $(CFLAGS) $(@:-print.o=.c) -o $@ .c.o: $(CC) -c $(CFLAGS) $< -o $@ clean: -rm -f $(MAIN) $(OBJ) $(MAIN)-print $(OBJ:.o=-print.o) install: $(MAIN) install -d $(DESTDIR)$(PREFIX)/bin/ install -m 755 $(MAIN) $(DESTDIR)$(PREFIX)/bin/ [ -f $(MAIN)-print ] && install -m 755 $(MAIN)-print $(DESTDIR)$(PREFIX)/bin/ uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/$(MAIN) $(DESTDIR)$(PREFIX)/bin/$(MAIN)-print .PHONY: all clean install uninstall