Showing posts with label Linux Basic. Show all posts

Whiptail - Công cụ tạo giao diện đồ họa trên terminal (bash shell)

Công cụ này được dùng để tạo ra một giao diện đồ họa đơn giản để install hoặc settting một phần mềm nào đó trên môi trường bash shell của terminal.

Một ví dụ, chẳng hạn khi muốn config cấu hình của raspberry pi:
Gõ lệnh "sudo raspi-config" 

sẽ ra giao diện như dưới đây :


Note: Chi tiết cách sử dụng có thể tham khảo wiki





Tuesday, December 31, 2019

System start - init - /etc/init.d

1. Init


Init là chương trình khởi động được chạy tiếp theo sau khi chạy xong kernel
các script được Init gọi dùng để chạy các service.
Các step:
+ Init đọc và phân tích file /etc/inittab để khởi chạy các service, tuy nhiên các version sau này inittab không còn được sử dụng
+ Lần lượt chạy các script
    - /etc/init.d/rcS         => chạy start script trong /etc/rcS.d
    - /etc/init.d/rc           => chạy lần lượt các script tring /etc/rc*.d
    - /etc/init.d/rc.local  => user add thêm các script của riêng mình
+ getty => login user & password

2. Các folder
+ /etc/init.d   :  thư mục chứa các script để start/stop service
+ /etc/rc*.d   : gồm các script được bắt đầu bằng
                        - S****         => start service
                        - K****        => stop service
                      các script này thực chấy được symbol link từ /etc/init.d
     



Sunday, October 15, 2017

QMake


QMake là một chương trình thuộc bộ công cụ QT Framework có tác dụng tạo ra Makefile cho các QT project, nói chung tương tự như CMake.
Xem thêm các bài viết về QT Framework tại đây.


Sunday, October 4, 2015

GNU Make (GMake/Make)


GNU Make hay còn gọi là gmake hoặc make, là một công cụ mặc định trên Linux được dùng trong quá trình compile thư viện hoặc một chương trình nào đó. Một bộ 3 công cụ và script sau được dùng trong qúa trình trên:
+ Make (GNU Make)
+ Makefile (Shell script)
+ GCC Compiler

Makefile chứa các thông tin và chỉ dẫn (các lời gọi lệnh GCC Compiler); Make sẽ đọc, phân tích Makefile để làm các công việc theo các hướng dẫn trong đó.

Để xem thông tin về make

 [ninhld@localhost ~]$   
 [ninhld@localhost ~]$ gmake --version  
 GNU Make 3.82  
 Built for x86_64-redhat-linux-gnu  
 Copyright (C) 2010 Free Software Foundation, Inc.  
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>  
 This is free software: you are free to change and redistribute it.  
 There is NO WARRANTY, to the extent permitted by law.  
 [ninhld@localhost ~]$   
 [ninhld@localhost ~]$   
 [ninhld@localhost ~]$   
 [ninhld@localhost ~]$ make --version  
 GNU Make 3.82  
 Built for x86_64-redhat-linux-gnu  
 Copyright (C) 2010 Free Software Foundation, Inc.  
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>  
 This is free software: you are free to change and redistribute it.  
 There is NO WARRANTY, to the extent permitted by law.  
 [ninhld@localhost ~]$   

 [ninhld@localhost ~]$   
 [ninhld@localhost ~]$ make --help  
 Usage: make [options] [target] ...  
 Options:  
  -b, -m           Ignored for compatibility.  
  -B, --always-make      Unconditionally make all targets.  
  -C DIRECTORY, --directory=DIRECTORY  
                Change to DIRECTORY before doing anything.  
  -d             Print lots of debugging information.  
  --debug[=FLAGS]       Print various types of debugging information.  
  -e, --environment-overrides  
                Environment variables override makefiles.  
  --eval=STRING        Evaluate STRING as a makefile statement.  
  -f FILE, --file=FILE, --makefile=FILE  
                Read FILE as a makefile.  
  -h, --help         Print this message and exit.  
  -i, --ignore-errors     Ignore errors from recipes.  
  -I DIRECTORY, --include-dir=DIRECTORY  
                Search DIRECTORY for included makefiles.  
  -j [N], --jobs[=N]     Allow N jobs at once; infinite jobs with no arg.  
  -k, --keep-going      Keep going when some targets can't be made.  
  -l [N], --load-average[=N], --max-load[=N]  
                Don't start multiple jobs unless load is below N.  
  -L, --check-symlink-times  Use the latest mtime between symlinks and target.  
  -n, --just-print, --dry-run, --recon  
                Don't actually run any recipe; just print them.  
  -o FILE, --old-file=FILE, --assume-old=FILE  
                Consider FILE to be very old and don't remake it.  
  -p, --print-data-base    Print make's internal database.  
  -q, --question       Run no recipe; exit status says if up to date.  
  -r, --no-builtin-rules   Disable the built-in implicit rules.  
  -R, --no-builtin-variables Disable the built-in variable settings.  
  -s, --silent, --quiet    Don't echo recipes.  
  -S, --no-keep-going, --stop  
                Turns off -k.  
  -t, --touch         Touch targets instead of remaking them.  
  -v, --version        Print the version number of make and exit.  
  -w, --print-directory    Print the current directory.  
  --no-print-directory    Turn off -w, even if it was turned on implicitly.  
  -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE  
                Consider FILE to be infinitely new.  
  --warn-undefined-variables Warn when an undefined variable is referenced.  
  --warn-undefined-functions Warn when an undefined user function is called.  
   
 This program built for x86_64-redhat-linux-gnu  
 Report bugs to <bug-make@gnu.org>  
 [ninhld@localhost ~]$  

Các bài viết liên quan:
+ Makefile
+ Cross Compiler
Cross compiling the libraries



Sunday, July 5, 2015

CMake

Bài viết liên quan:

CMake là một công cụ trợ giúp cho việc build library, có chức năng sinh ra Makefile tương tự như script configure như thông thường.
Install CMake trên Fedora:
yum install cmake cmake-gui
Trong đó cmake là command line, cmake-gui là công cụ CMake bằng giao diện đồ họa, dễ sử dụng hơn so với command line.

Để bắt đầu chúng ta cùng build thư viện OpenCV-2.3.1, một thư viện sử dụng Cmake để build.
Download và giải nén, bạn sẽ thấy trong thư mục OpenCV-2.3.1 có một file cấu hình của CMake có tên CMakeLists.txt


 cd /home/ninhld/Documents/OpenCV-2.3.1  
 mkdir release  
 cd release  
 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/usr/local ..  #chu y phai co hai dau cham  
 make  
 make install  

Sau khi installed xong, bạn mở thư mục /home/usr/local 





Install GTK
yum install gtk2-devel

DisplayImage.cpp
 #include <stdio.h>  
 #include <opencv2/opencv.hpp>  
   
 using namespace cv;  
   
 int main(int argc, char** argv )  
 {  
   if ( argc != 2 )  
   {  
     printf("usage: DisplayImage.out <Image_Path>\n");  
     return -1;  
   }  
   
   Mat image;  
   image = imread( argv[1], 1 );  
   
   if ( !image.data )  
   {  
     printf("No image data \n");  
     return -1;  
   }  
   namedWindow("Display Image", CV_WINDOW_AUTOSIZE );  
   imshow("Display Image", image);  
   
   waitKey(0);  
   
   return 0;  
 }  
   


Build application
 export OPENCV_DIR=/home/usr/local
 export PATH=$PATH:${OPENCV_DIR}/bin  
 export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${OPENCV_DIR}/lib/pkgconfig #open opencv.pc and check install folder link  
 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${OPENCV_DIR}/lib  
   
 g++ `pkg-config --cflags opencv` `pkg-config --libs opencv` DisplayImage.cpp -o DisplayImage  
   

FromId3.jpg



Execute
 [ninhld@localhost ex]$   
 [ninhld@localhost ex]$ export OPENCV_DIR=/home/usr/local    
 [ninhld@localhost ex]$ export PATH=$PATH:${OPENCV_DIR}/bin  
 [ninhld@localhost ex]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${OPENCV_DIR}/lib  
 [ninhld@localhost ex]$     
 [ninhld@localhost ex]$ ./DisplayImage FromId3.jpg   
   

Kết quả



Ở phần trên là build OpenCV cho host, bạn xem thêm bài viết về phần cross compiling OpenCV cho board nhúng FriendlyARM Mini2440 tại đây.

Bài viết liên quan:
+ CMake Cross Compiling

Saturday, July 4, 2015

Pkg-config

Bài viết liên quan:
+ Cross compiling the libraries

pkg-config là một chương trình build-in sẵn trong linux, có chức năng lấy thông tin về một thư viện nào đó đã được installed để phục vụ cho việc build một ứng dụng hoặc một thư viện khác có sử dụng thư viện này.
Thư viện đã installed sẽ có các file có đuôi mở rộng ".pc" chứa các thông tin về thư viện, chương trình pkg-config sẽ đọc thông tin từ các file này ra thông qua một biến môi trường có tên là PKG_CONFIG_PATH.
Theo như ví dụ như trong bài viết Cross compiling the libraries chúng ta đã build xong thư viện taglib-1.6.3


taglib.pc
 prefix=/home/ninhld/Documents/taglib_install  
 exec_prefix=${prefix}  
 libdir=${exec_prefix}/lib64  
 includedir=${prefix}/include  
   
 Name: TagLib  
 Description: Audio meta-data library  
 Requires:   
 Version: 1.6.3  
 Libs: -L${libdir} -ltag  
 Cflags: -I${includedir}/taglib   
   

