aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2014-01-09 18:14:09 +0000
committerWerner Koch <[email protected]>2014-01-17 16:54:59 +0000
commitd83b12213231443b93de39863b916ada6232035a (patch)
tree6096c3c710f24185435d130edf9549c96e274efa
parentFix linking for last change on non-ELF platforms. (diff)
downloadlibgpg-error-d83b12213231443b93de39863b916ada6232035a.tar.gz
libgpg-error-d83b12213231443b93de39863b916ada6232035a.zip
Extend the platform dependent build rules.
* src/mkheader.c (mk_include_name): New. (include_file): Implement '&' substitution. (try_include_file): New. (write_special): Use try_include_file and syscfg/. (main): Add a new arg. * configure.ac (CROSS_COMPILING): New am_conditional. (HOST_TRIPLET_STRING): New ac_define. * src/gen-posix-lock-obj.c (main): Print the host triplet. * src/w32-lock-obj-pub.in: Move to ... * src/syscfg/lock-obj-pub.mingw32.h: here. * src/Makefile.am (lock_obj_pub): New. (pre_mkheader_cmds): New. (gpg-error.h): Run pre_mkheader_cmds. (parts_of_gpg_error_h, lock-obj-pub.native.h): Do not use when cross-compiling. Signed-off-by: Werner Koch <[email protected]>
-rw-r--r--README24
-rw-r--r--configure.ac3
-rw-r--r--src/Makefile.am45
-rw-r--r--src/gen-posix-lock-obj.c17
-rw-r--r--src/mkheader.c117
-rw-r--r--src/syscfg/lock-obj-pub.mingw32.h (renamed from src/w32-lock-obj-pub.in)0
6 files changed, 162 insertions, 44 deletions
diff --git a/README b/README
index 73af551..3d4640c 100644
--- a/README
+++ b/README
@@ -95,6 +95,30 @@ version:
./autogen.sh --build-w64
+Cross-Compiling
+---------------
+
+Libgpg-error needs to figure out some platform specific properties.
+These are used to build the platform specific gpg-error.h file. The
+detection is done during build time but can't be done when
+cross-compiling. Thus if you run into an error during building you
+need to figure out these values. You may use these commands:
+
+ build="$(build-aux/config.guess)"
+ ./configure --prefix=TARGETDIR --host=TARGET --build=$build
+ cd src
+ make gen-posix-lock-obj
+ scp gen-posix-lock-obj TARGET:
+ ssh TARGET ./gen-posix-lock-obj >tmp.h
+ mv tmp.h "syscfg/$(awk 'NR==1 {print $2}' tmp.h)"
+
+If you are using a VPATH build adjust accordingly. If this all works
+for you (make sure to run the test programs on the target platform),
+please send the generated file to the gnupg-devel mailing list so that
+we can include it in the next release.
+
+
+
Known Problems
--------------
diff --git a/configure.ac b/configure.ac
index 3d1e12f..21a36e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -202,6 +202,9 @@ fi
AM_CONDITIONAL(HAVE_W32_SYSTEM, test "$have_w32_system" = yes)
AM_CONDITIONAL(HAVE_W64_SYSTEM, test "$have_w64_system" = yes)
AM_CONDITIONAL(HAVE_W32CE_SYSTEM, test "$have_w32ce_system" = yes)
+AM_CONDITIONAL(CROSS_COMPILING, test x$cross_compiling = xyes)
+
+AC_DEFINE_UNQUOTED(HOST_TRIPLET_STRING, "$host", [The host triplet])
#
diff --git a/src/Makefile.am b/src/Makefile.am
index 9ced1e5..77ece16 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,6 +39,11 @@ else
noinst_PROGRAMS = gen-posix-lock-obj
endif
+# Distributed lock object definitions for cross compilation.
+lock_obj_pub = \
+ syscfg/lock-obj-pub.mingw32.h
+
+
lib_LTLIBRARIES = libgpg-error.la
include_HEADERS = gpg-error.h
bin_SCRIPTS = gpg-error-config
@@ -51,7 +56,7 @@ EXTRA_DIST = mkstrtable.awk err-sources.h.in err-codes.h.in \
mkheader.c gpg-error.h.in mkw32errmap.c w32-add.h w32ce-add.h \
err-sources.h err-codes.h gpg-error-config.in gpg-error.m4 \
gpg-error.def.in versioninfo.rc.in \
- w32-lock-obj-pub.in
+ $(lock_obj_pub)
BUILT_SOURCES = err-sources.h err-codes.h code-to-errno.h code-from-errno.h \
err-sources-sym.h err-codes-sym.h errnos-sym.h gpg-error.h \
@@ -62,7 +67,7 @@ tmp_files = _mkerrcodes.h _gpg-error.def.h mkw32errmap.tab.h mkw32errmap.map.c
CLEANFILES = err-sources.h err-codes.h code-to-errno.h code-from-errno.h \
gpg-error.h mkerrcodes mkerrcodes.h gpg-error.def mkw32errmap.tab.h \
mkw32errmap.map.c err-sources-sym.h err-codes-sym.h errnos-sym.h \
- gpg-extra/errno.h mkheader $(tmp_files) posix-lock-obj-pub.in
+ gpg-extra/errno.h mkheader $(tmp_files) lock-obj-pub.native.h
if HAVE_W32_SYSTEM
arch_sources = w32-gettext.c w32-lock.c w32-lock-obj.h w32-thread.c
@@ -106,20 +111,6 @@ libgpg_error_la_LDFLAGS = -version-info \
@LIBGPG_ERROR_LT_CURRENT@:@LIBGPG_ERROR_LT_REVISION@:@LIBGPG_ERROR_LT_AGE@ \
$(no_undefined) $(export_symbols)
-parts_of_gpg_error_h = \
- gpg-error.h.in \
- err-sources.h.in \
- err-codes.h.in \
- errnos.in \
- w32-add.h \
- w32ce-add.h \
- w32-lock-obj-pub.in
-
-if ! HAVE_W32_SYSTEM
-parts_of_gpg_error_h += posix-lock-obj-pub.in
-endif
-
-
libgpg_error_la_SOURCES = gpg-error.h gettext.h $(arch_sources) \
init.c init.h version.c lock.h thread.h \
strsource.c strerror.c code-to-errno.c code-from-errno.c
@@ -212,14 +203,32 @@ errnos-sym.h: Makefile mkstrtable.awk errnos.in
mkheader: mkheader.c Makefile
$(CC_FOR_BUILD) -g -O0 -I. -I$(srcdir) -o $@ $(srcdir)/mkheader.c
+parts_of_gpg_error_h = \
+ gpg-error.h.in \
+ err-sources.h.in \
+ err-codes.h.in \
+ errnos.in \
+ w32-add.h \
+ w32ce-add.h \
+ $(lock_obj_pub)
-posix-lock-obj-pub.in: Makefile gen-posix-lock-obj posix-lock-obj.h
+# If we are cross-compiling we better make sure that no stale native
+# lock include file will be found by mkheader.
+if CROSS_COMPILING
+pre_mkheader_cmds = -rm lock-obj-pub.native.h 2>/dev/null
+else
+pre_mkheader_cmds = :
+parts_of_gpg_error_h += ./lock-obj-pub.native.h
+
+lock-obj-pub.native.h: Makefile gen-posix-lock-obj posix-lock-obj.h
./gen-posix-lock-obj >$@
+endif
# We also depend on versioninfo.rc because that is build by
# config.status and thus has up-to-date version numbers.
gpg-error.h: Makefile mkheader $(parts_of_gpg_error_h) versioninfo.rc
- ./mkheader $(host_os) $(srcdir)/gpg-error.h.in \
+ $(pre_mkheader_cmds)
+ ./mkheader $(host_os) $(host_triplet) $(srcdir)/gpg-error.h.in \
$(PACKAGE_VERSION) $(VERSION_NUMBER) >$@
diff --git a/src/gen-posix-lock-obj.c b/src/gen-posix-lock-obj.c
index b641fd0..5dbc6c6 100644
--- a/src/gen-posix-lock-obj.c
+++ b/src/gen-posix-lock-obj.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <errno.h>
#include <pthread.h>
#include "posix-lock-obj.h"
@@ -65,7 +66,8 @@ main (void)
/* To force a probably suitable alignment of the structure we use a
union and include a long and a pointer to a long. */
- printf ("## File created by " PGM " - DO NOT EDIT\n"
+ printf ("## lock-obj.%s.h\n"
+ "## File created by " PGM " - DO NOT EDIT\n"
"## To be included by mkheader into gpg-error.h\n"
"\n"
"typedef union\n"
@@ -79,6 +81,7 @@ main (void)
"} gpgrt_lock_t;\n"
"\n"
"#define GPGRT_LOCK_INITIALIZER {{{",
+ HOST_TRIPLET_STRING,
SIZEOF_PTHREAD_MUTEX_T);
p = (unsigned char *)&mtx;
for (i=0; i < sizeof mtx; i++)
@@ -90,6 +93,18 @@ main (void)
putchar (',');
}
printf ("},%d}}\n", LOCK_ABI_VERSION);
+ fputs ("##\n"
+ "## Loc" "al Variables:\n"
+ "## mode: c\n"
+ "## buffer-read-only: t\n"
+ "## End:\n"
+ "##\n", stdout);
+
+ if (ferror (stdout))
+ {
+ fprintf (stderr, PGM ": error writing to stdout: %s\n", strerror (errno));
+ return 1;
+ }
return 0;
}
diff --git a/src/mkheader.c b/src/mkheader.c
index e7db729..43e7fd8 100644
--- a/src/mkheader.c
+++ b/src/mkheader.c
@@ -16,12 +16,14 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
#define PGM "mkheader"
#define LINESIZE 1024
static const char *host_os;
+static const char *host_triplet;
static char *srcdir;
static const char *hdr_version;
static const char *hdr_version_number;
@@ -128,6 +130,45 @@ write_errnos_in (char *line)
}
+/* Create the full file name for NAME and return a newly allocated
+ string with it. If name contains a '&' and REPL is not NULL
+ replace '&' with REPL. */
+static char *
+mk_include_name (const char *name, const char *repl)
+{
+ FILE *fp;
+ char *incfname, *p;
+ const char *s;
+
+ incfname = malloc (strlen (srcdir) + strlen (name)
+ + (repl?strlen (repl):0) + 1);
+ if (!incfname)
+ {
+ fputs (PGM ": out of core\n", stderr);
+ exit (1);
+ }
+
+ if (*name == '.' && name[1] == '/')
+ *incfname = 0;
+ else
+ strcpy (incfname, srcdir);
+ p = incfname + strlen (incfname);
+ for (s=name; *s; s++)
+ {
+ if (*s == '&' && repl)
+ {
+ while (*repl)
+ *p++ = *repl++;
+ repl = NULL; /* Replace only once. */
+ }
+ else
+ *p++ = *s;
+ }
+ *p = 0;
+ return incfname;
+}
+
+
/* Include the file NAME from the source directory. The included file
is not further expanded. It may have comments indicated by a
double hash mark at the begin of a line. OUTF is called for each
@@ -141,21 +182,18 @@ include_file (const char *fname, int lnr, const char *name, void (*outf)(char*))
char *incfname;
int inclnr;
char line[LINESIZE];
+ int repl_flag;
- incfname = malloc (strlen (srcdir) + strlen (name) + 1);
- if (!incfname)
+ repl_flag = !!strchr (name, '&');
+ incfname = mk_include_name (name, repl_flag? host_triplet : NULL);
+ fp = fopen (incfname, "r");
+ if (!fp && repl_flag)
{
- fputs (PGM ": out of core\n", stderr);
- exit (1);
+ /* Try again using the OS string. */
+ free (incfname);
+ incfname = mk_include_name (name, host_os);
+ fp = fopen (incfname, "r");
}
-
- if (*name == '.' && name[1] == '/')
- *incfname = 0;
- else
- strcpy (incfname, srcdir);
- strcat (incfname, name);
-
- fp = fopen (incfname, "r");
if (!fp)
{
fprintf (stderr, "%s:%d: error including `%s': %s\n",
@@ -163,6 +201,10 @@ include_file (const char *fname, int lnr, const char *name, void (*outf)(char*))
exit (1);
}
+ if (repl_flag)
+ fprintf (stderr,"%s:%d: note: including '%s'\n",
+ fname, lnr, incfname);
+
inclnr = 0;
while (fgets (line, LINESIZE, fp))
{
@@ -206,6 +248,33 @@ include_file (const char *fname, int lnr, const char *name, void (*outf)(char*))
}
+/* Try to include the file NAME. Returns true if it does not
+ exist. */
+static int
+try_include_file (const char *fname, int lnr, const char *name,
+ void (*outf)(char*))
+{
+ int rc;
+ char *incfname;
+ int repl_flag;
+
+ repl_flag = !!strchr (name, '&');
+ incfname = mk_include_name (name, repl_flag? host_triplet : NULL);
+ rc = access (incfname, R_OK);
+ if (rc && repl_flag)
+ {
+ free (incfname);
+ incfname = mk_include_name (name, host_os);
+ rc = access (incfname, R_OK);
+ }
+ if (!rc)
+ include_file (fname, lnr, name, outf);
+
+ free (incfname);
+ return rc;
+}
+
+
static int
write_special (const char *fname, int lnr, const char *tag)
{
@@ -249,12 +318,8 @@ write_special (const char *fname, int lnr, const char *tag)
}
else if (!strcmp (tag, "include:lock-obj"))
{
- if (!strcmp (host_os, "mingw32"))
- {
- include_file (fname, lnr, "w32-lock-obj-pub.in", write_line);
- }
- else
- include_file (fname, lnr, "./posix-lock-obj-pub.in", write_line);
+ if (try_include_file (fname, lnr, "./lock-obj-pub.native.h", write_line))
+ include_file (fname, lnr, "syscfg/lock-obj-pub.&.h", write_line);
}
else
return 0; /* Unknown tag. */
@@ -277,16 +342,18 @@ main (int argc, char **argv)
argc--; argv++;
}
- if (argc != 4)
+ if (argc != 5)
{
- fputs ("usage: " PGM " host_os template.h version version_number\n",
+ fputs ("usage: " PGM
+ " host_os host_triplet template.h version version_number\n",
stderr);
return 1;
}
host_os = argv[0];
- fname = argv[1];
- hdr_version = argv[2];
- hdr_version_number = argv[3];
+ host_triplet = argv[1];
+ fname = argv[2];
+ hdr_version = argv[3];
+ hdr_version_number = argv[4];
srcdir = malloc (strlen (fname) + 2 + 1);
if (!srcdir)
@@ -337,8 +404,8 @@ main (int argc, char **argv)
if (!strcmp (p1, "configure_input"))
{
s = strrchr (fname, '/');
- printf ("Do not edit. Generated from %s by %s for %s.",
- s? s+1 : fname, PGM, host_os);
+ printf ("Do not edit. Generated from %s for %s.",
+ s? s+1 : fname, host_triplet);
fputs (p2, stdout);
putchar ('\n');
}
diff --git a/src/w32-lock-obj-pub.in b/src/syscfg/lock-obj-pub.mingw32.h
index 2f3f911..2f3f911 100644
--- a/src/w32-lock-obj-pub.in
+++ b/src/syscfg/lock-obj-pub.mingw32.h