2013年2月6日水曜日

[ImageMagick]フォーマッ ト変換

BMP から JPEG へ変換
> convert.exe image.bmp image.jpg
PNG から XPM への変換
> convert.exe image.png image.xpm
ディレクトリ内の画像フォーマットを一括変換
ディレクトリ内の BMP 画像をすべて JPEG に変換するには mogrify.exe を使う
> mogrify.exe -format jpg *.bmp

2013年2月2日土曜日

txt2tags

インストール

実行方法
python txt2tags
  • Windowsの場合は txt2tags ファイルを txt2tags.py と改名して、PATHの通ったディレクトリに置けば直接実行可能となる
  • Linuxの場合はtxt2tagsに実行権限を与え、/usr/bin にコピーすれば実行可能となる

Emacs の tag
  1. extras/txt2tags-mode.el を emacs/site-lisp にコピーする
  2. .emacs に以下を追記する
    (add-to-list 'load-path "~/projetos/txt2tags/2.x/")
    (setq auto-mode-alist (append (list
      '("\\.t2t$" . t2t-mode)
      )
      (if (boundp 'auto-mode-alist) auto-mode-alist)
    ))
    (autoload 't2t-mode "txt2tags-mode" "Txt2tags Mode" t)
    

書き方
  • 最初の 3 行は header として扱われるので注意
  • 推奨は
    • 1 行目: タイトル
    • 2 行目: 筆者
    • 3 行目: 日付、バージョン
    Title
    Author
    Data %%date(%Y/%m/%d)
    = Title level 1 =
    + Numberd titile level 1 +
    ++ Numberd title level 2 ++
    
    == Title level 2 ==
    
    === Title level 3 ===
    
    % comment
    
    **bold** and //italic//
    
    = Lists =
    == list ==
    - List 1
    - List 2
    - list 2.1
    
    
    == Numberd list ==
    + List 1
    + List 2
    
    
    == Definition list ==
    : Definition list
    This is definition list
    
    
    = Table =
    | cell1 | cell2 | cell3 |
    | cell4 | cell5 ||
    | cell6 | cell7 | cell8 |
    

[Makefile]Automake でサブディレクトリ内もコンパイルする

次のようなディレクトリ構成のソースをコンパイルする場合
hello
└─src
    │  hello.c
    │  hello.h
    │  main.c
    │  Makefile.am
    │
    └─extfunc
            extfunc.c
            extfunc.h
            Makefile.am
main.c から extfunc.c 内の関数をコールするようにしている。
#include "hello.h"
#include "extfunc/extfunc.h"

int main(void)
{
 say_hello();
 test();
 extfunc();

 return 0;
}
Example 1. extfunc.c
#include "extfunc.h"

int extfunc(void)
{
 printf("extfunc is called!!\n");

 return 0;
}
Example 2. extfunc.h
#ifndef __EXTFUNC_H__
#define __EXTFUNC_H__

extern int extfunc(void);

#endif /* __EXTFUNC_H__ */
automake では直接サブディレクトリのソースを取り込んでコンパイルすることができないようなので、extfunc ディレクトリ内のオブジェクトはライブラリにして最後にリンクさせるようにする。

Example 3. src/extfunc/Makefile.am
noinst_LIBRARIES = libextfunc.a
libextfunc_a_SOURCES = extfunc.c
Example 4. src/Makefile.am
bin_PROGRAMS = hello
hello_SOURCES = hello.c hello.h main.c
hello_LDADD = extfunc/libextfunc.a
SUBDIRS = extfunc
LDADD を使用するために configure.ac に AC_PROG_RANLIB を追加する必要がある。そのため automake を行うスクリプトも修正する。
#!/bin/bash -v
autoscan
sed -e "s/FULL-PACKAGE-NAME/hello/g" -e "s/VERSION/1.0/g" -e "s/BUG-REPORT-ADDRESS/hoge@hogehoge/g" -e "6 i AM_INIT_AUTOMAKE([foreign])" -e "$ i AC_PROG_RANLIB" configure.scan > configure.ac
autoheader
aclocal
automake --add-missing --copy
autoconf
./configure
sed -e "$ i AC_PROG_RANLIB" configure.scan > configure.ac
で configure.scan の最後の行に AC_PROG_RANLIB を追加している。

[Makefile]automake を使用して Makefile を作成するまでのスクリプト

autoscan, autoheader, aclocal などのコマンドを順番に実行するのは面倒なのでスクリプトにまとめてみた。
#!/bin/bash -v
autoscan
sed -e "s/FULL-PACKAGE-NAME/hello/g" -e "s/VERSION/1.0/g" -e "s/BUG-REPORT-ADDRESS/hoge@hogehoge/g" -e "6 i AM_INIT_AUTOMAKE([foreign])" configure.scan > configure.ac
autoheader
aclocal
automake --add-missing --copy
autoconf
./configure
#!/bin/bash -v
としておくことで実行コマンドを表示させることができる。
configure.scan の中身を書き換えて configure.ac を生成するところは sed コマンドで置換と挿入を行う。

[Makefile]automakeを使用してMakefileを作成する手順

以下のディレクトリ構成でautomakeを実施する手順を記述する。
hello
│
└─src
        hello.c
        hello.h
        main.c
  1. hello/Makefile.am を作成
  2. SUBDIRS = src
    
  3. hello/src/Makefile.am を作成
    bin_PROGRAMS = hello
    hello_SOURCES = hello.c hello.h main.c
    
    この時点でのディレクトリ構成は以下の通り(*は新規追加されたファイル)
    hello
    │  Makefile.am (*)
    │
    └─src
            hello.c
            hello.h
            main.c
            Makefile.am (*)
    
  4. hello直下でautoscanを実行しconfigure.scanを作成する
  5. configure.scanをconfigure.acに改名して以下の箇所を修正
    1. AC_INITの中身を修正
      AC_INIT([hello, 1.0], [hoge@hogehoge])
      
    2. AC_INITの次の行に以下を追加
      AM_INIT_AUTOMAKE([foreign])
      
    この時点でのディレクトリ構成は以下の通り(*は新規追加されたファイル)
    hello
    │  autoscan-2.63.log (*)
    │  configure.ac (*)
    │  Makefile.am
    │
    └─src
            hello.c
            hello.h
            main.c
            Makefile.am
    
  6. autoheader 実行
    この時点でのディレクトリ構成は以下の通り(*は新規追加されたファイル)
    hello
    │  autoscan-2.63.log
    │  config.h.in (*)
    │  configure.ac
    │  Makefile.am
    │
    ├─autom4te.cache (*)
    │      output.0 (*)
    │      requests (*)
    │      traces.0 (*)
    │
    └─src
            hello.c
            hello.h
            main.c
            Makefile.am
    
  7. aclocalを実行
    この時点でのディレクトリ構成は以下の通り(*は新規追加されたファイル)
    hello
    │  aclocal.m4 (*)
    │  autoscan-2.63.log
    │  config.h.in
    │  configure.ac
    │  Makefile.am
    │
    ├─autom4te.cache
    │      output.0
    │      output.1 (*)
    │      requests
    │      traces.0
    │      traces.1 (*)
    │
    └─src
            hello.c
            hello.h
            main.c
            Makefile.am
    
  8. automake ‑‑add-missing ‑‑copyを実行
    この時点でのディレクトリ構成は以下の通り(*は新規追加されたファイル)
    hello
    │  aclocal.m4
    │  autoscan-2.63.log
    │  config.h.in
    │  configure.ac
    │  depcomp (*)
    │  install-sh (*)
    │  Makefile.am
    │  Makefile.in (*)
    │  missing (*)
    │
    ├─autom4te.cache
    │      output.0
    │      output.1
    │      output.2 (*)
    │      requests
    │      traces.0
    │      traces.1
    │      traces.2 (*)
    │
    └─src
            hello.c
            hello.h
            main.c
            Makefile.am
            Makefile.in (*)
    
  9. autoconfを実行
    この時点でのディレクトリ構成は以下の通り(*は新規追加されたファイル)
    hello
    │  aclocal.m4
    │  autoscan-2.63.log
    │  config.h.in
    │  configure (*)
    │  configure.ac
    │  depcomp
    │  install-sh
    │  Makefile.am
    │  Makefile.in
    │  missing
    │
    ├─autom4te.cache
    │      output.0
    │      output.1
    │      output.2
    │      requests
    │      traces.0
    │      traces.1
    │      traces.2
    │
    └─src
            hello.c
            hello.h
            main.c
            Makefile.am
            Makefile.in
    
  10. configureを実行
    この時点でのディレクトリ構成は以下の通り(*は新規追加されたファイル)
    hello
    │  aclocal.m4
    │  autoscan-2.63.log
    │  config.h (*)
    │  config.h.in
    │  config.log (*)
    │  config.status (*)
    │  configure
    │  configure.ac
    │  depcomp
    │  install-sh
    │  Makefile (*)
    │  Makefile.am
    │  Makefile.in
    │  missing
    │  stamp-h1 (*)
    │
    ├─autom4te.cache
    │      output.0
    │      output.1
    │      output.2
    │      requests
    │      traces.0
    │      traces.1
    │      traces.2
    │
    └─src
        │  hello.c
        │  hello.h
        │  main.c
        │  Makefile (*)
        │  Makefile.am
        │  Makefile.in
        │
        └─.deps (*)
                hello.Po (*)
                main.Po (*)
    
  11. makeを実行
    この時点でのディレクトリ構成は以下の通り(*は新規追加されたファイル)
    hello
    │  aclocal.m4
    │  autoscan-2.63.log
    │  config.h
    │  config.h.in
    │  config.h.in~ (*)
    │  config.log
    │  config.status
    │  configure
    │  configure.ac
    │  depcomp
    │  install-sh
    │  Makefile
    │  Makefile.am
    │  Makefile.in
    │  missing
    │  stamp-h1
    │
    ├─autom4te.cache
    │      output.0
    │      output.1
    │      output.2
    │      requests
    │      traces.0
    │      traces.1
    │      traces.2
    │
    └─src
        │  hello.c
        │  hello.exe (*)
        │  hello.h
        │  hello.o (*)
        │  main.c
        │  main.o (*)
        │  Makefile
        │  Makefile.am
        │  Makefile.in
        │
        └─.deps
                hello.Po
                main.Po
    

[MinGW]GSL - GNU Scientific Library インストール

  1. GSL - GNU Scientific Library から gsl-1.14.tar.gz (2010/04/27 時点の最新) をダウンロードする
  2. ダウンロードしたファイルを解凍する
    > tar zxvf gsl-1.14.tar.gz
    
  3. configure
    > sh ./configure --prefix=/c/usr/MinGW
    
  4. make, make install
    > make
    > make install
    
    • c:/usr/MinGW/lib 以下に libgslcblas.la, libgslcblas.dll.a libgslcblas.a, libgsl.la, libgsl.dll.a, libgsl.a がインストールされる
    • c:/usr/MinGW/include 以下に gsl ディレクトリがインストールされる
    • c:/usr/MinGW/bin 以下に gsl-config, gsl-histogram.exe gsl-randist.exe, libgsl-0.dll, libgslcblas-0.dll などがインストールされる
  5. 動作確認
    コンパイルできるか gsl-1.14/doc/example にあるソースで試す
    > gcc -o blas.exe blas.c -lgsl
    > gcc -o vector.exe vector.c -lgsl
    > gcc -o vectorview.exe vectorview.c -lgsl
    > gcc -o eigen.exe eigen.c -lgsl
    > gcc -o matrix.exe matrix.c -lgsl
    

[MinGW]M4, Autoconf, Automake の準備

  • MSYS Supplementary Tools にある msysDTK-1.0.1.exe をダウンロード、インストールする
  • 実行時は shell script を使うので以下のようにする
    > sh automake --add-missing --copy