spectrwm/linux/Makefile
Helmut Grohne ceaf8699f8 linux: Accept user-provided pkg-config command
When cross-building, it's necessary to use versions of the various
toolchain commands that have been built specifically to target the
desired architecture, and that are named accordingly.

In practice, the make invocation will look something like

  $ make CC=aarch64-linux-gnu-gcc \
         PKG_CONFIG=aarch64-linux-gnu-pkg-config

However, whereas $(CC) is a built-in make variable and so it
behaves correctly out of the box, for $(PKG_CONFIG) we have to do
some work ourselves.
2020-04-18 03:47:13 +08:00

91 lines
4 KiB
Makefile

PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/lib
SYSCONFDIR ?= $(PREFIX)/etc
DATAROOTDIR ?= $(PREFIX)/share
MANDIR ?= $(DATAROOTDIR)/man
DOCDIR ?= $(DATAROOTDIR)/doc/spectrwm
XSESSIONSDIR ?= $(DATAROOTDIR)/xsessions
PKG_CONFIG ?= pkg-config
BUILDVERSION = $(shell sh $(CURDIR)/../buildver.sh)
LIBVERSION = $(shell . $(CURDIR)/../lib/shlib_version; echo $$major.$$minor)
LIBMAJORVERSION = $(shell . $(CURDIR)/../lib/shlib_version; echo $$major)
MAINT_CFLAGS = -std=c99 -Wmissing-prototypes -Wall -Wextra -Wshadow -Wno-uninitialized -g
MAINT_LDFLAGS = -Wl,--as-needed
MAINT_CPPFLAGS = -I. -D_GNU_SOURCE -DSWM_LIB=\"$(LIBDIR)/libswmhack.so.$(LIBVERSION)\"
ifneq ("${BUILDVERSION}", "")
MAINT_CPPFLAGS += -DSPECTRWM_BUILDSTR=\"$(BUILDVERSION)\"
endif
BIN_CFLAGS = -fPIE
BIN_LDFLAGS = -fPIE -pie
BIN_CPPFLAGS = $(shell $(PKG_CONFIG) --cflags x11 x11-xcb xcb-icccm xcb-keysyms xcb-randr xcb-util xcb-xinput xcb-xtest xcursor xft)
BIN_LDLIBS = $(shell $(PKG_CONFIG) --libs x11 x11-xcb xcb-icccm xcb-keysyms xcb-randr xcb-util xcb-xinput xcb-xtest xcursor xft)
LIB_CFLAGS = -fPIC
LIB_LDFLAGS = -fPIC -shared
LIB_CPPFLAGS = $(shell $(PKG_CONFIG) --cflags x11)
LIB_LDLIBS = $(shell $(PKG_CONFIG) --libs x11) -ldl
all: spectrwm libswmhack.so.$(LIBVERSION)
spectrwm: spectrwm.o linux.o
$(CC) $(MAINT_LDFLAGS) $(BIN_LDFLAGS) $(LDFLAGS) -o $@ $+ $(BIN_LDLIBS) $(LDLIBS)
spectrwm.o: ../spectrwm.c ../version.h tree.h util.h
$(CC) $(MAINT_CFLAGS) $(BIN_CFLAGS) $(CFLAGS) $(MAINT_CPPFLAGS) $(BIN_CPPFLAGS) $(CPPFLAGS) -c -o $@ $<
linux.o: linux.c util.h
$(CC) $(MAINT_CFLAGS) $(BIN_CFLAGS) $(CFLAGS) $(MAINT_CPPFLAGS) $(BIN_CPPFLAGS) $(CPPFLAGS) -c -o $@ $<
libswmhack.so.$(LIBVERSION): swm_hack.so
$(CC) $(MAINT_LDFLAGS) $(LIB_LDFLAGS) $(LDFLAGS) -Wl,-soname,$@ -o $@ $+ $(LIB_LDLIBS) $(LDLIBS)
swm_hack.so: ../lib/swm_hack.c
$(CC) $(MAINT_CFLAGS) $(LIB_CFLAGS) $(CFLAGS) $(MAINT_CPPFLAGS) $(LIB_CPPFLAGS) $(CPPFLAGS) -c -o $@ $<
clean:
rm -f spectrwm *.o libswmhack.so.* *.so
install: all
install -m 755 -d $(DESTDIR)$(BINDIR)
install -m 755 -d $(DESTDIR)$(LIBDIR)
install -m 755 -d $(DESTDIR)$(SYSCONFDIR)
install -m 755 -d $(DESTDIR)$(MANDIR)/man1
install -m 755 -d $(DESTDIR)$(DOCDIR)
install -m 755 -d $(DESTDIR)$(DOCDIR)/examples
install -m 755 -d $(DESTDIR)$(XSESSIONSDIR)
install -m 755 spectrwm $(DESTDIR)$(BINDIR)
ln -sf spectrwm $(DESTDIR)$(BINDIR)/scrotwm
install -m 755 libswmhack.so.$(LIBVERSION) $(DESTDIR)$(LIBDIR)
ln -sf libswmhack.so.$(LIBVERSION) $(DESTDIR)$(LIBDIR)/libswmhack.so.$(LIBMAJORVERSION)
ln -sf libswmhack.so.$(LIBVERSION) $(DESTDIR)$(LIBDIR)/libswmhack.so
install -m 644 ../spectrwm.conf $(DESTDIR)$(SYSCONFDIR)
install -m 644 ../spectrwm.1 $(DESTDIR)$(MANDIR)/man1
install -m 644 ../CHANGELOG.md $(DESTDIR)$(DOCDIR)
install -m 644 ../LICENSE.md $(DESTDIR)$(DOCDIR)
install -m 644 baraction.sh $(DESTDIR)$(DOCDIR)/examples
install -m 644 ../initscreen.sh $(DESTDIR)$(DOCDIR)/examples
install -m 644 ../screenshot.sh $(DESTDIR)$(DOCDIR)/examples
install -m 644 ../spectrwm_*.conf $(DESTDIR)$(DOCDIR)/examples
install -m 644 spectrwm.desktop $(DESTDIR)$(XSESSIONSDIR)
uninstall:
rm -f $(DESTDIR)$(BINDIR)/spectrwm
rm -f $(DESTDIR)$(BINDIR)/scrotwm
rm -f $(DESTDIR)$(LIBDIR)/libswmhack.so.$(LIBVERSION)
rm -f $(DESTDIR)$(LIBDIR)/libswmhack.so.$(LIBMAJORVERSION)
rm -f $(DESTDIR)$(LIBDIR)/libswmhack.so
rm -f $(DESTDIR)$(SYSCONFDIR)/spectrwm.conf
rm -f $(DESTDIR)$(MANDIR)/man1/spectrwm.1
rm -f $(DESTDIR)$(DOCDIR)/CHANGELOG.md
rm -f $(DESTDIR)$(DOCDIR)/LICENSE.md
rm -f $(DESTDIR)$(DOCDIR)/examples/baraction.sh
rm -f $(DESTDIR)$(DOCDIR)/examples/initscreen.sh
rm -f $(DESTDIR)$(DOCDIR)/examples/screenshot.sh
rm -f $(DESTDIR)$(DOCDIR)/examples/spectrwm_*.conf
rm -f $(DESTDIR)$(XSESSIONSDIR)/spectrwm.desktop
.PHONY: all clean install uninstall