diff options
| author | Abhinav Prasai <abhinav.prsai@gmail.com> | 2025-08-27 19:52:58 +0100 |
|---|---|---|
| committer | Abhinav Prasai <abhinav.prsai@gmail.com> | 2025-08-28 09:54:09 +0100 |
| commit | 6962146b747e449e7281b6c6acda0a32fb1ff453 (patch) | |
| tree | 3875d5852852015aa3e8d3360358c17bff8e1413 /Makefile | |
| parent | ce3f2d4fa36c0c4e13a30e958ec8aa5f5e84b883 (diff) | |
update Makefile + fix warnings
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 93 |
1 files changed, 59 insertions, 34 deletions
@@ -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 |
