2013년 10월 12일 토요일

Example of autoconfig and automake in Ubuntu


今度はautomakeとautoconfの使い方を調べてみた。手順は長いけど自分で用意するのは「ソースコード」「Makefile.am」の二つで、
이번에는 automake와 autoconf의 사용법을 조사해 봤다. 순서는 길지만, 준비할 것은 "소스코드", Makefile.am" 으로, "configure.in"
「condigure.in」(autorecnfの時は「condigure.ac」)はテンプレを修正して作成すればおけらしい。
この3つさえ用意すればあとは環境にあわせてライブラリやヘッダファイルの存在などをチェケしつつコンパイルするというなんかカッコいいのが作れる!

cmakeはクロスプラットフォーム向け、autoconfはGNU系列なのでLinux向けってことか?どっちも設定ファイルは実質1つ(Makefile.amは2行だし)なので労力はそんなにかわらないと思われ。個人的にはcmakeの方が好みだな、ドキュメント少ないけど、、、

事前準備

ソースコード「strchr.c」

//config.hが存在するなら読み込む
#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#if HAVE_STDIO_H
#  include 
#else
int printf (const char *format, ...);
#endif

#if HAVE_STRING_H
#  include 
#else
#  ifndef HAVE_STRRCHR
#    define strrchr rindex
#  endif
char *strrchr ();
#endif

int main (int   argc, char *argv[]){
  char *p, *program_name;

  p = strrchr (argv[0], '/');
  if (p == NULL) program_name = argv[0];
  else program_name = p+1;

  printf ("program_name: %s \n", program_name);

  return 0;
}

configure.inの生成

autoscanコマンドで「configure.scan」を作成
>>autoscan
「configure.scan」を修正し、「configure.in」を作成。赤字が修正部分。
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
#初期化
AC_INIT(StrChr, 0.1, yosilove@mail)
#automakeの初期化
AM_INIT_AUTOMAKE(strchr, 1.0.0, no-define)
AC_CONFIG_SRCDIR([strchr.c])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL

# Checks for libraries.

# Checks for header files.
AC_HEADER_STDC
#ヘッダファイルの存在確認
AC_CHECK_HEADERS([stdio.h],[AC_DEFINE(HAVE_STDIO_H)],[AC_MSG_ERROR([Sorry, can't do anything for you])])
AC_CHECK_HEADERS([string.h],[AC_DEFINE(HAVE_STRING_H)],[AC_MSG_ERROR([Sorry, can't do anything for you])])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

# Checks for library functions.
AC_CHECK_FUNCS([strrchr])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

Makefile.amを作成

automakeの設定ファイルである「Makefile.am」を用意
#実行ファイル名
bin_PROGRAMS = strchr
#ソースコード
strchr_SOURCES = strchr.c
以下、「1.自分でやるよ」と「2.autoreconfに任せるよ」に分岐 

1-1) aclocal

automake用のマクロファイル(.m4)を生成するために「aclocal」コマンドを実行
>>aclocal
「autom4te.cache」と「aclocal.m4」ができる。 



1-2) config.h.inの生成

>>autoheader
「config.h.in」が生成される 



1-3) Makefile.inの生成

automakeコマンドに「-a」オプションを付けてMakefile.inの生成
>>touch NEWS README AUTHORS ChangeLog
>>automake -a
「NEWS」「README」「AUTHORS」「ChangeLog」がないといけないのでtouchコマンドで生成。automakeすると「INSTALL」「COPYING」「depcomp」「missing」「install-sh」と「Makefile.in」が生成される。 



1-4) configureの生成

>>autoconf
「configure」が生成される。 



2) autoreconfでconfigureを作る

1)シリーズのコマンドってテンプレだし、いちいち入力するのめんどいよね〜

というわけで、普通はまとめて実行出来るように「bootstrap」や「autogen.sh」なスクリプトを書いておくんだけど、、、

それらをまとめてやってくれるコマンド「autoreconf」を使うという方法もある。ちなみに、「configure.in」でもできたりするが、autoreconfを使うときはファイル名は「configure.ac」の方が正式。
>>touch NEWS README AUTHORS ChangeLog
>>autoreconf -i
「bootstrap」や「autogen.sh」と比べるとちょっと劣るらしいけど、大体のプログラムはこれで通るらしい。 



Makefileの生成

>>./configure
「config.status」「config.log」「config.h」「stamp-h1」と「Makefile」ができる。 



実行ファイルの生成

>>make
「strchr.o」と「strchr」ができる、strchrを実行すると
>>./strchr 
program_name: strchr 

apt-get server resetting (서버 변경하기)

apt-get install, update, upgrade로 상당한 고생을 많이 했다. 우연히 알게된 apt-get서버 변경방법~, 정말 유용합니다. 많은 도움이 되었으면 좋겠습니다.

---------------------------------- 
apt-get 이용하다가 가끔 서버가 사망한다고 할지 응답이 없을경우가 있다. 이럴 때 업데이트 서버를 변경하여 사용하면 되겠다. 말필요 없고 그림 따라서~ 

1. 시스템 - 관리 - 소프트웨어 소스 영문판도 그대로 :: System - Administration - Software Source

 2. 원하는 서버가 없다면 기타를 눌러주자.


 3. 원하는 서버를 선택 가까운 서버 찾기 하니까 본인은 일본쪽 선택되더라....

Networking restart in Ubuntu

Ubuntu Linux user use sudo command with above Debian Linux command:
# sudo /etc/init.d/networking restart

To start Linux network service:
# sudo /etc/init.d/networking start

To stop Linux network service:
# sudo /etc/init.d/networking stop

sudo passwd root in Ubuntu (루트계정 만들기)

다음은 우분투에 root 계정과 암호를 만들어 주는 방법입니다.

프롬프트에서
>> sudo passwd root



그러면 현재 암호를 먼저 묻습니다. 현재 로그인한 ID의 암호를 한번 입력해 주면 이제

>> Enter new UNIX password:

라고 나오며 root 의 암호를 2번 묻습니다. 새 암호를 만들어 적어 주면 됩니다.

그러면 이제 root 로 로그인할 수 있습니다. root 계정이 생기는 것입니다.

Ctrl+D키를 눌러, 로그아웃한 후 root 로 로그인해 봅니다.


그런데 root 의 패스워드가 짧고 간단하다면 해커들의 표적이 됩니다. 되도록 길고 복잡해야 합니다.

Howto update kernels in Ubuntu

--
우분투에서 와이어레스드라이버가 잡히지 않을 때,
이 문제를 해결하는 가장 간단한 방법 중 하나가 우분투 커널을 업데이트 하는 것이다.
When there is no wireless driver in Ubuntu OS You update kernels.
One of the simplest ways to solve the problem with that is to update Ubuntu kernels.

$ sudo apt-add-repository ppa:francisbrwn9/kernels

$ sudo apt-get update

$ sudo apt-get dist-upgrade


그리고, 재부팅, 아래와 같은 방법으로 업데이된 커널의 버전을 확인한다.
And then, reboot, and confirm the version of the kernels updated.

$ uname -r

--

Howto install Emacs in Ubuntu.

>>
>>sudo apt-get install emacs-snapshot-gtk
>>

Howto Install OpenCV-2.3 in Ubuntu (OpenCV-2.3 설치하기)

OpenCV-2.3버전 설치하는 방법에 대해서 설명한다. OpenCV-2.4버전에서도 이 방법은 유효하다.
Installing OpenCV 2.3 in Ubuntu.I had a lot of problems initially to install and port the OpenCV library to Python. But after reading a lot of blogs I finally found a solution which I have posted below.

1)사전에 필요한 라이브러리 설치한다.
1)Install all pre requisites

