momo zone

调核人的blog

Monthly Archives: 3月 2012

一个硬盘压力测试脚本

主要调用iozone 进行压力测试测试,另外要求hdparm新版本

 

#!/bin/sh

# usage : ./hddtest.sh [device] mode [loop count]

# default device is /dev/sda
# "mode" can be "test","benchmark"
# "loop count" is only for benchmark mode

HDPARM=$(which hdparm 2>/dev/null)
DD=$(which dd 2>/dev/null)
SMARTCTL=$(which smartctl 2>/dev/null)
IOZONE="/opt/iozone/bin/iozone"

TOTAL_MEM=$(grep MemTotal /proc/meminfo|awk '{print $2}')

DEV="/dev/sda"
HD_PARM="-T -t"

LOOP=100

if [ -z ${HDPARM}   ]
then	echo "hdparm can't found"
	exit 1
fi

if [ -z ${DD}   ]
then    echo "dd can't found"
	exit 1
fi

if [ -z ${SMARTCTL}   ]
then    echo "smartctl can't found"
	exit 1
fi

if [ -b "$1"  ]
then 
	DEV=$1
	echo "set device to ${DEV}"
#else
# echo "device can't found , set default $DEV"

fi

#get MAX_SPACE(KB) to alloc fsblk for iozone and dd write test
MAX_SPACE_SIZE=$(df |sort -n -k 4 |grep -e "^${DEV}"|tail -1|awk '{printf $4}')
TMP_PATH="$(df |sort -n -k 4 |grep -e "^${DEV}"|tail -1|awk '{printf $6}')/test.tmp"

#IOZ_PARM="-i 0 -i 1 -i 2 -r 16k -s $((TOTAL_MEM*2))"
IOZ_PARM="-a -s 32g -y 4k -q 10240k -i 0 -f ${TMP_PATH} -b report.xls"

usage(){
	echo 'Usage:'
	echo -e ' hddtest.sh device mode [loop_count]\n'
	echo -e '"device" is block device in /dev'
	echo '"mode" can be "test" or "benchmark"'
	echo '"loop count" is only for benchmark mode,default is 100'

	echo -e '\nExample:\n\thddtest.sh /dev/sda test\n'
	echo -e '\thddtest.sh /dev/sda benchmark 1000\n'
}

hddinfo(){	
	$HDPARM -I $DEV
}

hddspeed(){
	echo -e "\n#####################################"
	echo -e "Start cached and buffered read test:"
	echo -e "\n#####################################"
	$HDPARM $HD_PARM $DEV
}

ddspeed(){
	echo -e "\n#####################################"
	echo -e "Start direct read and write test:"
	echo -e "\n#####################################"

	dd if=${DEV} of=/dev/null bs=16384K count=100 iflag=nonblock,noatime,direct oflag=nonblock,noatime,nocache
	dd if=/proc/kcore of=${TMP_PATH} bs=16384K count=100 iflag=nonblock,nocache,noatime oflag=nonblock,direct,noatime	

	rm ${TMP_PATH}
}

fsspeed(){
	echo -e "\n#####################################"
	echo -e "Start file-system read and write test"
	echo -e "\n#####################################"

	$IOZONE $IOZ_PARM
}

benchmark(){

        echo -e "\n#####################################"
        echo -e "Start to benchmark fs I/O"
        echo -e "\n#####################################"

	while [  $LOOP -gt 0  ]
	do
		ctime=$(date '+%Y-%m-%d-%H-%M-%S')
		$SMARTCTL -A $DEV > /tmp/smartlog
		grep -E '(Reallocated_Sector_Ct|Current_Pending_Sector)' /tmp/smartlog > /tmp/smartlog.${ctime}

		$IOZONE $IOZ_PARM

		grep -E '(Reallocated_Sector_Ct|Current_Pending_Sector)' /tmp/smartlog > /tmp/smartlog.after

		diff -u /tmp/smartlog.${ctime} /tmp/smartlog.after > /tmp/smartlog

		if [ $? -ne 0  ]
		then
			printf "33[31m!!Found HDD issue,please cat /tmp/smartlog for detail!!\n33[0m"
			echo "remain loop: ${LOOP}" >> /tmp/smartlog
	# diff -u /tmp/smartlog.${ctime} /tmp/smartlog.after > /tmp/smartlog
			break
		fi

		LOOP=$((LOOP-1))
	done

# rm /tmp/smartlog*
}

# start here

if [ "$2" = "test" ]
then
	hddinfo
	hddspeed
	ddspeed
	fsspeed
elif [ "$2" = "benchmark" ]
then
	if [ -n "$3" ]
	then
		LOOP=$3
	else
		echo "loop count set to $LOOP"
	fi
	benchmark
else
	echo -e "Unknow command\n"
	usage
	exit 1
fi

vim 复制内容到系统剪切版

/*
* vim 复制内容到系统剪切版
*/
// 寄存器 “+ “* x11
vim 有很多寄存器,可以通过 :reg 查看,其中两个是 “* 和 “+;在 linux 下的 X11下
分别表示 X11 selection 和 clipboard, 在 windows 下都表示 clipboard( 因为
windows 的窗口系统不是 X11);
在 linux 下,选择一段文件(只是选择,并不复制),这段选择的文字会自动被复制到一个
空间,这个空间就是 X11 selection,在一个可以粘贴的区域点击鼠标中键就可以复制出
selection 中内容;Vim 的visual mode 下选择的区域会自动复制到 X11 selection,
因此 vim中复制到系统剪切版的方法:直接在 visual mode下选中文字,然后在其他可以
粘贴的地方直接点击鼠标中键就可以;反过来就可以把其他应用中的内容复制到 vim。
在类 unix 系统下的 vim 中,clipboard 只有在 vim 开启了 xterm_clipboard是才可以
使用( 使用 :version 查看 vim 是否启用了 xterm_clipboard )

// 来自 vim help( :help x11-selection)
X11 provides two basic types of global store, selections and cut-buffers,
which differ in one important aspect: selections are “owned” by an
application, and disappear when that application (e.g., Vim) exits, thus
losing the data, whereas cut-buffers, are stored within the X-server itself
and remain until written over or the X-server exits (e.g., upon logging out).
The contents of selections are held by the originating application (e.g., upon
a copy), and only passed on to another application when that other application
asks for them (e.g., upon a paste).
The contents of cut-buffers are immediately written to, and are then
accessible directly from the X-server, without contacting the originating
application.
// :help quoteplus
There are three documented X selections: PRIMARY (which is expected to
represent the current visual selection – as in Vim’s Visual mode), SECONDARY
(which is ill-defined) and CLIPBOARD (which is expected to be used for cut,
copy and paste operations).
Of these three, Vim uses PRIMARY when reading and writing the “* register
(hence when the X11 selections are available, Vim sets a default value for
|’clipboard’| of “autoselect”), and CLIPBOARD when reading and writing the “+
register. Vim does not access the SECONDARY selection.

[转]makefile与静态库的几个实例

目的 从复杂的工作中简化出来。

网上有一些制作Makfile的文章,只停留在Makefile而已。用autotools的工具相对来说要简单的多,其它一些介绍autotools文章又有很多漏洞,而且步骤烦琐。

