Make fc-arch stuff cross-compiling-safe

Fixes:
Bug 32679 - fontconfig-2.8.0 does not cross compile
Bug 25462 - Cross-compilation doesn't work
This commit is contained in:
Behdad Esfahbod 2010-12-28 00:59:19 -06:00
parent 2a6b235ff6
commit d1a0fca316
12 changed files with 167 additions and 316 deletions

View File

@ -22,7 +22,7 @@
# PERFORMANCE OF THIS SOFTWARE.
DOCSRC=@DOCSRC@
SUBDIRS=fontconfig fc-case fc-lang fc-glyphname fc-arch src \
SUBDIRS=fontconfig fc-case fc-lang fc-glyphname src \
fc-cache fc-cat fc-list fc-match fc-pattern fc-query fc-scan \
conf.d $(DOCSRC) test

View File

@ -56,7 +56,7 @@ AC_SUBST(LIBT_CURRENT_MINUS_AGE)
dnl ==========================================================================
AM_CONFIG_HEADER(config.h)
AC_CONFIG_HEADERS(config.h)
AC_PROG_CC
AC_PROG_INSTALL
@ -98,59 +98,12 @@ AM_CONDITIONAL(CROSS_COMPILING, test $cross_compiling = yes)
dnl ==========================================================================
# Setup for compiling build tools (fc-glyphname, etc)
AC_MSG_CHECKING([for a C compiler for build tools])
if test $cross_compiling = yes; then
AC_CHECK_PROGS(CC_FOR_BUILD, gcc cc)
else
CC_FOR_BUILD=$CC
fi
AC_MSG_RESULT([$CC_FOR_BUILD])
AC_SUBST(CC_FOR_BUILD)
AC_MSG_CHECKING([for suffix of executable build tools])
if test $cross_compiling = yes; then
cat >conftest.c <<\_______EOF
int
main ()
{
exit (0);
}
_______EOF
for i in .exe ""; do
compile="$CC_FOR_BUILD conftest.c -o conftest$i"
if AC_TRY_EVAL(compile); then
if (./conftest) 2>&AC_FD_CC; then
EXEEXT_FOR_BUILD=$i
break
fi
fi
done
rm -f conftest*
if test "${EXEEXT_FOR_BUILD+set}" != set; then
AC_MSG_ERROR([Cannot determine suffix of executable build tools])
fi
else
EXEEXT_FOR_BUILD=$EXEEXT
fi
AC_MSG_RESULT([$EXEEXT_FOR_BUILD])
AC_SUBST(EXEEXT_FOR_BUILD)
dnl ==========================================================================
AC_ARG_WITH(arch, [ --with-arch=ARCH Force architecture to ARCH], arch="$withval", arch=auto)
if test $cross_compiling = yes; then
case "$arch" in
auto)
AC_MSG_ERROR([Cannot autodetect architecture in cross compile environment]
[Use --with-arch=ARCH to specify architecture])
;;
esac
if test "x$arch" != xauto; then
AC_DEFINE_UNQUOTED([FC_ARCHITECTURE], "$arch", [Architecture prefix to use for cache file names])
fi
ARCHITECTURE=$arch
AC_SUBST(ARCHITECTURE)
dnl ==========================================================================
@ -529,13 +482,20 @@ fi
AC_SUBST(DOCSRC)
AC_SUBST(DOCMAN3)
dnl Figure out what cache format suffix to use for this architecture
AC_C_BIGENDIAN
AC_CHECK_SIZEOF([void *])
AC_CHECK_ALIGNOF([double])
AC_OUTPUT([
Makefile
fontconfig/Makefile
fc-lang/Makefile
fc-glyphname/Makefile
fc-case/Makefile
fc-arch/Makefile
src/Makefile
conf.d/Makefile
fc-cache/Makefile

View File

@ -1,54 +0,0 @@
#
# $Id $
#
# Copyright © 2003 Keith Packard
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of the author(s) not be used in
# advertising or publicity pertaining to distribution of the software without
# specific, written prior permission. The authors make no
# representations about the suitability of this software for any purpose. It
# is provided "as is" without express or implied warranty.
#
# THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
CC = @CC_FOR_BUILD@
EXEEXT = @EXEEXT_FOR_BUILD@
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
INCLUDES=-I${top_srcdir}/src -I${top_srcdir} $(WARN_CFLAGS)
TMPL=fcarch.tmpl.h
STMPL=${top_srcdir}/fc-arch/fcarch.tmpl.h
TARG=fcarch.h
ARCHITECTURE=@ARCHITECTURE@
.PRECIOUS: $(TARG)
noinst_PROGRAMS=fc-arch
EXTRA_DIST=$(TMPL)
$(TARG):fc-arch${EXEEXT} $(STMPL) ${top_srcdir}/src/fcint.h ../config.h
$(AM_V_GEN) $(RM) $(TARG); \
./fc-arch${EXEEXT} $(ARCHITECTURE) < $(STMPL) > $(TARG).tmp && \
mv $(TARG).tmp $(TARG)
ALIAS_FILES = fcalias.h fcaliastail.h
BUILT_SOURCES = $(ALIAS_FILES) $(TARG)
$(ALIAS_FILES):
touch $(ALIAS_FILES)
CLEANFILES=$(TARG) $(ALIAS_FILES)

View File

@ -1,138 +0,0 @@
/*
* Copyright © 2006 Keith Packard
* Copyright © 2005 Patrick Lam
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include "fcint.h"
#include <ctype.h>
#define ENDIAN_TEST 0x01020304
#define MACHINE_SIGNATURE_SIZE 1024
static char *
FcCacheMachineSignature (void)
{
static char buf[MACHINE_SIGNATURE_SIZE];
int32_t magic = ENDIAN_TEST;
char * m = (char *)&magic;
sprintf (buf, "%01x%01x%01x%01x_"
"%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_"
"%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x",
m[0], m[1], m[2], m[3],
(unsigned int)sizeof (FcAlign),
(unsigned int)sizeof (char),
(unsigned int)sizeof (char *),
(unsigned int)sizeof (int),
(unsigned int)sizeof (intptr_t),
(unsigned int)sizeof (FcPattern),
(unsigned int)sizeof (FcPatternEltPtr),
(unsigned int)sizeof (struct FcPatternElt *),
(unsigned int)sizeof (FcPatternElt),
(unsigned int)sizeof (FcObject),
(unsigned int)sizeof (FcValueListPtr),
(unsigned int)sizeof (FcValue),
(unsigned int)sizeof (FcValueBinding),
(unsigned int)sizeof (struct FcValueList *),
(unsigned int)sizeof (FcStrSet *), /* For FcLangSet */
(unsigned int)sizeof (FcCharSet),
(unsigned int)sizeof (FcCharLeaf **),
(unsigned int)sizeof (FcChar16 *),
(unsigned int)sizeof (FcChar16),
(unsigned int)sizeof (FcCharLeaf),
(unsigned int)sizeof (FcChar32),
(unsigned int)sizeof (FcCache));
return buf;
}
int
main (int argc, char **argv)
{
static char line[1024];
char *signature;
int signature_length;
char *space;
char *arch = NULL;
int lineno = 0;
if (argc != 2)
fprintf (stderr, "Usage: %s <architecture>|auto < fcarch.tmpl.h > fcarch.h\n",
argv[0]);
arch = argv[1];
/*
* Scan the input until the marker is found
*/
while (fgets (line, sizeof (line), stdin))
{
lineno++;
if (!strncmp (line, "@@@", 3))
break;
fputs (line, stdout);
}
signature = FcCacheMachineSignature();
signature_length = strlen (signature);
if (strcmp (arch, "auto") == 0)
{
arch = NULL;
/*
* Search for signature
*/
while (fgets (line, sizeof (line), stdin))
{
lineno++;
/*
* skip comments
*/
if (!strncmp (line, "@@@", 3))
continue;
space = line;
while (*space && !isspace (*space))
space++;
if (!space)
{
fprintf (stderr, "%s: malformed input on line %d\n",
argv[0], lineno);
exit (1);
}
*space++ = '\0';
while (isspace (*space))
space++;
if (!strncmp (space, signature, signature_length))
{
arch = line;
break;
}
}
}
if (!arch)
{
fprintf (stderr, "%s: unknown signature \"%s\"\n", argv[0], signature);
fprintf (stderr, "\tPlease update fcarch.tmpl.h and rebuild\n");
exit (1);
}
printf ("#define FC_ARCHITECTURE \"%s\"\n", arch);
fflush (stdout);
exit (ferror (stdout));
}

