2008年4月16日水曜日

build gcc for ARM

(1) gccのコンパイルの前に,codesourceryからダウンロードしたARM GNU/Linux の バイナリを展開し,ターゲット用のヘッダとライブラリ一式をホスト環境へコピーしておく。
$ bunzip2 -c arm-2008q1-126-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 | tar xvf -
$ cd arm-2008q1
$ sudo cp -r arm-none-linux-gnueabi/libc /opt/codesourcery/arm-none-linux-gnueabi/libc

(2) gccのソースファイルを展開する。
$ bunzip2 -c gcc-2008q1-126.tar.bz2 | tar xf -

(3) binutilsの場合と同様に,pdf をインストールしないようあらかじめMakefile.inを修正しておく。
*** gcc-4.2/Makefile.in 2008-04-17 01:22:09.000000000 +0900
--- gcc-4.2/Makefile.in.orig 2008-04-17 01:21:51.000000000 +0900
***************
*** 2352,2358 ****
@r=`${PWD_COMMAND}`; export r; \
s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
$(MAKE) $(RECURSE_FLAGS_TO_PASS) installdirs \
! install-host install-target install-html

.PHONY: install-host-nogcc
install-host-nogcc: \
--- 2352,2358 ----
@r=`${PWD_COMMAND}`; export r; \
s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
$(MAKE) $(RECURSE_FLAGS_TO_PASS) installdirs \
! install-host install-target install-html install-pdf

.PHONY: install-host-nogcc
install-host-nogcc: \

*** gcc-4.2/gcc/Makefile.in 2008-04-17 01:22:48.000000000 +0900
--- gcc-4.2/gcc/Makefile.in.orig 2008-04-17 01:22:25.000000000 +0900
***************
*** 3779,3785 ****
# Install the driver last so that the window when things are
# broken is small.
install: install-common $(INSTALL_HEADERS) $(INSTALL_LIBGCC) \
! install-cpp install-man install-info install-html \
install-@POSUB@ install-driver

# Handle cpp installation.
--- 3779,3785 ----
# Install the driver last so that the window when things are
# broken is small.
install: install-common $(INSTALL_HEADERS) $(INSTALL_LIBGCC) \
! install-cpp install-man install-info install-html install-pdf \
install-@POSUB@ install-driver

# Handle cpp installation.

(4) arm-2008q1-126-arm-none-linux-gnueabi.sh のbuild手順を参考に arm 用の gcc をコンパイルする。
$ mkdir -p BUILD/gcc-final
$ pushd BUILD/gcc-final
$ export AR_FOR_TARGET=arm-none-linux-gnueabi-ar
$ export NM_FOR_TARGET=arm-none-linux-gnueabi-nm
$ export OBJDUMP_FOR_TARGET=arm-none-linux-gnueabi-objdump
$ export STRIP_FOR_TARGET=arm-none-linux-gnueabi-strip
$ export PATH=/opt/codesourcery/bin:${PATH}
$ ../../gcc-4.2/configure \
--build=i686-apple-darwin9 --host=i686-apple-darwin9 \
--target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp \
--disable-libgomp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --enable-languages=c,c++ \
--enable-shared --enable-symvers=gnu --enable-__cxa_atexit --disable-nls \
--prefix=/opt/codesourcery \
--with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc \
--with-build-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc \
--enable-poison-system-directories \
--with-build-time-tools=/opt/codesourcery/arm-none-linux-gnueabi/bin \
--with-build-time-tools=/opt/codesourcery/arm-none-linux-gnueabi/bin 2>&1 |tee configure.out
$ sudo make -j4 LDFLAGS_FOR_TARGET=--sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc \
CPPFLAGS_FOR_TARGET=--sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc \
build_tooldir=/opt/codesourcery/arm-none-linux-gnueabi 2>&1 | tee make.out
$ make prefix=/opt/codesourcery exec_prefix=/opt/codesourcery \
libdir=/opt/codesourcery/lib \
htmldir=/opt/codesourcery/share/doc/arm-arm-none-linux-gnueabi/html \
pdfdir=/opt/codesourcery/share/doc/arm-arm-none-linux-gnueabi/pdf \
infodir=/opt/codesourcery/share/doc/arm-arm-none-linux-gnueabi/info \
mandir=/opt/codesourcery/share/doc/arm-arm-none-linux-gnueabi/man \
install 2>&1 |tee make_install.out
$ popd

これで /opt/codesourcery 以下にARM Linux用のクロスコンパイラ一式が整った。

2008年4月8日火曜日

build binutils for ARM

(1) CodeSourceryからダウンロードしたarm-2008q1-126-arm-none-linux-gnueabi.src.tar.bz2を展開するとarm-2008q1-126-arm-none-linux-gnueabi以下にtoolchainの各ソースコードが展開されるので,まずbinutilsをコンパイルする。binutils-2008q1-126.tar.bz2を展開するとディレクトリbinutils-stable以下にソースが展開される。
$ bunzip2 -c arm-2008q1-126-arm-none-linux-gnueabi.src.tar.bz2 | tar xf -
$ cd arm-2008q1-126-arm-none-linux-gnueabi
$ bunzip2 -c binutils-2008q1-126.tar.bz2 | tar xf -

(2) TeXがないとインストール時にエラーが発生するので,あらかじめ pdf をインストールしないようMakefile.inを修正しておく。

*** binutils-stable/Makefile.in 2008-04-17 01:06:54.000000000 +0900
--- binutils-stable/Makefile.in.orig 2008-04-17 01:06:13.000000000 +0900
***************
*** 2471,2477 ****
@r=`${PWD_COMMAND}`; export r; \
s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
$(MAKE) $(RECURSE_FLAGS_TO_PASS) installdirs \
! install-host install-target install-html