制作一个最简单的helloworld程序:

现有目录test

mkdir src 建立src目录存放 源代码
在src下。
编辑hello.c文件

#include <stdio.h>

int main()
{
printf(“hello world\n”);
return 0;
}

在src目录下建立Makefile.am文件 (src/Makefile.am)

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS = hello
hello_SOURCES = hello.c
hello_LDADD = -lpthread (只是测试,实际不需要连接该库)

保存退出

退到test目录

编辑Makefile.am文件 (Makefile.am)

SUBDIRS = src

退出保存

然后
执行
autoscan
生成configure.scan文件

按此编辑此文件

#                                                -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.AC_PREREQ(2.59)
AC_INIT(hello,1.0, [miaoquan@nou.com.cn])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/hello.c])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.
# FIXME: Replace `main’ with a function in `-lpthread’:
AC_CHECK_LIB([pthread], [main])

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

#AC_CONFIG_FILES([Makefile
#                  src/Makefile])
AC_OUTPUT(Makefile src/Makefile)

退出保存
将此文件更名 mv configure.scan configure.in
然后执行
touch NEWS README AUTHORS ChangeLog然后执行
autoreconf -fvi

至此生成configure文件
执行configure文件

生成Makefile文件

make
make install
make uninstall
make dist
试验一下吧。

/*********************************************************************/

继续完善这个例子,论坛里有人问,如何生成静态库,并连接.

完善hello.c这个例子

当前目录
|-   src 目录
|-   hello.c 文件
|-   include 目录
|-   hello.h文件
|-   lib 目录
|-   test.c文件 此文件用来生成 libhello.a

在当前目录 编写Makefile.am

SUBDIRS = lib src

在include目录下 编写hello.h

extern void print(char *);

在lib目录下编写test.c

#include <stdio.h>

void print(char *msg)
{
printf(“%s\n”,msg);
}

在lib目录下编写Makefile.am

noinst_LIBRARIES=libhello.a
libhello_a_SOURCES=test.c

这里noinst_LIBRARIES 的意思是生成的静态库 ,不会被make install 安装
然后指定libhello.a的源文件test.c

在src目录下编写hello.c

#include “hello.h”

int main()
{
print(“haha”);   //这里是静态库里的print函数
return 0;
}

在src目录下编写Makefile.am

INCLUDES= -I../include

bin_PROGRAMS=hello
hello_SOURCES=hello.c
hello_LDADD=../lib/libhello.a

首先指定头文件的位置 ../include
然后指定要生成执行文件 hello
然后指定源代码文件 hello.c
最后添加静态库的位置 ../lib/libhello.a

按照我首篇帖子的方式.
执行autoscan 生成configure.scan

修改该文件

按照首篇帖子修改.

然后不同之处
需要添加一行:AC_PROG_RANLIB

#                                                -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.AC_PREREQ(2.59)
AC_INIT(hello,1.1,[miaoquan@nou.com.cn])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/hello.c])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.
AC_PROG_RANLIB
# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

#AC_CONFIG_FILES([Makefile
#                 lib/Makefile
#                src/Makefile])
AC_OUTPUT([Makefile
lib/Makefile
src/Makefile])

mv configure.scan configure.in

touch NEWS README AUTHORS ChangeLog

执行autoreconf -fvi

生成configure.执行configure生成Makefile..

后面同上…

通过IP查询AS信息

IP TO ASN MAPPING

*** SPECIAL NOTICE ***

If you are planning on implementing the use of this service in any software, application, or device PLEASE let us know in advance. We would like to adequately plan for capacity and make sure that we can adequately handle the load. If at all possible, PLEASE use the DNS based service since it is faster and more efficient, particularly for larger deployments of individual IP based queries. We have had instances where large deployments are put in place without informing us in advance, making it difficult to maintain a stable service for the rest of the community.

Introduction

Team Cymru is happy to announce the availability of various service options dedicated to mapping IP numbers to BGP prefixes and ASNs. These services come in various flavors, including:

Each of the services is based on the same BGP feeds from 50+ BGP peers, and is updated at 4 hour intervals. Using the above services one can obtain all of the following information:

  • BGP Origin ASN
  • BGP Peer ASN
  • BGP Prefix
  • Prefix Country Code (assigned)
  • Prefix Registry (assigned)
  • Prefix Allocation date
  • ASN Country Code (assigned)
  • ASN Registry (assigned)
  • ASN Allocation date
  • ASN Description

IP to ASN Mapping is NOT a GeoIP service!

The country code, registry, and allocation date are all based on data obtained directly from the regional registries including: ARIN, RIPE, AFRINIC, APNIC, LACNIC. The information returned relating to these categories will only be as accurate as the data present in the RIR databases. IMPORTANT NOTE: Country codes are likely to vary significantly from actual IP locations, and we must stronglyadvise that the IP to ASN mapping tool not be used as an IP geolocation (GeoIP) service. The exact links for each of the datasets are as follows:

The ASN descriptions are based on data obtained from cidr-report. If you are looking for an IP geolocation service, please check out one of the following (note: links do not constitute an endorsement, please contact us if you have a major commercial or free IP geolocation service you would like listed here):

Following is a brief summary on how to use each of the services.

WHOIS

The whois daemon acts like a standard whois server would, but with some added functionality. It accepts arguments on the command-line for single whois queries, and it also supports BULK IP submissions when combined with GNU’s netcat for those who wish to optimize their queries. When issuing requests for two or more IPs we strongly suggest you use netcat for BULK IP submissions, or DNS since there is less overhead. As a measure of speed, queries of approximately 100,000 IPs should return in less than a minute given a moderately sized Internet link. WARNING: IPs that are seen abusing the whois server with large numbers of individual queries instead of using the bulk netcat interface will be null routed. If at all possible you should consider using the DNS based query interface since it is much more efficient for individual queries. The netcat interface should be used for large groups of IP lists at a time in one single TCP query. There are presently two whois servers available:

  • whois.cymru.com (v4.whois.cymru.com)
  • peer.whois.cymru.com (v4-peer.whois.cymru.com)

The v4.whois.cymru.com server is primarily designed to map an IP address to a BGP Origin ASN and prefix. The v4-peer.whois.cymru.com server is designed to map an IP address to the possible BGP peer ASNs that are one AS hop away from the BGP Origin ASN’s prefix. This can be useful at times when you’re looking for a quick view into who an IP’s upstreams might be. Note that this method of finding peers is FAR from perfect and not an exact science. When the Origin ASN is a Tier 1 any concept of ‘upstream’ tends to lose its meaning. The syntax for whois and netcat whois IP queries is as follows:

Whois   Netcat          Action
        begin           enable bulk input mode          (netcat only)
        end             exit the whois/netcat client    (netcat only)
