diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-03-20 10:13:45 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-03-21 11:44:46 +0100 |
| commit | 66015cde8cb421915553e273adc5917ce75a5e9b (patch) | |
| tree | 65ff93570d4b4358fb649a6674b65770d37d9f8e | |
| parent | a3ef0d1246f9f0d52f8e705efa7300d68dd81ac3 (diff) | |
| download | vis-66015cde8cb421915553e273adc5917ce75a5e9b.tar.gz vis-66015cde8cb421915553e273adc5917ce75a5e9b.tar.xz | |
build: overhaul build system auto detect stuff using a configure script
The new build instructions are:
$ ./configure && make && sudo make install
The configure script tries to auto detect support for various libraries
and compiler options. These choices can be overwritten by explicitly
specifing --{en,dis}able-{lua,selinux,acl}. See ./configure --help for
all supported options.
The configure script generates config.mk which should allow portable
(among GNU and BSD make) Makefiles. Manually editing config.mk is
still supported.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | GNUmakefile | 165 | ||||
| -rw-r--r-- | Makefile | 200 | ||||
| -rw-r--r-- | README.md | 34 | ||||
| -rw-r--r-- | config.mk | 68 | ||||
| -rwxr-xr-x | configure | 449 |
6 files changed, 663 insertions, 254 deletions
@@ -1,4 +1,5 @@ /config.h +/config.mk *.swo *.swp *.o diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..f6e57d7 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,165 @@ +include Makefile + +SRCDIR = $(realpath $(dir $(firstword $(MAKEFILE_LIST)))) + +DEPS_ROOT = $(SRCDIR)/dependency/install +DEPS_PREFIX = $(DEPS_ROOT)/usr +DEPS_BIN = $(DEPS_PREFIX)/bin +DEPS_LIB = $(DEPS_PREFIX)/lib +DEPS_INC = $(DEPS_PREFIX)/include + +LIBMUSL = musl-1.1.14 +LIBMUSL_SHA1 = b71208e87e66ac959d0e413dd444279d28a7bff1 + +LIBNCURSES = ncurses-6.0 +LIBNCURSES_SHA1 = acd606135a5124905da770803c05f1f20dd3b21c + +LIBTERMKEY = libtermkey-0.18 +LIBTERMKEY_SHA1 = 0a78ba7aaa2f3b53f2273268366fef349c9be4ab + +#LIBLUA = lua-5.3.1 +#LIBLUA_SHA1 = 1676c6a041d90b6982db8cef1e5fb26000ab6dee +LIBLUA = lua-5.2.4 +LIBLUA_SHA1 = ef15259421197e3d85b7d6e4871b8c26fd82c1cf +#LIBLUA = lua-5.1.5 +#LIBLUA_SHA1 = b3882111ad02ecc6b972f8c1241647905cb2e3fc + +LIBLPEG = lpeg-1.0.0 +LIBLPEG_SHA1 = 64a0920c9243b624a277c987d2219b6c50c43971 + +LIBNCURSES_CONFIG = --disable-database --with-fallbacks=st,st-256color,xterm,xterm-256color,vt100 \ + --with-shared --enable-widec --enable-ext-colors --with-termlib=tinfo \ + --without-ada --without-cxx --without-cxx-binding --without-manpages --without-progs \ + --without-tests --without-progs --without-debug --without-profile \ + --without-cxx-shared --without-termlib --without--ticlib + +dependency/sources: + mkdir -p $@ + +dependency/sources/musl-%: | dependency/sources + wget -c -O $@.part http://www.musl-libc.org/releases/$(LIBMUSL).tar.gz + mv $@.part $@ + [ -z $(LIBMUSL_SHA1) ] || (echo '$(LIBMUSL_SHA1) $@' | sha1sum -c) + +dependency/sources/extract-libmusl: dependency/sources/$(LIBMUSL).tar.gz + tar xzf $< -C $(dir $<) + touch $@ + +dependency/sources/configure-libmusl: dependency/sources/extract-libmusl + cd $(dir $<)/$(LIBMUSL) && ./configure --prefix=$(DEPS_PREFIX) --syslibdir=$(DEPS_PREFIX)/lib + touch $@ + +dependency/sources/build-libmusl: dependency/sources/configure-libmusl + $(MAKE) -C $(dir $<)/$(LIBMUSL) + touch $@ + +dependency/sources/install-libmusl: dependency/sources/build-libmusl + $(MAKE) -C $(dir $<)/$(LIBMUSL) install + touch $@ + +dependency/sources/ncurses-%: | dependency/sources + wget -c -O $@.part http://ftp.gnu.org/gnu/ncurses/$(LIBNCURSES).tar.gz + mv $@.part $@ + [ -z $(LIBNCURSES_SHA1) ] || (echo '$(LIBNCURSES_SHA1) $@' | sha1sum -c) + +dependency/sources/extract-libncurses: dependency/sources/$(LIBNCURSES).tar.gz + tar xzf $< -C $(dir $<) + touch $@ + +dependency/sources/configure-libncurses: dependency/sources/extract-libncurses + cd $(dir $<)/$(LIBNCURSES) && ./configure --prefix=/usr --libdir=/usr/lib $(LIBNCURSES_CONFIG) + touch $@ + +dependency/sources/build-libncurses: dependency/sources/configure-libncurses + $(MAKE) -C $(dir $<)/$(LIBNCURSES) + touch $@ + +dependency/sources/install-libncurses: dependency/sources/build-libncurses + $(MAKE) -C $(dir $<)/$(LIBNCURSES) install.libs DESTDIR=$(DEPS_ROOT) + touch $@ + +dependency/sources/libtermkey-%: | dependency/sources + wget -c -O $@.part http://www.leonerd.org.uk/code/libtermkey/$(LIBTERMKEY).tar.gz + mv $@.part $@ + [ -z $(LIBTERMKEY_SHA1) ] || (echo '$(LIBTERMKEY_SHA1) $@' | sha1sum -c) + +dependency/sources/extract-libtermkey: dependency/sources/$(LIBTERMKEY).tar.gz + tar xzf $< -C $(dir $<) + touch $@ + +dependency/sources/build-libtermkey: dependency/sources/extract-libtermkey + # TODO no sane way to avoid pkg-config and specify LDFLAGS? + sed -i 's/LDFLAGS+=-lncurses$$/LDFLAGS+=-lncursesw/g' $(dir $<)/$(LIBTERMKEY)/Makefile + $(MAKE) -C $(dir $<)/$(LIBTERMKEY) PREFIX=$(DEPS_PREFIX) termkey.h libtermkey.la + touch $@ + +dependency/sources/install-libtermkey: dependency/sources/build-libtermkey + $(MAKE) -C $(dir $<)/$(LIBTERMKEY) PREFIX=$(DEPS_PREFIX) install-inc install-lib + touch $@ + +dependency/sources/lua-%: | dependency/sources + wget -c -O $@.part http://www.lua.org/ftp/$(LIBLUA).tar.gz + mv $@.part $@ + [ -z $(LIBLUA_SHA1) ] || (echo '$(LIBLUA_SHA1) $@' | sha1sum -c) + +dependency/sources/extract-liblua: dependency/sources/$(LIBLUA).tar.gz + tar xzf $< -C $(dir $<) + touch $@ + +dependency/sources/patch-liblua: dependency/sources/extract-liblua + cd $(dir $<) && ([ -e $(LIBLUA)-lpeg.patch ] || wget http://www.brain-dump.org/projects/vis/$(LIBLUA)-lpeg.patch) + cd $(dir $<)/$(LIBLUA) && patch -p1 < ../$(LIBLUA)-lpeg.patch + touch $@ + +dependency/sources/build-liblua: dependency/sources/patch-liblua dependency/sources/install-liblpeg + $(MAKE) -C $(dir $<)/$(LIBLUA)/src all CC=$(CC) MYCFLAGS="-DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL -DLUA_USE_POSIX -DLUA_USE_DLOPEN -fPIC" MYLIBS="-Wl,-E -ldl -lncursesw -lm" + #$(MAKE) -C $(dir $<)/$(LIBLUA) posix CC=$(CC) + touch $@ + +dependency/sources/install-liblua: dependency/sources/build-liblua + $(MAKE) -C $(dir $<)/$(LIBLUA) INSTALL_TOP=$(DEPS_PREFIX) install + touch $@ + +dependency/sources/lpeg-%: | dependency/sources + wget -c -O $@.part http://www.inf.puc-rio.br/~roberto/lpeg/$(LIBLPEG).tar.gz + mv $@.part $@ + [ -z $(LIBLPEG_SHA1) ] || (echo '$(LIBLPEG_SHA1) $@' | sha1sum -c) + +dependency/sources/extract-liblpeg: dependency/sources/$(LIBLPEG).tar.gz + tar xzf $< -C $(dir $<) + touch $@ + +dependency/sources/build-liblpeg: dependency/sources/extract-liblpeg + $(MAKE) -C $(dir $<)/$(LIBLPEG) LUADIR=../$(LIBLUA)/src CC=$(CC) + touch $@ + +dependency/sources/install-liblpeg: dependency/sources/build-liblpeg dependency/sources/extract-liblua + cp $(dir $<)/$(LIBLPEG)/*.o $(dir $<)/$(LIBLUA)/src + touch $@ + +dependencies: dependency/sources/install-libtermkey dependency/sources/install-liblua dependency/sources/install-liblpeg + +dependencies-full: dependency/sources/install-libncurses dependencies + +local: clean dependencies + $(MAKE) CFLAGS="$(CFLAGS) -I$(DEPS_INC)" LDFLAGS="$(LDFLAGS) -L$(DEPS_LIB)" \ + CFLAGS_CURSES="-I/usr/include/ncursesw" LDFLAGS_CURSES="-lncursesw" \ + CFLAGS_TERMKEY= LDFLAGS_TERMKEY=-ltermkey \ + CFLAGS_LUA="-DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL" \ + LDFLAGS_LUA="-llua -lm -ldl" + @echo Run with: LD_LIBRARY_PATH=$(DEPS_LIB) VIS_PATH=. ./vis + +standalone: clean dependency/sources/install-libmusl + PATH=$(DEPS_BIN):$$PATH PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR= $(MAKE) \ + CC=musl-gcc dependencies-full + PATH=$(DEPS_BIN):$$PATH PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR= $(MAKE) \ + CC=musl-gcc CFLAGS="--static -Wl,--as-needed" \ + CFLAGS_CURSES= LDFLAGS_CURSES="-lncursesw" \ + CFLAGS_TERMKEY= LDFLAGS_TERMKEY=-ltermkey \ + CFLAGS_LUA="-DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL" \ + LDFLAGS_LUA="-llua -lm -ldl" \ + CONFIG_ACL=0 CFLAGS_ACL= LDFLAGS_ACL= \ + CONFIG_SELINUX=0 CFLAGS_SELINUX= LDFLAGS_SELINUX= + @echo Run with: VIS_PATH=. ./vis + +.PHONY: standalone dependencies dependencies-full local
\ No newline at end of file @@ -1,61 +1,38 @@ -include config.mk - -# try to get a tag and hash first -GITHASH = $(shell git log -1 --format='%h' 2>/dev/null) -GITTAG = $(shell git describe --abbrev=0 --tags 2>/dev/null) -ifneq ($(GITTAG),) - # we have a tag and revcount from there - GITREVCOUNT = $(shell git rev-list --count ${GITTAG}.. 2>/dev/null) - VERSION = ${GITTAG}.r${GITREVCOUNT}.g${GITHASH} -else ifneq ($(GITHASH),) - # we have no tags in git, so just use revision count an hash for now - GITREVCOUNT = $(shell git rev-list --count HEAD) - VERSION = 0.r${GITREVCOUNT}.g${GITHASH} -endif - -SRCDIR = $(realpath $(dir $(firstword $(MAKEFILE_LIST)))) - -ALL = *.c *.h config.mk Makefile LICENSE README.md vis.1 - -DEPS_ROOT = $(SRCDIR)/dependency/install -DEPS_PREFIX = $(DEPS_ROOT)/usr -DEPS_BIN = $(DEPS_PREFIX)/bin -DEPS_LIB = $(DEPS_PREFIX)/lib -DEPS_INC = $(DEPS_PREFIX)/include - -LIBMUSL = musl-1.1.14 -LIBMUSL_SHA1 = b71208e87e66ac959d0e413dd444279d28a7bff1 - -LIBNCURSES = ncurses-6.0 -LIBNCURSES_SHA1 = acd606135a5124905da770803c05f1f20dd3b21c - -LIBTERMKEY = libtermkey-0.18 -LIBTERMKEY_SHA1 = 0a78ba7aaa2f3b53f2273268366fef349c9be4ab - -#LIBLUA = lua-5.3.1 -#LIBLUA_SHA1 = 1676c6a041d90b6982db8cef1e5fb26000ab6dee -LIBLUA = lua-5.2.4 -LIBLUA_SHA1 = ef15259421197e3d85b7d6e4871b8c26fd82c1cf -#LIBLUA = lua-5.1.5 -#LIBLUA_SHA1 = b3882111ad02ecc6b972f8c1241647905cb2e3fc - -LIBLPEG = lpeg-1.0.0 -LIBLPEG_SHA1 = 64a0920c9243b624a277c987d2219b6c50c43971 - -LIBNCURSES_CONFIG = --disable-database --with-fallbacks=st,st-256color,xterm,xterm-256color,vt100 \ - --with-shared --enable-widec --enable-ext-colors --with-termlib=tinfo \ - --without-ada --without-cxx --without-cxx-binding --without-manpages --without-progs \ - --without-tests --without-progs --without-debug --without-profile \ - --without-cxx-shared --without-termlib --without--ticlib +-include config.mk + +VERSION = $(shell git describe 2>/dev/null || echo "0.1.x") + +CONFIG_LUA ?= 1 +CONFIG_ACL ?= 0 +CONFIG_SELINUX ?= 0 + +CFLAGS_STD ?= -std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG -Os +LDFLAGS_STD ?= -lc + +CFLAGS_VIS = $(CFLAGS_AUTO) $(CFLAGS_TERMKEY) $(CFLAGS_CURSES) $(CFLAGS_ACL) \ + $(CFLAGS_SELINUX) $(CFLAGS_LUA) $(CFLAGS_STD) + +CFLAGS_VIS += -DVERSION=\"${VERSION}\" +CFLAGS_VIS += -DCONFIG_LUA=${CONFIG_LUA} +CFLAGS_VIS += -DCONFIG_SELINUX=${CONFIG_SELINUX} +CFLAGS_VIS += -DCONFIG_ACL=${CONFIG_ACL} + +LDFLAGS_VIS = $(LDFLAGS_AUTO) $(LDFLAGS_TERMKEY) $(LDFLAGS_CURSES) $(LDFLAGS_ACL) \ + $(LDFLAGS_SELINUX) $(LDFLAGS_LUA) $(LDFLAGS_STD) + +DEBUG_CFLAGS_VIS = ${CFLAGS_VIS} -UNDEBUG -O0 -g -ggdb -Wall -Wextra -pedantic \ + -Wno-missing-field-initializers -Wno-unused-parameter + +STRIP?=strip + all: vis config.h: cp config.def.h config.h -vis: config.h config.mk *.c *.h - @echo ${CC} ${CFLAGS} ${CFLAGS_VIS} *.c ${LDFLAGS} ${LDFLAGS_VIS} -o $@ - @${CC} ${CFLAGS} ${CFLAGS_VIS} *.c ${LDFLAGS} ${LDFLAGS_VIS} -o $@ +vis: config.h *.c *.h + ${CC} ${CFLAGS} ${CFLAGS_VIS} *.c ${LDFLAGS} ${LDFLAGS_VIS} -o $@ debug: clean @$(MAKE) CFLAGS_VIS='${DEBUG_CFLAGS_VIS}' @@ -103,121 +80,4 @@ uninstall: @echo removing support files from ${DESTDIR}${SHAREPREFIX} @[ ! -z "${SHAREPREFIX}" ] && rm -rf ${DESTDIR}${SHAREPREFIX} -dependency/sources: - mkdir -p $@ - -dependency/sources/musl-%: | dependency/sources - wget -c -O $@.part http://www.musl-libc.org/releases/$(LIBMUSL).tar.gz - mv $@.part $@ - [ -z $(LIBMUSL_SHA1) ] || (echo '$(LIBMUSL_SHA1) $@' | sha1sum -c) - -dependency/sources/extract-libmusl: dependency/sources/$(LIBMUSL).tar.gz - tar xzf $< -C $(dir $<) - touch $@ - -dependency/sources/configure-libmusl: dependency/sources/extract-libmusl - cd $(dir $<)/$(LIBMUSL) && ./configure --prefix=$(DEPS_PREFIX) --syslibdir=$(DEPS_PREFIX)/lib - touch $@ - -dependency/sources/build-libmusl: dependency/sources/configure-libmusl - $(MAKE) -C $(dir $<)/$(LIBMUSL) - touch $@ - -dependency/sources/install-libmusl: dependency/sources/build-libmusl - $(MAKE) -C $(dir $<)/$(LIBMUSL) install - touch $@ - -dependency/sources/ncurses-%: | dependency/sources - wget -c -O $@.part http://ftp.gnu.org/gnu/ncurses/$(LIBNCURSES).tar.gz - mv $@.part $@ - [ -z $(LIBNCURSES_SHA1) ] || (echo '$(LIBNCURSES_SHA1) $@' | sha1sum -c) - -dependency/sources/extract-libncurses: dependency/sources/$(LIBNCURSES).tar.gz - tar xzf $< -C $(dir $<) - touch $@ - -dependency/sources/configure-libncurses: dependency/sources/extract-libncurses - cd $(dir $<)/$(LIBNCURSES) && ./configure --prefix=/usr --libdir=/usr/lib $(LIBNCURSES_CONFIG) - touch $@ - -dependency/sources/build-libncurses: dependency/sources/configure-libncurses - $(MAKE) -C $(dir $<)/$(LIBNCURSES) - touch $@ - -dependency/sources/install-libncurses: dependency/sources/build-libncurses - $(MAKE) -C $(dir $<)/$(LIBNCURSES) install.libs DESTDIR=$(DEPS_ROOT) - touch $@ - -dependency/sources/libtermkey-%: | dependency/sources - wget -c -O $@.part http://www.leonerd.org.uk/code/libtermkey/$(LIBTERMKEY).tar.gz - mv $@.part $@ - [ -z $(LIBTERMKEY_SHA1) ] || (echo '$(LIBTERMKEY_SHA1) $@' | sha1sum -c) - -dependency/sources/extract-libtermkey: dependency/sources/$(LIBTERMKEY).tar.gz - tar xzf $< -C $(dir $<) - touch $@ - -dependency/sources/build-libtermkey: dependency/sources/extract-libtermkey - # TODO no sane way to avoid pkg-config and specify LDFLAGS? - sed -i 's/LDFLAGS+=-lncurses$$/LDFLAGS+=-lncursesw/g' $(dir $<)/$(LIBTERMKEY)/Makefile - $(MAKE) -C $(dir $<)/$(LIBTERMKEY) PREFIX=$(DEPS_PREFIX) termkey.h libtermkey.la - touch $@ - -dependency/sources/install-libtermkey: dependency/sources/build-libtermkey - $(MAKE) -C $(dir $<)/$(LIBTERMKEY) PREFIX=$(DEPS_PREFIX) install-inc install-lib - touch $@ - -dependency/sources/lua-%: | dependency/sources - wget -c -O $@.part http://www.lua.org/ftp/$(LIBLUA).tar.gz - mv $@.part $@ - [ -z $(LIBLUA_SHA1) ] || (echo '$(LIBLUA_SHA1) $@' | sha1sum -c) - -dependency/sources/extract-liblua: dependency/sources/$(LIBLUA).tar.gz - tar xzf $< -C $(dir $<) - touch $@ - -dependency/sources/patch-liblua: dependency/sources/extract-liblua - cd $(dir $<) && ([ -e $(LIBLUA)-lpeg.patch ] || wget http://www.brain-dump.org/projects/vis/$(LIBLUA)-lpeg.patch) - cd $(dir $<)/$(LIBLUA) && patch -p1 < ../$(LIBLUA)-lpeg.patch - touch $@ - -dependency/sources/build-liblua: dependency/sources/patch-liblua dependency/sources/install-liblpeg - $(MAKE) -C $(dir $<)/$(LIBLUA)/src all CC=$(CC) MYCFLAGS="-DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL -DLUA_USE_POSIX -DLUA_USE_DLOPEN -fPIC" MYLIBS="-Wl,-E -ldl -lncursesw -lm" - #$(MAKE) -C $(dir $<)/$(LIBLUA) posix CC=$(CC) - touch $@ - -dependency/sources/install-liblua: dependency/sources/build-liblua - $(MAKE) -C $(dir $<)/$(LIBLUA) INSTALL_TOP=$(DEPS_PREFIX) install - touch $@ - -dependency/sources/lpeg-%: | dependency/sources - wget -c -O $@.part http://www.inf.puc-rio.br/~roberto/lpeg/$(LIBLPEG).tar.gz - mv $@.part $@ - [ -z $(LIBLPEG_SHA1) ] || (echo '$(LIBLPEG_SHA1) $@' | sha1sum -c) - -dependency/sources/extract-liblpeg: dependency/sources/$(LIBLPEG).tar.gz - tar xzf $< -C $(dir $<) - touch $@ - -dependency/sources/build-liblpeg: dependency/sources/extract-liblpeg - $(MAKE) -C $(dir $<)/$(LIBLPEG) LUADIR=../$(LIBLUA)/src CC=$(CC) - touch $@ - -dependency/sources/install-liblpeg: dependency/sources/build-liblpeg dependency/sources/extract-liblua - cp $(dir $<)/$(LIBLPEG)/*.o $(dir $<)/$(LIBLUA)/src - touch $@ - -dependencies: dependency/sources/install-libtermkey dependency/sources/install-liblua dependency/sources/install-liblpeg - -dependencies-full: dependency/sources/install-libncurses dependencies - -local: dependencies - CFLAGS="$(CFLAGS) -I$(DEPS_INC)" LDFLAGS="$(LDFLAGS) -L$(DEPS_LIB)" $(MAKE) CFLAGS_LUA= CFLAGS_TERMKEY= LDFLAGS_LUA="-llua -lm" LDFLAGS_TERMKEY=-ltermkey - @echo Run with: LD_LIBRARY_PATH=$(DEPS_LIB) VIS_PATH=. ./vis - -standalone: dependency/sources/install-libmusl - PATH=$(DEPS_BIN):$$PATH CC=musl-gcc PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR= CFLAGS=-I$(DEPS_INC)/ncursesw $(MAKE) dependencies-full - PATH=$(DEPS_BIN):$$PATH CC=musl-gcc PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR= CFLAGS="--static -Wl,--as-needed -I$(DEPS_INC)/ncursesw" $(MAKE) CFLAGS_LIBS= debug - @echo Run with: VIS_PATH=. ./vis - -.PHONY: all clean dist install uninstall debug profile standalone dependencies dependencies-full local +.PHONY: all clean dist install uninstall debug profile @@ -41,24 +41,26 @@ In order to build vis you will need a C99 compiler as well as: * [libcurses](http://www.gnu.org/software/ncurses/), preferably in the wide-character version * [libtermkey](http://www.leonerd.org.uk/code/libtermkey/) - * [lua](http://www.lua.org/) >= 5.2 - * [LPeg](http://www.inf.puc-rio.br/~roberto/lpeg/) >= 0.12 (runtime - dependency required for syntax highlighting) - -If you want a self contained statically linked binary you can try -to run `make standalone` which will attempt to download, compile -and install all of the above dependencies. `make local` will do -the same but only for libtermkey, lua and LPeg (i.e. the system -C and curses libraries are used). - -To build a regular dynamically linked binary using the system -libraries, simply run `make` (possibly after adapting `config.mk` -to match your system). - - $ $EDITOR config.mk - $ make + * [lua](http://www.lua.org/) >= 5.2 (optional) + * [LPeg](http://www.inf.puc-rio.br/~roberto/lpeg/) >= 0.12 + (optional runtime dependency required for syntax highlighting) + +Assuming these dependencies are met, execute: + + $ ./configure && make $ VIS_PATH=. ./vis config.h +By default the `configure` script will try to auto detect support for +Lua. See `configure --help` for a list of supported options. You can +also manually tweak the generated `config.mk` file. + +On Linux based systems `make standalone` will attempt to download, +compile and install all of the above dependencies into a subfolder +inorder to build a self contained statically linked binary. + +`make local` will do the same but only for libtermkey, Lua and LPeg +(i.e. the system C and curses libraries are used). + Editing Features ================ diff --git a/config.mk b/config.mk deleted file mode 100644 index bdc1702..0000000 --- a/config.mk +++ /dev/null @@ -1,68 +0,0 @@ -# vis version -VERSION = 0.1 - -# optional features -CONFIG_LUA=1 -CONFIG_ACL=0 -CONFIG_SELINUX=0 - -# Customize below to fit your system - -PREFIX ?= /usr/local -MANPREFIX = ${PREFIX}/share/man -SHAREPREFIX = ${PREFIX}/share/vis - -LIBS = -lc - -CFLAGS_TERMKEY = $(shell pkg-config --cflags termkey 2> /dev/null || echo "") -LDFLAGS_TERMKEY = $(shell pkg-config --libs termkey 2> /dev/null || echo "-ltermkey") - -CFLAGS_CURSES = $(shell pkg-config --cflags ncursesw 2> /dev/null || echo "-I/usr/include/ncursesw") -LDFLAGS_CURSES = $(shell pkg-config --libs ncursesw 2> /dev/null || echo "-lncursesw") - -ifeq (${CONFIG_LUA},1) - CFLAGS_LUA = $(shell pkg-config --cflags lua5.2 2> /dev/null || echo "-I/usr/include/lua5.2") - LDFLAGS_LUA = $(shell pkg-config --libs lua5.2 2> /dev/null || echo "-llua -lm") -endif - -ifeq (${CONFIG_ACL},1) - LIBS += -lacl -endif - -OS = $(shell uname) - -ifeq (${OS},Linux) - ifeq (${CONFIG_SELINUX},1) - LIBS += -lselinux - endif -else ifeq (${OS},Darwin) - CFLAGS += -D_DARWIN_C_SOURCE -else ifeq (${OS},OpenBSD) - CFLAGS += -D_BSD_SOURCE -else ifeq (${OS},FreeBSD) - CFLAGS += -D_BSD_SOURCE -else ifeq (${OS},NetBSD) - CFLAGS += -D_BSD_SOURCE -else ifeq (${OS},AIX) - CFLAGS += -D_ALL_SOURCE -endif - -CFLAGS_LIBS = $(CFLAGS_LUA) $(CFLAGS_TERMKEY) $(CFLAGS_CURSES) -LDFLAGS_LIBS = $(LDFLAGS_LUA) $(LDFLAGS_TERMKEY) $(LDFLAGS_CURSES) $(LIBS) - -CFLAGS_STD = -std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 - -CFLAGS_VIS = $(CFLAGS_LIBS) $(CFLAGS_STD) -Os -DVERSION=\"${VERSION}\" -DNDEBUG -CFLAGS_VIS += -DCONFIG_LUA=${CONFIG_LUA} -CFLAGS_VIS += -DCONFIG_SELINUX=${CONFIG_SELINUX} -CFLAGS_VIS += -DCONFIG_ACL=${CONFIG_ACL} -ifeq (${CONFIG_LUA},1) - CFLAGS_VIS += -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL -endif - -LDFLAGS_VIS = $(LDFLAGS_LIBS) - -DEBUG_CFLAGS_VIS = ${CFLAGS_VIS} -UNDEBUG -O0 -g -ggdb -Wall -Wextra -pedantic -Wno-missing-field-initializers -Wno-unused-parameter - -CC ?= cc -STRIP ?= strip diff --git a/configure b/configure new file mode 100755 index 0000000..13d155a --- /dev/null +++ b/configure @@ -0,0 +1,449 @@ +#!/bin/sh +# Based on the configure script from musl libc, MIT licensed + +usage () { +cat <<EOF +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + --srcdir=DIR source directory [detected] + +Installation directories: + --prefix=PREFIX main installation prefix [/usr/local] + --exec-prefix=EPREFIX installation prefix for executable files [PREFIX] + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + +Optional features: + --enable-lua build with Lua support [auto] + --enable-selinux build with SELinux support [auto] + --enable-acl build with POSIX ACL support [auto] + +Some influential environment variables: + CC C compiler command [detected] + CFLAGS C compiler flags [-Os -pipe ...] + LDFLAGS Linker flags + +Use these variables to override the choices made by configure. + +EOF +exit 0 +} + +# Helper functions + +quote () { +tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; } +$1 +EOF +printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#" +} +echo () { printf "%s\n" "$*" ; } +fail () { echo "$*" ; exit 1 ; } +fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; } +cmdexists () { type "$1" >/dev/null 2>&1 ; } +trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; } + +stripdir () { +while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done +} + +trycppif () { +printf "checking preprocessor condition %s... " "$1" +echo "typedef int x;" > "$tmpc" +echo "#if $1" >> "$tmpc" +echo "#error yes" >> "$tmpc" +echo "#endif" >> "$tmpc" +if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then +printf "false\n" +return 1 +else +printf "true\n" +return 0 +fi +} + +tryflag () { +printf "checking whether compiler accepts %s... " "$2" +echo "typedef int x;" > "$tmpc" +if $CC $CFLAGS_TRY $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then +printf "yes\n" +eval "$1=\"\${$1} \$2\"" +eval "$1=\${$1# }" +return 0 +else +printf "no\n" +return 1 +fi +} + +tryldflag () { +printf "checking whether linker accepts %s... " "$2" +echo "typedef int x;" > "$tmpc" +if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then +printf "yes\n" +eval "$1=\"\${$1} \$2\"" +eval "$1=\${$1# }" +return 0 +else +printf "no\n" +return 1 +fi +} + +# Beginning of actual script + +CFLAGS_AUTO= +CFLAGS_TRY= +LDFLAGS_AUTO= +LDFLAGS_TRY= +srcdir= +prefix=/usr/local +exec_prefix='$(prefix)' +bindir='$(exec_prefix)/bin' + +lua=auto +selinux=auto +acl=auto + +for arg ; do +case "$arg" in +--help|-h) usage ;; +--srcdir=*) srcdir=${arg#*=} ;; +--prefix=*) prefix=${arg#*=} ;; +--exec-prefix=*) exec_prefix=${arg#*=} ;; +--bindir=*) bindir=${arg#*=} ;; +--enable-lua|--enable-lua=yes) lua=yes ;; +--disable-lua|--enable-lua=no) lua=no ;; +--enable-selinux|--enable-selinux=yes) selinux=yes ;; +--disable-selinux|--enable-selinux=no) selinux=no ;; +--enable-acl|--enable-acl=yes) acl=yes ;; +--disable-acl|--enable-acl=no) acl=no ;; +--enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;; +-* ) echo "$0: unknown option $arg" ;; +CC=*) CC=${arg#*=} ;; +CFLAGS=*) CFLAGS=${arg#*=} ;; +CPPFLAGS=*) CPPFLAGS=${arg#*=} ;; +LDFLAGS=*) LDFLAGS=${arg#*=} ;; +*=*) ;; +*) ;; +esac +done + +for i in srcdir prefix exec_prefix bindir ; do +stripdir $i +done + +# +# Get the source dir for out-of-tree builds +# +if test -z "$srcdir" ; then +srcdir="${0%/configure}" +stripdir srcdir +fi +abs_builddir="$(pwd)" || fail "$0: cannot determine working directory" +abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir" +test "$abs_srcdir" = "$abs_builddir" && srcdir=. +test "$srcdir" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory" + +# +# Get a temp filename we can use +# +i=0 +set -C +while : ; do i=$(($i+1)) +tmpc="./conf$$-$PPID-$i.c" +2>|/dev/null > "$tmpc" && break +test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc" +done +set +C +trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP + +# +# Find a C compiler to use +# +printf "checking for C compiler... " +trycc c99 +trycc cc +trycc gcc +printf "%s\n" "$CC" +test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; } + +printf "checking whether C compiler works... " +echo "typedef int x;" > "$tmpc" +if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then +printf "yes\n" +else +printf "no; compiler output follows:\n%s\n" "$output" +exit 1 +fi + +# +# Figure out options to force errors on unknown flags. +# +tryflag CFLAGS_TRY -Werror=unknown-warning-option +tryflag CFLAGS_TRY -Werror=unused-command-line-argument +tryldflag LDFLAGS_TRY -Werror=unknown-warning-option +tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument + +CFLAGS_STD="-std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG -Os" +LDFLAGS_STD="-lc" + +OS=$(uname) + +case "$OS" in +*BSD) CFLAGS_STD+=-D_DARWIN_C_SOURCE ;; +Darwin) CFLAGS_STD+=-D_BSD_SOURCE ;; +AIX) CFLAGS_STD+=-D_ALL_SOURCE ;; +esac + +have_pkgconfig=no +printf "checking for pkg-config... " +cmdexists pkg-config && have_pkgconfig=yes +printf "%s\n" "$have_pkgconfig" + +tryflag CFLAGS_AUTO -pipe + +# libcurses is a mandatory dependency + +printf "checking for libcurses...\n" +cat > "$tmpc" <<EOF +#include <curses.h> + +int main(int argc, char *argv[]) { + initscr(); + endwin(); + return 0; +} +EOF + +CONFIG_CURSES=0 + +for curses in ncursesw ncurses curses; do + printf " checking for %s... " "$curses" + + if test "$have_pkgconfig" = "yes" ; then + CFLAGS_CURSES=$(pkg-config --cflags $curses 2>/dev/null) + LDFLAGS_CURSES=$(pkg-config --libs $curses 2>/dev/null) + if $? -a $CC $CFLAGS $LDFLAGS $CFLAGS_CURSES $LDFLAGS_CURSES \ + -o /dev/null "$tmpc" >/dev/null 2>&1 ; then + CONFIG_CURSES=1 + printf "yes\n" + break + fi + fi + + CFLAGS_CURSES="-I/usr/include/$curses" + LDFLAGS_CURSES="-l$curses" + + if $CC $CFLAGS $LDFLAGS $CFLAGS_CURSES $LDFLAGS_CURSES \ + -o /dev/null "$tmpc" >/dev/null 2>&1 ; then + CONFIG_CURSES=1 + printf "yes\n" + break + else + printf "no\n" + fi +done + +test $CONFIG_CURSES -ne 1 && fail "$0: cannot find libcurses" + +# libtermkey is a mandatory dependency + +printf "checking for libtermkey... " +cat > "$tmpc" <<EOF +#include <termkey.h> + +int main(int argc, char *argv[]) { + TERMKEY_CHECK_VERSION; + return 0; +} +EOF + +if test "$have_pkgconfig" = "yes" ; then + CFLAGS_TERMKEY=$(pkg-config --cflags termkey 2>/dev/null) + LDFLAGS_TERMKEY=$(pkg-config --libs termkey 2>/dev/null) +fi + +if test -z "$LDFLAGS_TERMKEY"; then + CFLAGS_TERMKEY="" + LDFLAGS_TERMKEY="-ltermkey" +fi + +if $CC $CFLAGS $CFLAGS_TERMKEY $LDFLAGS $LDFLAGS_TERMKEY \ + -o /dev/null "$tmpc" >/dev/null 2>&1; then + printf "%s\n" "yes" +else + printf "%s\n" "no" + fail "$0: cannot find libtermkey" +fi + +CONFIG_LUA=0 + +if test "$lua" != "no" ; then + + printf "checking for liblua...\n" + +cat > "$tmpc" <<EOF +#include <lua.h> +#include <lauxlib.h> + +int main(int argc, char *argv[]) { + lua_State *L = luaL_newstate(); + luaL_openlibs(L); + lua_close(L); + return 0; +} +EOF + + for liblua in lua lua5.2 lua5.3; do + printf " checking for %s... " "$liblua" + + if test "$have_pkgconfig" = "yes" ; then + CFLAGS_LUA=$(pkg-config --cflags $liblua 2>/dev/null) + LDFLAGS_LUA=$(pkg-config --libs $liblua 2>/dev/null) + if test $? -eq 0 && $CC $CFLAGS $LDFLAGS $CFLAGS_LUA $LDFLAGS_LUA \ + -o /dev/null "$tmpc" >/dev/null 2>&1 ; then + CONFIG_LUA=1 + printf "yes\n" + break + fi + fi + + CFLAGS_LUA="-I/usr/include/$liblua" + LDFLAGS_LUA="-l$liblua -lm" + + if $CC $CFLAGS $LDFLAGS $CFLAGS_LUA $LDFLAGS_LUA \ + -o /dev/null "$tmpc" >/dev/null 2>&1 ; then + CONFIG_LUA=1 + printf "yes\n" + break + else + printf "no\n" + fi + done + + test "$lua" = "yes" -a $CONFIG_LUA -ne 1 && fail "$0: cannot find liblua" + test $CONFIG_LUA -eq 1 && CFLAGS_LUA+=" -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL" +fi + +CONFIG_ACL=0 + +if test "$OS" = "Linux" -a "$acl" != "no"; then + printf "checking for libacl... " + +cat > "$tmpc" <<EOF +#include <sys/types.h> +#include <sys/acl.h> + +int main(int argc, char *argv[]) { + acl_t acl = acl_get_fd(0); + return 0; +} +EOF + + if test "$have_pkgconfig" = "yes" ; then + CFLAGS_ACL=$(pkg-config --cflags acl 2>/dev/null) + LDFLAGS_ACL=$(pkg-config --libs acl 2>/dev/null) + fi + + if test -z "$LDFLAGS_ACL"; then + CFLAGS_ACL="" + LDFLAGS_ACL="-lacl" + fi + + if $CC $CFLAGS $LDFLAGS $CFLAGS_ACL $LDFLAGS_ACL \ + -o /dev/null "$tmpc" >/dev/null 2>&1; then + CONFIG_ACL=1 + printf "%s\n" "yes" + else + printf "%s\n" "no" + CFLAGS_ACL="" + LDFLAGS_ACL="" + test "$acl" = "yes" && fail "$0: cannot find libacl" + fi +fi + +CONFIG_SELINUX=0 + +if test "$OS" = "Linux" -a "$selinux" != "no"; then + printf "checking for libselinux... " + +cat > "$tmpc" <<EOF +#include <selinux/selinux.h> + +int main(int argc, char *argv[]) { + return is_selinux_enabled(); +} +EOF + + if test "$have_pkgconfig" = "yes" ; then + CFLAGS_SELINUX=$(pkg-config --cflags selinux 2>/dev/null) + LDFLAGS_SELINUX=$(pkg-config --libs selinux 2>/dev/null) + fi + + if test -z "$LDFLAGS_SELINUX"; then + CFLAGS_SELINUX="" + LDFLAGS_SELINUX="-lselinux" + fi + + if $CC $CFLAGS $LDFLAGS $CFLAGS_SELINUX $LDFLAGS_SELINUX \ + -o /dev/null "$tmpc" >/dev/null 2>&1; then + CONFIG_SELINUX=1 + printf "%s\n" "yes" + else + printf "%s\n" "no" + CFLAGS_SELINUX="" + LDFLAGS_SELINUX="" + test "$selinux" = "yes" && fail "$0: cannot find libselinux" + fi +fi + +printf "creating config.mk... " + +cmdline=$(quote "$0") +for i ; do cmdline="$cmdline $(quote "$i")" ; done + +exec 3>&1 1>config.mk + +cat << EOF +# This version of config.mk was generated by: +# $cmdline +# Any changes made here will be lost if configure is re-run +srcdir = $srcdir +prefix = $prefix +exec_prefix = $exec_prefix +bindir = $bindir +CC = $CC +CFLAGS = $CFLAGS +CFLAGS_STD = $CFLAGS_STD +LDFLAGS_STD = $LDFLAGS_STD +CFLAGS_AUTO = $CFLAGS_AUTO +LDFLAGS_AUTO = $LDFLAGS_AUTO +LDFLAGS = $LDFLAGS +LDFLAGS_AUTO = $LDFLAGS_AUTO +CFLAGS_CURSES = $CFLAGS_CURSES +LDFLAGS_CURSES = $LDFLAGS_CURSES +CFLAGS_TERMKEY = $CFLAGS_TERMKEY +LDFLAGS_TERMKEY = $LDFLAGS_TERMKEY +CONFIG_LUA = $CONFIG_LUA +CFLAGS_LUA = $CFLAGS_LUA +LDFLAGS_LUA = $LDFLAGS_LUA +CONFIG_ACL = $CONFIG_ACL +CFLAGS_ACL = $CFLAGS_ACL +LDFLAGS_ACL = $LDFLAGS_ACL +CONFIG_SELINUX = $CONFIG_SELINUX +CFLAGS_SELINUX = $CFLAGS_SELINUX +LDFLAGS_SELINUX = $LDFLAGS_SELINUX +EOF +exec 1>&3 3>&- + +test "$srcdir" = "." || ln -sf $srcdir/Makefile . + +printf "done\n" |