View File

@ -1,65 +0,0 @@
/*
* Copyright © 2006 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the author(s) not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. The authors make no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
@@@
@@@ Each unique machine architecture needs an entry in this file
@@@ If fc-arch runs and doesn't find a matching entry, it will print
@@@ out the archtecture signature in the error message. Take that
@@@ signature and place it in this file along with a suitable architecture
@@@ name. Architecture names are used to construct file names, so
@@@ use something reasonable and don't include any spaces
@@@
@@@ So far the differences boil down to: endianness, 32 vs 64 bit pointers,
@@@ and on 32bit ones, whether double is aligned to one word or two words.
@@@ Those result in the 6 formats listed below.
@@@
@@@ ,name (endianness,pointer-size,double-alignment)
@@@ | ,endian
@@@ | | ,FcAlign
@@@ | | | ,char
@@@ | | | | ,char*
@@@ | | | | | ,int
@@@ | | | | | | ,intptr_t
@@@ | | | | | | | ,Pattern
@@@ | | | | | | | | ,EltPtr
@@@ | | | | | | | | | ,Elt *
@@@ | | | | | | | | | | ,Elt
@@@ | | | | | | | | | | | ,ObjPtr
@@@ | | | | | | | | | | | | ,ValueListPtr
@@@ | | | | | | | | | | | | | ,Value
@@@ | | | | | | | | | | | | | | ,ValueBinding
@@@ | | | | | | | | | | | | | | | ,ValueList *
@@@ | | | | | | | | | | | | | | | | ,StrSet *
@@@ | | | | | | | | | | | | | | | | | ,CharSet
@@@ | | | | | | | | | | | | | | | | | | ,CharLeaf **
@@@ | | | | | | | | | | | | | | | | | | | ,Char16 *
@@@ | | | | | | | | | | | | | | | | | | | | ,Char16
@@@ | | | | | | | | | | | | | | | | | | | | | ,CharLeaf
@@@ | | | | | | | | | | | | | | | | | | | | | | ,Char32
@@@ | | | | | | | | | | | | | | | | | | | | | | | ,Cache
@@@ | | | | | | | | | | | | | | | | | | | | | | | |
le32d4 4321_08_01_04_04_04_10_04_04_08_04_04_0c_04_04_04_10_04_04_02_20_04_20
le32d8 4321_08_01_04_04_04_10_04_04_08_04_04_10_04_04_04_10_04_04_02_20_04_20
le64 4321_08_01_08_04_08_18_08_08_10_04_08_10_04_08_08_18_08_08_02_20_04_38
be32d4 1234_08_01_04_04_04_10_04_04_08_04_04_0c_04_04_04_10_04_04_02_20_04_20
be32d8 1234_08_01_04_04_04_10_04_04_08_04_04_10_04_04_04_10_04_04_02_20_04_20
be64 1234_08_01_08_04_08_18_08_08_10_04_08_10_04_08_08_18_08_08_02_20_04_38

View File

@ -22,7 +22,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "../fc-arch/fcarch.h"
#include "../src/fcarch.h"
#ifdef HAVE_CONFIG_H
#include <config.h>

View File

@ -32,7 +32,7 @@
#endif
#include <fontconfig/fontconfig.h>
#include "../fc-arch/fcarch.h"
#include "../src/fcarch.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -84,13 +84,12 @@ noinst_HEADERS=fcint.h fcftint.h fcdeprecate.h
ALIAS_FILES = fcalias.h fcaliastail.h fcftalias.h fcftaliastail.h
BUILT_SOURCES = $(ALIAS_FILES) \
../fc-arch/fcarch.h \
../fc-case/fccase.h \
../fc-glyphname/fcglyphname.h \
../fc-lang/fclang.h
../fc-arch/fcarch.h:
cd ../fc-arch && $(MAKE) $(AM_MAKEFLAGS) fcarch.h
noinst_PROGRAMS = fcarch
../fc-case/fccase.h:
cd ../fc-case && $(MAKE) $(AM_MAKEFLAGS) fccase.h
../fc-glyphname/fcglyphname.h:
@ -99,6 +98,7 @@ BUILT_SOURCES = $(ALIAS_FILES) \
cd ../fc-lang && $(MAKE) $(AM_MAKEFLAGS) fclang.h
libfontconfig_la_SOURCES = \
fcarch.h \
fcatomic.c \
fcblanks.c \
fccache.c \

72
src/fcarch.c Normal file
View File

@ -0,0 +1,72 @@
/*
* Copyright © 2002 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the author(s) not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. The authors make no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/* If architecture is hardcoded, skip the assert tests */
#ifndef FC_ARCHITECTURE
#include "fcarch.h"
/* Make sure the cache structure is consistent with what we expect */
#include "fcint.h"
FC_ASSERT_STATIC (1 == sizeof (char));
FC_ASSERT_STATIC (2 == sizeof (FcChar16));
FC_ASSERT_STATIC (4 == sizeof (int));
FC_ASSERT_STATIC (4 == sizeof (FcChar32));
FC_ASSERT_STATIC (4 == sizeof (FcObject));
FC_ASSERT_STATIC (4 == sizeof (FcValueBinding));
FC_ASSERT_STATIC (8 == sizeof (FcAlign));
FC_ASSERT_STATIC (0x20 == sizeof (FcCharLeaf));
FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (intptr_t));
FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcPatternEltPtr));
FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcValueListPtr));
FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (char *));
FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (struct FcPatternElt *));
FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcValueList *));
FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcStrSet *));
FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcCharLeaf **));
FC_ASSERT_STATIC (SIZEOF_VOID_P == sizeof (FcChar16 *));
FC_ASSERT_STATIC (0x08 + 1*SIZEOF_VOID_P == sizeof (FcValue));
FC_ASSERT_STATIC (0x00 + 2*SIZEOF_VOID_P == sizeof (FcPatternElt));
FC_ASSERT_STATIC (0x08 + 2*SIZEOF_VOID_P == sizeof (FcPattern));
FC_ASSERT_STATIC (0x08 + 2*SIZEOF_VOID_P == sizeof (FcCharSet));
FC_ASSERT_STATIC (0x08 + 6*SIZEOF_VOID_P == sizeof (FcCache));
#endif
int
main (int argc, char **argv)
{
printf ("%s\n", FC_ARCHITECTURE);
return 0;
}