-p      prefix          include matching prefix
-q      noprefix        disable matching prefix (default)
-c      countrycode     include matching country code
-d      nocountrycode   disable country codes (default)
-n      asname          include asnames (default)
-o      noasname        disable asnames
-r      registry        display matching registry
-s      noregistry      disable registry display (default)
-a      allocdate       enable allocation date
-b      noallocdate     disable allocation date (default)
-t      truncate        truncate asnames (default)
-u      notruncate      do not truncate asnames
-v      verbose         enable all flags (-c -r -p -a -u -a)
-e      header          enable column headings (default)
-f      noheader        disable column headings
-w      asnumber        include asnumber column (default)
-x      noasnumber      disable asnumber column (will not work for IP mappings)
-h      help            this help message

To use the command-line arguments on a single IP query, be sure to enclose the request in quotes and to have a space before the first argument so that your whois client will not try to interpret the flags locally. For example, to enable the verbose mode (all flags) one would use:

$ whois -h whois.cymru.com " -v 216.90.108.31 2005-12-25 13:23:01 GMT"

AS      | IP               | BGP Prefix          | CC | Registry | Allocated  | Info                    | AS Name
23028   | 216.90.108.31    | 216.90.108.0/24     | US | arin     | 1998-09-25 | 2005-12-25 13:23:01 GMT | TEAMCYMRU - SAUNET

You may also query for some basic AS information directly:

$ whois -h whois.cymru.com " -v AS23028"

AS      | CC | Registry | Allocated  | AS Name
23028   | US | arin     | 2002-01-04 | TEAMCYMRU - SAUNET

We recommend the use GNU’s version of netcat, not nc. (nc has been known to cause buffering problems with our server and will not always return the full output for larger IP lists). GNU netcat can be downloaded fromhttp://netcat.sourceforge.net. This is the same as gnetcat in FreeBSD ports. To issue bulk queries, follow these steps: 1. Create a file with a list of IPs, one per line. Add the word begin at the top of the file and the word end at the bottom. Example of list01:

 begin
 68.22.187.5
 207.229.165.18
 ...
 198.6.1.65
 end

Remember: you can add comments and other flags per the table above if you’d like.

 begin
 verbose
 68.22.187.5 2005-06-30 05:05:05 GMT
 207.229.165.18 2005-06-30 05:05:05 GMT
 ...
 198.6.1.65 2005-06-30 05:05:05 GMT
 end

2. Run the list through GNU netcat (NOT the venerable nc).

 $ netcat whois.cymru.com 43 < list01 | sort -n > list02

The file list02 will be sorted by origin AS, and should appear as:

 Bulk mode; one IP per line. [2005-06-30 15:37:07 GMT]
 701     | 198.6.1.65       | UU UUNET Technologies, Inc.
 6079    | 207.229.165.18   | RCN RCN Corporation
 23028   | 68.22.187.5      | SAUNET SAUNET

Additional help can be obtained by issuing the help command.

 $ whois -h whois.cymru.com help

DNS

The DNS daemon is designed for rapid reverse lookups, much in the same way as RBL lookups are done. DNS has the added advantage of being cacheable and based on UDP so there is much less overhead. Similar to the whois TCP based daemon, there are three IPv4 zones available, and one for IPv6:

  • origin.asn.cymru.com
  • origin6.asn.cymru.com
  • peer.asn.cymru.com
  • asn.cymru.com

The origin.asn.cymru.com zone is used to map an IP address or prefix to a corresponding BGP Origin ASN. The origin6.asn.cymru.com zone is used to map an IPv6 address or prefix to a corresponding BGP Origin ASN. The peer.asn.cymru.com zone is used to map an IP address or prefix to the possible BGP peer ASNs that are one AS hop away from the BGP Origin ASN’s prefix. The asn.cymru.com zone is used to determine the AS description of a given BGP ASN. All DNS-based queries should be made by pre-pending the reversed octets of the IP address of interest to the appropriate zone listed above, demonstrated in the following examples:

 $ dig +short 31.108.90.216.origin.asn.cymru.com TXT
 "23028 | 216.90.108.0/24 | US | arin | 1998-09-25"

The same query could be expressed as:

 $ dig +short 108.90.216.origin.asn.cymru.com TXT
 "23028 | 216.90.108.0/24 | US | arin | 1998-09-25"

IPv6 queries are formed by reversing the nibbles of the address, and placing dots between each nibble, just like an IPv6 reverse DNS lookup, except against origin6.asn.cymru.com instead of ip6.arpa. Note that you must pad out all omitted zeroes in the IPv6 address, so this can get quite long! For example, to look up 2001:4860:b002::68, you would issue the following query:

 $ dig +short 8.6.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.b.0.6.8.4.1.0.0.2.origin6.asn.cymru.com. TXT
 "15169 | 2001:4860::/32 | US | arin | 2005-03-14"

