/*--------------------------------------------------------------------------
Program to fix embedded paths in files.
Useful especially for gcc < 3.0 and binutils < 2.14, which
do not work if you move them after installation;
running this program fixes the paths and lets the programs work again.
By Clay Wood and Dan Kegel
Copyright 2005 Google Inc.
Licensed under the GPL.
Example:
You generated a gcc/glibc/binutils toolchain using http://kegel.com/crosstool,
installed it to /tmp/myverylongpath, and later moved it with the command
mv /tmp/myverylongpath /usr/crosstool
Sadly, running gcc now fails because gcc still looks for internal files
that no longer exist, using absolute paths like
/tmp/myverylongpath/gcc-3.4.3-glibc-2.3.2/lib/gcc/i686-unknown-linux-gnu/3.4.3/specs
embedded in its binaries and data files.
Fortunately for you, this program implements the appropriate simple
search-and-replace on the files. Running it with arguments
"/tmp/myverylongpath /usr/crosstool /usr/crosstool" changes the example
string above to
/usr/crosstool/gcc-3.4.3-glibc-2.3.2/lib/gcc/i686-unknown-linux-gnu/3.4.3/specs
It carefully preserves long paths and string terminators (which
vary from file type to file type). It detects string terminators by
assuming that any character not in a small set known to be used as
gcc/glibc/binutils filenames is a terminator. This is a fragile hack,
but in practice it seems to work for the binary and ascii files that
make up gcc/glibc/binutils.
Changelog:
Sat Apr 9 PDT 2005 Dan Kegel <dank at kegel.com>
* Created
Sun Jul 17 PDT 2005 Dan Kegel
* Added optional 4th parameter to let you re-relocate
e.g. if you relocated to a too-short path, and now
want to relocate to a longer path (but still not
longer than the original one)
--------------------------------------------------------------------------*/
#ifdef _WIN32
/* Under msvc2003, PATH_MAX is only defined if _POSIX_ is set */
#define _POSIX_ 1 /* for PATH_MAX */
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>
/* #include <unistd.h> */
#include <sys/stat.h>
/* The first few functions are wrappers around os-specific stuff
* Hopefully this will make it easier to port to win32
*/
/*------- fatalError --------------------------------------------------------*/
/* Display an error to the user, and abort.
* Use a macro so we can get line number (for debugging).
*/
#define fatalError(s, arg) do { \
fprintf(stderr, s, arg); \
fprintf(stderr, "Failed at line %d\n", __LINE__); \
exit(1);\
} while (0)
/*------- struct permissions -----------------------------------------------*/
/* Tiny class to let you make a file writable, then restore its permissions later. */
struct permissions {
struct stat perms;
};
/* Make the given file writable, and save its old permissions state in *perms.
*/
static void permissions_makeWriteable(struct permissions *perms,
const char *file_name)
{
assert(NULL != perms);
if (0 != stat(file_name, &perms->perms))
fatalError("Can't get stats for %s\n", file_name);
if ((perms->perms.st_mode & S_IWRITE) == 0) {
/* Change the permissions to allow writes */
if (chmod(file_name, perms->perms.st_mode | S_IWRITE) != 0)
fatalError("Can't make writeable: %s\n", file_name);
}
}
/* Restore the given file's permissions.
*/
static void permissions_restore(const struct permissions *perms,
const char *file_name)
{
assert(NULL != perms);
assert(NULL != file_name);
if ((perms->perms.st_mode & S_IWRITE) == 0) {
if (chmod(file_name, perms->perms.st_mode) != 0)
fatalError("Could not make change permissions back: %s\n", file_name);
}
}
/*----- struct filefinder --------------------------------------------------*/
/* Tiny class to search a directory tree for files containing a substring */
struct filefinder {
FILE *file_list;
};
/* Start searching a directory tree for files containing the given string
*/
static void filefinder_init(struct filefinder *finder,
const char *oldroot,
const char *search_path)
{
char search_cmd[PATH_MAX * 3];
assert(NULL != finder);
assert(NULL != oldroot);
assert(NULL != search_path);
finder->file_list = NULL;
/* Assume we have GNU grep. (Could have used xargs and standard grep.) */
sprintf(search_cmd, "grep -lr '%s' '%s'", oldroot, search_path);
finder->file_list = popen(search_cmd, "r");
if (NULL == finder->file_list)
fatalError("Can't run %s\n", search_cmd);
}
/* Stop searching.
*/
static void filefinder_end(struct filefinder *finder)
{
if (finder->file_list) {
fclose(finder->file_list);
finder->file_list = NULL;
}
}
/* Get the path to the next matching file.
* file_name must be PATH_MAX bytes or longer.
* Return 1 on success, 0 if no more files
*/
static int filefinder_GetNextFile(struct filefinder *finder,
char *file_name)
{
int i;
assert(NULL != finder);
assert(NULL != file_name);
if (NULL == fgets(file_name, PATH_MAX, finder->file_list))
return 0;
/* Strip newline */
for (i = 0; i < PATH_MAX && file_name[i] != 0; ++i) {
if (file_name[i] == '\n') {
file_name[i] = 0;
break;
}
}
return 1;
}
/*----- the business end ---------------------------------------------------*/
/* Return TRUE iff c is likely to be part the name of a file or directory
* within the gnu gcc, glibc, or binutils trees.
* There are generally no colons or spaces in these filenames even
* on Windows (though there may be in the old or new root prefixes,
* which aren't tested with this function).
*/
static int isLikelyFilenameChar(char c)
{
return isalnum(c) ||
c == '_' || c == '.' ||
c == '\\' || c == '/' || c == '-' || c == '+';
}
/* Replace oldroot with newroot in 'path' buffer.
* On entry,
* path[0..path_len-2] contains the absolute path of some file in the old tree
* path[path_len-1] is the terminator for the string (NUL, space, eol, etc)
* On exit,
* path has been adjusted to contain the absolute path of the same file in the new tree
* followed by the terminator. Any extra space after the terminator
* is filled with ascii 0x20 (space).
* Returns number of chars to write
*/
static int
replaceOneString(char *path,
unsigned int path_len,
const char *newroot,
unsigned int newroot_len,
unsigned int oldroot_len)
{
unsigned int i;
assert(oldroot_len <= path_len);
assert(NULL != path);
assert(NULL != newroot);
if (newroot_len < oldroot_len) {
unsigned int delta = oldroot_len - newroot_len;
/* Overwrite the beginning of the path with the new root */
for (i=0; i < newroot_len; i++)
path[i] = newroot[i];
/* Scoot rest of path (and its terminator!) down to fit */
for (; i < path_len - delta; i++)
path[i] = path[i + delta];
/* Pad with spaces */
for (; i < path_len; i++)
path[i] = 0x20; /* ascii space */
return path_len;
} else {
unsigned int delta = newroot_len - oldroot_len;
/* Scoot rest of path (and its terminator!) up to fit */
for (i = path_len + delta; i > delta; i--)
path[i - 1] = path[i - delta - 1];
/* Overwrite the beginning of the path with the new root */
for (i=0; i < newroot_len; i++)
path[i] = newroot[i];
return path_len + delta;
}
}
/* Opens the give file, searches for all occurences of oldroot,
* replaces them with newroot, carefully scooting the following
* string (if any) and terminator down to fit.
*/
static void ReplaceStringsInOneFile(const char *file_name,
没有合适的资源?快使用搜索试试~ 我知道了~
ezx-crosstool-0.5
共86个文件
patch:64个
sh:10个
dat:2个
4星 · 超过85%的资源 需积分: 3 97 下载量 133 浏览量
2008-03-14
21:15:11
上传
评论 1
收藏 189KB RAR 举报
温馨提示
配置moto e680系列和a1200系列开发环境所需的东东,原地址打不开了,我就上传一个给有需要的朋友
资源推荐
资源详情
资源评论
收起资源包目录
ezx-crosstool-0.5.rar (86个子文件)
ezx-crosstool-0.5
COPYING 18KB
getandpatch.sh 11KB
build.sh 493B
mkoverride.sh 2KB
arm-ezx.dat 187B
crosstest.sh 10KB
gcc-3.3.6-glibc-2.3.2.dat 137B
patches
binutils-2.15
binutils-skip-comments.patch 3KB
binutils-2.15-solaris-qsort.patch 682B
binutils-arm-undef-imm.patch 2KB
s390-invalid-insn-format.patch 1KB
binutils-2.15-psignal.patch 2KB
gccpr15247-fix.patch 11KB
cross-gprof.patch 2KB
binutils-2.15-vmx.patch 2KB
linux-2.4.26
linux-2.4.26-wdt977-uaccess.patch 587B
linux-2.4.26-arm-nonofpu.patch 2KB
01-kmap-types-cleanup.patch 8KB
linux-2.4.26-allow-gcc-3.4-arm-kernel.patch 1001B
linux-2.4.26-mkdep-xargs.patch 2KB
kaz-types.patch 2KB
linux-2.4.21-allow-gcc-3.3-arm-lib.patch 5KB
linux-2.4-bsd-expr.patch 1KB
glibc-2.3.2
sscanf.patch 3KB
glibc-2.3.2-allow-gcc-3.5-sunrpc.patch 8KB
gcc-pr-9552-workaround.patch 780B
glibc-2.3.2-powerpc-as.patch 2KB
glibc-2.3.2-allow-gcc-3.5-PR14096.patch 2KB
glibc-2.3.2-allow-gcc-3.5-xdr.patch 2KB
glibc-2.3.2-sparc64-dl-machine.patch 1KB
glibc-2.3.2-hostgcc-4.x.patch 506B
glibc-2.3.2-sparc64-pause.patch 1KB
glibc-2.3.2-arm-fix-strlen.patch 2KB
glibc-2.3.2-sh4-trapa.patch 2KB
glibc-2.3.2-mips.patch 3KB
old
glibc-2.3.2-powerpc-procfs.patch 938B
glibc-2.3.2-override.patch 2KB
nobits.patch 1KB
glibc-2.3.2-without-fp.patch 4KB
glibc-2.3.2-allow-gcc-3.5-elf.patch 989B
errlist-awk.patch 399B
glibc-2.3.2-allow-gcc-3.4-nounit.patch 8KB
glibc-2.2.5-mips-clone-local-label.patch 3KB
glibc-2.3.2-cross.patch 1KB
glibc-2.3.2-pr139-fix.patch 4KB
arm-asm-clobber.patch 1KB
glibc-2.3.2-sparc32-sysdep.patch 3KB
glibc-2.3.2-sh4-socket.patch 1KB
glibc-2.3.2-sparc64-pwrite64.patch 1KB
arm-mcount_internal.patch 726B
arm-ctl_bus_isa.patch 3KB
glibc-2.3.2-cygwin.patch 4KB
glibc-2.3.2-allow-gcc-3.4-inline.patch 915B
glibc-drow-sh.patch 3KB
README-hppa 2KB
glibc-2.3.2-allow-gcc-3.5-gconv.patch 7KB
glibc-2.3.2-cross-2.patch 773B
glibc-2.2.5-crosstest.patch 1021B
glibc-2.3.2-allow-gcc-3.5-msort.patch 1KB
glibc-configure-apple-as.patch 1KB
glibc-2.3.2-mips-user.patch 21KB
glibc-2.3.2-alpha-pwrite64.patch 2KB
glibc-2.3.3-allow-gcc-4.0-powerpc-procfs.patch 3KB
string2-typedef.patch 1KB
epoll-stdint.patch 834B
epoll-epollet.patch 962B
glibc-fp-byteorder.patch 7KB
glibc-test-lowram.patch 371B
fixup.patch 3KB
gcc-3.3.6
gcc-3.3.6-arm-bigendian.patch 2KB
gcc-3.3.6-arm-softfloat.patch 66KB
gcc-3.3.6-iwmmxt.patch 186KB
arm.config 20KB
LICENSE 18KB
masq.sh 2KB
all.sh 5KB
install-shared-lib.sh 699B
downloads
build
README.crosstool 381B
config.guess 40KB
README 688B
testhello.sh 1KB
fix-embedded-paths.c 14KB
COPYING.LIB 26KB
crosstool.spec.in 15KB
crosstool-cygwin.sh 11KB
crosstool.sh 29KB
共 86 条
- 1
资源评论
- l_1h2014-12-25挺不错,是在Windows下模拟linux环境的好助手
- ba7hu2013-04-24呵呵这个可以用,编译成功
- ALLSTARONE2014-02-04不错!是我要的!可以用
tian_7
- 粉丝: 11
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功