am7xxx: mention open_device() in the comment about scan_devices()
[libam7xxx.git] / HACKING.asciidoc
1 == Hacking libam7xxx
2
3 === Coding style
4
5 libam7xxx uses the linux kernel coding style:
6 http://kernel.org/doc/Documentation/CodingStyle
7
8 === Getting and compiling libam7xxx
9
10 libam7xxx depends on 'libusb-1.0' and optionally on 'libav' or 'ffmpeg' for
11 its example programs, the build system used is 'cmake'.
12
13 On a Debian based system, the dependencies can be installed with this command:
14
15   $ sudo aptitude install cmake \
16                           libusb-1.0-0-dev \
17                           libavformat-dev \
18                           libavcodec-dev \
19                           libavdevice-dev \
20                           libswscale-dev
21
22 With libav/ffmpeg version previous than 0.9 this patch is needed:
23 http://git.ao2.it/libam7xxx.git/blob_plain/refs/heads/debian:/debian/patches/0001-Revert-am7xxx-play-switch-to-avcodec_encode_video2.patch
24
25 The library and the example programs can be compiled following these steps:
26
27   $ git clone git://git.ao2.it/libam7xxx.git
28   $ cd libam7xxx
29   $ mkdir build
30   $ cd build
31   $ cmake ../
32   $ make
33
34 After that the example programs can be found in the +bin/+ subdirectory.
35
36 === Debug builds
37
38 The suggested way to hack on the project is:
39
40   $ mkdir build
41   $ cd build
42   $ cmake -D CMAKE_BUILD_TYPE=debug -D STRICT_COMPILATION_CHECKS=ON ../
43   $ make
44
45 If you want to check the code with the ''sparse'' static analysis tool you
46 can run:
47
48   $ mkdir build
49   $ cd build
50   $ cmake -D CMAKE_C_COMPILER=cgcc ../
51   $ make
52
53 And for a pre-release check with a different compiler, which never hurts:
54
55   $ mkdir build
56   $ cd build
57   $ cmake -D CMAKE_C_COMPILER=clang -D CMAKE_BUILD_TYPE=debug -D STRICT_COMPILATION_CHECKS=ON ../
58   $ make
59
60 === Cross Builds
61
62 If you want to build for MS Windows:
63
64   $ sudo aptitude install mingw-w64
65   $ mkdir build
66   $ cd build
67   $ wget -nv http://download.sourceforge.net/project/libusb/libusb-1.0/libusb-1.0.18/libusb-1.0.18-win.7z
68   $ 7z -olibusb-1.0.18-win x libusb-1.0.18-win.7z
69   $ wget -nv http://win32.libav.org/releases/libav-10.1-win32.7z
70   $ 7z -olibav-10.1-win32 x libav-10.1-win32.7z
71   $ cmake  \
72           -D GNU_HOST=i686-w64-mingw32 \
73           -D CMAKE_TOOLCHAIN_FILE=../cmake_modules/mingw_cross_toolchain.cmake \
74           -D CMAKE_INSTALL_PREFIX=libam7xxx-win/ \
75           -D LIBUSB_1_INCLUDE_DIR=libusb-1.0.18-win/include/libusb-1.0 \
76           -D LIBUSB_1_LIBRARY=libusb-1.0.18-win/MinGW32/dll/libusb-1.0.dll \
77           -D FFMPEG_ROOT=$(pwd)/libav-10.1-win32/win32/usr \
78           ../
79   $ make
80
81 After that you will find libam7xxx.dll in lib/ and picoproj.exe in the bin/
82 directory.
83
84 === Valgrind
85
86 You can run the test program under the http://valgrind.org/[valgrind]
87 dynamic analyzer by using a command like:
88
89   $ valgrind --leak-check=full --show-reachable=yes --track-origins=yes \
90     ./bin/picoproj -W 800 -H 480 -f my_image.jpg
91
92 or, for am7xxx-play:
93
94   $ valgrind --leak-check=full --show-reachable=yes --track-origins=yes \
95     ./bin/am7xxx-play -f x11grab -i :0