71
src/fcarch.h Normal file
View File

@ -0,0 +1,71 @@
/*
* Copyright © 2006 Keith Packard
* Copyright © 2010 Behdad Esfahbod
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the author(s) not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. The authors make no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _FCARCH_H_
#define _FCARCH_H_
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/*
* Each unique machine architecture needs an entry in this file
* So far the differences boil down to: endianness, 32 vs 64 bit pointers,
* and on 32bit ones, whether double is aligned to one word or two words.
* Those result in the 6 formats listed below.
*
* If any of the assertion errors in fccache.c fail, you need to add a new
* architecture. Contact the fontconfig mailing list in that case.
*
* name endianness pointer-size double-alignment
*
* le32d4 4321 4 4
* le32d8 4321 4 8
* le64 4321 8 8
* be32d4 1234 4 4
* be32d8 1234 4 8
* be64 1234 8 8
*/
#if defined(WORDS_BIGENDIAN) && WORDS_BIGENDIAN
# define FC_ARCH_ENDIAN "be"
#else /* !WORDS_BIGENDIAN */
# define FC_ARCH_ENDIAN "le"
#endif
#if SIZEOF_VOID_P == 4
# if ALIGNOF_DOUBLE == 4
# define FC_ARCH_SIZE_ALIGN "32d4"
# else /* ALIGNOF_DOUBLE != 4 */
# define FC_ARCH_SIZE_ALIGN "32d8"
# endif
#else /* SIZEOF_VOID_P != 4 */
# define FC_ARCH_SIZE_ALIGN "64"
#endif
#ifdef ARCHITECTURE
# define ARCHITECTURE FC_ARCHITECTURE
#else
# define FC_ARCHITECTURE FC_ARCH_ENDIAN FC_ARCH_SIZE_ALIGN
#endif
#endif /* _FCARCH_H_ */

View File

@ -22,7 +22,7 @@
*/
#include "fcint.h"
#include "../fc-arch/fcarch.h"
#include "fcarch.h"
#include <stdio.h>
#include <fcntl.h>
#include <dirent.h>
@ -41,6 +41,7 @@
#define O_BINARY 0
#endif
struct MD5Context {
FcChar32 buf[4];
FcChar32 bits[2];

View File

@ -107,6 +107,10 @@
#define FC_MEM_NUM 30
#define _FC_ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
#define _FC_ASSERT_STATIC0(_line, _cond) _FC_ASSERT_STATIC1 (_line, (_cond))
#define FC_ASSERT_STATIC(_cond) _FC_ASSERT_STATIC0 (__LINE__, (_cond))
#define FC_MIN(a,b) ((a) < (b) ? (a) : (b))
#define FC_MAX(a,b) ((a) > (b) ? (a) : (b))
#define FC_ABS(a) ((a) < 0 ? -(a) : (a))