taglib_c.pc
 prefix=/home/ninhld/Documents/taglib_install  
 exec_prefix=${prefix}  
 libdir=${exec_prefix}/lib64  
 includedir=${prefix}/include  
   
 Name: TagLib C Bindings  
 Description: Audio meta-data library (C bindings)  
 Requires: taglib  
 Version: 1.6.3  
 Libs: -L${libdir} -ltag_c  
 Cflags: -I${includedir}/taglib   
   


Các thông tin chính bao gồm:
+ Đường dẫn đến thư mục header, tương ứng với CFLAGS
+ Đường dẫn đến thư mục lib (chứa .la, .so), tương ứng với LDFLAGS


pkg-config hoạt động như thế nào:
+ Export biến môi trường PKG_CONFIG_PATH
+ Sử dụng lệnh pkg-config cùng với các options như --cflags, --libs, ...

 [ninhld@localhost examples]$   
 [ninhld@localhost examples]$ export TAGLIBDIR=/home/ninhld/Documents/taglib_install  
 [ninhld@localhost examples]$ export PATH=$PATH:${TAGLIBDIR}/bin 
 [ninhld@localhost examples]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${TAGLIBDIR}/lib64 
 [ninhld@localhost examples]$ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${TAGLIBDIR}/lib64/pkgconfig  
 [ninhld@localhost examples]$   
 [ninhld@localhost examples]$ pkg-config --cflags taglib taglib_c  
 -I/home/ninhld/Documents/taglib_install/include/taglib   
 [ninhld@localhost examples]$   
 [ninhld@localhost examples]$ pkg-config --libs taglib taglib_c  
 -L/home/ninhld/Documents/taglib_install/lib64 -ltag_c -ltag   
 [ninhld@localhost examples]$   
 [ninhld@localhost examples]$   

Như vậy có thể thấy thay vì export các biến CFLAGS / LDFLAGS:
 export CFLAGS+="-I${TAGLIBDIR}/include/taglib -DDEBUG -Wall -g"    
 export LDFLAGS+="-L${TAGLIBDIR}/lib64 -ltag_c -ltag"    

thì bạn có thể dùng pkg-config:
 export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${TAGLIBDIR}/lib64/pkgconfig  
 pkg-config --libs --cflags taglib taglib_c  

Note: taglib / taglib_c tương ứng với taglib.pc / taglib_c.pc

Cuối cùng, cũng với ví dụ taglreader_c.c như trong bài  Cross compiling the libraries, hai cách dưới đây là tương đương:

 gcc -o tagreader tagreader_c.c ${CFLAGS} ${LDFLAGS}  

 gcc -o tagreader tagreader_c.c $(pkg-config --libs --cflags taglib taglib_c)  

Note: pkg-config rất hữu ích khi có rất nhiều thư viện được installed ở các thư mục khác nhau, thay vì phải liệt kê tất cả các đường dẫn và lib trong CFLAGS / LDFLAGS thì chỉ cần export PKG_CONFIG_PATH đến các thư mục pkgconfig của các thư viện installed là đủ.

Friday, July 3, 2015

Linux /dev directory


