summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile93
1 files changed, 59 insertions, 34 deletions
diff --git a/Makefile b/Makefile
index 3faa801..c283518 100644
--- a/Makefile
+++ b/Makefile
@@ -1,28 +1,56 @@
-CC ?= gcc
-CFLAGS ?= -std=c99 -Wall -Wextra -Os
-LDFLAGS ?= -lX11 -lXinerama -lXcursor -Isrc
-
-PREFIX ?= /usr/local
-BIN := sxwm
-SRC_DIR := src
-OBJ_DIR := build
-SRC := $(wildcard $(SRC_DIR)/*.c)
-OBJ := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC))
-DEP := $(OBJ:.o=.d)
-
-MAN := sxwm.1
-MAN_DIR := $(PREFIX)/share/man/man1
+# tools
+CC ?= cc
+PKG_CONFIG ?= pkg-config
+# install dirs
+PREFIX ?= /usr/local
+DESTDIR ?=
+BIN := sxwm
+MAN := sxwm.1
+MAN_DIR := $(PREFIX)/share/man/man1
XSESSIONS := $(DESTDIR)$(PREFIX)/share/xsessions
+# layout
+SRC_DIR := src/
+OBJ_DIR := build/
+SRC := $(wildcard $(SRC_DIR)/*.c)
+OBJ := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC))
+DEP := $(OBJ:.o=.d)
+
+# flags
+CPPFLAGS ?= -Isrc -D_FORTIFY_SOURCE=2
+
+# compile flags + warnings, hardening
+CFLAGS ?= -std=c99 -Os -pipe \
+ -Wall -Wextra -Wformat=2 -Werror=format-security \
+ -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings \
+ -Wmissing-prototypes -Wstrict-prototypes -Wswitch-enum \
+ -Wundef -Wvla -fno-common -fno-strict-aliasing \
+ -fstack-protector-strong -fPIE
+
+# linker
+LDFLAGS ?= -Wl,-O1 -pie
+
+# libraries
+LDLIBS ?= -lX11 -lXinerama -lXcursor
+
+# prefer pkg-confgi
+ifneq ($(shell $(PKG_CONFIG) --exists x11 xinerama xcursor && echo yes),)
+CPPFLAGS += $(shell $(PKG_CONFIG) --cflags x11 xinerama xcursor)
+LDLIBS := $(shell $(PKG_CONFIG) --libs x11 xinerama xcursor)
+endif
+
+.PHONY: all clean install uninstall clangd
+.SUFFIXES:
+
all: $(BIN)
$(BIN): $(OBJ)
- $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
+ $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
@mkdir -p $(dir $@)
- $(CC) $(CFLAGS) -MMD -MP -c -o $@ $<
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c -o $@ $<
-include $(DEP)
@@ -33,34 +61,31 @@ clean:
@rm -rf $(OBJ_DIR) $(BIN)
install: all
- @echo "Installing $(BIN) to $(DESTDIR)$(PREFIX)/bin..."
+ @echo "installing $(BIN) to $(DESTDIR)$(PREFIX)/bin..."
@mkdir -p "$(DESTDIR)$(PREFIX)/bin"
@install -m 755 $(BIN) "$(DESTDIR)$(PREFIX)/bin/$(BIN)"
- @echo "Installing sxwm.desktop to $(XSESSIONS)..."
+ @echo "installing sxwm.desktop to $(XSESSIONS)..."
@mkdir -p "$(XSESSIONS)"
@install -m 644 sxwm.desktop "$(XSESSIONS)/sxwm.desktop"
- @echo "Installing man page to $(DESTDIR)$(MAN_DIR)..."
- @mkdir -p $(DESTDIR)$(MAN_DIR)
- @install -m 644 $(MAN) $(DESTDIR)$(MAN_DIR)/
- @echo "Copying default configuration to $(DESTDIR)$(PREFIX)/share/sxwmrc..."
+ @echo "installing man page to $(DESTDIR)$(MAN_DIR)..."
+ @mkdir -p "$(DESTDIR)$(MAN_DIR)"
+ @install -m 644 $(MAN) "$(DESTDIR)$(MAN_DIR)/"
+ @echo "copying default config to $(DESTDIR)$(PREFIX)/share/sxwmrc..."
@mkdir -p "$(DESTDIR)$(PREFIX)/share"
@install -m 644 default_sxwmrc "$(DESTDIR)$(PREFIX)/share/sxwmrc"
- @echo "Installation complete."
+ @echo "installation complete :)"
uninstall:
- @echo "Uninstalling $(BIN) from $(DESTDIR)$(PREFIX)/bin..."
+ @echo "uninstalling $(BIN) from $(DESTDIR)$(PREFIX)/bin..."
@rm -f "$(DESTDIR)$(PREFIX)/bin/$(BIN)"
- @echo "Uninstalling sxwm.desktop from $(XSESSIONS)..."
+ @echo "uninstalling sxwm.desktop from $(XSESSIONS)..."
@rm -f "$(XSESSIONS)/sxwm.desktop"
- @echo "Uninstalling man page from $(DESTDIR)$(MAN_DIR)..."
- @rm -f $(DESTDIR)$(MAN_DIR)/$(MAN)
- @echo "Uninstallation complete."
+ @echo "uninstalling man page from $(DESTDIR)$(MAN_DIR)..."
+ @rm -f "$(DESTDIR)$(MAN_DIR)/$(MAN)"
+ @echo "uninstallation complete :)"
+# dev tools
clangd:
- @echo "Generating compile_flags.txt"
+ @echo "generating compile_flags.txt"
@rm -f compile_flags.txt
- @for flag in $(CFLAGS) $(LDFLAGS); do \
- echo $$flag >> compile_flags.txt; \
- done
-
-.PHONY: all clean install uninstall clangd
+ @for flag in $(CPPFLAGS) $(CFLAGS); do echo $$flag >> compile_flags.txt; done