>>sudo apt-get install build-essential
>>sudo apt-get install cmake
>>sudo apt-get install pkg-config
>>sudo apt-get install libpng12-0 libpng12-dev libpng-dev libpng3
>>sudo apt-get install libpnglite-dev libpngwriter0-dev libpngwriter0c2
>>sudo apt-get install zlib1g-dbg zlib1g zlib1g-dev
>>sudo apt-get install libjasper-dev libjasper-runtime libjasper1
>>sudo apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools
>>sudo apt-get install libjpeg62 libjpeg62-dev libjpeg-progs libjpeg62-dbg
>>sudo apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev
>>sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev
>>sudo apt-get install libxine1-ffmpeg  libxine-dev libxine1-bin
>>sudo apt-get install libunicap2 libunicap2-dev
>>sudo apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils
>>sudo apt-get install swig
>>sudo apt-get install libv4l-0 libv4l-dev
>>sudo apt-get install python-numpy
>>sudo apt-get install build-essential libgtk2.0-dev libjpeg62-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
2) 파이센 헤더를 설치한다
2)Install the python development headers

>>sudo apt-get install python-dev

3) OpenCV소스코드를 다운로드 한다.
3)Download the source code:
http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3/
4)압축을 푼다.
4)Go to the directory where OpenCV is downloaded via the terminal only and then un zip the package:
(note:- It is recommended that you move the downloaded OpenCV package to the home/ directory

>>tar -xvf OpenCV-2.3.1a.tar.bz2
>>cd OpenCV-2.3.1/

5) 압출을 풀어서 만들어 진 OpenCV 폴더 안에 build 디렉토리를 만든다
5)Now make a new directory called build and go in to it
>>mkdir build
>>cd build
6)Cmake한다.
6)Run Cmake

>>cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..

7) Make한다.
7)Now make

>>make
8) make install 한다.
8) Make it permanent

>>sudo make install
9)공유라이브러리 사용을 위한 OpenCV설정
9)Configuring OpenCV for using shared libraries:

