VERSION := $(VERSION)$(EXTRAVERSION)
endif
# Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc.
-LC_ALL := C
+# To allow gen_wc8bit.c to compile without US UTF installed, LC_CTYPE can be
+# set to another UTF (eg. en_GB.utf8) before typing "make". However, loading
+# LC_ALL here causes the charmap to be replaced with ANSI_X3.4-1968. This
+# breaks building gen_wc8bit.c (when the previously mentioned US UTF isn't
+# installed). Hack workaround is to assume all will be OK without all
+# locale categories set to 'C'.
+# LC_ALL := C
export MAJOR_VERSION MINOR_VERSION SUBLEVEL VERSION LC_ALL
LIBC := libc
#include <stdlib.h>
#include <string.h>
#include <locale.h>
+#include <langinfo.h>
#include <stddef.h>
#include <wctype.h>
#include <limits.h>
{
FILE *fp;
FILE *out;
+ char *ctype;
charset_data csd[30];
unsigned long max_wchar;
unsigned char *p;
int codeset_list_end = 0;
int total_size = 0;
- if (!setlocale(LC_CTYPE, "en_US.UTF-8")) {
+ /*
+ * Kludge to allow building on a system without the US UTF installed.
+ * If cannot load the US UTF, then restore the char encoding and
+ * continue if it is a UTF encoding.
+ */
+
+ ctype = setlocale(LC_CTYPE, "");
+ if (ctype != NULL) {
+ i = strlen(ctype);
+ if (i < sizeof (buf)) {
+ memcpy(buf, ctype, i + 1);
+ } else {
+ ctype = NULL;
+ }
+ }
+ if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL && ctype != NULL) {
+ (void) setlocale(LC_CTYPE, buf);
+ }
+ if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0 &&
+ setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) {
printf("setlocale(LC_CTYPE,\"en_US.UTF-8\") failed!\n");
return EXIT_FAILURE;
}