You can considerably shorten your query if you assume that the long runs of zeroes are in the host portion of the address (as is often the case with IPv6 addresses:

 $ dig +short 2.0.0.b.0.6.8.4.1.0.0.2.origin6.asn.cymru.com. TXT
 "15169 | 2001:4860::/32 | US | arin | 2005-03-14"

To query for a given IP/prefix peer ASNs, one would use the peer.asn.cymru.com zone as follows:

 $ dig +short 31.108.90.216.peer.asn.cymru.com TXT
 "701 1239 3549 3561 7132 | 216.90.108.0/24 | US | arin | 1998-09-25"

When there are multiple Origin ASNs or Peer ASNs, they will all be included in the same TXT record such as in the example above. Notice that the format is very similar to the data returned in the verbose whois based query. The major difference is that the AS Description information has been omitted. In order to return the ASN Description and additional info, one use:

 $ dig +short AS23028.asn.cymru.com TXT
 "23028 | US | arin | 2002-01-04 | TEAMCYMRU - SAUNET"

If a given prefix does not exist in the table, the daemon will return a standard NXDOMAIN response (domain does not exist).

HTTP/HTTPS

The HTTP and HTTPS daemons act as a web based proxy to the whois based service. You can reach the service directly by browsing to: http://asn.cymru.com or https://asn.cymru.com Simply click on one of the above links and follow the onscreen instructions on how translate IPs to their corresponding BGP ASNs.

FREQUENTLY ASKED QUESTIONS (FAQ)

  1. Why are you showing two or more different ASNs/networks for the same address or route prefix?

    We monitor route announcements from multiple locations and from multiple providers. In some cases a network prefix will be announced by multiple, but disparate, networks or autonomous systems. The most likely reason for this is something known as “multihoming”. This is perfectly normal. Depending on your view of the Internet topology and the originating network’s policies, one of those originating networks will be the preferred path for sending and receiving traffic with the netblock in question. We choose to show you the list of all those we know about.

  2. Why, when I query for address ‘a.0.0.0’ does it show me one originating ASN/network, but when I query for ‘a.b.c.d’, an address whose first few bits match that of the first address, I’m given a completely different originating ASN/network?

    Most likely there are at least two route announcements we know about, one larger prefix that matches your first query and the latter is matched by a separate, more specific route announcement from someone else. This is perfectly normal. It may occur for a variety of reasons, most likely due to the routing policies by the originating networks to influence how traffic is delivered for specific prefixes.

  3. Why do I see an originating ASN and route announcement when I query for a bogon address?

    Some of the routes we learn from partners may contain “leaked” or otherwise bogon routes. The originating network is likely using those routes internally, and they are not meant to be publicly accessible. All routes we publish through our mapping service are presented unfiltered. Note, these routes may be filtered out by other networks so they may not show up in traceroutes, other route monitoring collectors or other online tools.

REFERENCES

Following is small sampling of the public projects and sites that have incorporated these tools:

翻译一下: 通过IP获得ASN信息的方法:
1. 访问http://asn.cymru.comhttps://asn.cymru.com 这个很简单了
2. 透过whois查询:
whois -h whois.cymru.com -v 114.85.241.81
返回消息
Warning: RIPE flags used with a traditional server.
AS | IP | BGP Prefix | CC | Registry | Allocated |
AS Name 4812 | 114.85.241.81 | 114.85.224.0/19 | CN | apnic | 2008-05-14 | CHINANET-SH-AP China Telecom (Group)
3. 透过DNS查询,这个是最强大的:
  • origin.asn.cymru.com:ip(v4)和BGP prefix,ASN的映射
  • origin6.asn.cymru.com:ip(v6)和BGP prefix,ASN的映射
  • peer.asn.cymru.com:查询一个给定ip地址的下一条的AS号
  • asn.cymru.com:查询asn号的信息
注意这里的ip要逆序写
dig +short 220.181.111.147.origin.asn.cymru.com TXT
“41572 | 147.111.0.0/16 | EU | ripencc | 1991-03-19”
查询ASN对应的信息
dig +short AS41572.asn.cymru.com TXT
“41572 | NO | ripencc | 2006-09-15 | HAFSLUND Hafslund Telekom Nettjenester AS”
查询ip的下一个AS
dig +short 220.181.111.147.peer.asn.cymru.com TXT
“3549 6453 | 147.111.0.0/16 | EU | ripencc | 1991-03-19”
这里也可以找到ASN的信息http://bgp.he.net ,提供可视化的AS到AS关系图

交叉编译python到android-mips失败

一系列折腾让我领教了系统库的缺失和不一致是一个多么糟糕的状况。尽管mips官方发布的NDK同时包含mips和arm交叉编译链,但我感觉mips的库支持状况比arm的差一些 。

1. 首先编译出本地的python和pgen:

./configure

make python Parser/pgen

mv python hostpython

mv Parser/pgen

make distclean

2. 给python2.7.2 打补丁

Index: Python/pythonrun.c
===================================================================
— Python/pythonrun.c (revisión: 29)
+++ Python/pythonrun.c (copia de trabajo)
@@ -158,6 +158,10 @@
return;
initialized = 1;

+ // Redirect stderr, stdout
+ freopen(“/sdcard/python.stdout.log”, “w”, stdout);
+ freopen(“/sdcard/python.stderr.log”, “w”, stderr);
+
if ((p = Py_GETENV(“PYTHONDEBUG”)) && *p != ”)
Py_DebugFlag = add_flag(Py_DebugFlag, p);
if ((p = Py_GETENV(“PYTHONVERBOSE”)) && *p != ”)
Index: Python/pystrtod.c
===================================================================
— Python/pystrtod.c (revisión: 29)
+++ Python/pystrtod.c (copia de trabajo)
@@ -126,7 +126,6 @@
{
char *fail_pos;
double val = -1.0;
– struct lconv *locale_data;
const char *decimal_point;
size_t decimal_point_len;
const char *p, *decimal_point_pos;
@@ -138,8 +137,7 @@

fail_pos = NULL;

– locale_data = localeconv();
– decimal_point = locale_data->decimal_point;
+ decimal_point = “.”;
decimal_point_len = strlen(decimal_point);

assert(decimal_point_len != 0);
@@ -375,8 +373,7 @@
Py_LOCAL_INLINE(void)
change_decimal_from_locale_to_dot(char* buffer)
{
– struct lconv *locale_data = localeconv();
– const char *decimal_point = locale_data->decimal_point;
+ const char *decimal_point = “.”;

if (decimal_point[0] != ‘.’ || decimal_point[1] != 0) {
size_t decimal_point_len = strlen(decimal_point);
Index: Python/dynload_win.c
===================================================================
— Python/dynload_win.c (revisión: 29)
+++ Python/dynload_win.c (copia de trabajo)
@@ -28,21 +28,7 @@
/* Case insensitive string compare, to avoid any dependencies on particular
C RTL implementations */

-static int strcasecmp (char *string1, char *string2)
-{
– int first, second;

– do {
– first = tolower(*string1);
– second = tolower(*string2);
– string1++;
– string2++;
– } while (first && first == second);

– return (first – second);
-}


/* Function to return the name of the “python” DLL that the supplied module
directly imports. Looks through the list of imported modules and
returns the first entry that starts with “python” (case sensitive) and
Index: Python/getplatform.c
===================================================================
— Python/getplatform.c (revisión: 29)
+++ Python/getplatform.c (copia de trabajo)
@@ -1,6 +1,31 @@

#include “Python.h”

+#ifdef ANDROID
+#include <sys/utsname.h>
+#include <string.h>
+
+char _PLATFORM[20]={0}; // taken as base linux-armv7l-2.6
+
+const char *
+Py_GetPlatform(void)
+{
+ if (_PLATFORM[0]!=0)
+ return _PLATFORM;
+
+ struct utsname u;
+ int i;
+ if ( uname(&u) < 0 )
+ return “unknown”;
+
+ strcat (_PLATFORM, u.sysname);
+ strcat (_PLATFORM, “-“);
+ strcat (_PLATFORM, u.machine);
+ for (i=0; _PLATFORM[i]; i++)
+ _PLATFORM[i]=tolower(_PLATFORM[i]);
+ return _PLATFORM;
+}
+#else
+
#ifndef PLATFORM
#define PLATFORM “unknown”
#endif
@@ -10,3 +35,4 @@
{
return PLATFORM;
}
+#endif
Index: configure
===================================================================
— configure (revisión: 29)
+++ configure (copia de trabajo)
@@ -13673,7 +13673,7 @@
$as_echo_n “(cached) ” >&6
else
if test “$cross_compiling” = yes; then :
– ac_cv_have_long_long_format=no
+ ac_cv_have_long_long_format=yes
else
cat confdefs.h – <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -13738,15 +13738,15 @@
fi

-{ $as_echo “$as_me:${as_lineno-$LINENO}: checking for %zd printf() format support” >&5
-$as_echo_n “checking for %zd printf() format support… ” >&6; }
-if ${ac_cv_have_size_t_format+:} false; then :
– $as_echo_n “(cached) ” >&6
-else
– if test “$cross_compiling” = yes; then :
– ac_cv_have_size_t_format=”cross — assuming yes”
+#{ $as_echo “$as_me:${as_lineno-$LINENO}: checking for %zd printf() format support” >&5
+#$as_echo_n “checking for %zd printf() format support… ” >&6; }
+#if ${ac_cv_have_size_t_format+:} false; then :
+# $as_echo_n “(cached) ” >&6
+#else
+# if test “$cross_compiling” = yes; then :
+# ac_cv_have_size_t_format=”cross — assuming yes”

-else
+#else
cat confdefs.h – <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

@@ -13793,17 +13793,9 @@
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
+#fi

-fi
-{ $as_echo “$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_size_t_format” >&5
-$as_echo “$ac_cv_have_size_t_format” >&6; }
-if test “$ac_cv_have_size_t_format” != no ; then

-$as_echo “#define PY_FORMAT_SIZE_T \”z\”” >>confdefs.h

-fi

ac_fn_c_check_type “$LINENO” “socklen_t” “ac_cv_type_socklen_t” ”
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
Index: configure.in
===================================================================
— configure.in (revisión: 29)
+++ configure.in (copia de trabajo)
@@ -4171,106 +4171,45 @@
AC_MSG_RESULT(no)
fi

-if test “$have_long_long” = yes
-then
– AC_MSG_CHECKING(for %lld and %llu printf() format support)
– AC_CACHE_VAL(ac_cv_have_long_long_format,
– AC_RUN_IFELSE([AC_LANG_SOURCE([[[
– #include <stdio.h>
– #include <stddef.h>
– #include <string.h>
+#AC_MSG_CHECKING(for %zd printf() format support)
+#AC_TRY_RUN([#include <stdio.h>
+##include <stddef.h>
+##include <string.h>
+#
+##ifdef HAVE_SYS_TYPES_H
+##include <sys/types.h>
+##endif
+#
+##ifdef HAVE_SSIZE_T
+#typedef ssize_t Py_ssize_t;
+##elif SIZEOF_VOID_P == SIZEOF_LONG
+#typedef long Py_ssize_t;
+##else
+#typedef int Py_ssize_t;
+##endif
+#
+#int main()
+#{
+# char buffer[256];
+#
+# if(sprintf(buffer, “%zd”, (size_t)123) < 0)
+# return 1;
+#
+# if (strcmp(buffer, “123”))
+# return 1;
+#
+# if (sprintf(buffer, “%zd”, (Py_ssize_t)-123) < 0)
+# return 1;
+#
+# if (strcmp(buffer, “-123”))
+# return 1;
+#
+# return 0;
+#}],
+#[AC_MSG_RESULT(yes)
+# AC_DEFINE(PY_FORMAT_SIZE_T, “z”, [Define to printf format modifier for Py_ssize_t])],
+# AC_MSG_RESULT(no))

– #ifdef HAVE_SYS_TYPES_H
– #include <sys/types.h>
– #endif

– int main()
– {
– char buffer[256];

– if (sprintf(buffer, “%lld”, (long long)123) < 0)
– return 1;
– if (strcmp(buffer, “123”))
– return 1;

– if (sprintf(buffer, “%lld”, (long long)-123) < 0)
– return 1;
– if (strcmp(buffer, “-123”))
– return 1;

– if (sprintf(buffer, “%llu”, (unsigned long long)123) < 0)
– return 1;
– if (strcmp(buffer, “123”))
– return 1;

– return 0;
– }
– ]]])],
– [ac_cv_have_long_long_format=yes],
– [ac_cv_have_long_long_format=no],
– [ac_cv_have_long_long_format=no])
– )
– AC_MSG_RESULT($ac_cv_have_long_long_format)
-fi

-if test “$ac_cv_have_long_long_format” = yes
-then
– AC_DEFINE(PY_FORMAT_LONG_LONG, “ll”,
– [Define to printf format modifier for long long type])
-fi

-if test $ac_sys_system = Darwin
-then
– LIBS=”$LIBS -framework CoreFoundation”
-fi


-AC_CACHE_CHECK([for %zd printf() format support], ac_cv_have_size_t_format, [dnl
-AC_RUN_IFELSE([AC_LANG_SOURCE([[
-#include <stdio.h>
-#include <stddef.h>
-#include <string.h>

-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif

-#ifdef HAVE_SSIZE_T
-typedef ssize_t Py_ssize_t;
-#elif SIZEOF_VOID_P == SIZEOF_LONG
-typedef long Py_ssize_t;
-#else
-typedef int Py_ssize_t;
-#endif

-int main()
-{
– char buffer[256];

– if(sprintf(buffer, “%zd”, (size_t)123) < 0)
– return 1;

– if (strcmp(buffer, “123”))
– return 1;

– if (sprintf(buffer, “%zd”, (Py_ssize_t)-123) < 0)
– return 1;

– if (strcmp(buffer, “-123″))
– return 1;

– return 0;
-}
-]])],
-[ac_cv_have_size_t_format=yes],
-[ac_cv_have_size_t_format=no],
-[ac_cv_have_size_t_format=”cross — assuming yes”
-])])
-if test “$ac_cv_have_size_t_format” != no ; then
– AC_DEFINE(PY_FORMAT_SIZE_T, “z”,
– [Define to printf format modifier for Py_ssize_t])
-fi

AC_CHECK_TYPE(socklen_t,,
AC_DEFINE(socklen_t,int,
[Define to `int’ if <sys/socket.h> does not define.]),[
Index: setup.py
===================================================================
— setup.py (revisión: 29)
+++ setup.py (copia de trabajo)
@@ -304,13 +304,15 @@
self.announce(‘WARNING: skipping import check for Cygwin-based “%s”‘
% ext.name)
return
+ if os.environ.get(‘CROSS_COMPILE_TARGET’) == ‘yes’:
+ return
ext_filename = os.path.join(
self.build_lib,
self.get_ext_filename(self.get_ext_fullname(ext.name)))
try:
imp.load_dynamic(ext.name, ext_filename)
except ImportError, why:
– self.failed.append(ext.name)
+ if os.environ.get(‘CROSS_COMPILE_TARGET’) != “yes”:
self.announce(‘*** WARNING: renaming “%s” since importing it’
‘ failed: %s’ % (ext.name, why), level=3)
assert not self.inplace
@@ -331,6 +333,10 @@
os.remove(filename)
except AttributeError:
self.announce(‘unable to remove files (ignored)’)
+ else:
+ self.announce(‘WARNING: “%s” failed importing, but we leave it ‘
+ ‘because we are cross-compiling’ %
+ ext.name)
except:
exc_type, why, tb = sys.exc_info()
self.announce(‘*** WARNING: importing extension “%s” ‘
@@ -754,7 +760,7 @@
min_openssl_ver = 0x00907000
have_any_openssl = ssl_incs is not None and ssl_libs is not None
have_usable_openssl = (have_any_openssl and
– openssl_ver >= min_openssl_ver)
+ openssl_ver >= min_openssl_ver and False)

if have_any_openssl:
if have_usable_openssl:
@@ -779,7 +785,7 @@
depends = [‘md5.h’]) )

min_sha2_openssl_ver = 0x00908000
– if COMPILED_WITH_PYDEBUG or openssl_ver < min_sha2_openssl_ver:
+ if COMPILED_WITH_PYDEBUG or (True or openssl_ver < min_sha2_openssl_ver):
# OpenSSL doesn’t do these until 0.9.8 so we’ll bring our own hash
exts.append( Extension(‘_sha256’, [‘sha256module.c’]) )
exts.append( Extension(‘_sha512’, [‘sha512module.c’]) )
@@ -1860,7 +1866,7 @@
ffi_configfile):
from distutils.dir_util import mkpath
mkpath(ffi_builddir)
– config_args = []
+ config_args = sysconfig.get_config_var(“CONFIG_ARGS”).split(” “)

# Pass empty CFLAGS because we’ll just append the resulting
# CFLAGS to Python’s; -g or -O2 is to be avoided.
Index: Objects/stringlib/localeutil.h
===================================================================
— Objects/stringlib/localeutil.h (revisión: 29)
+++ Objects/stringlib/localeutil.h (copia de trabajo)
@@ -202,10 +202,8 @@
Py_ssize_t n_digits,
Py_ssize_t min_width)
{
– struct lconv *locale_data = localeconv();
– const char *grouping = locale_data->grouping;
– const char *thousands_sep = locale_data->thousands_sep;

+ const char *grouping = 3;
+ const char *thousands_sep = “,”;
return _Py_InsertThousandsGrouping(buffer, n_buffer, digits, n_digits,
min_width, grouping, thousands_sep);
}
Index: Objects/stringlib/formatter.h
===================================================================
— Objects/stringlib/formatter.h (revisión: 29)
+++ Objects/stringlib/formatter.h (copia de trabajo)
@@ -639,13 +639,7 @@
get_locale_info(int type, LocaleInfo *locale_info)
{
switch (type) {
– case LT_CURRENT_LOCALE: {
– struct lconv *locale_data = localeconv();
– locale_info->decimal_point = locale_data->decimal_point;
– locale_info->thousands_sep = locale_data->thousands_sep;
– locale_info->grouping = locale_data->grouping;
– break;
– }
+ case LT_CURRENT_LOCALE:
case LT_DEFAULT_LOCALE:
locale_info->decimal_point = “.”;
locale_info->thousands_sep = “,”;
Index: Objects/longobject.c
===================================================================
— Objects/longobject.c (revisión: 29)
+++ Objects/longobject.c (copia de trabajo)
@@ -813,13 +813,18 @@
return (void *)x;
}

+#ifdef ANDROID
+ #define IS_LITTLE_ENDIAN (int)*(unsigned char*)&one
+#endif
+
#ifdef HAVE_LONG_LONG

/* Initial PY_LONG_LONG support by Chris Herborth (chrish@qnx.com), later
* rewritten to use the newer PyLong_{As,From}ByteArray API.
*/

-#define IS_LITTLE_ENDIAN (int)*(unsigned char*)&one
+#ifndef ANDROID
+ #define IS_LITTLE_ENDIAN (int)*(unsigned char*)&one
+#endif
#define PY_ABS_LLONG_MIN (0-(unsigned PY_LONG_LONG)PY_LLONG_MIN)

/* Create a new long int object from a C PY_LONG_LONG int. */
@@ -891,7 +896,7 @@
}
return (PyObject *)v;
}

+#ifndef ANDROID
/* Create a new long int object from a C Py_ssize_t. */

PyObject *
@@ -913,6 +918,7 @@
return _PyLong_FromByteArray((unsigned char *)&bytes,
SIZEOF_SIZE_T, IS_LITTLE_ENDIAN, 0);
}
+#endif

/* Get a C PY_LONG_LONG int from a long int object.
Return -1 and set an error if overflow occurs. */
@@ -1121,7 +1127,32 @@
}
return res;
}
+#ifdef ANDROID
+/* Create a new long int object from a C Py_ssize_t. */