Thư mục /dev trong linux là một thư mục đặc biệt chứa tất cả các device file, để xem được bên trong /dev có gì bạn dùng lệnh:

 $ ls -l /dev/  
 total 0  
 crw-------. 1 root root    10, 235 Jul 2 20:18 autofs  
 drwxr-xr-x. 2 root root      240 Jul 3 2015 block  
 drwxr-xr-x. 2 root root      80 Jul 3 2015 bsg  
 crw-------. 1 root root    10, 234 Jul 2 20:18 btrfs-control  
 drwxr-xr-x. 3 root root      60 Jul 3 2015 bus  
 lrwxrwxrwx. 1 root root       3 Jul 2 20:18 cdrom -> sr0  
 drwxr-xr-x. 2 root root     3720 Jul 2 20:18 char  
 crw-------. 1 root root    5,  1 Jul 2 20:18 console  
 lrwxrwxrwx. 1 root root      11 Jul 3 2015 core -> /proc/kcore  
 drwxr-xr-x. 6 root root      140 Jul 2 20:18 cpu  
 crw-------. 1 root root    10, 62 Jul 2 20:18 cpu_dma_latency  
 drwxr-xr-x. 5 root root      100 Jul 3 2015 disk  
 drwxr-xr-x. 2 root root      100 Jul 3 2015 dri  
 crw-rw----. 1 root video   29,  0 Jul 2 20:18 fb0  
 lrwxrwxrwx. 1 root root      13 Jul 3 2015 fd -> /proc/self/fd  
 crw-rw-rw-. 1 root root    1,  7 Jul 2 20:18 full  
 crw-rw-rw-. 1 root root    10, 229 Jul 2 20:18 fuse  
 crw-------. 1 root root   247,  0 Jul 2 20:18 fw0  
 crw-------. 1 root root   250,  0 Jul 2 20:18 hidraw0  
 crw-------. 1 root root    10, 228 Jul 2 20:18 hpet  
 drwxr-xr-x. 2 root root       0 Jul 2 20:18 hugepages  
 prw-------. 1 root root       0 Jul 2 20:18 initctl  
 drwxr-xr-x. 4 root root      500 Jul 2 20:18 input  
 crw-r--r--. 1 root root    1, 11 Jul 2 20:18 kmsg  
 crw-rw----+ 1 root root    10, 232 Jul 2 20:18 kvm  
 srw-rw-rw-. 1 root root       0 Jul 3 2015 log  
 crw-rw----. 1 root disk    10, 237 Jul 2 20:18 loop-control  
 crw-rw----. 1 root lp     6,  0 Jul 2 20:18 lp0  
 crw-rw----. 1 root lp     6,  1 Jul 2 20:18 lp1  
 crw-rw----. 1 root lp     6,  2 Jul 2 20:18 lp2  
 crw-rw----. 1 root lp     6,  3 Jul 2 20:18 lp3  
 drwxr-xr-x. 2 root root      60 Jul 3 2015 mapper  
 crw-------. 1 root root    10, 227 Jul 2 20:18 mcelog  
 crw-------. 1 root root   245,  0 Jul 2 20:18 media0  
 crw-------. 1 root root   246,  0 Jul 2 20:18 mei0  
 crw-r-----. 1 root kmem    1,  1 Jul 2 20:18 mem  
 crw-------. 1 root root    10, 59 Jul 2 20:18 memory_bandwidth  
 drwxrwxrwt. 2 root root      40 Jul 3 2015 mqueue  
 drwxr-xr-x. 2 root root      60 Jul 2 20:18 net  
 crw-------. 1 root root    10, 61 Jul 2 20:18 network_latency  
 crw-------. 1 root root    10, 60 Jul 2 20:18 network_throughput  
 crw-rw-rw-. 1 root root    1,  3 Jul 2 20:18 null  
 crw-------. 1 root root    10, 144 Jul 2 20:18 nvram  
 crw-r-----. 1 root kmem    1,  4 Jul 2 20:18 port  
 crw-------. 1 root root   108,  0 Jul 2 20:18 ppp  
 crw-rw-rw-. 1 root tty     5,  2 Jul 2 21:06 ptmx  
 crw-------. 1 root root   248,  0 Jul 2 20:18 ptp0  
 drwxr-xr-x. 2 root root       0 Jul 3 2015 pts  
 crw-rw-rw-. 1 root root    1,  8 Jul 2 20:18 random  
 drwxr-xr-x. 2 root root      60 Jul 3 2015 raw  
 lrwxrwxrwx. 1 root root       4 Jul 3 2015 resume -> sda7  
 crw-rw-r--+ 1 root root    10, 55 Jul 2 20:18 rfkill  
 lrwxrwxrwx. 1 root root       4 Jul 2 20:18 rtc -> rtc0  
 crw-------. 1 root root   254,  0 Jul 2 20:18 rtc0  
 brw-rw----. 1 root disk    8,  0 Jul 2 20:18 sda  
 brw-rw----. 1 root disk    8,  1 Jul 2 20:18 sda1  
 brw-rw----. 1 root disk    8,  2 Jul 2 20:18 sda2  
 brw-rw----. 1 root disk    8,  3 Jul 2 20:18 sda3  
 brw-rw----. 1 root disk    8,  5 Jul 2 20:18 sda5  
 brw-rw----. 1 root disk    8,  6 Jul 2 20:18 sda6  
 brw-rw----. 1 root disk    8,  7 Jul 2 20:18 sda7  
 brw-rw----. 1 root disk    8,  8 Jul 2 20:18 sda8  
 brw-rw----. 1 root disk    8,  9 Jul 2 20:18 sda9  
 crw-rw----. 1 root disk    21,  0 Jul 2 20:18 sg0  
 crw-rw----+ 1 root cdrom   21,  1 Jul 2 20:18 sg1  
 drwxrwxrwt. 2 root root      120 Jul 2 21:06 shm  
 crw-------. 1 root root    10, 231 Jul 2 20:18 snapshot  
 drwxr-xr-x. 3 root root      280 Jul 2 20:18 snd  
 brw-rw----+ 1 root cdrom   11,  0 Jul 2 20:18 sr0  
 lrwxrwxrwx. 1 root root      15 Jul 3 2015 stderr -> /proc/self/fd/2  
 lrwxrwxrwx. 1 root root      15 Jul 3 2015 stdin -> /proc/self/fd/0  
 lrwxrwxrwx. 1 root root      15 Jul 3 2015 stdout -> /proc/self/fd/1  
 crw-------. 1 root root    10, 224 Jul 2 20:18 tpm0  
 crw-rw-rw-. 1 root tty     5,  0 Jul 2 20:18 tty  
 crw--w----. 1 root tty     4,  0 Jul 2 20:18 tty0  
 crw--w----. 1 root tty     4,  1 Jul 2 20:18 tty1  
 crw--w----. 1 root tty     4, 10 Jul 2 20:18 tty10  
 crw--w----. 1 root tty     4, 11 Jul 2 20:18 tty11  
 crw--w----. 1 root tty     4, 12 Jul 2 20:18 tty12  
 crw--w----. 1 root tty     4, 13 Jul 2 20:18 tty13  
 crw--w----. 1 root tty     4, 14 Jul 2 20:18 tty14  
 crw--w----. 1 root tty     4, 15 Jul 2 20:18 tty15  
 crw--w----. 1 root tty     4, 16 Jul 2 20:18 tty16  
 crw--w----. 1 root tty     4, 17 Jul 2 20:18 tty17  
 crw--w----. 1 root tty     4, 18 Jul 2 20:18 tty18  
 crw--w----. 1 root tty     4, 19 Jul 2 20:18 tty19  
 crw--w----. 1 root tty     4,  2 Jul 2 20:18 tty2  
 crw--w----. 1 root tty     4, 20 Jul 2 20:18 tty20  
 crw--w----. 1 root tty     4, 21 Jul 2 20:18 tty21  
 crw--w----. 1 root tty     4, 22 Jul 2 20:18 tty22  
 crw--w----. 1 root tty     4, 23 Jul 2 20:18 tty23  
 crw--w----. 1 root tty     4, 24 Jul 2 20:18 tty24  
 crw--w----. 1 root tty     4, 25 Jul 2 20:18 tty25  
 crw--w----. 1 root tty     4, 26 Jul 2 20:18 tty26  
 crw--w----. 1 root tty     4, 27 Jul 2 20:18 tty27  
 crw--w----. 1 root tty     4, 28 Jul 2 20:18 tty28  
 crw--w----. 1 root tty     4, 29 Jul 2 20:18 tty29  
 crw--w----. 1 root tty     4,  3 Jul 2 20:18 tty3  
 crw--w----. 1 root tty     4, 30 Jul 2 20:18 tty30  
 crw--w----. 1 root tty     4, 31 Jul 2 20:18 tty31  
 crw--w----. 1 root tty     4, 32 Jul 2 20:18 tty32  
 crw--w----. 1 root tty     4, 33 Jul 2 20:18 tty33  
 crw--w----. 1 root tty     4, 34 Jul 2 20:18 tty34  
 crw--w----. 1 root tty     4, 35 Jul 2 20:18 tty35  
 crw--w----. 1 root tty     4, 36 Jul 2 20:18 tty36  
 crw--w----. 1 root tty     4, 37 Jul 2 20:18 tty37  
 crw--w----. 1 root tty     4, 38 Jul 2 20:18 tty38  
 crw--w----. 1 root tty     4, 39 Jul 2 20:18 tty39  
 crw--w----. 1 root tty     4,  4 Jul 2 20:18 tty4  
 crw--w----. 1 root tty     4, 40 Jul 2 20:18 tty40  
 crw--w----. 1 root tty     4, 41 Jul 2 20:18 tty41  
 crw--w----. 1 root tty     4, 42 Jul 2 20:18 tty42  
 crw--w----. 1 root tty     4, 43 Jul 2 20:18 tty43  
 crw--w----. 1 root tty     4, 44 Jul 2 20:18 tty44  
 crw--w----. 1 root tty     4, 45 Jul 2 20:18 tty45  
 crw--w----. 1 root tty     4, 46 Jul 2 20:18 tty46  
 crw--w----. 1 root tty     4, 47 Jul 2 20:18 tty47  
 crw--w----. 1 root tty     4, 48 Jul 2 20:18 tty48  
 crw--w----. 1 root tty     4, 49 Jul 2 20:18 tty49  
 crw--w----. 1 root tty     4,  5 Jul 2 20:18 tty5  
 crw--w----. 1 root tty     4, 50 Jul 2 20:18 tty50  
 crw--w----. 1 root tty     4, 51 Jul 2 20:18 tty51  
 crw--w----. 1 root tty     4, 52 Jul 2 20:18 tty52  
 crw--w----. 1 root tty     4, 53 Jul 2 20:18 tty53  
 crw--w----. 1 root tty     4, 54 Jul 2 20:18 tty54  
 crw--w----. 1 root tty     4, 55 Jul 2 20:18 tty55  
 crw--w----. 1 root tty     4, 56 Jul 2 20:18 tty56  
 crw--w----. 1 root tty     4, 57 Jul 2 20:18 tty57  
 crw--w----. 1 root tty     4, 58 Jul 2 20:18 tty58  
 crw--w----. 1 root tty     4, 59 Jul 2 20:18 tty59  
 crw--w----. 1 root tty     4,  6 Jul 2 20:18 tty6  
 crw--w----. 1 root tty     4, 60 Jul 2 20:18 tty60  
 crw--w----. 1 root tty     4, 61 Jul 2 20:18 tty61  
 crw--w----. 1 root tty     4, 62 Jul 2 20:18 tty62  
 crw--w----. 1 root tty     4, 63 Jul 2 20:18 tty63  
 crw--w----. 1 root tty     4,  7 Jul 2 20:18 tty7  
 crw--w----. 1 root tty     4,  8 Jul 2 20:18 tty8  
 crw--w----. 1 root tty     4,  9 Jul 2 20:18 tty9  
 crw-rw----. 1 root dialout   4, 64 Jul 2 20:18 ttyS0  
 crw-rw----. 1 root dialout   4, 65 Jul 2 20:18 ttyS1  
 crw-rw----. 1 root dialout   4, 66 Jul 2 20:18 ttyS2  
 crw-rw----. 1 root dialout   4, 67 Jul 2 20:18 ttyS3  
 crw-------. 1 root root    10, 239 Jul 2 20:18 uhid  
 crw-------. 1 root root    10, 223 Jul 2 20:18 uinput  
 crw-rw-rw-. 1 root root    1,  9 Jul 2 20:18 urandom  
 drwxr-xr-x. 2 root root      60 Jul 3 2015 usb  
 crw-------. 1 root root   251,  0 Jul 2 20:18 usbmon0  
 crw-------. 1 root root   251,  1 Jul 2 20:18 usbmon1  
 crw-------. 1 root root   251,  2 Jul 2 20:18 usbmon2  
 drwxr-xr-x. 4 root root      80 Jul 2 20:18 v4l  
 crw-------. 1 root root    10, 58 Jul 2 20:18 vboxdrv  
 crw-------. 1 root root    10, 57 Jul 2 20:18 vboxdrvu  
 crw-------. 1 root root    10, 56 Jul 2 20:18 vboxnetctl  
 drwxr-x---. 4 root vboxusers    80 Jul 2 20:18 vboxusb  
 crw-rw----. 1 root tty     7,  0 Jul 2 20:18 vcs  
 crw-rw----. 1 root tty     7,  1 Jul 2 20:18 vcs1  
 crw-rw----. 1 root tty     7,  2 Jul 2 20:18 vcs2  
 crw-rw----. 1 root tty     7,  3 Jul 2 20:18 vcs3  
 crw-rw----. 1 root tty     7,  4 Jul 2 20:18 vcs4  
 crw-rw----. 1 root tty     7,  5 Jul 2 20:18 vcs5  
 crw-rw----. 1 root tty     7,  6 Jul 2 20:18 vcs6  
 crw-rw----. 1 root tty     7, 128 Jul 2 20:18 vcsa  
 crw-rw----. 1 root tty     7, 129 Jul 2 20:18 vcsa1  
 crw-rw----. 1 root tty     7, 130 Jul 2 20:18 vcsa2  
 crw-rw----. 1 root tty     7, 131 Jul 2 20:18 vcsa3  
 crw-rw----. 1 root tty     7, 132 Jul 2 20:18 vcsa4  
 crw-rw----. 1 root tty     7, 133 Jul 2 20:18 vcsa5  
 crw-rw----. 1 root tty     7, 134 Jul 2 20:18 vcsa6  
 drwxr-xr-x. 2 root root      60 Jul 2 20:18 vfio  
 crw-------. 1 root root    10, 63 Jul 2 20:18 vga_arbiter  
 crw-------. 1 root root    10, 137 Jul 2 20:18 vhci  
 crw-------. 1 root root    10, 238 Jul 2 20:18 vhost-net  
 crw-rw----+ 1 root video   81,  0 Jul 2 20:18 video0  
 crw-------. 1 root root    10, 130 Jul 2 20:18 watchdog  
 crw-------. 1 root root   253,  0 Jul 2 20:18 watchdog0  
 crw-------. 1 root root   253,  1 Jul 2 20:18 watchdog1  
 crw-rw-rw-. 1 root root    1,  5 Jul 2 20:18 zero  


/dev/fd0
Đĩa mềm

/dev/fb0
Framebuffer device.

