diff --git a/.gitignore b/.gitignore index d5de5af..714c29f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.so *.out *.hex +*.gz # Ignore /bin/ directory /bin/ diff --git a/LICENSE b/COPYING similarity index 100% rename from LICENSE rename to COPYING diff --git a/Makefile b/Makefile index ffa69b4..494a7d8 100644 --- a/Makefile +++ b/Makefile @@ -3,43 +3,72 @@ include config.mk -SRC = drw.c dwm.c util.c -OBJ = ${SRC:.c=.o} +INSTALL ?= install +GZIP ?= gzip +TAR ?= tar -all: dwm +SRC = $(wildcard src/*.c) +OBJ = $(addsuffix .o,$(SRC)) +DEP = $(addsuffix .d,$(SRC)) -.c.o: - ${CC} -c ${CFLAGS} $< +# Set Q to @ to silence commands being printed, unless --no-silent has been set +ifeq (0, $(words $(findstring --no-silent,$(MAKEFLAGS)))) +Q=@ +endif -${OBJ}: config.h config.mk +msg = @printf '%-8s %s\n' "$(1)" "$(2)" -config.h: - cp config.def.h $@ +.PHONY: +all: bin/dwm -dwm: ${OBJ} - ${CC} -o $@ ${OBJ} ${LDFLAGS} +.PHONY: +install: $(DESTDIR)/bin/dwm $(DESTDIR)/share/man/man1/dwm.1.gz +$(DESTDIR)/bin/%: bin/% + $(call msg,INSTALL,$@) + $(Q)$(INSTALL) -D -m0755 $< $@ -clean: - rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz - -dist: clean - mkdir -p dwm-${VERSION} - cp -R LICENSE Makefile README config.def.h config.mk\ - dwm.1 drw.h util.h ${SRC} dwm.png transient.c dwm-${VERSION} - tar -cf dwm-${VERSION}.tar dwm-${VERSION} - gzip dwm-${VERSION}.tar - rm -rf dwm-${VERSION} - -install: all - mkdir -p ${DESTDIR}${PREFIX}/bin - cp -f dwm ${DESTDIR}${PREFIX}/bin - chmod 755 ${DESTDIR}${PREFIX}/bin/dwm - mkdir -p ${DESTDIR}${MANPREFIX}/man1 - sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1 - chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1 +$(DESTDIR)/share/man/%: man/% + $(call msg,INSTALL,$@) + $(Q)$(INSTALL) -D -m0644 $< $@ +.PHONY: uninstall: - rm -f ${DESTDIR}${PREFIX}/bin/dwm\ - ${DESTDIR}${MANPREFIX}/man1/dwm.1 + $(Q)$(RM) $(DESTDIR)/bin/dwm\ + $(DESTDIR)/share/man/man1/dwm.1.gz -.PHONY: all clean dist install uninstall +.PHONY: +clean: + $(call msg,CLEAN,src/) + $(Q)$(RM) $(OBJ) + $(call msg,CLEAN,man/) + $(Q)$(RM) $(MAN) + $(call msg,CLEAN,bin/) + $(Q)$(RM) -r bin/ + +# Links together the object files into the final binary. +bin/dwm: $(OBJ) | bin/ + $(call msg,LD,$@) + $(Q)$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^ + +# Compiles C sources into Object files +%.c.o: %.c + $(call msg,CC,$@) + $(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $< + +# Compress files requested for compression using GZIP +%.gz: % + $(call msg,GZIP,$@) + $(Q)$(GZIP) -k $< + +# Create directories +%/: + $(call msg-mkdir,$@) + $(Q)mkdir $@ + +# Generate and include dependencies, +# ignoring any errors that may occur when doing so. +%.c.d: %.c + $(Q)$(CC) -MM $(CPPFLAGS) -MF $@ $< +ifeq (0, $(words $(findstring $(MAKECMDGOALS), clean))) +-include $(DEP) +endif diff --git a/dwm.1 b/man/man1/dwm.1 similarity index 100% rename from dwm.1 rename to man/man1/dwm.1 diff --git a/config.def.h b/src/config.h similarity index 100% rename from config.def.h rename to src/config.h diff --git a/drw.c b/src/drw.c similarity index 100% rename from drw.c rename to src/drw.c diff --git a/drw.h b/src/drw.h similarity index 100% rename from drw.h rename to src/drw.h diff --git a/dwm.c b/src/dwm.c similarity index 100% rename from dwm.c rename to src/dwm.c diff --git a/transient.c b/src/transient.c similarity index 100% rename from transient.c rename to src/transient.c diff --git a/util.c b/src/util.c similarity index 100% rename from util.c rename to src/util.c diff --git a/util.h b/src/util.h similarity index 100% rename from util.h rename to src/util.h