>>sudo gedit /etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file (it may be an empty file, that is ok) and then save it:

/usr/local/lib

Close the file and run the following command to configure the library:

>>sudo ldconfig

OR RUN : export LD_LIBRARY_PATH=/usr/local/lib

10).bashrc file을 열고 아래를 덧붙인다.
10)Open your .bashrc file and add the following:
>>gedit .bashrc

or sudo gedit /etc/bash.bashrc


add the following at the end of the file -


PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

Save and close the file
11)재부팅한다.
11)Reboot the system

http://ubuntuone.com/0qwnXh8VoufDMHGiu5kLIK (Link to download this text file)

How to install audio driver for realtek

Make sure that your system is updated (including the kernel and libncurses5-dev) and ready to compile the drivers: update and then use the following command to make sure that all the libraries and packages are installed for compiling the sound driver:

To update the package cache and checks for broken dependencies
>>sudo apt-get check


To resynchronize the package index files from their sources
>>sudo apt-get update

To install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list, Packages currently installed with new versions available are retrieved and upgraded;
>>sudo apt-get upgrade

To prepare systems to compile driver; we need to insall the following package:
>>sudo apt-get install build-essential checkinstall automake linux-headers-generic libncurses5 libncurses5-dev xmlto gettext

to install :
>> sudo aptitude install build-essential libncurses-dev gettext xmlto xmltoman linux-headers-`uname -r`



Download the realtek audio driver from the following url:

http://www.realtek.com.tw/downloads/downloadsView.aspx?Langid=1&PNid=24&PFid=24&Level=4&Conn=3&DownTypeID=3&GetDown=false#High%20Definition%20Audio%20Codecs

Alternate Location:

http://122.146.118.42/downloads/downloadsView.aspx?Langid=1&PNid=24&PFid=24&Level=4&Conn=3&DownTypeID=3&GetDown=false

Look for HDA Drivers and accept the License and then Go to the Linux/Unix section and then clink on one of the download site links for Linux driver (2.4 or 2.6), download and save this file on your hard disk in a folder:

Open a terminal; change to folder where you saved the driver.
to unpack use the command:

>>tar -jxvf "downloaded-driver-file-name"

It shall extract and create a folder with the name "realtek-linux-audiopack-X.XX"

change to the folder and to compile and install the driver run
>>sudo ./install

It would show lots on info on the screen while driver is complied and installed;
After the driver is installed a configuration screen pops up

Configure the system according to your preference:

It would play a sound; if you hear the sound; it working; Enjoy.

You may have to configure front speaker and headphone volumes.

If jack sense does not work i.e. headphone plug does not mutes the speakers;
added the following options line to the file /etc/modprobe.d/alsa-base:

>>gksu gedit /etc/modprobe.d/alsa-base

at the end of above file add the following line:

options snd-hda-intel model=acer

Report back if it works or not.

ssh setting in ubuntu

A way to set up ssh in ubuntu will be presented.
the detail of ssh manual contains URL below for Korean version.

http://wiki.kldp.org/wiki.php/DocbookSgml/SSH-KLDP

1. install by apt-get

$ sudo apt-get install ssh

2. change port

$ sudo gedit /etc/ssh/sshd_config

# port 22 : remove # then, enable port22 to be active

3. restart demon

$ sudo /etc/init.d/ssh restart

4. confirm whether server works or not

$ netstat -ntl
tcp6        0        0        :::22(port number)       :::*        LISTEN    →   works well

Howto use apt in Ubuntu

apt는 최신 패키지를 다운로드 하여 설치하게 되는데 upgrade 하기전에 update 해서 source.list 를 갱신 하는것이 좋다.
1. 패키지 캐쉬 갱신 및 자동 업그레이드
# apt-get update
# apt-get upgrade

2. 개별 패키지 설치
# apt-get install <패키지명>

3. 원하는 패키지 찾기
# apt-cache  search <패키지명>

4. 원하는 패키지 찾은 다음 정보 출력
# apt-cache show <패키지명>

5. 의존성 검사 수행하면서 업그레이드
# apt-get -s dist-upgrade

6. 설치한 패키지에 이상이 있어 다시 설치시
# apt-get --reinstall install <패키지명>

7. CD-ROM 목록 추가
# apt-cdrom add

8. 패키지 삭제
# apt-get remove <패키지명>
또는 # dpkg -P <패키지명>

9. 삭제하는 패키지의 설정화일들가지 모두 삭제시
# apt-get --purge remove <패키지명>

10. dselect에서 선택한 패키지의 설치 및 삭제
# apt-get dselect-upgrade

11. 설치된 패키지를 볼때
# dpkg -l
참고)   apt-get install 명령어로 받은 deb 파일의 저장 위치
          /var/cache/apt/archive/
        위 폴더에 .deb 패키지파일로 저장됨

12. 설치에 실패한 패키지를 삭제할 때
# apt-get -f install
# dpkg -r (패키지 이름)