.PHONY: install-host-nogcc
install-host-nogcc: \
--- 2471,2477 ----
@r=`${PWD_COMMAND}`; export r; \
s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
$(MAKE) $(RECURSE_FLAGS_TO_PASS) installdirs \
! install-host install-target install-html install-pdf

.PHONY: install-host-nogcc
install-host-nogcc: \

(3) arm-2008q1-126-arm-none-linux-gnueabi.sh のbuild手順を参考に arm 用の binutils をコンパイルする。
$ mkdir -p ./BUILD/binutils
$ pushd BUILD/binutils
$ ../../binutils-stable/configure \
--build=i686-apple-darwin9 --target=arm-none-linux-gnueabi \
--prefix=/opt/codesourcery --host=i686-apple-darwin9 \
--disable-nls --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc \
--enable-poison-system-directories 2>&1 | tee configure.out
$ make -j4 2>&1 | tee make.out
$ sudo make install \
prefix=/opt/codesourcery exec_prefix=/opt/codesourcery \
libdir=/opt/codesourcery/lib \
htmldir=/opt/codesourcery/share/doc/arm-arm-none-linux-gnueabi/html \
pdfdir=/opt/codesourcery/share/doc/arm-arm-none-linux-gnueabi/pdf \
infodir=/opt/codesourcery/share/doc/arm-arm-none-linux-gnueabi/info \
mandir=/opt/codesourcery/share/doc/arm-arm-none-linux-gnueabi/man \
datadir=/opt/codesourcery/share 2>&1 |tee make_install.out
$ popd

※ 手順を2008Q1リリース版に合わせる(2008年4月17日)

2008年4月7日月曜日

GNU Toolchain for ARM

androidはじめました」ということで,まずはARMのクロスコンパイラをOS X上に準備。CodeSourceryから提供されるGNU Toolchainをベースに環境を構築することにして
  • Target: ARM GNU/Linux,Host: IA32 GNU/Linuxのバイナリ
  • Target: ARM GNU/Linuxのソース
をダウンロード。

2008年4月4日金曜日

iTunesのプレイリストをSO905iへ

m4aファイルに3gpメタデータを埋め込むことができたので,iTunesのプレイリストからmicroSDカードへのAACファイルの書き込み,メタデータ埋め込みを自動化してみる。iTunesのプレイリストに登録された曲の取得にはScriptingBridgeを使う。
(1) iTunesのプレイリスト"SO905i"からScriptingBridgeを通してtrack一覧を取得,(2) 各ファイルの拡張子を.m4aから.3gpに変えながらmicroSDにコピー,(3)3gpメタデータを埋め込む,という手順でrubyスクリプトを作ってみた。

#!/usr/bin/env ruby

# configuration
LIB_NAME = 'ライブラリ'
PLAYLIST_NAME = 'SO905i'
DEST_DIR = '/Volume/Untitled/MUSIC'
ITUNES_BASE = '/Users/nishio/Music/iTunes/iTunes Music/'
CMD_M4A = '/Users/nishio/bin/AtomicParsley'
CMD_3GP = '/Users/nishio/bin/AtomicParsley_3gp'

# load libraries
require 'fileutils'
require 'pathname'
require 'osx/cocoa' # load cocoa library.
include OSX # setup for scripting bridge.
OSX.require_framework 'ScriptingBridge'

###
### convert m4a metadata to 3gp metadata
###
def m4a_to_3gp(file)
file = file.gsub(/"/) {|s| '\\' + s} # escape double quote
# parse .m4a atom
h = Hash.new
open("| #{CMD_M4A} \"#{file}\" -t") { |f|
while line = f.gets
line =~ /Atom "(.*)".* contains: (.*)/
h[$1] = $2.gsub(/"/) {|s| '\\' + s} # escape double quote
end
}

# put .3gp atom
h["trkn"] =~ /([0-9]*) of [0-9]*/
num = $1
args = "--3gp-title \"#{h["\302\251nam"]}\" lang=jpn --3gp-performer \"#{h["\302\251ART"]}\" lang=jpn --3gp-album \"#{h["\302\251alb"]}\" track=#{num} lang=jpn --3gp-genre \"#{h["\302\251gen"]}\" lang=jpn --3gp-year '#{h["\302\251day"]}' --overWrite"
system("#{CMD_3GP} \"#{file}\" #{args}")
end

######################################################################
# main routine begins here.

iTunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
iTunes.sources.each do |source|
next unless source.name == LIB_NAME
source.userPlaylists.each do |playlist|
next unless playlist.name == PLAYLIST_NAME
base = Pathname.new(ITUNES_BASE)
playlist.fileTracks.each do |track|
next unless track.enabled?

path = track.location.path
path_name = Pathname.new(path)
ext_name = File.extname(path)
dst_name = DEST_DIR + path_name.relative_path_from(base)
dst_dir = File.dirname(dst_name)

# create destination directories if not exists.
if !FileTest.exist?(dst_dir) then
puts "make directory: #{dst_dir}"
FileUtils.mkdir_p(dst_dir)
end

# copy a file
puts "copy file: #{dst_name}"
case ext_name
when '.m4a' then
dst_name = File.join(dst_dir, File.basename(dst_name, ext_name) + '.3gp')
FileUtils.cp(path, dst_name)
m4a_to_3gp(dst_name)
else
FileUtils.cp(path, dst_name)
end
end
end
end