/dev/hda
/dev/hda is the master IDE drive on the primary IDE controller. /dev/hdb the slave drive on the primary controller. /dev/hdc , and /dev/hdd are the master and slave devices on the secondary controller respectively

/dev/psaux
The PS/2 mouse port.

/dev/random or /dev/urandom
These are kernel random number generators. /dev/random is a non-deterministic generator which means that the value of the next number cannot be guessed from the preceding ones. It uses the entropy of the system hardware to generate numbers. When it has no more entropy to use then it must wait until it has collected more before it will allow any more numbers to be read from it. /dev/urandom works similarly. Initially it also uses the entropy of the system hardware, but when there is no more entropy to use it will continue to return numbers using a pseudo random number generating formula. This is considered to be less secure for vital purposes such as cryptographic key pair generation. If security is your overriding concern then use /dev/random, if speed is more important then /dev/urandom works fine. They are character devices on major node 1 with minor nodes 8 for /dev/random and 9 for /dev/urandom.

/dev/sda
The first SCSI drive on the first SCSI bus. The following drives are named similar to IDE drives. /dev/sdb is the second SCSI drive, /dev/sdc is the third SCSI drive, and so forth.

/dev/ttyS0
The first serial port.

/dev/input/*
Mouse and keyboard,...

/dev/zero
This is a simple way of getting many 0s. Every time you read from this device it will return 0. This can be useful sometimes, for example when you want a file of fixed length but don't really care what it contains. It is a character device on major node 1 and minor node 5.

/dev/null
The bit bucket. A black hole where you can send data for it never to be seen again. Anything sent to /dev/null will disappear. This can be useful if, for example, you wish to run a command but not have any feedback appear on the terminal. It is a character device on major node 1 and minor node 3.

Bài viết liên quan:
+ File System
+ Device file
+ Wiki

Thursday, July 2, 2015

Environment, Parameter Variables


1. Environment variables
Biến môi trường thường được dùng để chứa các thông tin như là options hoặc các đường dẫn (path) đến một thư mục nào đó.
Để show các biến môt trường mặc định của Linux OS và một số phần mềm tạo ra, bạn dùng lệnh env:

 $ env  
 XDG_VTNR=1  
 MATE_DESKTOP_SESSION_ID=this-is-deprecated  
 SSH_AGENT_PID=1421  
 XDG_SESSION_ID=1  
 HOSTNAME=localhost.localdomain  
 XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/ninhld  
 IMSETTINGS_INTEGRATE_DESKTOP=yes  
 GPG_AGENT_INFO=/home/ninhld/.cache/keyring-fbkBhK/gpg:0:1  
 TERM=xterm-256color  
 SHELL=/bin/bash  
 HISTSIZE=1000  
 WINDOWID=73400351  
 GNOME_KEYRING_CONTROL=/home/ninhld/.cache/keyring-fbkBhK  
 QTDIR=/usr/lib64/qt-3.3  
 QTINC=/usr/lib64/qt-3.3/include  
 IMSETTINGS_MODULE=IBus  
 QT_GRAPHICSSYSTEM_CHECKED=1  
 USER=ninhld  
 LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:  
 XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0  
 XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0  
 SSH_AUTH_SOCK=/home/ninhld/.cache/keyring-fbkBhK/ssh  
 SESSION_MANAGER=local/unix:@/tmp/.ICE-unix/1324,unix/unix:/tmp/.ICE-unix/1324  
 PATH=/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/ninhld/.local/bin:/home/ninhld/bin  
 MAIL=/var/spool/mail/ninhld  
 DESKTOP_SESSION=mate  
 QT_IM_MODULE=xim  
 PWD=/home/ninhld  
 XMODIFIERS=@im=ibus  
 GNOME_KEYRING_PID=1320  
 LANG=en_US.utf8  
 KDE_IS_PRELINKED=1  
 GDM_LANG=en_US.utf8  
 KDEDIRS=/usr  
 GDMSESSION=mate  
 HISTCONTROL=ignoredups  
 HOME=/home/ninhld  
 XDG_SEAT=seat0  
 SHLVL=2  
 LOGNAME=ninhld  
 QTLIB=/usr/lib64/qt-3.3/lib  
 DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-MoTJpiQTi2,guid=1471c082de74b829c532fffc5593dfa5  
 LESSOPEN=||/usr/bin/lesspipe.sh %s  
 XDG_RUNTIME_DIR=/run/user/1000  
 DISPLAY=:0.0  
 CCACHE_HASHDIR=  
 COLORTERM=mate-terminal  
 XAUTHORITY=/var/run/lightdm/ninhld/xauthority  
 _=/usr/bin/env  


Biến môi trường mặc định:

Để có thể show nội dung của một biến môi trường cụ thể nào đó bạn dùng lệnh echo:
 [ninhld@localhost env]$ echo $HOME  
 /home/ninhld  
 [ninhld@localhost env]$   
 [ninhld@localhost env]$   
 [ninhld@localhost env]$ echo $PATH  
 /usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/ninhld/.local/bin:/home/ninhld/bin  
 [ninhld@localhost env]$   

Phạm vi hoạt động biến môi trường:
+ Local
Biến chỉ có giá trị trong phạm vi ngữ cảnh của terminal, các script hoặc chương trình khác không thể đọc được nội dung của biến
+ Global
Phạm vị toàn cục, các script hoặc chương trình ngoài có thể đọc được nội dung biến, để tạo ra biến global dùng lệnh export trên terminal

Ví dụ có một Shell script để show các biến môi trường như sau:
env.sh
 #!/bin/sh  
 echo "HELLO=$HELLO"
 echo "XINCHAO=$XINCHAO"  

Command
 [ninhld@localhost env]$   
 [ninhld@localhost env]$ HELLO=hello             #bien local
 [ninhld@localhost env]$ export XINCHAO=xinchao  #bien global
 [ninhld@localhost env]$     
 [ninhld@localhost env]$ ./env.sh   
 HELLO=             #khong doc duoc 
 XINCHAO=xinchao    #doc duoc gia tri
 [ninhld@localhost env]$  


2. Parameter variable
Là các đối số được đưa vào một Shell script, gần giống như đối số đưa vào một hàm trong C/C++.



para.sh

 #!/bin/sh  
 echo "para1 = $1"  
 echo "para2 = $2"  
 echo "para3 = $3"  
   
 echo "\$* = $*"  
 echo "\$@ = $@"  
   

Execute
 [ninhld@localhost env]$   
 [ninhld@localhost env]$ ./para.sh pa1 pa2 pa3  
 para1 = pa1  
 para2 = pa2  
 para3 = pa3  
 $* = pa1 pa2 pa3  
 $@ = pa1 pa2 pa3  
 [ninhld@localhost env]$  

3. Một số biến môi trường quan trọng
+ PATH
Chỉ đường dẫn đến các thư mục chứa file chương trình nhị phân hoặc script.

Ex:
 [ninhld@localhost env]$   
 [ninhld@localhost env]$ export PATH=$PATH:/home/ninhld/Github/eslinuxprogramming/Shell  
 [ninhld@localhost env]$      
 [ninhld@localhost env]$ cd $HOME  
 [ninhld@localhost ~]$    
 [ninhld@localhost ~]$ para.sh pa1 pa2 pa3  
 para1 = pa1  
 para2 = pa2  
 para3 = pa3  
 $* = pa1 pa2 pa3  
 $@ = pa1 pa2 pa3  
 [ninhld@localhost ~]$   

Chương trình para.sh ở trong thư mục Shell, nhờ việc export biến PATH mà para.sh có thể được chạy ở bất cứ đâu mà không cần thư mục làm việc hiện tại trên terminal phải là Shell.



+ LD_LIBRARY_PATH
Biến môi trường của linker chỉ dẫn đến thư mục chứa các thư viện đã được installed, dùng trong quá trình compile thư viện cũng như khi chạy chương trình ứng dụng có sử dụng thư viện đã installed đó.
Bài viết liên quan:
+ Makefile
+ Cross compiling the libraries


PKG_CONFIG_PATH
Biến môi trường chỉ dẫn đến thư mục chứa các file ".pc", được dùng bởi chương trình pkg-config, dùng trong quá trình compile thư viện.
Bài viết liên quan:
+ Pkg-config

Cross compiling the libraries

Bìa viết liên quan:
+ Cross compler 
+ Makefile (Part 1)
+ Makefile (Part 2)
+ Cài đặt môi trường làm việc

1. Library configuration
Trong bài viết này hướng dẫn compile/cross compiling thư viện taglib-1.6.3 (thư viện có chức năng lấy thông tin meta-data của file nhạc) để minh họa cho dễ hiểu. Yêu cầu để thực hiện được phần này thì ít nhất phải biến cách sử dụng máy tính Linux Fedora, biết các command cơ bản trên terminal, biết phân quyền trong Linux, xem lại các bài viết trong mục  Linux PC và Linux Basic nếu bạn chưa rõ.

Một số thuật ngữ:
+ Compile: compile thư viện cho host
+ Cross compiling: compile thư viện cho target (board nhúng), ở blog này sử dụng board nhúng Linux là FriendlyARM Mini2440
+ Build: tương đương với compile / cross compiling

Thư viện được cung cấp dưới dạng source code C/C++ và một shell script đi kèm có tên configure dùng để cài đặt các options phụ vụ cho việc build thư viện, file configure này có thể mở được bằng các text editor thông thường như gedit, geany. Sau khi cấu hình xong với configure thì sẽ thu được một Makefile, từ đó dùng lệnh make để build thư viện. Kết quả thu được sau khi build xong thư viện thường có cấu trúc thư mục như sau:

 bin         #chứa các file execute nhị phân (tương tự file .exe bên Windows)
 etc         #chứa các file cấu hình (vd: file.conf)
 include     #chứa các file header để include vào các chương trình 
              có sử dụng thư viện này (vd: tag.h)
 lib         #chứa các file thư viện tĩnh/động .la/.so, cùng với header file để phục vụ 
              cho các chương trình khác có sử dụng thư viện này (vd: libtag.la, libtag.so)
 man         #chứa các file tài liệu / hướng dẫn sử dụng dạng text
 share       #chứa nhiều loại file như hướng dẫn / script / media, ...
 ...

Để bắt đầu bạn download taglib-1.6.3 (có thể tải các version khác ngoài 1.6.3), sau đó giải nén, chuyển terminal vào thư mục taglib-1.6.3 vừa giải nén, chạy lệnh ./configure --help để xem hướng dẫn build thư viện:

./configure --help
 [ninhld@localhost taglib-1.6.3]$ ./configure --help  
 `configure' configures this package to adapt to many kinds of systems.  
   
 Usage: ./configure [OPTION]... [VAR=VALUE]...  
   
 To assign environment variables (e.g., CC, CFLAGS...), specify them as  
 VAR=VALUE. See below for descriptions of some of the useful variables.  
   
 Defaults for the options are specified in brackets.  
   
 Configuration:  (1)
  -h, --help       display this help and exit  
    --help=short    display options specific to this package  
    --help=recursive  display the short help of all the included packages  
  -V, --version      display version information and exit  
  -q, --quiet, --silent  do not print `checking...' messages  
    --cache-file=FILE  cache test results in FILE [disabled]  
  -C, --config-cache   alias for `--cache-file=config.cache'  
  -n, --no-create     do not create output files  
    --srcdir=DIR    find the sources in DIR [configure dir or `..']  
   
 Installation directories:  (2)
  --prefix=PREFIX     install architecture-independent files in PREFIX  
              [/usr/local]  
  --exec-prefix=EPREFIX  install architecture-dependent files in EPREFIX  
              [PREFIX]  
   
 By default, `make install' will install all the files in  
 `/usr/local/bin', `/usr/local/lib' etc. You can specify  
 an installation prefix other than `/usr/local' using `--prefix',  
 for instance `--prefix=$HOME'.  
   
 For better control, use the options below.  
   
 Fine tuning of the installation directories:  (3)
  --bindir=DIR      user executables [EPREFIX/bin]  
  --sbindir=DIR      system admin executables [EPREFIX/sbin]  
  --libexecdir=DIR    program executables [EPREFIX/libexec]  
  --sysconfdir=DIR    read-only single-machine data [PREFIX/etc]  
  --sharedstatedir=DIR  modifiable architecture-independent data [PREFIX/com]  
  --localstatedir=DIR   modifiable single-machine data [PREFIX/var]  
  --libdir=DIR      object code libraries [EPREFIX/lib]  
  --includedir=DIR    C header files [PREFIX/include]  
  --oldincludedir=DIR   C header files for non-gcc [/usr/include]  
  --datarootdir=DIR    read-only arch.-independent data root [PREFIX/share]  
  --datadir=DIR      read-only architecture-independent data [DATAROOTDIR]  
  --infodir=DIR      info documentation [DATAROOTDIR/info]  
  --localedir=DIR     locale-dependent data [DATAROOTDIR/locale]  
  --mandir=DIR      man documentation [DATAROOTDIR/man]  
  --docdir=DIR      documentation root [DATAROOTDIR/doc/PACKAGE]  
  --htmldir=DIR      html documentation [DOCDIR]  
  --dvidir=DIR      dvi documentation [DOCDIR]  
  --pdfdir=DIR      pdf documentation [DOCDIR]  
  --psdir=DIR       ps documentation [DOCDIR]  
   
 Program names:  (4)
  --program-prefix=PREFIX      prepend PREFIX to installed program names  
  --program-suffix=SUFFIX      append SUFFIX to installed program names  
  --program-transform-name=PROGRAM  run sed PROGRAM on installed program names  
   
 System types:  (*5)
  --build=BUILD   configure for building on BUILD [guessed]  
  --host=HOST    cross-compile to build programs to run on HOST [BUILD]  
  --target=TARGET  configure for building compilers for TARGET [HOST]  
   
 Optional Features:  (6)
  --disable-option-checking ignore unrecognized --enable/--with options  
  --disable-FEATURE    do not include FEATURE (same as --enable-FEATURE=no)  
  --enable-FEATURE[=ARG] include FEATURE [ARG=yes]  
  --disable-fast-perl   disable fast Makefile generation (needs perl)  
  --enable-debug=ARG   enables debug symbols (yes|no|full) default=no  
  --disable-debug     disables debug output and debug symbols default=no  
  --enable-strict     compiles with strict compiler options (may not  
              work!)  
  --disable-warnings   disables compilation with -Wall and similar  
  --enable-profile    creates profiling infos default=no  
  --disable-dependency-tracking speeds up one-time build  
  --enable-dependency-tracking  do not reject slow dependency extractors  
  --enable-pch      enables precompiled header support (currently only  
              KCC or gcc >=3.4+unsermake) default=no  
  --enable-coverage    use gcc coverage testing  
  --enable-new-ldflags  enable the new linker flags  
  --enable-final     build size optimized apps (experimental - needs lots  
              of memory)  
  --enable-closure    delay template instantiation  
  --enable-nmcheck    enable automatic namespace cleanness check  
  --enable-shared[=PKGS] build shared libraries [default=yes]  
  --enable-static[=PKGS] build static libraries [default=no]  
  --enable-libsuffix   /lib directory suffix (64,32,none,auto=default)  
  --enable-fast-install[=PKGS]  
              optimize for fast installation [default=yes]  
  --disable-libtool-lock avoid locking (might break parallel builds)  
  --enable-mp4      add MP4 support  
  --enable-asf      add ASF support  
   
 Optional Packages:  (7)
  --with-PACKAGE[=ARG]  use PACKAGE [ARG=yes]  
  --without-PACKAGE    do not use PACKAGE (same as --with-PACKAGE=no)  
  --with-gnu-ld      assume the C compiler uses GNU ld [default=no]  
  --with-pic       try to use only PIC/non-PIC objects [default=use  
              both]  
  --with-tags[=TAGS]   include additional configurations [automatic]  
   
 Some influential environment variables:  (*8)
  CC     C compiler command  
  CFLAGS   C compiler flags  
  LDFLAGS   linker flags, e.g. -L<lib dir> if you have libraries in a  
        nonstandard directory <lib dir>  
  LIBS    libraries to pass to the linker, e.g. -l<library>  
  CPPFLAGS  C/C++/Objective C preprocessor flags, e.g. -I<include dir> if  
        you have headers in a nonstandard directory <include dir>  
  CPP     C preprocessor  
  CXX     C++ compiler command  
  CXXFLAGS  C++ compiler flags  
  CXXCPP   C++ preprocessor  
  F77     Fortran 77 compiler command  
  FFLAGS   Fortran 77 compiler flags  
   
 Use these variables to override the choices made by `configure' or to help  
 it to find libraries and programs with nonstandard names/locations.  
   
 [ninhld@localhost taglib-1.6.3]$   


1.1 Configuration
Các options để show thông tin về thư viện, ví dụ:
 configure --help hoặc configure -h  
 configure --version hoặc configure -V  

1.2 Installation directories
Thư mục để install thư viện vào đó:
 export PREFIX=/home/ninhld/Documents/taglib_install   #export biến môi trường
 ./configure --prefix=$PREFIX  

hoặc
./configure --prefix=/home/ninhld/Documents/taglib_install   

Nếu không cài đặt --prefix thì mặc định nó sẽ install vào thư mục /usr/local

--exec-prefix : mặc định được gán với PREFIX, giống với --prefix

1.3 Fine tuning of the installation directories
  --bindir=DIR   user executables [EPREFIX/bin]   
  --sbindir=DIR   system admin executables [EPREFIX/sbin]   
  --libexecdir=DIR  program executables [EPREFIX/libexec]   
  --sysconfdir=DIR  read-only single-machine data [PREFIX/etc]   
  ...  

Các thư mục sẽ được tạo ra để chứa thư viện: bin, include, lib, etc, ...
Mặc định chúng sẽ là thư mục con của --prefix/PREFIX đã đươc đặt ở bước (2)

1.4 Program names
Không cần quan tâm

1.5 System types
Các options rất quan trong để compile cho host hoặc cross-compiling cho target (board nhúng), nếu bạn compile cho host, bạn không cần cài đặt các options này, nếu bạn cross-compiling cho target bạn cài đặt như sau:
 export HOST=arm-none-linux-gnueabi  
 export BUILD=x86_64  
 ./configure --build=${BUILD} --host=${HOST}  

hoặc
 ./configure --build=x86_64 --host=arm-none-linux-gnueabi  

+ HOST
Là nơi mà chương trình sẽ chạy, trong ví dụ trên là board nhúng chạy chíp ARM

+BUILD
Là nơi mà chương trình compiler chạy, hoặc được build ra, ở đây là máy tính chạy chip Inter x86/64bits

+TARGET
Tương tự như HOST, thông số này không cần đặt

1.6 Optional Features
Các options có tiền tố --enable / --disable để cấu hình bật / tắt một tính năng nào đó của thư viện. Các tính năng này được cấu hình mặc định default=yes hoặc default=no ghi rõ trong phần chú thích, nhưng thông thường thì option thuộc dạng --enable thì mặc định là no, option dạng --disable thì mặc định là yes.

Ví dụ:
 ./configure --disable-debug --disable-warnings --enable-static=no --enable-mp4  

+ Tắt debug (default=yes)
+ Tắt warning (default=yes)
+ Không build thư viện static (default=no, cho thêm vào cho chắc :D)
+ Bật support MP4 (default=no)

Có rất nhiều options, bạn nên xem kỹ để lựa chọn enable/disable những options cần quan tâm, cái nào không quan tâm cứ để mặc định, thông thường bạn để tất cả chúng mặc định là đã ok rồi.

1.7 Optional Packages
Options này gần giống với --enable

1.8 Some influential environment variables
Ở đây là các biến môi trường sử dụng bởi compiler

+ CFLAGS / CXXFLAGS / CPPFLAGS
C/C++ compiler flags được pass vào cho compiler, bao gồm:
    - Đường dẫn header file của thư viện phụ thuộc (nếu có), có dạng -I/path/to/include
      Thư viện phụ thuộc: A là thư viện phụ thuộc của B nếu trong B có sử dụng các API do A cung cấp, vì thế A phải được build trước thì mới có thể build B được, vì thế -I/path/to/include có tác dụng cung cấp các API của A cho B trong quá trình compile ra object file.
    - Các options riêng của compiler, ví dụ: -Wll, -g

+ CC / CXX / CPP
C compiler và C++ compiler
 
 #x86
 CC=gcc  
 CXX=g++
 CPP=g++
   
 hoặc   
 #arm
 CC=arm-none-linux-gnueabi-gcc  
 CXX=arm-none-linux-gnueabi-g++  
 CPP=arm-none-linux-gnueabi-g++

+ LDFLAGS
Linker flags, gồm các thông tin:
    - Đường dẫn đến thư mục chứa thư viện phụ thuộc (.la, .so), có dạng -L/path/to/lib
    - Các thư viện sẽ dùng, có dạng -l<name>; ví dụ:  -ltag tương ứng với libtag

+ LIBS
Tương tự như phần "Các thư viện sẽ dùng" trong LDFLAGS, thông thường LIBS ít được dùng vì nó đã được bao hàm trong LDFLAGS

Ex:
 #export biến môi trường 
 export CC_PATH=/opt/FriendlyARM/toolschain/4.4.3  
 export CROSS_COMPILE=${CC_PATH}/bin/arm-none-linux-gnueabi-  
 export PATH=$PATH:${CC_PATH}/bin  
   
   
 export CC=${CROSS_COMPILE}gcc  
 export CXX=${CROSS_COMPILE}g++  
   
 export CFLAGS+="-I/friendlyarm/usr/local/include -DDEBUG -Wall -g"  
 export CXXFLAGS=$CFLAGS  
 export LDFLAGS+="-L/friendlyarm/usr/local/lib -lm"  
   
 ./configure   

hoặc

 export CC_PATH=/opt/FriendlyARM/toolschain/4.4.3  
 export CROSS_COMPILE=${CC_PATH}/bin/arm-none-linux-gnueabi-  
 export PATH=$PATH:${CC_PATH}/bin  
 
 #nhúng các flags vào thẳng configure  
 ./configure CC=${CROSS_COMPILE}gcc CXX=${CROSS_COMPILE}g++ \  
 CFLAGS="-I/friendlyarm/usr/local/include -Wall -g" \  
 CXXFLAGS=$CFLAGS LDFLAGS="-L/friendlyarm/usr/local/lib -lm"   

Note:
PATH: là biến môi trường chỉ ra đường dẫn đến file nhị phân của compiler


2. Compile taglib-1.6.3 for Linux Fedora x86_64

./configure: cấu hình mặc định, có chỉ ra thư mục để install, sau bước này sẽ có được Makefile
   
 [ninhld@localhost taglib-1.6.3]$   
 [ninhld@localhost taglib-1.6.3]$ export PREFIX=/home/ninhld/Documents/taglib_install  
 [ninhld@localhost taglib-1.6.3]$ ./configure --prefix=$PREFIX
 checking build system type... x86_64-unknown-linux-gnu  
 checking host system type... x86_64-unknown-linux-gnu  
 checking target system type... x86_64-unknown-linux-gnu  
 ...  
 ... 
 config.status: creating Makefile  
 config.status: creating bindings/Makefile  
 config.status: creating bindings/c/Makefile  
 config.status: creating examples/Makefile  
 config.status: creating taglib/Makefile  
 config.status: creating taglib/ape/Makefile  
 config.status: creating taglib/asf/Makefile  
 config.status: creating taglib/flac/Makefile  
 config.status: creating taglib/mp4/Makefile  
 config.status: creating taglib/mpc/Makefile  
 config.status: creating taglib/mpeg/Makefile  
 config.status: creating taglib/mpeg/id3v1/Makefile  
 config.status: creating taglib/mpeg/id3v2/Makefile  
 config.status: creating taglib/mpeg/id3v2/frames/Makefile  
 config.status: creating taglib/ogg/Makefile  
 config.status: creating taglib/ogg/flac/Makefile  
 config.status: creating taglib/ogg/speex/Makefile  
 config.status: creating taglib/ogg/vorbis/Makefile  
 config.status: creating taglib/riff/Makefile  
 config.status: creating taglib/riff/aiff/Makefile  
 config.status: creating taglib/riff/wav/Makefile  
 config.status: creating taglib/toolkit/Makefile  
 config.status: creating taglib/trueaudio/Makefile  
 config.status: creating taglib/wavpack/Makefile  
 config.status: creating tests/Makefile  
 config.status: creating taglib-config  
 config.status: creating taglib.pc  
 config.status: creating bindings/c/taglib_c.pc  
 config.status: creating config.h  
 config.status: creating taglib/taglib_config.h  
 config.status: executing depfiles commands  
   
 Good - your configure finished. Start make now  
   
 [ninhld@localhost taglib-1.6.3]$   

make
 [ninhld@localhost taglib-1.6.3]$   
 [ninhld@localhost taglib-1.6.3]$ make  
 make all-recursive  
 make[1]: Entering directory `/home/ninhld/Documents/taglib-1.6.3'  
 Making all in taglib  
 make[2]: Entering directory `/home/ninhld/Documents/taglib-1.6.3/taglib'  
 make all-recursive  
 make[3]: Entering directory `/home/ninhld/Documents/taglib-1.6.3/taglib'  
 Making all in toolkit  
 make[4]: Entering directory `/home/ninhld/Documents/taglib-1.6.3/taglib/toolkit'  
 /bin/sh ../../libtool --silent --tag=CXX  --mode=compile g++ -DMAKE_TAGLIB_LIB -DHAVE_CONFIG_H -I. -I../.. -I../../taglib -I../../taglib   -O2 -fno-exceptions -fno-check-new -fno-common -fexceptions -MT tstring.lo -MD -MP -MF .deps/tstring.Tpo -c -o tstring.lo tstring.cpp  
 ..  
 ...  
 make[3]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3/bindings/c'  
 make[3]: Entering directory `/home/ninhld/Documents/taglib-1.6.3/bindings'  
 make[3]: Nothing to be done for `all-am'.  
 make[3]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3/bindings'  
 make[2]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3/bindings'  
 Making all in tests  
 make[2]: Entering directory `/home/ninhld/Documents/taglib-1.6.3/tests'  
 make[2]: Nothing to be done for `all'.  
 make[2]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3/tests'  
 make[2]: Entering directory `/home/ninhld/Documents/taglib-1.6.3'  
 make[2]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3'  
 make[1]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3'  
 [ninhld@localhost taglib-1.6.3]$   
 [ninhld@localhost taglib-1.6.3]$  


make install
 [ninhld@localhost taglib-1.6.3]$ make install  
 Making install in taglib  
 make[1]: Entering directory `/home/ninhld/Documents/taglib-1.6.3/taglib'  
 Making install in toolkit  
 make[2]: Entering directory `/home/ninhld/Documents/taglib-1.6.3/taglib/toolkit'  
 make[3]: Entering directory `/home/ninhld/Documents/taglib-1.6.3/taglib/toolkit'  
 make[3]: Nothing to be done for `install-exec-am'.  
 test -z "/home/ninhld/Documents/taglib_install/include/taglib" || /usr/bin/mkdir -p "/home/ninhld/Documents/taglib_install/include/taglib"  
  /usr/bin/install -c -p -m 644 'taglib.h' '/home/ninhld/Documents/taglib_install/include/taglib/taglib.h'  
  /usr/bin/install -c -p -m 644 'tstring.h' '/home/ninhld/Documents/taglib_install/include/taglib/tstring.h'  
  /usr/bin/install -c -p -m 644 'tlist.h' '/home/ninhld/Documents/taglib_install/include/taglib/tlist.h'  
  /usr/bin/install -c -p -m 644 'tlist.tcc' '/home/ninhld/Documents/taglib_install/include/taglib/tlist.tcc'  
  /usr/bin/install -c -p -m 644 'tstringlist.h' '/home/ninhld/Documents/taglib_install/include/taglib/tstringlist.h'  
  /usr/bin/install -c -p -m 644 'tbytevector.h' '/home/ninhld/Documents/taglib_install/include/taglib/tbytevector.h'  
  /usr/bin/install -c -p -m 644 'tbytevectorlist.h' '/home/ninhld/Documents/taglib_install/include/taglib/tbytevectorlist.h'  
  /usr/bin/install -c -p -m 644 'tfile.h' '/home/ninhld/Documents/taglib_install/include/taglib/tfile.h'  
  /usr/bin/install -c -p -m 644 'tmap.h' '/home/ninhld/Documents/taglib_install/include/taglib/tmap.h'  
  /usr/bin/install -c -p -m 644 'tmap.tcc' '/home/ninhld/Documents/taglib_install/include/taglib/tmap.tcc'  
 make[3]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3/taglib/toolkit'  
 make[2]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3/taglib/toolkit'  
 Making install in mpeg  
 ...  
 ...  
  /usr/bin/install -c -p -m 644 'taglib.pc' '/home/ninhld/Documents/taglib_install/lib64/pkgconfig/taglib.pc'  
 make[2]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3'  
 make[1]: Leaving directory `/home/ninhld/Documents/taglib-1.6.3'  
 [ninhld@localhost taglib-1.6.3]$   




tagreader_c.c (chương trình ví dụ có sử dụng thư viện taglib vừa build xong)
 /* Copyright (C) 2003 Scott Wheeler <wheeler@kde.org>  
  *  
  * Redistribution and use in source and binary forms, with or without  
  * modification, are permitted provided that the following conditions  
  * are met:  
  *  
  * 1. Redistributions of source code must retain the above copyright  
  *  notice, this list of conditions and the following disclaimer.  
  * 2. Redistributions in binary form must reproduce the above copyright  
  *  notice, this list of conditions and the following disclaimer in the  
  *  documentation and/or other materials provided with the distribution.  
  *  
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR  
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  
  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,  
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT  
  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  
  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
  */  
   
 #include <stdio.h>  
 #include <tag_c.h>  
   
 #ifndef FALSE  
 #define FALSE 0  
 #endif  
   
 int main(int argc, char *argv[])  
 {  
  int i;  
  int seconds;  
  int minutes;  
  TagLib_File *file;  
  TagLib_Tag *tag;  
  const TagLib_AudioProperties *properties;  
   
  taglib_set_strings_unicode(FALSE);  
   
  for(i = 1; i < argc; i++) {  
   printf("******************** \"%s\" ********************\n", argv[i]);  
   
   file = taglib_file_new(argv[i]);  
   
   if(file == NULL)  
    break;  
   
   tag = taglib_file_tag(file);  
   properties = taglib_file_audioproperties(file);  
   
   if(tag != NULL) {  
    printf("-- TAG --\n");  
    printf("title  - \"%s\"\n", taglib_tag_title(tag));  
    printf("artist - \"%s\"\n", taglib_tag_artist(tag));  
    printf("album  - \"%s\"\n", taglib_tag_album(tag));  
    printf("year  - \"%i\"\n", taglib_tag_year(tag));  
    printf("comment - \"%s\"\n", taglib_tag_comment(tag));  
    printf("track  - \"%i\"\n", taglib_tag_track(tag));  
    printf("genre  - \"%s\"\n", taglib_tag_genre(tag));  
   }  
   
   if(properties != NULL) {  
    seconds = taglib_audioproperties_length(properties) % 60;  
    minutes = (taglib_audioproperties_length(properties) - seconds) / 60;  
   
    printf("-- AUDIO --\n");  
    printf("bitrate   - %i\n", taglib_audioproperties_bitrate(properties));  
    printf("sample rate - %i\n", taglib_audioproperties_samplerate(properties));  
    printf("channels  - %i\n", taglib_audioproperties_channels(properties));  
    printf("length   - %i:%02i\n", minutes, seconds);  
   }  
   
   taglib_tag_free_strings();  
   taglib_file_free(file);  
  }  
   
  return 0;  
 }  
   


