Subject: Repair cross-tools on FreeBSD 4.9-STABLE host
To: None <netbsd-bugs@netbsd.org>
From: Alexander Yurchenko <grange@rt.mipt.ru>
List: netbsd-bugs
Date: 03/25/2004 14:07:07
FreeBSD prior to 5.0 (4.9-STABLE in my case) has wchar.h file but it's
rather useless:

__BEGIN_DECLS
#if 0
/* XXX: not implemented */
size_t  mbrlen __P((const char * __restrict, size_t, mbstate_t * __restrict));
size_t  mbrtowc __P((wchar_t * __restrict, const char * __restrict, size_t,
            mbstate_t * __restrict));
int     mbsinit __P((const mbstate_t *));
size_t  mbsrtowcs __P((wchar_t * __restrict, const char ** __restrict, size_t,
            mbstate_t * __restrict));


and so on. This causes new file(1) to fail on linking:

/usr/local/bin/bash ../libtool --mode=link cc  -O    -o file  file.o libmagic.la -lz
cc -O -o .libs/file file.o  ./.libs/libmagic.so -lz -Wl,--rpath -Wl,/home/users/grange/NetBSD/src/../tooldir/lib
file.o: In function `file_mbswidth':
file.o(.text+0x6e1): undefined reference to `mbrtowc'
file.o(.text+0x712): undefined reference to `wcwidth'

*** Failed target:  file
*** Failed command: /usr/local/bin/bash ../libtool --mode=link cc -O -o file file.o libmagic.la -lz
*** Error code 1

Stop.
nbmake: stopped in /home/users/grange/NetBSD/obj/tools/file/build/src


Here's a quick fix:

Index: dist/file/src/file.c
===================================================================
RCS file: /cvsroot/src/dist/file/src/file.c,v
retrieving revision 1.5
diff -u -r1.5 file.c
--- dist/file/src/file.c	23 Mar 2004 08:40:12 -0000	1.5
+++ dist/file/src/file.c	25 Mar 2004 10:48:16 -0000
@@ -64,6 +64,10 @@
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
 #endif
+/* XXX: FreeBSD prior to 5.0 doesn't have real wchar support */
+#if defined(__FreeBSD_version) && __FreeBSD_version < 500000
+#undef HAVE_WCHAR_H
+#endif
 #ifdef HAVE_WCHAR_H
 #include <wchar.h>
 #endif

-- 
   Alexander Yurchenko (aka grange)