Skip to content

Commit

Permalink
Remove hard-coded version from autotools build
Browse files Browse the repository at this point in the history
Moves version fetch code into external shell script.
Adds another possibility to provide the version on compile
time by VERSION file. We still give higher priority to the
environment variable or the version from git if available.
Addresses #892
  • Loading branch information
mgreter committed Feb 24, 2015
1 parent 2274c51 commit 11719d2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ WINDRES ?= windres
CFLAGS ?= -Wall -O2
CXXFLAGS ?= -Wall -O2
LDFLAGS ?= -Wall -O2 -Wl,--no-undefined
CAT ?= $(if $(filter $(OS),Windows_NT),type,cat)

ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
Expand All @@ -28,6 +29,12 @@ ifeq "$(LIBSASS_VERSION)" ""
endif
endif

ifeq "$(LIBSASS_VERSION)" ""
ifneq ("$(wildcard VERSION)","")
LIBSASS_VERSION ?= $(shell $(CAT) VERSION)
endif
endif

ifneq "$(LIBSASS_VERSION)" ""
CFLAGS += -DLIBSASS_VERSION="\"$(LIBSASS_VERSION)\""
CXXFLAGS += -DLIBSASS_VERSION="\"$(LIBSASS_VERSION)\""
Expand Down
19 changes: 12 additions & 7 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
ACLOCAL_AMFLAGS = -I m4

AM_LDFLAGS = -lstdc++ -lm
AM_CFLAGS = -Wall -fPIC
AM_CXXFLAGS = -Wall -fPIC
AM_CFLAGS += -DLIBSASS_VERSION="\"$(LIBSASS_VERSION)\""
AM_CXXFLAGS += -DLIBSASS_VERSION="\"$(LIBSASS_VERSION)\""
AM_CFLAGS = -Wall
AM_CXXFLAGS = -Wall

AM_CXXFLAGS += -std=c++0x
if COMPILER_IS_MINGW32
AM_CXXFLAGS += -std=gnu++0x
else
AM_CFLAGS += -fPIC
AM_CXXFLAGS += -fPIC
AM_CXXFLAGS += -std=c++0x
endif

AM_CFLAGS += -DLIBSASS_VERSION="\"$(VERSION)\""
AM_CXXFLAGS += -DLIBSASS_VERSION="\"$(VERSION)\""

if ENABLE_COVERAGE
AM_CFLAGS += -O0 --coverage
Expand All @@ -18,8 +25,6 @@ else
AM_LDFLAGS += -O2
endif

VERSION = $(LIBSASS_VERSION)

EXTRA_DIST = \
COPYING \
INSTALL \
Expand Down
28 changes: 7 additions & 21 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.61])
AC_INIT([libsass], [3.0.3], [[email protected]])

AC_INIT([libsass], m4_esyscmd_s([./version.sh]), [[email protected]])
AC_CONFIG_SRCDIR([ast.hpp])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
Expand Down Expand Up @@ -62,7 +63,7 @@ the --with-sass-spec-dir=<dir> argument.
# Automake doesn't like its tests in an absolute path, so we make it relative.
case $sass_spec_dir in
/*)
SASS_SPEC_PATH=`$RUBY -e "require 'pathname';puts Pathname.new('$sass_spec_dir').relative_path_from(Pathname.new('$PWD')).to_s"`
SASS_SPEC_PATH=`$RUBY -e "require 'pathname'; puts Pathname.new('$sass_spec_dir').relative_path_from(Pathname.new('$PWD')).to_s"`
;;
*)
SASS_SPEC_PATH="$sass_spec_dir"
Expand Down Expand Up @@ -106,25 +107,10 @@ fi

AM_CONDITIONAL(ENABLE_COVERAGE, test "x$enable_cov" = "xyes")

AC_ARG_VAR(LIBSASS_VERSION, libsass version)
if test "x$LIBSASS_VERSION" = "x"; then
AC_CHECK_PROG(GIT, git, git)
if test "x$GIT" = "x"; then
LIBSASS_VERSION=$VERSION
else
AC_CHECK_FILE(.git/config, [
LIBSASS_VERSION=`$GIT describe --abbrev=4 --dirty --always --tags`
], [
LIBSASS_VERSION=$VERSION
])
fi
if test "x$LIBSASS_VERSION" = "x"; then
AC_MSG_ERROR([LIBSASS_VERSION not defined.
You can solve this by setting LIBSASS_VERSION:
# export LIBSASS_VERSION="x.y.z"
])
fi
fi
AS_CASE([$host], [*-*-mingw32], [is_mingw32=yes], [is_mingw32=no])
AM_CONDITIONAL(COMPILER_IS_MINGW32, test "x$is_mingw32" = "xyes")

AC_MSG_NOTICE([Building libsass ($VERSION)])

AC_CONFIG_FILES([Makefile support/libsass.pc])
AC_OUTPUT
10 changes: 10 additions & 0 deletions version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if test "x$LIBSASS_VERSION" = "x"; then
LIBSASS_VERSION=`git describe --abbrev=4 --dirty --always --tags 2>/dev/null`
fi
if test "x$LIBSASS_VERSION" = "x"; then
LIBSASS_VERSION=`cat VERSION 2>/dev/null`
fi
if test "x$LIBSASS_VERSION" = "x"; then
LIBSASS_VERSION="[na]"
fi
echo $LIBSASS_VERSION

0 comments on commit 11719d2

Please sign in to comment.