Provide od+sed replacement for the bin2char helper 39/2139/7
authorPaul Fertser <fercerpav@gmail.com>
Sun, 11 May 2014 18:15:55 +0000 (22:15 +0400)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Sat, 2 Aug 2014 09:00:28 +0000 (09:00 +0000)
Using custom build-time tools is always more problematic, especially
for cross-compiling.

This alternative implementation assumes "od" (IEEE Std 1003.1-2001)
and sed are available which should be the case for any reasonably
modern system.

Change-Id: I0208f475648c78e7dca127ff4bab60d314b2bf53
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2139
Tested-by: jenkins
Reviewed-by: Fatih Aşıcı <fatih.asici@gmail.com>
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
configure.ac
src/Makefile.am
src/helper/Makefile.am
src/helper/bin2char.c [deleted file]
src/helper/bin2char.sh [new file with mode: 0755]
src/target/Makefile.am

index 13d2559..6b61b1b 100644 (file)
@@ -1248,47 +1248,6 @@ if test $gcc_warnings = yes; then
   CFLAGS="$CFLAGS $GCC_WARNINGS"
 fi
 
-# Setup for compiling build tools
-AC_MSG_CHECKING([for a C compiler for build tools])
-if test $cross_compiling = yes; then
-  AC_CHECK_PROGS(CC_FOR_BUILD, gcc cc)
-  CFLAGS_FOR_BUILD="-g -O2 $GCC_WARNINGS"
-else
-  CC_FOR_BUILD=$CC
-  CFLAGS_FOR_BUILD=$CFLAGS
-fi
-
-AC_MSG_RESULT([$CC_FOR_BUILD])
-AC_SUBST([CC_FOR_BUILD])
-AC_SUBST([CFLAGS_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])
-
 AC_CONFIG_FILES([
   Makefile
   src/Makefile
index d630bd6..b539ec4 100644 (file)
@@ -91,7 +91,7 @@ BUILT_SOURCES = startup.tcl
 startup.tcl: $(STARTUP_TCL_SRCS)
        cat $^ > $@
 
-BIN2C = $(top_builddir)/src/helper/bin2char$(EXEEXT_FOR_BUILD)
+BIN2C = $(top_srcdir)/src/helper/bin2char.sh
 
 # Convert .tcl to cfile
 startup_tcl.c: startup.tcl $(BIN2C)
index 215bbae..9477267 100644 (file)
@@ -44,18 +44,9 @@ noinst_HEADERS = \
        replacements.h \
        fileio.h \
        system.h \
-       bin2char.c \
+       bin2char.sh \
        jim-nvp.h
 
 EXTRA_DIST = startup.tcl
 
-BIN2C = bin2char$(EXEEXT_FOR_BUILD)
-
-BUILT_SOURCES = $(BIN2C)
-
-$(BIN2C): bin2char.c
-       ${CC_FOR_BUILD} ${CFLAGS_FOR_BUILD} $(srcdir)/bin2char.c -o $@
-
-CLEANFILES = bin2char$(EXEEXT_FOR_BUILD)
-
 MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
diff --git a/src/helper/bin2char.c b/src/helper/bin2char.c
deleted file mode 100644 (file)
index d5fe7f3..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2005 by Dominic Rath                                    *
- *   Dominic.Rath@gmx.de                                                   *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
- ***************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifdef _WIN32
- #include <fcntl.h>
-#endif
-
-int main(int argc, char **argv)
-{
-       int c;
-       unsigned int n;
-       const char *name;
-
-       if (argc == 1) {
-               fprintf(stderr, "bin2char <varname>\n");
-               fprintf(stderr, "read from standard input and write a char"
-                       " array out to standard output\n");
-               exit(1);
-       }
-
-#ifdef _WIN32
-       /* for win32 set stdin/stdout to binary mode */
-       _setmode(_fileno(stdin), _O_BINARY);
-       _setmode(_fileno(stdout), _O_BINARY);
-#endif
-
-       n = 0;
-       name = argv[1];
-       fprintf(stdout, "/* autogenerated from %s */\n", argv[0]);
-       fprintf(stdout, "unsigned const char %s[] = {\n", name);
-       while ((c = getc(stdin)) != EOF) {
-               fprintf(stdout, "0x%02x,", c & 0xff);
-               if ((++n % 16) == 0)
-                       fprintf(stdout, "\n");
-       }
-       fprintf(stdout, "0 /* terminate with a null */};\n");
-       return 0;
-}
diff --git a/src/helper/bin2char.sh b/src/helper/bin2char.sh
new file mode 100755 (executable)
index 0000000..f9da309
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+[ $# = 0 ] && {
+    echo "Usage: $0 <varname>"
+    echo
+    echo "Read binary data from standard input and write it as a C character"
+    echo "array <varname> to standard output. Add a final NULL for terminating."
+    exit 1
+}
+
+echo "/* Autogenerated with $0 */"
+echo "unsigned const char $1[] = {"
+od -v -A n -t x1 | sed 's/ *\(..\) */0x\1,/g'
+echo "0 /* NULL-terminated */ };"
index 08d0db4..efbeb33 100644 (file)
@@ -9,7 +9,7 @@ endif
 SUBDIRS = openrisc
 libtarget_la_LIBADD = $(top_builddir)/src/target/openrisc/libopenrisc.la
 
-BIN2C          = $(top_builddir)/src/helper/bin2char$(EXEEXT_FOR_BUILD)
+BIN2C          = $(top_srcdir)/src/helper/bin2char.sh
 
 DEBUG_HANDLER  = $(srcdir)/xscale/debug_handler.bin
 EXTRA_DIST = \