Makefile (Makefile cho ví dụ tagreader_c.c)
 .PHONY: all, install, clean  
   
 TARGET:=tagreader  
   
 HDRS+=  
 CSRCS+= tagreader_c.c  
 CPPSRCS+=  
   
 OBJSDIR=./build  
 OBJS:= $(patsubst %.cpp, $(OBJSDIR)/%.o, $(CPPSRCS))  
 OBJS+= $(patsubst %.c, $(OBJSDIR)/%.o, $(CSRCS))  
   
   
 INCDIR+= -I/home/ninhld/Documents/taglib_install/include \  
      -I/home/ninhld/Documents/taglib_install/include/taglib  
 CFLAGS += -DDEBUG -Wall -g  
 LDFLAGS += -L/home/ninhld/Documents/taglib_install/lib64 -ltag -ltag_c  
   
 CC:= gcc  
 CXX:= g++  
   
 all: ${TARGET}  
 ${TARGET} : $(OBJS)  
      @echo " [LINK] $@"  
      @mkdir -p $(shell dirname $@)  
      @$(CXX) $(OBJS) -o $@ $(LDFLAGS)  
        
 $(OBJSDIR)/%.o: %.c $(HDRS)  
      @echo " [CC]  $@"  
      @mkdir -p $(shell dirname $@)  
      @$(CC) -c $< -o $@ $(CFLAGS) ${INCDIR}  
   
 $(OBJSDIR)/%.o: %.cpp $(HDRS)  
      @echo " [CXX] $@"  
      @mkdir -p $(shell dirname $@)  
      @$(CXX) -c $< -o $@ $(CFLAGS) ${INCDIR}  
   
 install:  
      cp -rf ${TARGET} /usr/local/bin  
             
 clean:  
      rm -rf ${OBJSDIR}  
      rm -rf ${TARGET}  