+PyObject *
+PyLong_FromSsize_t(Py_ssize_t ival)
+{
+ Py_ssize_t bytes = ival;
+ int one = 1;
+ return _PyLong_FromByteArray(
+ (unsigned char *)&bytes,
+ SIZEOF_SIZE_T, IS_LITTLE_ENDIAN, 1);
+}
+
+/* Create a new long int object from a C size_t. */
+
+PyObject *
+PyLong_FromSize_t(size_t ival)
+{
+ size_t bytes = ival;
+ int one = 1;
+ return _PyLong_FromByteArray(
+ (unsigned char *)&bytes,
+ SIZEOF_SIZE_T, IS_LITTLE_ENDIAN, 0);
+}
+#endif
+
#undef IS_LITTLE_ENDIAN

#endif /* HAVE_LONG_LONG */
Index: Lib/ctypes/__init__.py
===================================================================
— Lib/ctypes/__init__.py (revisión: 29)
+++ Lib/ctypes/__init__.py (copia de trabajo)
@@ -6,6 +6,13 @@
import os as _os, sys as _sys

__version__ = “1.1.0”
+import _ctypes
+odlopen = getattr(_ctypes, ‘dlopen’)
+def __dlopen(name, flag=_ctypes.RTLD_GLOBAL|_ctypes.RTLD_LOCAL):
+ if name:
+ return odlopen(name, flag)
+ return 0L
+_sys.modules[“_ctypes”].dlopen=__dlopen

