From 6bd0175db04b44f27caa75df4a48fbff6492a74b Mon Sep 17 00:00:00 2001 From: Philippe Pepiot Date: Tue, 16 Nov 2010 13:09:40 +0100 Subject: [PATCH] BuildSystem: complete rewrite Should compile properly on Linux, FreeBSD, OpenBSD and NetBSD --- .gitignore | 2 +- BSDmakefile | 65 -------------------------------- Makefile | 85 +++++++++++++++++++++++------------------- Makefile.in | 79 +++++++++++++++++++++++++++++++++++++++ README | 2 +- common.mk | 37 ------------------ config.mk | 24 ------------ configure | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 232 insertions(+), 167 deletions(-) delete mode 100644 BSDmakefile create mode 100644 Makefile.in delete mode 100644 common.mk delete mode 100644 config.mk create mode 100755 configure diff --git a/.gitignore b/.gitignore index a3eabb8..2c83f39 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ wmfs #* \#* -build +Makefile diff --git a/BSDmakefile b/BSDmakefile deleted file mode 100644 index eb70925..0000000 --- a/BSDmakefile +++ /dev/null @@ -1,65 +0,0 @@ -.include "config.mk" -.include "common.mk" - -PROG= wmfs -MAN1= wmfs.1 - -MANDIR= ${MANPREFIX}/man - -.for lib in xrandr xinerama -.if !empty(LIBS:M${lib}) -CFLAGS+= -DHAVE_${lib:U} -.endif -.endfor - -.if !empty(LIBS:Mimlib2) -CFLAGS+= -DHAVE_IMLIB -.endif - -.if !defined(CFLAGS_LIBS) -CFLAGS_LIBS!= pkg-config --cflags-only-I ${LIBS} -.endif - -.if !defined(LDFLAGS_LIBS) -LDFLAGS_LIBS!= pkg-config --libs ${LIBS} -.endif - -CFLAGS+= ${CFLAGS_LIBS} -LDADD+= ${LDFLAGS_LIBS} -lpthread - -options: - @echo wmfs compile with ${LIBS} - @echo - CFLAGS ${CFLAGS} - @echo - LDFLAGS ${LDFLAGS} - @echo - OUTPUT ${.OBJDIR} - - -install: all maninstall - @echo installing executable file to ${DESTDIR}${PREFIX}/bin - @mkdir -p ${DESTDIR}${PREFIX}/bin - @install ${.OBJDIR}/wmfs ${DESTDIR}${PREFIX}/bin - @echo installing xsession file to ${DESTDIR}${PREFIX}/share/xsessions - @mkdir -p ${DESTDIR}${PREFIX}/share/xsessions - @install -m 644 ${.CURDIR}/wmfs.desktop ${DESTDIR}${PREFIX}/share/xsessions/ - @echo installing default config file to ${DESTDIR}${XDG_CONFIG_DIR} - @mkdir -p ${DESTDIR}${XDG_CONFIG_DIR} - @install -m 444 ${.CURDIR}/wmfsrc ${DESTDIR}${XDG_CONFIG_DIR} - -uninstall: - @echo removing executable file from ${DESTDIR}${PREFIX}/bin - @rm -f ${DESTDIR}${PREFIX}/bin/wmfs - @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 - @rm -f ${DESTDIR}${MANPREFIX}/man1/wmfs.1.gz - @echo removing xsession file from ${DESTDIR}${PREFIX}/share/xsessions/ - @rm -f ${DESTDIR}${PREFIX}/share/xsessions/wmfs.desktop - @echo removing config file from ${DESTDIR}${XDG_CONFIG_DIR} - @rm -f ${DESTDIR}${XDG_CONFIG_DIR}/wmfsrc - -all: options - -.include - -.c.o: config.mk - @if [ ! -d `dirname ${.TARGET}` ]; then mkdir -p `dirname ${.TARGET}`; fi - ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} - diff --git a/Makefile b/Makefile index 3fd56d0..d255df5 100644 --- a/Makefile +++ b/Makefile @@ -1,61 +1,68 @@ -include config.mk -include common.mk +PREFIX=/usr/local +XDG_CONFIG_DIR=/usr/local/etc/xdg/wmfs +MANPREFIX=/usr/local/man -OBJ = ${patsubst %.c,${O}/%.o,${SRCS}} +CFLAGS=-I/usr/include/freetype2 -DHAVE_XINERAMA -DHAVE_XRANDR -DHAVE_IMLIB2 +LDFLAGS=-lX11 -lXft -lfreetype -lXinerama -lXrandr -lImlib2 -lpthread -ifneq ($(findstring xrandr, ${LIBS}),) -CFLAGS+= -DHAVE_XRANDR -endif +PROG=wmfs +MAN=wmfs.1 -ifneq ($(findstring xinerama, ${LIBS}),) -CFLAGS+= -DHAVE_XINERAMA -endif +# wmfs version +VERSION= 201011 -ifneq ($(findstring imlib2, ${LIBS}),) -CFLAGS+= -DHAVE_IMLIB -endif +SRCS= \ +src/barwin.c \ +src/client.c \ +src/config.c \ +src/draw.c \ +src/event.c \ +src/ewmh.c \ +src/frame.c \ +src/getinfo.c \ +src/infobar.c \ +src/init.c \ +src/launcher.c \ +src/layout.c \ +src/menu.c \ +src/mouse.c \ +src/parse/api.c \ +src/parse/parse.c \ +src/screen.c \ +src/status.c \ +src/systray.c \ +src/tag.c \ +src/util.c \ +src/viwmfs.c \ +src/wmfs.c -ifndef CFLAGS_LIBS -CFLAGS_LIBS= $(shell pkg-config --cflags-only-I ${LIBS}) -endif +# flags +CFLAGS+= -DXDG_CONFIG_DIR=\"${XDG_CONFIG_DIR}\" +CFLAGS+= -DWMFS_VERSION=\"${VERSION}\" -ifndef LDFLAGS_LIBS -LDFLAGS_LIBS= $(shell pkg-config --libs ${LIBS}) -endif +OBJS= ${SRCS:.c=.o} -CFLAGS+= ${CFLAGS_LIBS} -LDFLAGS+= ${LDFLAGS_LIBS} -lpthread +all: ${PROG} ${MAN}.gz -all: options ${O}/wmfs ${O}/wmfs.1.gz +${PROG}: ${OBJS} src/structs.h src/wmfs.h src/parse/parse.h + ${CC} -o $@ ${OBJS} ${LDFLAGS} -${O}/wmfs.1.gz: wmfs.1 - gzip -cn -9 $< > $@ +${MAN}.gz: ${MAN} + gzip -cn -9 ${MAN} > $@ -${O}/%.o: %.c config.mk - @if [ ! -d `dirname ${O}/$<` ]; then mkdir -p `dirname ${O}/$<`; fi +.c.o: ${CC} -c ${CFLAGS} $< -o $@ -options: - @echo wmfs compile with ${LIBS} - @echo - CFLAGS ${CFLAGS} - @echo - LDFLAGS ${LDFLAGS} - @echo - OUTPUT ${O} - - @if [ ! -d ${O} ]; then mkdir -p ${O}; fi - -${O}/wmfs: ${OBJ} config.mk src/structs.h src/wmfs.h src/parse/parse.h - ${CC} -o $@ ${OBJ} ${LDFLAGS} - clean: - @rm -f ${OBJ} ${O}/wmfs ${O}/wmfs.1.gz + rm -f ${OBJS} wmfs ${MAN}.gz install: all @echo installing executable file to ${DESTDIR}${PREFIX}/bin mkdir -p ${DESTDIR}${PREFIX}/bin - install ${O}/wmfs ${DESTDIR}${PREFIX}/bin + install ${PROG} ${DESTDIR}${PREFIX}/bin @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 mkdir -p ${DESTDIR}${MANPREFIX}/man1 - install -m 644 ${O}/wmfs.1.gz ${DESTDIR}${MANPREFIX}/man1/ + install -m 644 ${MAN}.gz ${DESTDIR}${MANPREFIX}/man1/ @echo installing xsession file to ${DESTDIR}${PREFIX}/share/xsessions mkdir -p ${DESTDIR}${PREFIX}/share/xsessions install -m 644 wmfs.desktop ${DESTDIR}${PREFIX}/share/xsessions/ diff --git a/Makefile.in b/Makefile.in new file mode 100644 index 0000000..0d69de7 --- /dev/null +++ b/Makefile.in @@ -0,0 +1,79 @@ +PROG=wmfs +MAN=wmfs.1 + +# wmfs version +VERSION= 201011 + +SRCS= \ +src/barwin.c \ +src/client.c \ +src/config.c \ +src/draw.c \ +src/event.c \ +src/ewmh.c \ +src/frame.c \ +src/getinfo.c \ +src/infobar.c \ +src/init.c \ +src/launcher.c \ +src/layout.c \ +src/menu.c \ +src/mouse.c \ +src/parse/api.c \ +src/parse/parse.c \ +src/screen.c \ +src/status.c \ +src/systray.c \ +src/tag.c \ +src/util.c \ +src/viwmfs.c \ +src/wmfs.c + +# flags +CFLAGS+= -DXDG_CONFIG_DIR=\"${XDG_CONFIG_DIR}\" +CFLAGS+= -DWMFS_VERSION=\"${VERSION}\" + +OBJS= ${SRCS:.c=.o} + +all: ${PROG} ${MAN}.gz + +${PROG}: ${OBJS} src/structs.h src/wmfs.h src/parse/parse.h + ${CC} -o $@ ${OBJS} ${LDFLAGS} + +${MAN}.gz: ${MAN} + gzip -cn -9 ${MAN} > $@ + +.c.o: + ${CC} -c ${CFLAGS} $< -o $@ + +clean: + rm -f ${OBJS} wmfs ${MAN}.gz + +install: all + @echo installing executable file to ${DESTDIR}${PREFIX}/bin + mkdir -p ${DESTDIR}${PREFIX}/bin + install ${PROG} ${DESTDIR}${PREFIX}/bin + @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 + mkdir -p ${DESTDIR}${MANPREFIX}/man1 + install -m 644 ${MAN}.gz ${DESTDIR}${MANPREFIX}/man1/ + @echo installing xsession file to ${DESTDIR}${PREFIX}/share/xsessions + mkdir -p ${DESTDIR}${PREFIX}/share/xsessions + install -m 644 wmfs.desktop ${DESTDIR}${PREFIX}/share/xsessions/ + @echo installing default config file to ${DESTDIR}${XDG_CONFIG_DIR} + mkdir -p ${DESTDIR}${XDG_CONFIG_DIR} + install -m 444 wmfsrc ${DESTDIR}${XDG_CONFIG_DIR} + +uninstall: + @echo removing executable file from ${DESTDIR}${PREFIX}/bin + rm -f ${DESTDIR}${PREFIX}/bin/wmfs + @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 + rm -f ${DESTDIR}${MANPREFIX}/man1/wmfs.1.gz + @echo removing xsession file from ${DESTDIR}${PREFIX}/share/xsessions + rm -f ${DESTDIR}${PREFIX}/share/xsessions/wmfs.desktop + @echo removing config file from ${DESTDIR}${XDG_CONFIG_DIR} + rm -f ${DESTDIR}${XDG_CONFIG_DIR}/wmfsrc + + + +.PHONY: all clean install uninstall + diff --git a/README b/README index 7d620ca..1f5bf8a 100644 --- a/README +++ b/README @@ -29,7 +29,7 @@ OS : - FreeBSD/OpenBSD/NetBSD : Supported. INSTALL : -$EDITOR config.mk +./configure [--without-imlib2|--without-xrandr|--without-xinerama] (./configure -h) make sudo make install diff --git a/common.mk b/common.mk deleted file mode 100644 index 8c82390..0000000 --- a/common.mk +++ /dev/null @@ -1,37 +0,0 @@ -# wmfs version -VERSION= 201011 - -SRCS= \ -src/barwin.c \ -src/client.c \ -src/config.c \ -src/draw.c \ -src/event.c \ -src/ewmh.c \ -src/frame.c \ -src/getinfo.c \ -src/infobar.c \ -src/init.c \ -src/launcher.c \ -src/layout.c \ -src/menu.c \ -src/mouse.c \ -src/parse/api.c \ -src/parse/parse.c \ -src/screen.c \ -src/status.c \ -src/systray.c \ -src/tag.c \ -src/util.c \ -src/viwmfs.c \ -src/wmfs.c - -# Used libs -LIBS= x11 xft freetype2 ${OPTIONS} - -# flags -CFLAGS+= -DXDG_CONFIG_DIR=\"${XDG_CONFIG_DIR}\" -CFLAGS+= -DWMFS_VERSION=\"${VERSION}\" - -# build directory -O?= build diff --git a/config.mk b/config.mk deleted file mode 100644 index ea7264f..0000000 --- a/config.mk +++ /dev/null @@ -1,24 +0,0 @@ -# Customize below to fit your system -# x11 xft and freetype2 are REQUIRED, others are optionals -OPTIONS= xrandr xinerama imlib2 - -# If theses variables are defined, make will not call pkg-config -# -# Linux example -# CFLAGS_LIBS= -I/usr/include/freetype2 -# LDFLAGS_LIBS= -lX11 -lXft -lfreetype -lXrandr -lXinerama -lImlib2 -# -# FreeBSD example -# CFLAGS_LIBS= -I/usr/local/include -I/usr/local/include/freetype2 -# LDFLAGS_LIBS= -L/usr/local/lib -lXft -lXrender -lfontconfig -lX11 -lfreetype -lXrandr -lXinerama -lImlib2 -# -# OpenBSD example -# CFLAGS_LIBS= -I/usr/X11R6/include -I/usr/X11R6/include/freetype2 -I/usr/local/include -# LDFLAGS_LIBS= -L/usr/X11R6/lib -L/usr/local/lib -lXft -lfontconfig -lexpat -lXrandr -lXrender -lXinerama -lxcb -lpthread-subs -lXau -lXdmcp -lImlib2 -lfreetype -lz -lX11 -lXext -lm - -# paths -PREFIX= /usr/local -MANPREFIX= ${PREFIX}/man -XDG_CONFIG_DIR= /usr/local/etc/xdg/wmfs - -CFLAGS= -Wall diff --git a/configure b/configure new file mode 100755 index 0000000..0dbbbb7 --- /dev/null +++ b/configure @@ -0,0 +1,105 @@ +#!/bin/sh + +LIBS="x11 xft freetype2" +USE_XINERAMA="xinerama" +USE_XRANDR="xrandr" +USE_IMLIB2="imlib2" +OS=`uname -s` +PREFIX=/usr/local +MANPREFIX="$PREFIX/man" +XDG_CONFIG_DIR="$PREFIX/etc/xdg/wmfs" + +while true; do + case "$1" in + --without-xinerama) + USE_XINERAMA=""; shift;; + --without-xrandr) + USE_XRANDR=""; shift;; + --without-imlib2) + USE_IMLIB2=""; shift;; + --prefix) + [ -z "$2" ] && echo "Missing argument" && exit 1 + PREFIX=$2; shift 2;; + --xdg-config-dir) + [ -z "$2" ] && echo "Missing argument" && exit 1 + XDG_CONFIG_DIR=$2; shift 2;; + --man-prefix) + [ -z "$2" ] && echo "Missing argument" && exit 1 + MANPREFIX=$2; shift 2;; + --help|-h) + echo "Usage: ./configure [options] + --without-imlib2 : compile without imlib2 support + --without-xrandr : compile without xrandr support + --without-xinerama : compile without xinerama support + --prefix DIRECTORY : install binary with specified prefix (default $PREFIX) + --xdg-config-dir DIRECTORY : install configuration to specified directory (default $XDG_CONFIG_DIR) + --man-prefix DIRECTORY : install man page to specified prefix (default $MANPREFIX)" + exit 0;; + *) break;; + esac +done + +LIBS="$LIBS $USE_XINERAMA $USE_XRANDR $USE_IMLIB2" + +which pkg-config >/dev/null 2>&1 + +if [ $? -eq 0 ]; +then + CFLAGS=`pkg-config --cflags-only-I $LIBS` + LDFLAGS=`pkg-config --libs $LIBS` +else + # Try to use some known paths + case $OS in + FreeBSD) + CFLAGS="-I/usr/local/include -I/usr/local/include/freetype2" + LDFLAGS="-L/usr/local/lib";; + OpenBSD) + CFLAGS="-I/usr/X11R6/include -I/usr/X11R6/include/freetype2 -I/usr/local/include" + LDFLAGS="-L/usr/X11R6/lib -L/usr/local/lib";; + NetBSD) + CFLAGS="-I/usr/X11R7/include -I/usr/X11R7/include/freetype2 -I/usr/local/include" + LDFLAGS="-L/usr/X11R7/lib -L/usr/local/lib";; + Linux) + CFLAGS="-I/usr/include/freetype2" + LDFLAGS="" + ;; + *) + echo "No default CFLAGS and LDFLAGS found for your OS, feel free to contribute or install pkg-config :)" + exit 1;; + esac + + LDFLAGS="$LDFLAGS -lX11 -lXft -lfreetype" + + [ -n "$USE_XINERAMA" ] && LDFLAGS="$LDFLAGS -lXinerama" + [ -n "$USE_XRANDR" ] && LDFLAGS="$LDFLAGS -lXrandr" + [ -n "$USE_IMLIB2" ] && LDFLAGS="$LDFLAGS -lImlib2" +fi + +[ -n "$USE_XINERAMA" ] && CFLAGS="$CFLAGS -DHAVE_XINERAMA" +[ -n "$USE_XRANDR" ] && CFLAGS="$CFLAGS -DHAVE_XRANDR" +[ -n "$USE_IMLIB2" ] && CFLAGS="$CFLAGS -DHAVE_IMLIB2" + +LDFLAGS="$LDFLAGS -lpthread" + +cat > Makefile << EOF +PREFIX=$PREFIX +XDG_CONFIG_DIR=$XDG_CONFIG_DIR +MANPREFIX=$MANPREFIX + +CFLAGS=$CFLAGS +LDFLAGS=$LDFLAGS + +EOF + +cat Makefile.in >> Makefile + +echo "Compilation resume: +OS=$OS +CFLAGS=$CFLAGS +LDFLAGS=$LDFLAGS +PREFIX=$PREFIX +MANPREFIX=$MANPREFIX +XDG_CONFIG_DIR=$XDG_CONFIG_DIR + +You can run 'make' now :-) +"