Make (Build application, cần có các biến môi trường để chỉ dẫn đến thư viện là PATHLD_LIBRARY_PATH)
 [ninhld@localhost examples]$   
 [ninhld@localhost examples]$ export TAGLIBDIR=/home/ninhld/Documents/taglib_install  
 [ninhld@localhost examples]$ export PATH=$PATH:${TAGLIBDIR}/bin  
 [ninhld@localhost examples]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${TAGLIBDIR}/lib64  
 [ninhld@localhost examples]$   
 [ninhld@localhost examples]$   
 [ninhld@localhost examples]$ make  
  [CC]  build/tagreader_c.o  
  [LINK] tagreader  
 [ninhld@localhost examples]$     
 [ninhld@localhost examples]$ ldd tagreader  #kiểm tra các lib được dùng trong chương trình
      linux-vdso.so.1 => (0x00007fff7a8af000)  
      libtag.so.1 => /home/ninhld/Documents/taglib_install/lib64/libtag.so.1 (0x00007f72c4eb6000)  
      libtag_c.so.0 => /home/ninhld/Documents/taglib_install/lib64/libtag_c.so.0 (0x00007f72c4cb0000)  
      libstdc++.so.6 => /lib64/libstdc++.so.6 (0x0000003839a00000)  
      libm.so.6 => /lib64/libm.so.6 (0x000000382ae00000)  
      libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000382ca00000)  
      libc.so.6 => /lib64/libc.so.6 (0x0000003829e00000)  
      libz.so.1 => /lib64/libz.so.1 (0x000000382a600000)  
      /lib64/ld-linux-x86-64.so.2 (0x0000003829600000)  
 [ninhld@localhost examples]$   
 [ninhld@localhost examples]$   