from _ctypes import Union, Structure, Array
from _ctypes import _Pointer
@@ -438,7 +445,7 @@
elif _sys.platform == “cygwin”:
pythonapi = PyDLL(“libpython%d.%d.dll” % _sys.version_info[:2])
else:
– pythonapi = PyDLL(None)
+ pythonapi = PyDLL(“libpython%d.%d.so” % _sys.version_info[:2])

if _os.name in (“nt”, “ce”):
Index: Makefile.pre.in
===================================================================
— Makefile.pre.in (revisión: 29)
+++ Makefile.pre.in (copia de trabajo)
@@ -182,6 +182,7 @@

PYTHON= python$(EXE)
BUILDPYTHON= python$(BUILDEXE)
+HOSTPYTHON= ./$(BUILDPYTHON)

# The task to run while instrument when building the profile-opt target
PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 –with-gc –with-syscheck
@@ -407,8 +408,8 @@
# Build the shared modules
sharedmods: $(BUILDPYTHON)
@case $$MAKEFLAGS in \
– *s*) $(RUNSHARED) CC=’$(CC)’ LDSHARED=’$(BLDSHARED)’ OPT=’$(OPT)’ ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
– *) $(RUNSHARED) CC=’$(CC)’ LDSHARED=’$(BLDSHARED)’ OPT=’$(OPT)’ ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
+ *s*) $(RUNSHARED) CC=’$(CC)’ LDSHARED=’$(BLDSHARED)’ OPT=’$(OPT)’ $(HOSTPYTHON) -E $(srcdir)/setup.py -q build;; \
+ *) $(RUNSHARED) CC=’$(CC)’ LDSHARED=’$(BLDSHARED)’ OPT=’$(OPT)’ $(HOSTPYTHON) -E $(srcdir)/setup.py build;; \
esac

# Build static library
@@ -540,9 +541,9 @@

