In 8.0, PostgreSQL lost its previously postulated ability to be cross-compiled and it turns out some people actually used that, so here's an attempt to fix it.
The problem is that the program zic in src/timezone/ is built and run during the build process, which doesn't work if it's compiled by a cross-compiler. The standard way to go about this in autotools land (references: gcc, binutils) is to introduce a second variable CC_FOR_BUILD that is set to a native compiler. There is no particular way to determine this variable; it's passed by the user or defaults to $CC. This variable is then used in place of CC to build programs that are compiled and run during the build. The problem is that native compilations cannot rely on things that the build system normally provides because the tests are run for the target system, not the build system. It can be assumed that the compilers are of the same kind, so using CFLAGS etc. is OK. But one cannot rely on libraries for example without entering a world of pain. Since most programs that need native compilation are usually some small conversion programs, this generally works out well anyway. Attached is a patch that implements that principle for zic. zic can no longer use libpgport, but the only thing it seems to use from there is strerror() and I like to think that we can get away with that. I haven't actually tried this out with a cross compilation since I'm not set up for it, so if someone has an environment available, please give this a try. Comments? -- Peter Eisentraut http://developer.postgresql.org/~petere/
diff -cr -x configure ../cvs-pgsql/configure.in ./configure.in *** ../cvs-pgsql/configure.in 2005-05-30 17:34:59.000000000 +0200 --- ./configure.in 2005-05-30 18:35:15.212677930 +0200 *************** *** 304,309 **** --- 304,320 ---- # + # Native compiler + # + + if test -z "$CC_FOR_BUILD"; then + CC_FOR_BUILD=$CC + fi + + AC_SUBST(CC_FOR_BUILD) + + + # # Set up TAS assembly code if needed; the template file has now had its # chance to request this. # diff -cr -x configure ../cvs-pgsql/src/Makefile.global.in ./src/Makefile.global.in *** ../cvs-pgsql/src/Makefile.global.in 2005-05-30 17:35:05.000000000 +0200 --- ./src/Makefile.global.in 2005-05-30 18:39:39.750672139 +0200 *************** *** 182,187 **** --- 182,188 ---- endif # not PGXS CC = @CC@ + CC_FOR_BUILD = @CC_FOR_BUILD@ GCC = @GCC@ CFLAGS = @CFLAGS@ diff -cr -x configure ../cvs-pgsql/src/timezone/Makefile ./src/timezone/Makefile *** ../cvs-pgsql/src/timezone/Makefile 2005-01-04 20:41:01.000000000 +0100 --- ./src/timezone/Makefile 2005-05-30 19:11:46.708533716 +0200 *************** *** 18,24 **** OBJS= localtime.o strftime.o pgtz.o # files needed to build zic utility program ! ZICOBJS= zic.o ialloc.o scheck.o localtime.o # timezone data files TZDATA := africa antarctica asia australasia europe northamerica southamerica \ --- 18,24 ---- OBJS= localtime.o strftime.o pgtz.o # files needed to build zic utility program ! ZICOBJS= zic.o ialloc.o scheck.o localtime-zic.o # timezone data files TZDATA := africa antarctica asia australasia europe northamerica southamerica \ *************** *** 30,37 **** SUBSYS.o: $(OBJS) $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS) zic: $(ZICOBJS) ! $(CC) $(CFLAGS) $(ZICOBJS) $(LDFLAGS) $(LIBS) -o [EMAIL PROTECTED](X) install: all installdirs ./zic -d $(DESTDIR)$(datadir)/timezone $(TZDATAFILES) --- 30,46 ---- SUBSYS.o: $(OBJS) $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS) + # In case of cross-compilation, zic needs to be built with a native + # compiler because it is run during the build, not on the final + # system. + + localtime-zic.c: localtime.c + $(LN_S) $< $@ + + $(ZICOBJS): CC=$(CC_FOR_BUILD) + zic: $(ZICOBJS) ! $(CC_FOR_BUILD) $(CFLAGS) $(ZICOBJS) -o [EMAIL PROTECTED](X) install: all installdirs ./zic -d $(DESTDIR)$(datadir)/timezone $(TZDATAFILES) *************** *** 40,43 **** $(mkinstalldirs) $(DESTDIR)$(datadir) clean distclean maintainer-clean: ! rm -f SUBSYS.o zic$(X) $(OBJS) $(ZICOBJS) --- 49,52 ---- $(mkinstalldirs) $(DESTDIR)$(datadir) clean distclean maintainer-clean: ! rm -f SUBSYS.o zic zic$(X) $(OBJS) $(ZICOBJS) localtime-zic.c
---------------------------(end of broadcast)--------------------------- TIP 8: explain analyze is your friend