Execute (Cũng cần có biến môi trường như khi buil app)
 [ninhld@localhost examples]$ export TAGLIBDIR=/home/ninhld/Documents/taglib_install  
 [ninhld@localhost examples]$ export PATH=$PATH:${TAGLIBDIR}/bin  
 [ninhld@localhost examples]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${TAGLIBDIR}/lib64  
 [ninhld@localhost examples]$  
 [ninhld@localhost examples]$ ./tagreader /home/ninhld/Music/hanh_phuc_neu_co_em.mp3   
 ******************** "/home/ninhld/Music/hanh_phuc_neu_co_em.mp3" ********************  
 -- TAG --  
 title  - "Hạnh Phúc Nếu Anh Có Em "  
 artist - "Phúc bồ "  
 album  - "mp3.zing.vn"  
 year  - "0"  
 comment - "Zing MP3 - Dinh cao am nhac"  
 track  - "0"  
 genre  - ""  
 -- AUDIO --  
 bitrate   - 128  
 sample rate - 44100  
 channels  - 2  
 length   - 3:05  
 [ninhld@localhost examples]$  


3. Cross compiling taglib-1.6.3 for Friendlyarm mini2440
Phần build sẽ thực hiện trên máy tính (host), còn khi chạy chương trình thì trên board nhúng. Các command sẽ được biểu diễn ngắn gọn vì nó tương tự như trên mục 2.
Nếu bạn không có board nhúng thì bạn chỉ cần thực hiện xong bước build là ok rồi.
Trước hết, download toolchain cho board Friendlyarm Mini2440 arm-linux-gcc; giải nén, copy thư mục FriendlyARM vào thư mục /opt.