# Use a stamp file to prevent make -j invoking pgen twice
$(GRAMMAR_H) $(GRAMMAR_C): Parser/pgen.stamp
-Parser/pgen.stamp: $(PGEN) $(GRAMMAR_INPUT)
+Parser/pgen.stamp: $(HOSTPGEN) $(GRAMMAR_INPUT)
-@$(INSTALL) -d Include
– $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
+ $(HOSTPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
-touch Parser/pgen.stamp

$(PGEN): $(PGENOBJS)
@@ -926,25 +927,25 @@
done
$(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
– ./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
+ $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x ‘bad_coding|badsyntax|site-packages|lib2to3/tests/data’ \
$(DESTDIR)$(LIBDEST)
PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
– ./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ $(HOSTPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x ‘bad_coding|badsyntax|site-packages|lib2to3/tests/data’ \
$(DESTDIR)$(LIBDEST)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
– ./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
+ $(HOSTPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
– ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ $(HOSTPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
– ./$(BUILDPYTHON) -Wi -t -c “import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()”
+ $(HOSTPYTHON) -Wi -t -c “import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()”

# Create the PLATDIR source directory, if one wasn’t distributed..
$(srcdir)/Lib/$(PLATDIR):
@@ -1049,7 +1050,7 @@
# Install the dynamically loadable modules
# This goes into $(exec_prefix)
sharedinstall: sharedmods
– $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
+ $(RUNSHARED) $(HOSTPYTHON) -E $(srcdir)/setup.py install \
–prefix=$(prefix) \
–install-scripts=$(BINDIR) \
–install-platlib=$(DESTSHARED) \
Index: Modules/_localemodule.c
===================================================================
— Modules/_localemodule.c (revisión: 29)
+++ Modules/_localemodule.c (copia de trabajo)
@@ -205,6 +205,7 @@
static PyObject*
PyLocale_localeconv(PyObject* self)
{
+#ifndef ANDROID
PyObject* result;
struct lconv *l;
PyObject *x;
@@ -265,6 +266,7 @@
failed:
Py_XDECREF(result);
Py_XDECREF(x);
+#endif
return NULL;
}

Index: Modules/termios.c
===================================================================
— Modules/termios.c (revisión: 29)
+++ Modules/termios.c (copia de trabajo)
@@ -227,6 +227,7 @@
return Py_None;
}

+#ifndef ANDROID
PyDoc_STRVAR(termios_tcdrain__doc__,
“tcdrain(fd) -> None\n\
\n\
@@ -246,6 +247,7 @@
Py_INCREF(Py_None);
return Py_None;
}
+#endif

PyDoc_STRVAR(termios_tcflush__doc__,
“tcflush(fd, queue) -> None\n\
@@ -301,8 +303,10 @@
METH_VARARGS, termios_tcsetattr__doc__},
{“tcsendbreak”, termios_tcsendbreak,
METH_VARARGS, termios_tcsendbreak__doc__},
+#ifndef ANDROID
{“tcdrain”, termios_tcdrain,
METH_VARARGS, termios_tcdrain__doc__},
+#endif
{“tcflush”, termios_tcflush,
METH_VARARGS, termios_tcflush__doc__},
{“tcflow”, termios_tcflow,
Index: Modules/pwdmodule.c
===================================================================
— Modules/pwdmodule.c (revisión: 29)
+++ Modules/pwdmodule.c (copia de trabajo)
@@ -68,14 +68,14 @@
#define SETS(i,val) sets(v, i, val)

SETS(setIndex++, p->pw_name);
-#ifdef __VMS
+#if defined(__VMS) || defined(ANDROID)
SETS(setIndex++, “”);
#else
SETS(setIndex++, p->pw_passwd);
#endif
SETI(setIndex++, p->pw_uid);
SETI(setIndex++, p->pw_gid);
-#ifdef __VMS
+#if defined(__VMS) || defined(ANDROID)
SETS(setIndex++, “”);
#else
SETS(setIndex++, p->pw_gecos);
Index: Modules/posixmodule.c
===================================================================
— Modules/posixmodule.c (revisión: 29)
+++ Modules/posixmodule.c (copia de trabajo)
@@ -155,6 +155,9 @@
#define HAVE_SYSTEM 1
#define HAVE_WAIT 1
#define HAVE_TTYNAME 1
+#ifdef ANDROID
+ #undef HAVE_TTYNAME
+#endif
#endif /* PYOS_OS2 && PYCC_GCC && __VMS */
#endif /* _MSC_VER */
#endif /* __BORLANDC__ */
@@ -3787,7 +3790,7 @@
slave_fd = open(slave_name, O_RDWR | O_NOCTTY); /* open slave */
if (slave_fd < 0)
return posix_error();
-#if !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC)
+#if !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC) && !defined(ANDROID)
ioctl(slave_fd, I_PUSH, “ptem”); /* push ptem */
ioctl(slave_fd, I_PUSH, “ldterm”); /* push ldterm */
#ifndef __hpux

3. 配置环境

android-ndk 环境配置如下:

export ANDROID_NDK=”/root/android-ndk-r7bm/android-mips-9″
export PATH=”$ANDROID_NDK/bin:$PATH”
export CFLAGS=”-mips32r2 -DANDROID -mandroid -fomit-frame-pointer”
export CXXFLAGS=”$CFLAGS”
export CC=”mips-linux-android-gcc $CFLAGS”
export CXX=”mips-linux-android-g++ $CXXFLAGS”
export AR=”mips-linux-android-ar”
export RANLIB=”mips-linux-android-ranlib”
export STRIP=”mips-linux-android-strip –strip-unneeded”
export LD=”mips-linux-android-ld”

4. 编译配置参数如下

./configure LDFLAGS=”-Wl,–allow-shlib-undefined” CFLAGS=”-mips32r2 -DANDROID -mandroid -fomit-frame-pointer” HOSTPYTHON=/root/Python-2.7.2/hostpython HOSTPGEN=/root/Python-2.7.2/Parser/hostpgen –host=mips-linux –build=i686-pc-linux-gnu –enable-shared –prefix=/root/Python-2.7.2/_build

5. 编译参数设置如下

export MAKE=”make -j4 HOSTPYTHON=/root/Python-2.7.2/hostpython HOSTPGEN=/root/Python-2.7.2/Parser/hostpgen CROSS_COMPILE=mips-linux-android- CROSS_COMPILE_TARGET=yes”

链接过程中可见大量错误,多为某某函数未找到等等。可见android-mips 库函数的缺陷 。由于链接器加了–allow-shlib-undefined参数,所以最后编译链接都完成了。cp到目标机后可以打python –help ,但无法开启shell 也无法执行脚本。暂时先告一段落吧~~~  (无奈)

参考资料:

http://www.cnx-software.com/2011/02/04/cross-compiling-python-for-mips-and-arm-platforms/  一篇移植python的文章,不过针对的是gnu库,而不是android的。

http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html 又一篇移植python的文章

http://mdqinc.com/blog/2011/09/cross-compiling-python-for-android/ 参照的原文

http://code.google.com/p/android-scripting/ SL4A 为android提供脚本支持的平台软件,包括python,perl,ruby等,当然不支持android-mips

http://pygame.renpy.org/ android上的python游戏平台软件。比较有价值的是提供了交叉编译python的脚本,但估计也只能在arm上编译通过。源码在这里https://launchpad.net/pgs4a (需要bzr 版本管理工具)

https://code.google.com/p/gaeproxy/downloads/list 使用python编写的gae代理,最大的特色是支持android ,当然也是for arm only

交叉编译后miredo跑不起来

需修改/注释掉这句:

#if ${ac_cv_file__proc_self_maps} false; then;
# echo $ECHO_N “(cached) $ECHO_C” >&6
#else
# test “$cross_compiling” = yes &&
# { { echo “$as_me:$LINENO: error: cannot check for file existence when cross compiling” >&5
#echo “$as_me: error: cannot check for file existence when cross compiling” >&2;}
# { (exit 1); exit 1; }; }

配置参数:

./configure –disable-shared –enable-static –host=mipsel-linux –build=i686-linux –without-Judy –prefix=/opt –disable-rpath –disable-chroot –enable-miredo-user=root

编译成功

 

但跑起来后 teredo进程进入Z 状态,看了如下配置档(来自https://netst.org/pub/linux/distrib/openwrt/source/packages/net/miredo/Makefile)发现,缺少依赖的内核模块 tun :

#
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id: Makefile 9695 2007-12-09 18:59:01Z nbd $

include $(TOPDIR)/rules.mk

PKG_NAME:=miredo
PKG_VERSION:=1.0.0
PKG_RELEASE:=1

PKG_SOURCE_URL:=http://www.remlab.net/files/miredo/
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_MD5SUM:=b5a51cb98732decc2ada96b2caee5d3c

include $(INCLUDE_DIR)/package.mk

define Package/miredo/Default
  SECTION:=net
  CATEGORY:=Network
  DEPENDS:=+libpthread +uclibcxx +kmod-ipv6 +kmod-tun
  SUBMENU:=miredo: Teredo (IPv6 tunneling over UDP through NAT)
  URL:=http://www.simphalempin.com/dev/miredo/
endef

define Package/miredo-server
$(call Package/miredo/Default)
  TITLE:=Teredo (IPv6 tunneling over UDP through NAT) server daemon
endef

define Package/miredo-server/conffiles
/etc/miredo-server.conf
endef

define Package/miredo-client
$(call Package/miredo/Default)
  TITLE:=Teredo (IPv6 tunneling over UDP through NAT) client and relay daemon
endef

define Package/miredo-client/conffiles
/etc/miredo.conf
endef

CONFIGURE_ARGS += \
	--disable-shared \
	--enable-static \
	--with-gnu-ld \
	--disable-rpath \
	--disable-chroot \
	--enable-teredo-client \
	--enable-teredo-relay \
	--enable-teredo-server \
	--enable-miredo-user=root \

CONFIGURE_VARS += \
	CPPFLAGS="$$$$CPPFLAGS -I$(STAGING_DIR)/usr/include/uClibc++" \
	CXXFLAGS="$$$$CXXFLAGS -fno-builtin -fno-rtti -nostdinc++"  \
	LIBS="-nodefaultlibs -luClibc++ -lm" \
	ac_cv_file__proc_self_maps=yes\

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		CXXLINK="\$$$$(LINK)" \
		DESTDIR="$(PKG_INSTALL_DIR)" \
		all install
endef

define Package/miredo-server/install
	$(INSTALL_DIR) $(1)/etc/
	$(CP) $(PKG_INSTALL_DIR)/etc/miredo-server.conf-dist $(1)/etc/miredo-server.conf
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/miredo-server.init $(1)/etc/init.d/miredo-server
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/miredo-server $(1)/usr/sbin/
endef

define Package/miredo-client/install	
	$(INSTALL_DIR) $(1)/etc
	$(CP) $(PKG_INSTALL_DIR)/etc/miredo.conf-dist $(1)/etc/miredo.conf
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_BIN) ./files/miredo.init $(1)/etc/init.d/miredo
	$(INSTALL_DIR) $(1)/usr/sbin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/miredo $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,miredo-server))
$(eval $(call BuildPackage,miredo-client))

mips for android 交叉编译工具链

在这里下载:http://developer.mips.com/android/download-android-ndk/

解包后进入./build/tools 目录 可以定制一个特定android 平台的工具链:

./make-standalone-toolchain.sh –platform=android-9 –install-dir=/root/android-ndk-r7bm/android-mips-9 –ndk-dir=/root/android-ndk-r7bm –arch=mips

Auto-config: –toolchain=mips-linux-android-4.4.3
Copying prebuilt binaries…
Copying sysroot headers and libraries…
Copying libstdc++ headers and libraries…
Copying files to: /root/android-ndk-r7bm/android-mips-9
Cleaning up…
Done.

这样就把android 3.2的mips  gcc ,库文件,头文件安装到了指定目录,方便环境搭建。

搜索路径如下:

 # /root/android-ndk-r7bm/android-mips-9/bin/mips-linux-android-gcc -print-search-dirs

install: /root/android-ndk-r7bm/android-mips-9/bin/../lib/gcc/mips-linux-android/4.4.3/

programs: =
/root/android-ndk-r7bm/android-mips-9/bin/../libexec/gcc/mips-linux-android/4.4.3/:
/root/android-ndk-r7bm/android-mips-9/bin/../libexec/gcc/:
/root/android-ndk-r7bm/android-mips-9/bin/../lib/gcc/mips-linux-android/4.4.3/../../../../mips-linux-android/bin/mips-linux-android/4.4.3/:
/root/android-ndk-r7bm/android-mips-9/bin/../lib/gcc/mips-linux-android/4.4.3/../../../../mips-linux-android/bin/

libraries: =
/root/android-ndk-r7bm/android-mips-9/bin/../lib/gcc/mips-linux-android/4.4.3/:
/root/android-ndk-r7bm/android-mips-9/bin/../lib/gcc/:
/root/android-ndk-r7bm/android-mips-9/bin/../lib/gcc/mips-linux-android/4.4.3/../../../../mips-linux-android/lib/mips-linux-android/4.4.3/:
/root/android-ndk-r7bm/android-mips-9/bin/../lib/gcc/mips-linux-android/4.4.3/../../../../mips-linux-android/lib/:
/root/android-ndk-r7bm/android-mips-9/bin/../sysroot/lib/mips-linux-android/4.4.3/:
/root/android-ndk-r7bm/android-mips-9/bin/../sysroot/lib/:
/root/android-ndk-r7bm/android-mips-9/bin/../sysroot/usr/lib/mips-linux-android/4.4.3/:
/root/android-ndk-r7bm/android-mips-9/bin/../sysroot/usr/lib/

默认的gnu 库在这里:

# /root/android-ndk-r7bm/android-mips-9/bin/mips-linux-android-gcc -print-libgcc-file-name
/root/android-ndk-r7bm/android-mips-9/bin/../lib/gcc/mips-linux-android/4.4.3/libgcc.a

指定编译出来的mips指令集版本:

-mips32

-mips32r2

-march=mips32|mips32r2 / -mtune=mips32|mips32r2

 

export ANDROID_NDK=”/root/android-ndk-r7bm/android-mips-9″
export PATH=”$ANDROID_NDK/bin:$PATH”
export CFLAGS=”-mips32r2 -DANDROID -mandroid -fomit-frame-pointer”
export CXXFLAGS=”$CFLAGS”
export CC=”mips-linux-android-gcc $CFLAGS”
export CXX=”mips-linux-android-g++ $CXXFLAGS”
export AR=”mips-linux-android-ar”
export RANLIB=”mips-linux-android-ranlib”
export STRIP=”mips-linux-android-strip –strip-unneeded”
export LD=”mips-linux-android-ld”