blob: f4bf8dbb1b130463d3b90fcf4a87ccf0060e2898 [file] [log] [blame]
Benny Prijono9033e312005-11-21 02:08:39 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJ_DOXYGEN_H__
20#define __PJ_DOXYGEN_H__
21
22/**
23 * @file doxygen.h
24 * @brief Doxygen's mainpage.
25 */
26
27/*////////////////////////////////////////////////////////////////////////// */
28/*
29 INTRODUCTION PAGE
30 */
31
32/**
33 * @mainpage Welcome to PJLIB!
34 *
35 * @section intro_sec What is PJLIB
36 *
37 * PJLIB is a small foundation library written in C for making scalable
38 * applications. Because of its small footprint, it can be used in embedded
39 * applications (we hope so!), but yet the library is also aimed for
40 * facilitating high performance protocol stacks.
41 *
42 * PJLIB is released under LGPL terms.
43 *
44 * @section download_sec Download
45 *
46 * PJLIB and all documentation can be downloaded from
47 * http://www.pjproject.net.
48 *
49 *
50 * @section how_to_use_sec About This Documentation
51 *
52 * This document is generated directly from PJLIB source file using
53 * \a doxygen (http://www.doxygen.org). Doxygen is a great (and free!)
54 * tools for generating such documentation.
55 *
56 * @subsection doc_ver_subsec Version
57 *
58 * This document corresponds to PJLIB version 0.3-pre2.
59 *
60 *
61 * @subsection find_samples_subsec How to Read This Document
62 *
63 * This documentation is laid out more to be a reference guide instead
64 * of tutorial, therefore first time users may find it difficult to
65 * grasp PJLIB by reading this document alone.
66 *
67 * However, we've tried our best to make this document easy to follow.
68 * For first time users, we would suggest that you follow these steps
69 * when reading this documentation:
70 *
71 * - continue reading this introduction chapter. At the end of this
72 * chapter, you'll find section called \ref pjlib_fundamentals_sec
73 * which should guide you to understand basic things about PJLIB.
74 *
75 * - find information about specific features that you want to use
76 * in PJLIB. Use the <b>Module Index</b> to find out about all
77 * features in PJLIB (if you're browsing the HTML documentation,
78 * click on the \a Module link on top of the page, or if you're
79 * reading the PDF documentation, click on \a Module \a Documentation
80 * on the navigation pane on the left).
81 *
82 * @subsection doc_organize_sec How To's
83 *
84 * Please find below links to specific tasks that you probably
85 * want to do:
86 *
87 * - <b>How to Build PJLIB</b>
88 *\n
89 * Please refer to \ref pjlib_build_sys_pg page for more information.
90 *
91 * - <b>How to Use PJLIB in My Application</b>
92 *\n
93 * Please refer to \ref configure_app_sec for more information.
94 *
95 * - <b>How to Port PJLIB</b>
96 *\n
97 * Please refer to \ref porting_pjlib_pg page.
98 *
99 * - <b>Where to Read Samples Documentation</b>
100 *\n
101 * Most of the modules provide link to the corresponding sample file.
102 * Alternatively, to get the list of all examples, you can click on
103 * <b>Related Pages</b> on the top of HTML document or on
104 * <b>PJLIB Page Documentation</b> on navigation pane of your PDF reader.
105 *
106 * - <b>How to Submit Code to PJLIB Project</b>
107 *\n
108 * Please read \ref pjlib_coding_convention_page before submitting
109 * your code. Send your code as patch against current Subversion tree
110 * to the appropriate mailing list.
111 *
112 *
113 * @section features_sec Features
114 *
115 * @subsection open_source_feat It's Open Source!
116 *
117 * PJLIB is currently released on LGPL license. We may release PJLIB under
118 * additional schemes in the future (such as GPL or MPL) to incorporate
119 * linking with specific application, however, one thing for sure is
120 * we will NEVER be able to make PJLIB a proprietary software.
121 *
122 * @subsection extreme_portable_feat Extreme Portability
123 *
124 * PJLIB is designed to be extremely portable. It can run on any kind
125 * of processors (16-bit, 32-bit, or 64-bit, big or little endian, single
126 * or multi-processors) and operating systems. Floating point or no
127 * floating point. Multi-threading or not.
128 * It can even run in environment where no ANSI LIBC is available.
129 *
130 * Currently PJLIB is being ported to:
131 * - x86, Win32 (Win95/98/ME, NT/2000/XP/2003, mingw).
132 * - x86, Linux (user mode and as <b>kernel module</b>(!)).
133 * - alpha, Linux
134 * And coming up:
135 * - x86, eCos
136 * - ultra-II, Solaris.
137 * - powerpc, MacOS
138 * - m68k, PalmOS.
139 * - arm, PocketPC
140 *
141 * No other library is known to have this extreme portability!
142 *
143 * @subsection small_size_feat Small in Size
144 *
145 * One of the primary objectives is to have library that is small in size for
146 * typical embedded applications. As a rough guidance, we aim to keep the
147 * library size below 100KB for it to be considered as small.
148 * As the result, most of the functionalities in the library can be tailored
149 * to meet the requirements; user can enable/disable specific functionalities
150 * to get the desired size/performance/functionality balance.
151 *
152 * For more info, please see @ref pj_config.
153 *
154 * @subsection no_dyn_mem No Dynamic Memory Allocations
155 *
156 * The central idea of PJLIB is that for applications to run as fast as it can,
157 * it should not use \a malloc() at all, but instead should get the memory
158 * from a preallocated storage pool. There are few things that can be
159 * optimized with this approach:
160 *
161 * - \a alloc() is a O(1) operation.
162 * - no mutex is used inside alloc(). It is assumed that synchronization
163 * will be used in higher abstraction by application anyway.
164 * - no \a free() is required. All chunks will be deleted when the pool is
165 * destroyed.
166 *
167 * The performance gained on some systems can be as high as 10x speed up
168 * against \a malloc() and \a free().
169 *
170 * For more information, see \ref PJ_POOL_GROUP
171 *
172 *
173 * @subsection os_abstract_feat Operating System Abstraction
174 *
175 * PJLIB has abstractions for features that are normally not portable
176 * across operating systems:
177 * - @ref PJ_THREAD
178 *\n
179 * Portable thread manipulation.
180 * - @ref PJ_TLS
181 *\n
182 * Storing data in thread's private data.
183 * - @ref PJ_MUTEX
184 *\n
185 * Mutual exclusion protection.
186 * - @ref PJ_SEM
187 *\n
188 * Semaphores.
189 * - @ref PJ_ATOMIC
190 *\n
191 * Atomic variables and their operations.
192 * - @ref PJ_CRIT_SEC
193 *\n
194 * Fast locking of critical sections.
195 * - @ref PJ_LOCK
196 *\n
197 * High level abstraction for lock objects.
198 * - @ref PJ_EVENT
199 *\n
200 * Event object.
201 * - @ref PJ_TIME
202 *\n
203 * Portable time manipulation.
204 * - @ref PJ_TIMESTAMP
205 *\n
206 * High resolution time value.
207 * - etc.
208 *
209 *
210 * @subsection ll_network_io_sec Low-Level Network I/O
211 *
212 * PJLIB has very portable abstraction and fairly complete set of API for
213 * doing network I/O communications. At the lowest level, PJLIB provides:
214 *
215 * - @ref PJ_SOCK
216 *\n
217 * A highly portable socket abstraction, runs on all kind of
218 * network APIs such as standard BSD socket, Windows socket, Linux
219 * \b kernel socket, PalmOS networking API, etc.
220 *
221 * - @ref pj_addr_resolve
222 *\n
223 * Portable address resolution, which implements #pj_gethostbyname().
224 *
225 * - @ref PJ_SOCK_SELECT
226 *\n
227 * A portable \a select() like API (#pj_sock_select()) which can be
228 * implemented with various back-end.
229 *
230 *
231 * @subsection hl_network_io_sec High-Level Network I/O
232 *
233 * At higher abstraction, PJLIB provides @ref PJ_IOQUEUE,
234 * which promotes creating high performance network
235 * applications by managing asynchronous I/O. This is a passive framework
236 * that utilizes the most effective way to manage asynchronous I/O
237 * on a given platform, such as:
238 * - IoCompletionPort on WinNT,
239 * - on Linux it can use either /dev/epoll or aio.
240 * - or to fall back to use @a select()
241 *
242 * At even a higher abstraction, PJLIB provides @ref PJ_EQUEUE, which
243 * combines asynchronous I/O with timer management and thread management
244 * to fasilitate creating trully high performance, event driven
245 * application.
246 *
247 *
248 * @subsection timer_mgmt_sec Timer Management
249 *
250 * A passive framework for managing timer, see @ref PJ_TIMER for more info.
251 * There is also function to retrieve high resolution timestamp
252 * from the system (see @ref PJ_TIMESTAMP).
253 *
254 *
255 * @subsection data_struct_sec Various Data Structures
256 *
257 * Various data structures are provided in the library:
258 *
259 * - @ref PJ_PSTR
260 * - @ref PJ_ARRAY
261 * - @ref PJ_HASH
262 * - @ref PJ_LIST
263 * - @ref PJ_RBTREE
264 *
265 *
266 * @subsection exception_sec Exception Construct
267 *
268 * A convenient TRY/CATCH like construct to propagate errors, which by
269 * default are used by the @ref PJ_POOL_GROUP "memory pool" and
270 * the lexical scanner in pjlib-util. The exception
271 * construct can be used to write programs like below:
272 *
273 * <pre>
274 * #define SYNTAX_ERROR 1
275 *
276 * PJ_TRY {
277 * msg = NULL;
278 * msg = parse_msg(buf, len);
279 * }
280 * PJ_CATCH ( SYNTAX_ERROR ) {
281 * .. handle error ..
282 * }
283 * PJ_END;
284 * </pre>
285 *
286 * Please see @ref PJ_EXCEPT for more information.
287 *
288 *
289 * @subsection logging_sec Logging Facility
290 *
291 * PJLIB @ref PJ_LOG consists of macros to write logging information to
292 * some output device. Some of the features of the logging facility:
293 *
294 * - the verbosity can be fine-tuned both at compile time (to control
295 * the library size) or run-time (to control the verbosity of the
296 * information).
297 * - output device is configurable (e.g. stdout, printk, file, etc.)
298 * - log decoration is configurable.
299 *
300 * See @ref PJ_LOG for more information.
301 *
302 *
303 * @subsection guid_gen_sec Random and GUID Generation
304 *
305 * PJLIB provides facility to create random string
306 * (#pj_create_random_string()) or globally unique identifier
307 * (see @ref PJ_GUID).
308 *
309 *
310 *
311 * @section configure_app_sec Configuring Application to use PJLIB
312 *
313 * @subsection pjlib_compil_sec Building PJLIB
314 *
315 * Follow the instructions in \ref pjlib_build_sys_pg to build
316 * PJLIB.
317 *
318 * @subsection pjlib_compil_app_sec Building Applications with PJLIB
319 *
320 * Use the following settings when building applications with PJLIB.
321 *
322 * @subsubsection compil_inc_dir_sec Include Search Path
323 *
324 * Add this to your include search path ($PJLIB is PJLIB root directory):
325 * <pre>
326 * $PJLIB/include
327 * </pre>
328 *
329 * @subsubsection compil_inc_file_sec Include PJLIB Header
330 *
331 * To include all PJLIB headers:
332 * \verbatim
333 #include <pjlib.h>
334 \endverbatim
335 *
336 * Alternatively, you can include individual PJLIB headers like this:
337 * \verbatim
338 #include <pj/log.h>
339 #include <pj/os.h>
340 \endverbatim
341 *
342 *
343 * @subsubsection compil_lib_dir_sec Library Path
344 *
345 * Add this to your library search path:
346 * <pre>
347 * $PJLIB/lib
348 * </pre>
349 *
350 * Then add the appropriate PJLIB library to your link specification. For
351 * example, you would add \c libpj-i386-linux-gcc.a when you're building
352 * applications in Linux.
353 *
354 *
355 * @subsection pjlib_fundamentals_sec Principles in Using PJLIB
356 *
357 * Few things that you \b MUST do when using PJLIB, to make sure that
358 * you create trully portable applications.
359 *
360 * @subsubsection call_pjlib_init_sec Call pj_init()
361 *
362 * Before you do anything else, call \c pj_init(). This would make sure that
363 * PJLIB system is properly set up.
364 *
365 * @subsubsection no_ansi_subsec Do NOT Use ANSI C
366 *
367 * Contrary to popular teaching, ANSI C (and LIBC) is not the most portable
368 * library in the world, nor it's the most ubiquitous. For example, LIBC
369 * is not available in Linux kernel. Also normally LIBC will be excluded
370 * from compilation of RTOSes to reduce size.
371 *
372 * So for maximum portability, do NOT use ANSI C. Do not even try to include
373 * any other header files outside <include/pj>. Stick with the functionalities
374 * provided by PJLIB.
375 *
376 *
377 * @subsubsection string_rep_subsubsec Use pj_str_t instead of C Strings
378 *
379 * PJLIB uses pj_str_t instead of normal C strings. You SHOULD follow this
380 * convention too. Remember, ANSI string-h is not always available. And
381 * PJLIB string is faster!
382 *
383 * @subsubsection mem_alloc_subsubsec Use Pool for Memory Allocations
384 *
385 * You MUST NOT use \a malloc() or any other memory allocation functions.
386 * Use PJLIB pool instead! It's faster and most portable.
387 *
388 * @subsection logging_subsubsec Use Logging for Text Display
389 *
390 * DO NOT use <stdio.h> for text output. Use PJLIB logging instead.
391 *
392 *
393 * @section porting_pjlib_sec0 Porting PJLIB
394 *
395 * Please see \ref porting_pjlib_pg page on more information to port
396 * PJLIB to new target.
397 *
398 * @section enjoy_sec Enjoy Using PJLIB!
399 *
400 * We hope that you find PJLIB usefull for your application. If you
401 * have any questions, suggestions, critics, bug fixes, or anything
402 * else, we would be happy to hear it.
403 *
404 * Enjoy using PJLIB!
405 *
406 * Benny Prijono < bennylp at pjproject dot net >
407 */
408
409
410
411/*////////////////////////////////////////////////////////////////////////// */
412/*
413 CODING CONVENTION
414 */
415
416/**
417 * @page pjlib_coding_convention_page Coding Convention
418 *
419 * Before you submit your code/patches to be included with PJLIB, you must
420 * make sure that your code is compliant with PJLIB coding convention.
421 * <b>This is very important!</b> Otherwise we would not accept your code.
422 *
423 * @section coding_conv_editor_sec Editor Settings
424 *
425 * The single most important thing in the whole coding convention is editor
426 * settings. It's more important than the correctness of your code (bugs will
427 * only crash the system, but incorrect tab size is mental!).
428 *
429 * Kindly set your editor as follows:
430 * - tab size to \b 8.
431 * - indentation to \b 4.
432 *
433 * With \c vi, you can do it with:
434 * <pre>
435 * :se ts=8
436 * :se sts=4
437 * </pre>
438 *
439 * You should replace tab with eight spaces.
440 *
441 * @section coding_conv_detail_sec Coding Style
442 *
443 * Coding style MUST strictly follow K&R style. The rest of coding style
444 * must follow current style. You SHOULD be able to observe the style
445 * currently used by PJLIB from PJLIB sources, and apply the style to your
446 * code. If you're not able to do simple thing like to observe PJLIB
447 * coding style from the sources, then logic dictates that your ability to
448 * observe more difficult area in PJLIB such as memory allocation strategy,
449 * concurrency, etc is questionable.
450 *
451 * @section coding_conv_comment_sec Commenting Your Code
452 *
453 * Public API (e.g. in header files) MUST have doxygen compliant comments.
454 *
455 */
456
457
458/*////////////////////////////////////////////////////////////////////////// */
459/*
460 BUILDING AND INSTALLING PJLIB
461 */
462
463
464
465/**
466 * @page pjlib_build_sys_pg Building, and Installing PJLIB
467 *
468 * @section build_sys_install_sec Build and Installation
469 *
470 * @subsection build_sys_install_win32_sec Visual Studio
471 *
472 * The PJLIB Visual Studio workspace supports the building of PJLIB
473 * for Win32 target. Although currently only the Visual Studio 6 Workspace is
474 * actively maintained, developers with later version of Visual Studio
475 * can easily imports VS6 workspace into their IDE.
476 *
477 * To start building PJLIB projects with Visual Studio 6 or later, open
478 * the \a workspace file in the corresponding \b \c build directory. You have
479 * several choices on which \a dsw file to open:
480 \verbatim
481 $PJPROJECT/build/pjproject.dsw
482 $PJPROJECT/pjlib/build/pjlib.dsw
483 $PJPROJECT/pjsip/build/pjsip.dsw
484 ..etc
485 \endverbatim
486 *
487 * The easiest way is to open <tt>pjproject.dsw</tt> file in \b \c $PJPROJECT/build
488 * directory. However this will only build the required projects, not
489 * the complete projects. For example, the PJLIB test and samples projects
490 * are not included in this workspace. To build the complete projects, you must
491 * open and build each \a dsw file in \c build directory in each
492 * subprojects. For example, to open the complete PJLIB workspace, open
493 * <tt>pjlib.dsw</tt> in <tt>$PJPROJECT/pjlib/build</tt> directory.
494 *
495 *
496 * @subsubsection config_site_create_vc_sec Create config_site.h
497 *
498 * The file <tt><b>$PJPROJECT/pjlib/include/pj/config_site.h</b></tt>
499 * is supposed to contain configuration that is specific to your site/target.
500 * This file is not part of PJLIB, so you must create it yourself. Normally
501 * you just need to create a blank file.
502 *
503 * The reason why it's not included in PJLIB is so that you would not accidently
504 * overwrite your site configuration.
505 *
506 * If you fail to do this, Visual C will complain with error like:
507 *
508 * <b>"fatal error C1083: Cannot open include file: 'pj/config_site.h': No such file
509 * or directory"</b>.
510 *
511 * @subsubsection build_vc_subsubsec Build the Projects
512 *
513 * Just hit the build button!
514 *
515 *
516 * @subsection build_sys_install_unix_sec Make System
517 *
518 * For other targets, PJLIB provides a rather comprehensive build system
519 * that uses GNU \a make (and only GNU \a make will work).
520 * Currently, the build system supports building * PJLIB for these targets:
521 * - i386/Win32/mingw
522 * - i386/Linux
523 * - i386/Linux (kernel)
524 * - alpha/linux
525 * - sparc/SunOS
526 * - etc..
527 *
528 *
529 * @subsubsection build_req_sec Requirements
530 *
531 * In order to use the \c make based build system, you MUST have:
532 *
533 * - <b>GNU make</b>
534 *\n
535 * The Makefiles heavily utilize GNU make commands which most likely
536 * are not available in other \c make system.
537 * - <b>bash</b> shell is recommended.
538 *\n
539 * Specificly, there is a command <tt>"echo -n"</tt> which may not work
540 * in other shells. This command is used when generating dependencies
541 * (<tt>make dep</tt>) and it's located in
542 * <tt>$PJPROJECT/build/rules.mak</tt>.
543 * - <b>ar</b>, <b>ranlib</b> from GNU binutils
544 *\n
545 * In your system has different <tt>ar</tt> or <tt>ranlib</tt> (e.g. they
546 * may have been installed as <tt>gar</tt> and <tt>granlib</tt>), then
547 * either you create the relevant symbolic links, <b>or</b> modify
548 * <tt>$PJPROJECT/build/cc-gcc.mak</tt> and rename <tt>ar</tt> and
549 * <tt>ranlib</tt> to the appropriate names.
550 * - <b>gcc</b> to generate dependency.
551 *\n
552 * Currently the build system uses <tt>"gcc -MM"</tt> to generate build
553 * dependencies. If <tt>gcc</tt> is not desired to generate dependency,
554 * then either you don't run <tt>make dep</tt>, <b>or</b> edit
555 * <tt>$PJPROJECT/build/rules.mak</tt> to calculate dependency using
556 * your prefered method. (And let me know when you do so so that I can
557 * update the file. :) )
558 *
559 * @subsubsection build_overview_sec Building the Project
560 *
561 * Generally, steps required to build the PJLIB are:
562 *
563 \verbatim
564 $ cd /home/user/pjproject # <-- go to $PJPROJECT
565 $ vi build.mak # <-- set build target etc
566 $ touch pjlib/include/pj/config_site.h
567 $ cd pjlib/build # <-- go to projet's build dir
568 $ make # <-- build the project
569 \endverbatim
570 *
571 * For other project, \a cd to <tt>build</tt> directory in the project
572 * and execute \a make from there.
573 *
574 * \note For Linux kernel target, there are additional steps required, which
575 * will be explained in section \ref linux_kern_target_subsec.
576 *
577 * @subsubsection build_mak_sec Editing build.mak
578 *
579 * The \c build.mak file in \c $PJPROJECT root directory is used to
580 * specify the build configuration. This file is expected to export
581 * the following \a make variables:
582 *
583 * - <tt><b>MACHINE_NAME</b></tt>
584 *\n
585 * Target machine/processor, one of: <b>{ i386 | alpha | sparc }</b>.
586 *
587 * - <tt><b>OS_NAME</b></tt>
588 *\n
589 * Target operating system, one of: <b>{ win32 | linux |
590 * linux-kernel | sunos }</b>.
591 *
592 * - <tt><b>CC_NAME</b></tt>
593 *\n
594 * Compiler name: <b>{ gcc | vc }</b>\n
595 * (Note that support for Visual C (vc) compiler with the \c make system is
596 * experimental, and it will only work when run inside a DOS shell
597 * (i.e. <tt>"HOST_NAME=win32"</tt>)).
598 *
599 * - <tt><b>HOST_NAME</b></tt>
600 *\n
601 * Build host: <b>{ unix | mingw | win32 }</b>\n
602 * (Note: win32 host means a DOS command prompt. Support for this type
603 * of development host is experimental).
604 *
605 * These variables will cause the correct configuration file in
606 * \c $PJPROJECT/build directory to be executed by \a make. For
607 * example, specifying \c OS_NAME=linux will cause file \c os-linux.mak
608 * in \c build directory to be executed. These files contain specific
609 * configuration for the option that is selected.
610 *
611 * For Linux kernel target, you are also required to declare the following
612 * variables in this file:
613 * - \c KERNEL_DIR: full path of kernel source tree.
614 * - \c KERNEL_ARCH: kernel ARCH options (e.g. "ARCH=um"), or leave blank
615 * for default.
616 * - \c PJPROJECT_DIR: full path of PJPROJECT source tree.
617 *
618 * Apart from these, there are also additional steps required to build
619 * Linux kernel target, which will be explained in \ref linux_kern_target_subsec.
620 *
621 * @subsubsection build_dir_sec Files in "build" Directory
622 *
623 * The <tt>*.mak</tt> files in \c $PJPROJECT/build directory are used to specify
624 * the configuration for the specified compiler, target machine target
625 * operating system, and host options. These files will be executed
626 * (included) by \a make during building process, depending on the values
627 * specified in <b>$PJPROJECT/build.mak</b> file.
628 *
629 * Normally you don't need to edit these files, except when you're porting
630 * PJLIB to new target.
631 *
632 * Below are the description of some files in this directory:
633 *
634 * - <tt>rules.mak</tt>: contains generic rules always included during make.
635 * - <tt>cc-gcc.mak</tt>: rules when gcc is used for compiler.
636 * - <tt>cc-vc.mak</tt>: rules when MSVC compiler is used.
637 * - <tt>host-mingw.mak</tt>: rules for building in mingw host.
638 * - <tt>host-unix.mak</tt>: rules for building in Unix/Posix host.
639 * - <tt>host-win32.mak</tt>: rules for building in Win32 command console
640 * (only valid when VC is used).
641 * - <tt>m-i386.mak</tt>: rules when target machine is an i386 processor.
642 * - <tt>m-m68k.mak</tt>: rules when target machine is an m68k processor.
643 * - <tt>os-linux.mak</tt>: rules when target OS is Linux.
644 * - <tt>os-linux-kernel.mak</tt>: rules when PJLIB is to be build as
645 * part of Linux kernel.
646 * - <tt>os-win32.mak</tt>: rules when target OS is Win32.
647 *
648 *
649 * @subsubsection config_site_create_sec Create config_site.h
650 *
651 * The file <tt><b>$PJPROJECT/pjlib/include/pj/config_site.h</b></tt>
652 * is supposed to contain configuration that is specific to your site/target.
653 * This file is not part of PJLIB, so you must create it yourself.
654 *
655 * The reason why it's not included in PJLIB is so that you would not accidently
656 * overwrite your site configuration.
657 *
658 *
659 * @subsubsection invoking_make_sec Invoking make
660 *
661 * Normally, \a make is invoked in \c build directory under each project.
662 * For example, to build PJLIB, you would invoke \a make in
663 * \c $PJPROJECT/pjlib/build directory like below:
664 *
665 \verbatim
666 $ cd pjlib/build
667 $ make
668 \endverbatim
669 *
670 * Alternatively you may invoke <tt>make</tt> in <tt>$PJPROJECT</tt>
671 * directory, to build all projects under that directory (e.g.
672 * PJLIB, PJSIP, etc.).
673 *
674 *
675 * @subsubsection linux_kern_target_subsec Linux Kernel Target
676 *
677 * \note
678 * <b>BUILDING APPLICATIONS IN LINUX KERNEL MODE IS A VERY DANGEROUS BUSINESS.
679 * YOU MAY CRASH THE WHOLE OF YOUR SYSTEM, CORRUPT YOUR HARDISK, ETC. PJLIB
680 * KERNEL MODULES ARE STILL IN EXPERIMENTAL PHASE. DO NOT RUN IT IN PRODUCTION
681 * SYSTEMS OR OTHER SYSTEMS WHERE RISK OF LOSS OF DATA IS NOT ACCEPTABLE.
682 * YOU HAVE BEEN WARNED.</b>
683 *
684 * \note
685 * <b>User Mode Linux (UML)</b> provides excellent way to experiment with Linux
686 * kernel without risking the stability of the host system. See
687 * http://user-mode-linux.sourceforge.net for details.
688 *
689 * \note
690 * I only use <b>UML</b> to experiment with PJLIB kernel modules.
691 * <b>I wouldn't be so foolish to use my host Linux machine to experiment
692 * with this.</b>
693 *
694 * \note
695 * You have been warned.
696 *
697 * For building PJLIB for Linux kernel target, there are additional steps required.
698 * In general, the additional tasks are:
699 * - Declare some more variables in <b><tt>build.mak</tt></b> file (this
700 * has been explained in \ref build_mak_sec above).
701 * - Perform these two small modifications in kernel source tree.
702 *
703 * There are two small modification need to be applied to the kernel tree.
704 *
705 * <b>1. Edit <tt>Makefile</tt> in kernel root source tree.</b>
706 *
707 * Add the following lines at the end of the <tt>Makefile</tt> in your
708 * <tt>$KERNEL_SRC</tt> dir:
709 \verbatim
710script:
711 $(SCRIPT)
712 \endverbatim
713 *
714 * \note Remember to replace spaces with <b>tab</b> in the Makefile.
715 *
716 * The modification above is needed to capture kernel's \c $CFLAGS and
717 * \c $CFLAGS_MODULE which will be used for PJLIB's compilation.
718 *
719 * <b>2. Add Additional Exports.</b>
720 *
721 * We need the kernel to export some more symbols for our use. So we declare
722 * the additional symbols to be exported in <tt>extra-exports.c</tt> file, and add
723 * a this file to be compiled into the kernel:
724 *
725 * - Copy the file <tt>extra-exports.c</tt> from <tt>pjlib/src/pj</tt>
726 * directory to <tt>$KERNEL_SRC/kernel/</tt> directory.
727 * - Edit <tt>Makefile</tt> in that directory, and add this line
728 * somewhere after the declaration of that variable:
729 \verbatim
730obj-y += extra-exports.o
731 \endverbatim
732 *
733 * To illustrate what have been done in your kernel source tree, below
734 * is screenshot of my kernel source tree _after_ the modification.
735 *
736 \verbatim
737[root@vpc-linux linux-2.6.7]# pwd
738/usr/src/linux-2.6.7
739[root@vpc-linux linux-2.6.7]#
740[root@vpc-linux linux-2.6.7]#
741[root@vpc-linux linux-2.6.7]# tail Makefile
742
743endif # skip-makefile
744
745FORCE:
746
747.PHONY: script
748
749script:
750 $(SCRIPT)
751
752[root@vpc-linux linux-2.6.7]#
753[root@vpc-linux linux-2.6.7]#
754[root@vpc-linux linux-2.6.7]# head kernel/extra-exports.c
755#include <linux/module.h>
756#include <linux/syscalls.h>
757
758EXPORT_SYMBOL(sys_select);
759
760EXPORT_SYMBOL(sys_epoll_create);
761EXPORT_SYMBOL(sys_epoll_ctl);
762EXPORT_SYMBOL(sys_epoll_wait);
763
764EXPORT_SYMBOL(sys_socket);
765[root@vpc-linux linux-2.6.7]#
766[root@vpc-linux linux-2.6.7]#
767[root@vpc-linux linux-2.6.7]# head -15 kernel/Makefile
768#
769# Makefile for the linux kernel.
770#
771
772obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
773 exit.o itimer.o time.o softirq.o resource.o \
774 sysctl.o capability.o ptrace.o timer.o user.o \
775 signal.o sys.o kmod.o workqueue.o pid.o \
776 rcupdate.o intermodule.o extable.o params.o posix-timers.o \
777 kthread.o
778
779obj-y += extra-exports.o
780
781obj-$(CONFIG_FUTEX) += futex.o
782obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
783[root@vpc-linux linux-2.6.7]#
784
785 \endverbatim
786 *
787 * Then you must rebuild the kernel.
788 * If you fail to do this, you won't be able to <b>insmod</b> pjlib.
789 *
790 * \note You will see a lots of warning messages during pjlib-test compilation.
791 * The warning messages complain about unresolved symbols which are defined
792 * in pjlib module. You can safely ignore these warnings. However, you can not
793 * ignore warnings about non-pjlib unresolved symbols.
794 *
795 *
796 * @subsection makefile_explained_sec Makefile Explained
797 *
798 * The \a Makefile for each project (e.g. PJLIB, PJSIP, etc) should be
799 * very similar in the contents. The Makefile is located under \c build
800 * directory in each project subdir.
801 *
802 * @subsubsection pjlib_makefile_subsec PJLIB Makefile.
803 *
804 * Below is PJLIB's Makefile:
805 *
806 * \include build/Makefile
807 *
808 * @subsubsection pjlib_os_makefile_subsec PJLIB os-linux.mak.
809 *
810 * Below is file <tt><b>os-linux.mak</b></tt> file in
811 * <tt>$PJPROJECT/pjlib/build</tt> directory,
812 * which is OS specific configuration file for Linux target that is specific
813 * for PJLIB project. For \b global OS specific configuration, please see
814 * <tt>$PJPROJECT/build/os-*.mak</tt>.
815 *
816 * \include build/os-linux.mak
817 *
818 */
819
820
821/*////////////////////////////////////////////////////////////////////////// */
822/*
823 PORTING PJLIB
824 */
825
826
827
828/**
829 * @page porting_pjlib_pg Porting PJLIB
830 *
831 *
832 * @section new_arch_sec Porting to New CPU Architecture
833 *
834 * Below is step-by-step guide to add support for new CPU architecture.
835 * This sample is based on porting to Alpha architecture; however steps for
836 * porting to other CPU architectures should be pretty similar.
837 *
838 * Also note that in this example, the operating system used is <b>Linux</b>.
839 * Should you wish to add support for new operating system, then follow
840 * the next section \ref porting_os_sec.
841 *
842 * Step-by-step guide to port to new CPU architecture:
843 * - decide the name for the new architecture. In this case, we choose
844 * <tt><b>alpha</b></tt>.
845 * - edit file <tt>$PJPROJECT/build.mak</tt>, and add new section for
846 * the new target:
847 * <pre>
848 * #
849 * # Linux alpha, gcc
850 * #
851 * export MACHINE_NAME := <b>alpha</b>
852 * export OS_NAME := linux
853 * export CC_NAME := gcc
854 * export HOST_NAME := unix
855 * </pre>
856 *
857 * - create a new file <tt>$PJPROJECT/build/<b>m-alpha</b>.mak</tt>.
858 * Alternatively create a copy from other file in this directory.
859 * The contents of this file will look something like:
860 * <pre>
861 * export M_CFLAGS := $(CC_DEF)<b>PJ_M_ALPHA=1</b>
862 * export M_CXXFLAGS :=
863 * export M_LDFLAGS :=
864 * export M_SOURCES :=
865 * </pre>
866 * - create a new file <tt>$PJPROJECT/pjlib/include/pj/compat/<b>m_alpha.h</b></tt>.
867 * Alternatively create a copy from other header file in this directory.
868 * The contents of this file will look something like:
869 * <pre>
870 * #define PJ_HAS_PENTIUM 0
871 * #define PJ_IS_LITTLE_ENDIAN 1
872 * #define PJ_IS_BIG_ENDIAN 0
873 * </pre>
874 * - edit <tt>pjlib/include/pj/<b>config.h</b></tt>. Add new processor
875 * configuration in this header file, like follows:
876 * <pre>
877 * ...
878 * #elif defined (PJ_M_ALPHA) && PJ_M_ALPHA != 0
879 * # include <pj/compat/m_alpha.h>
880 * ...
881 * </pre>
882 * - done. Build PJLIB with:
883 * <pre>
884 * $ cd $PJPROJECT/pjlib/build
885 * $ make dep
886 * $ make clean
887 * $ make
888 * </pre>
889 *
890 * @section porting_os_sec Porting to New Operating System Target
891 *
892 * This section will try to give you rough guideline on how to
893 * port PJLIB to a new target. As a sample, we give the target a name tag,
894 * for example <tt><b>xos</b></tt> (for X OS).
895 *
896 * @subsection new_compat_os_h_file_sec Create New Compat Header File
897 *
898 * You'll need to create a new header file
899 * <b><tt>include/pj/compat/os_xos.h</tt></b>. You can copy as a
900 * template other header file and edit it accordingly.
901 *
902 * @subsection modify_config_h_file_sec Modify config.h
903 *
904 * Then modify file <b><tt>include/pj/config.h</tt></b> to include
905 * this file accordingly (e.g. when macro <tt><b>PJ_XOS</b></tt> is
906 * defined):
907 *
908 \verbatim
909 ...
910 #elif defined(PJ_XOS)
911 # include <pj/compat/os_xos.h>
912 #else
913 #...
914 \endverbatim
915 *
916 * @subsection new_target_mak_file_sec Create New Global Make Config File
917 *
918 * Then you'll need to create global configuration file that
919 * is specific for this OS, i.e. <tt><b>os-xos.mak</b></tt> in
920 * <tt><b>$PJPROJECT/build</b></tt> directory.
921 *
922 * At very minimum, the file will normally need to define
923 * <tt><b>PJ_XOS=1</b></tt> in the \c CFLAGS section:
924 *
925 \verbatim
926#
927# $PJPROJECT/build/os-xos.mak:
928#
929export OS_CFLAGS := $(CC_DEF)PJ_XOS=1
930export OS_CXXFLAGS :=
931export OS_LDFLAGS :=
932export OS_SOURCES :=
933 \endverbatim
934 *
935 *
936 * @subsection new_target_prj_mak_file_sec Create New Project's Make Config File
937 *
938 * Then you'll need to create xos-specific configuration file
939 * for PJLIB. This file is also named <tt><b>os-xos.mak</b></tt>,
940 * but its located in <tt><b>pjlib/build</b></tt> directory.
941 * This file will specify source files that are specific to
942 * this OS to be included in the build process.
943 *
944 * Below is a sample:
945 \verbatim
946#
947# pjlib/build/os-xos.mak:
948# XOS specific configuration for PJLIB.
949#
950export PJLIB_OBJS += os_core_xos.o \
951 os_error_unix.o \
952 os_time_ansi.o
953export TEST_OBJS += main.o
954export TARGETS = pjlib pjlib-test
955 \endverbatim
956 *
957 * @subsection new_target_src_sec Create and Edit Source Files
958 *
959 * You'll normally need to create at least these files:
960 * - <tt><b>os_core_xos.c</b></tt>: core OS specific
961 * functionality.
962 * - <tt><b>os_timestamp_xos.c</b></tt>: how to get timestamp
963 * in this OS.
964 *
965 * Depending on how things are done in your OS, you may need
966 * to create these files:
967 * - <tt><b>os_error_*.c</b></tt>: how to manipulate
968 * OS error codes. Alternatively you may use existing
969 * <tt>os_error_unix.c</tt> if the OS has \c errno and
970 * \c strerror() function.
971 * - <tt><b>ioqueue_*.c</b></tt>: if the OS has specific method
972 * to perform asynchronous I/O. Alternatively you may
973 * use existing <tt>ioqueue_select.c</tt> if the OS supports
974 * \c select() function call.
975 * - <tt><b>sock_*.c</b></tt>: if the OS has specific method
976 * to perform socket communication. Alternatively you may
977 * use existing <tt>sock_bsd.c</tt> if the OS supports
978 * BSD socket API, and edit <tt>include/pj/compat/socket.h</tt>
979 * file accordingly.
980 *
981 * You will also need to check various files in
982 * <tt><b>include/pj/compat/*.h</b></tt>, to see if they're
983 * compatible with your OS.
984 *
985 * @subsection new_target_build_file_sec Build The Project
986 *
987 * After basic building blocks have been created for the OS, then
988 * the easiest way to see which parts need to be fixed is by building
989 * the project and see the error messages.
990 *
991 * @subsection new_target_edit_vs_new_file_sec Editing Existing Files vs Creating New File
992 *
993 * When you encounter compatibility errors in PJLIB during porting,
994 * you have three options on how to fix the error:
995 * - edit the existing <tt>*.c</tt> file, and give it <tt>#ifdef</tt>
996 * switch for the new OS, or
997 * - edit <tt>include/pj/compat/*.h</tt> instead, or
998 * - create a totally new file.
999 *
1000 * Basicly there is no strict rule on which approach is the best
1001 * to use, however the following guidelines may be used:
1002 * - if the file is expected to be completely different than
1003 * any existing file, then perhaps you should create a completely
1004 * new file. For example, file <tt>os_core_xxx.c</tt> will
1005 * normally be different for each OS flavour.
1006 * - if the difference can be localized in <tt>include/compat</tt>
1007 * header file, and existing <tt>#ifdef</tt> switch is there,
1008 * then preferably you should edit this <tt>include/compat</tt>
1009 * header file.
1010 * - if the existing <tt>*.c</tt> file has <tt>#ifdef</tt> switch,
1011 * then you may add another <tt>#elif</tt> switch there. This
1012 * normally is used for behaviors that are not totally
1013 * different on each platform.
1014 * - other than that above, use your own judgement on whether
1015 * to edit the file or create new file etc.
1016 */
1017
1018#endif /* __PJ_DOXYGEN_H__ */
1019