Build taglib (on Host)
 export CC_PATH=/opt/FriendlyARM/toolschain/4.4.3  
 export PATH=$PATH:${CC_PATH}/bin  
 export CROSS_COMPILE=${CC_PATH}/bin/arm-none-linux-gnueabi-  
 export CC=${CROSS_COMPILE}gcc  
 export HOST=arm-none-linux-gnueabi  
 export BUILD=x86_64  
   
 export PREFIX=/home/ninhld/Documents/taglib_install_target  
 ./configure --prefix=$PREFIX --build=${BUILD} --host=${HOST}  
 make  
 make install  



tagreader_c.c (như mục 2)
Makefile
 .PHONY: all, install, clean  
   
 TARGET:=tagreader  
   
 HDRS+=  
 CSRCS+= tagreader_c.c  
 CPPSRCS+=  
   
 OBJSDIR=./build  
 OBJS:= $(patsubst %.cpp, $(OBJSDIR)/%.o, $(CPPSRCS))  
 OBJS+= $(patsubst %.c, $(OBJSDIR)/%.o, $(CSRCS))  
   
   
 INCDIR+= -I/home/ninhld/Documents/taglib_install_target/include \  
      -I/home/ninhld/Documents/taglib_install_target/include/taglib  
 CFLAGS += -DDEBUG -Wall -g  
 LDFLAGS += -L/home/ninhld/Documents/taglib_install_target/lib -ltag -ltag_c  
   
 CC=${CROSS_COMPILE}gcc  
 CXX=${CROSS_COMPILE}g++  
   
 all: ${TARGET}  
 ${TARGET} : $(OBJS)  
      @echo " [LINK] $@"  
      @mkdir -p $(shell dirname $@)  
      @$(CXX) $(OBJS) -o $@ $(LDFLAGS)  
        
 $(OBJSDIR)/%.o: %.c $(HDRS)  
      @echo " [CC]  $@"  
      @mkdir -p $(shell dirname $@)  
      @$(CC) -c $< -o $@ $(CFLAGS) ${INCDIR}  
   
 $(OBJSDIR)/%.o: %.cpp $(HDRS)  
      @echo " [CXX] $@"  
      @mkdir -p $(shell dirname $@)  
      @$(CXX) -c $< -o $@ $(CFLAGS) ${INCDIR}  
   
 install:  
      cp -rf ${TARGET} /usr/local/bin  
             
 clean:  
      rm -rf ${OBJSDIR}  
      rm -rf ${TARGET}  

Build application (on Host)
 export TAGLIBDIR=/home/ninhld/Documents/taglib_install_target 
 export PATH=$PATH:${TAGLIBDIR}/bin  
 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${TAGLIBDIR}/lib  
 make


Execute application (on board - Friendlyarm mini2440)
Để thực hiện được bước này, bạn cần biết cách setup board Mini2440 kết nối với máy tính như thế nào, điều khiển board qua chương trình minicom, bước này chỉ có ý nghĩ khi bạn đã xem các hướng dẫn trong phần FriendlyARM, nếu bạn chưa biết thì tạm thời tạm không thực hiện bước này.
Copy toàn bộ thư viện, file app, file nhạc để test vào thư mục taglib trên SDCARD. Khi Mini2440 hoạt động, SDCARD sẽ được mount vào thư mục /sdcard, vì vậy thư mục taglib trên SDCARD sẽ có đường dẫn là /sdcard/taglib



 export TAGLIBDIR=/sdcard/taglib  
 export PATH=$PATH:${TAGLIBDIR}/bin  
 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${TAGLIBDIR}/lib  
   
 cd /sdcard/taglib 
 ./tagreader /sdcard/taglib/hanh_phuc_neu_co_em.mp3  

******************** "/sdcard/taglib/hanh_phuc_neu_co_em.mp3" ********************
-- TAG --
title   - "H�á�º�¡nh Ph�Ã�ºc N�á�º�¿u Anh C�Ã�³ Em "
artist  - "Ph�Ã�ºc b�á�»��“ "
album   - "mp3.zing.vn"
year    - "0"
comment - "Zing MP3 - Dinh cao am nhac"
track   - "0"
genre   - ""
-- AUDIO --
bitrate     - 128
sample rate - 44100
channels    - 2
length      - 3:05



Note: Biến môi trường PATH và LD_LIBRARY_PATH là cực kỳ quan trọng, chúng luôn phải được sử dụng trong tất cả các quá trình từ build library, build application đến khi execute chương trình.

Monday, June 29, 2015

Display message or driver message - dmesg


Lệnh dmesg sẽ trace ra rất nhiều thông tin từ lúc hệ thống khởi động cho đến thời điểm hiện tại, các thông tin có thể là về kernel, device driver, ... hoặc các thành phần phần cứng.

 [ninhld@localhost docs]$ dmesg   
 [  0.000000] Initializing cgroup subsys cpuset  
 [  0.000000] Initializing cgroup subsys cpu  
 [  0.000000] Initializing cgroup subsys cpuacct  
 [  0.000000] Linux version 3.18.6-100.fc20.x86_64 (mockbuild@bkernel02.phx2.fedoraproject.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-7) (GCC) ) #1 SMP Fri Feb 6 22:55:01 UTC 2015  
 [  0.000000] Command line: BOOT_IMAGE=/vmlinuz-3.18.6-100.fc20.x86_64 root=UUID=e1f37513-df0d-4ca7-9ec4-c4c9987dbe60 ro vconsole.font=latarcyrheb-sun16 rhgb quiet LANG=en_US.UTF-8  
 [  0.000000] Disabled fast string operations  
 [  0.000000] e820: BIOS-provided physical RAM map:  
 [  0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009d7ff] usable  
 [  0.000000] BIOS-e820: [mem 0x000000000009d800-0x000000000009ffff] reserved  
 [  0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000fffff] reserved  
 [  0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000da99efff] usable  
 [  0.000000] BIOS-e820: [mem 0x00000000da99f000-0x00000000dae9efff] reserved  
 [  0.000000] BIOS-e820: [mem 0x00000000dae9f000-0x00000000daf9efff] ACPI NVS  
 [  0.000000] BIOS-e820: [mem 0x00000000daf9f000-0x00000000daffefff] ACPI data  
 [  0.000000] BIOS-e820: [mem 0x00000000dafff000-0x00000000daffffff] usable  
 [  0.000000] BIOS-e820: [mem 0x00000000db000000-0x00000000df9fffff] reserved  
 [  0.000000] BIOS-e820: [mem 0x00000000f8000000-0x00000000fbffffff] reserved  
 [  0.000000] BIOS-e820: [mem 0x00000000fec00000-0x00000000fec00fff] reserved  
 [  0.000000] BIOS-e820: [mem 0x00000000fed08000-0x00000000fed08fff] reserved  
 [  0.000000] BIOS-e820: [mem 0x00000000fed10000-0x00000000fed19fff] reserved  
 [  0.000000] BIOS-e820: [mem 0x00000000fed1c000-0x00000000fed1ffff] reserved  
 [  0.000000] BIOS-e820: [mem 0x00000000fee00000-0x00000000fee00fff] reserved  
 [  0.000000] BIOS-e820: [mem 0x00000000ffd20000-0x00000000ffffffff] reserved  
 [  0.000000] BIOS-e820: [mem 0x0000000100000000-0x000000011e5fffff] usable  
 [  0.000000] NX (Execute Disable) protection: active  
 [  0.000000] SMBIOS 2.6 present.  
 [  0.000000] DMI: LENOVO 4180AD9/4180AD9, BIOS 83ET61WW (1.31 ) 07/07/2011  
 [  0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved  
 ...  
 [  82.586529] Bluetooth: RFCOMM TTY layer initialized  
 [  82.586562] Bluetooth: RFCOMM socket layer initialized  
 [  82.587813] Bluetooth: RFCOMM ver 1.11  
 [  96.951311] SELinux: initialized (dev proc, type proc), uses genfs_contexts  
 [  98.859836] SELinux: initialized (dev proc, type proc), uses genfs_contexts  
   
   

Bởi vì lệnh dmesg trace thông tin từ dưới kernel nên nó rất hữu ích trong một số trường hợp như:
+ Xem thông tin về peripheral device mới kết nối vào hệ thống
+ Debug kernel khi viết driver (khi viết driver, muốn trace thông tin thì phải dùng lệnh printk, tuy nhiên lệnh in này sẽ không trace trực tiếp ra terminal mà phải dùng lệnh dmesg mới thấy được)

Ex:
Gắn một thiết bị USB-to-COM (dùng với minicom phục vụ debug board nhúng) vào máy tính và dùng lệnh dmesg sẽ được các thông tin như dưới, cái quan trong nhất là biết được device node của thiết bị là /dev/ttyUSB0


 [ 7377.063526] usb 1-1.1: new full-speed USB device number 6 using ehci-pci  
 [ 7377.149745] usb 1-1.1: New USB device found, idVendor=067b, idProduct=2303  
 [ 7377.149756] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0  
 [ 7377.149762] usb 1-1.1: Product: USB 2.0 To COM Device  
 [ 7377.149766] usb 1-1.1: Manufacturer: Prolific Technology Inc.  
 [ 7378.264479] usbcore: registered new interface driver pl2303  
 [ 7378.264505] usbserial: USB Serial support registered for pl2303  
 [ 7378.264534] pl2303 1-1.1:1.0: pl2303 converter detected  
 [ 7378.267971] usb 1-1.1: pl2303 converter now attached to ttyUSB0  

Xem thêm tại:
+ Link 1
Sunday, June 21, 2015

- Copyright © Lập trình hệ thống nhúng Linux . Powered by Luong Duy Ninh -