Skip to content

Commit

Permalink
Setup proper configure script (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen authored and thomasp85 committed Jun 19, 2019
1 parent 878e73a commit 3dccd3b
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 27 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^\.travis\.yml$
^appveyor\.yml$
^codecov\.yml$
^src/Makevars$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ systemfonts.Rproj
src/*.o
src/*.so
src/*/*.o
src/Makevars
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
SystemRequirements: GNU make
Suggests:
testthat (>= 2.1.0),
covr
74 changes: 74 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash
# Anticonf (tm) script by Jeroen Ooms (2019)
# This script will query 'pkg-config' for the required cflags and ldflags.
# If pkg-config is unavailable or does not find the library, try setting
# INCLUDE_DIR and LIB_DIR manually via e.g:
# R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib'

# Library settings
PKG_CONFIG_NAME="freetype2"
PKG_DEB_NAME="libfreetype6-dev"
PKG_RPM_NAME="freetype-devel"
PKG_BREW_NAME="freetype"
PKG_TEST_HEADER="<ft2build.h>"
PKG_LIBS="-lfreetype"

# We use special config on MacOS
if [[ "$OSTYPE" == "darwin"* ]]; then
SYS="DARWIN"
PKG_LIBS="$PKG_LIBS -framework CoreText -framework Foundation"
else
SYS="UNIX"
PKG_CONFIG_NAME="$PKG_CONFIG_NAME fontconfig"
fi

# Use pkg-config if available
if [ $(command -v pkg-config) ]; then
PKGCONFIG_CFLAGS=$(pkg-config --cflags --silence-errors ${PKG_CONFIG_NAME})
PKGCONFIG_LIBS=$(pkg-config --libs ${PKG_CONFIG_NAME})
fi

# Note that cflags may be empty in case of success
if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then
echo "Found INCLUDE_DIR and/or LIB_DIR!"
PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS"
PKG_LIBS="-L$LIB_DIR $PKG_LIBS"
elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then
echo "Found pkg-config cflags and libs!"
PKG_CFLAGS=${PKGCONFIG_CFLAGS}
PKG_LIBS=${PKGCONFIG_LIBS}
fi

# For debugging
echo "Using PKG_CFLAGS=$PKG_CFLAGS"
echo "Using PKG_LIBS=$PKG_LIBS"

# Find compiler
CC=$(${R_HOME}/bin/R CMD config CC)
CFLAGS=$(${R_HOME}/bin/R CMD config CFLAGS)
CPPFLAGS=$(${R_HOME}/bin/R CMD config CPPFLAGS)

# Test configuration
echo "#include $PKG_TEST_HEADER" | ${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E -xc - >/dev/null

# Customize the error
if [ $? -ne 0 ]; then
echo "------------------------- ANTICONF ERROR ---------------------------"
echo "Configuration failed because $PKG_CONFIG_NAME was not found. Try installing:"
echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu, etc)"
echo " * rpm: $PKG_RPM_NAME (Fedora, EPEL)"
echo " * csw: $PKG_CSW_NAME (Solaris)"
echo " * brew: $PKG_BREW_NAME (OSX)"
echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your"
echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config"
echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:"
echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'"
echo "--------------------------------------------------------------------"
exit 1;
fi

# Write to Makevars
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" -e "s|@SYS@|$SYS|" src/Makevars.in > src/Makevars

# Success
exit 0
24 changes: 0 additions & 24 deletions src/Makevars

This file was deleted.

11 changes: 11 additions & 0 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PKG_CPPFLAGS=@cflags@ -DSTRICT_R_HEADERS
PKG_LIBS=@libs@

DARWIN_OBJECTS = mac/FontManagerMac.o
UNIX_OBJECTS = unix/FontManagerLinux.o
OBJECTS = systemfonts.o init.o $(@SYS@_OBJECTS)

all: clean

clean:
rm -f $(SHLIB) $(OBJECTS)
2 changes: 1 addition & 1 deletion src/mac/FontManagerMac.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Foundation/Foundation.h>
#include <CoreText/CoreText.h>
#include "FontDescriptor.h"
#include "../FontDescriptor.h"

// converts a CoreText weight (-1 to +1) to a standard weight (100 to 900)
static int convertWeight(float weight) {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/FontManagerLinux.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <fontconfig/fontconfig.h>
#include "FontDescriptor.h"
#include "../FontDescriptor.h"

int convertWeight(FontWeight weight) {
switch (weight) {
Expand Down

0 comments on commit 3dccd3b

Please sign in to comment.