1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
|
POCO C++ Libraries GNU Make Build System
AAAIntroduction
!!!Introduction
The POCO C++ Libraries use a built system based on
[[http://www.gnu.org/software/make/ GNU Make]] on every platform
capable of running it. This includes Linux, Mac OS X, virtually
every other Unix platform, as well as Cygwin and MinGW on Windows.
Why GNU Make? Well, GNU Make is available virtually everywhere
and it's usually readily available, such as on Linux and Mac OS X.
Sure, there are more advanced build systems out there, but the
philisophy for POCO is download -- compile -- go. Requiring the user
to download and install another build tool just for getting
POCO to work is unacceptable.
The build system consists of a number of make files, as well as a few
supporting shell scripts. All core files are located within the <*build*>
directory in the POCO distribution. For every library and executable,
there is a small make file describing the kind of project,
its input files, and the output.
The POCO build system automatically determines the dependencies
between source and header files. This is done when a source file is
compiled for the first time, or after a source file has been changed.
This relieves the developer from the tedious task of maintining file
dependencies manually - one of the biggest drawbacks of GNU Make.
!!Build System Features
The POCO build system supports the following features:
* building libraries, applications and plugins
* debug and release builds
* dynamic and static linking
* 32-bit and 64-bit builds
* automatic dependency detection
* easy to use
* support for cross-compiling for embedded platforms
such as Embedded Linux or iOS
!!Build System Overview
The core of the build system consists of three different kinds of files --
platform configuration files, make rules and shell scripts. All are located
in the <*build*> directory within the POCO C++ Libraries root directory.
build/
config/
Darwin
Linux
HP-UX
...
rules/
compile
dylib
exec
global
lib
script/
makedepend.gcc
makedepend.cxx
makedepend.SunCC
makeldpath
projname
shlibln
...
----
!Configuration Files
Configuration files contain all the knowledge how the toolchain (compiler and linker)
must be invoked for a given platform. Configuration files for the most common
Unix platforms and their toolchains, as well as for Cygwin and MinGW are already
part of POCO.
Support for an additional platform (or a variation of a platform) can be added
by creating a new (or copying and modifying) an existing build configuration file.
Configuration files are located in the <*build/config*> directory.
!Rule Files
Rule files contain platform independent make rules for compiling and
linking executables or (static and shared) libraries from source files,
using the tools defined in a configuration file. Rule files are located
in the <*build/rules*> directory.
!Script Files
Script files are called by the build system's make files to do things that
cannot be expressed in make files. For example, there are scripts for
invoking a particular C++ compiler in such a way that it produces a list of
dependencies for later inclusion by the build system. Script files are
located in the <*build/script*> directory.
!!Filesystem Layout
!Sources
The build system expects a project's files (header files, source files, Makefiles)
to be in a certain directory layout.
First, all project directories must be located in or under the same directory where the
<*build*> directory is located, or in a directory below.
All header files must be in the <*include*> directory (or a subdirectory of it).
All source files must be in the <*src*> directory.
Finally, there must be a Makefile (named <*Makefile*>) located in the project directory.
Below is a sample for a POCO source directory hierarchy:
poco/
build/
Foundation/
Net/
Util/
XML/
...
MyLib/
include/
MyLib.h
MyClass.h
src/
MyClass.cpp
Makefile
----
!Build Products
The POCO build system puts final build products (executables and libraries)
and intermediate products (object files, dependency files) into certain directories.
Unless specified otherwise (by setting the environment variable
POCO_BUILD accordingly -- see below), these directories are located within
the source directory tree. All libraries are put into a
directory with the path <*lib/<OSNAME>/<OSARCH>*>, within the POCO base directory.
Executables are put into a directory with the path <*bin/<OSNAME>/<OSARCH>*>,
within the project directory. Object files are put into a directory with the
path <*obj/<OSNAME>/<OSARCH>*>, within the project directory.
Dependency files are put into <*.dep/<OSNAME>/<OSARCH>*>,
also within the project directory.
Unless specified otherwise (by setting the Makefile variables
<[$(POCO_TARGET_OSNAME)]> and <[$(POCO_TARGET_OSARCH)]>, <*<OSNAME>*> is the
name of the host's operating system, as obtained by a call to
<*uname*> (or something equivalent), and <*<OSARCH>*> is the name of the
host's hardware architecture, as obtained by a call to <*uname -m*>
(or something equivalent).
Taking into account the build products, a typical project hierarchy looks like this:
poco/
build/
lib/
Linux/
i686/
libCppUnit.so.1
libCppUnitd.so.1
libCppUnit.so
libCppUnitd.so
libPocoFouncation.so.1
...
Foundation/
...
testsuite/
...
bin/
Linux/
i686/
testrunner
testrunnerd
...
Net/
Util/
XML/
...
MyLib/
.dep/
Linux/
i686/
MyClass.d
obj/
Linux/
i686/
MyClass.o
include/
MyLib.h
MyClass.h
src/
MyClass.cpp
Makefile
----
!!Project Makefiles
Depending on the kind of project, a project Makefile comes in one of three variants.
!Library Makefiles
The Makefile for a library always looks like this:
#
# Makefile for a library
#
include $(POCO_BASE)/build/rules/global
objects = MyClass ...
target = MyLib
target_version = 1
target_libs = PocoFoundation ...
include $(POCO_BASE)/build/rules/lib
----
Every Makefile always has to include <*$(POCO_BASE)/build/rules/global*> first.
In the <*objects*> section, the source files (located in the <*src*> directory)
must be specified. The file extension must not be included; the build system
will find files ending in .cpp (C++ sources) and .c (C sources).
<*target*> specifies the name of the library, <*target_version*> specifies the
version number for the shared library. <*target_libs*> specifies the
libraries required for linking the library.
Last in the Makefile is the inclusion of <*$(POCO_BASE)/build/rules/lib*>,
which includes the rules for building a shared or static library.
!Executable Makefiles
Makefiles for executables look similar to the ones for libraries.
#
# Makefile for a library
#
include $(POCO_BASE)/build/rules/global
objects = MyClass ...
target = MyLib
target_libs = PocoFoundation ...
include $(POCO_BASE)/build/rules/exec
----
The only differences are the missing <*target_version*> entry, and the
<*$(POCO_BASE)/build/rules/exec*> file, which is included instead of
<*$(POCO_BASE)/build/rules/lib*> at the end of the Makefile.
!Plugin Makefiles
Makefiles for plugins - shared libraries that are loadable dynamically at runtime - again look almost the same as Makefiles for ordinary libraries or executables.
#
# Makefile for a library
#
include $(POCO_BASE)/build/rules/global
objects = MyClass ...
target = MyPlugin
target_libs = PocoFoundation ...
include $(POCO_BASE)/build/rules/dylib
----
The difference is the file that is included at the end of the Makefile:
<*$(POCO_BASE)/build/rules/dylib*>.
!!!Build System Reference
!!Target Variables
!target
The <*target*> variable specifies the name of the resulting library or executable,
excluding the suffix.
!target_version
The <*target_version*> variable specifies the shared library version of the resulting
shared library.
!target_libs
The <*target_libs*> variable specifies all libraries that must be linked to the
target. These libraries must have been built with this build system and they
must follow the build system conventions, specifically, the names for debug
and release builds.
!target_extlibs
The <*target_extlibs*> variables specifies additional libraries that must be
linked to the target. No assumptions are made regarding debug or release builds.
The names given here are simply passed to the linker by prepending the <[-l]> flag.
!target_includes
The <*target_includes*> variable specifies a list of directories used for searching
header files.
!!Postbuild Command
A Makefile can contain a so-called postbuild command -- a shell command
that will be executed when the target has been built successfully.
To specify a postbuild command, define the variable <*postbuild*>
in your Makefile, e.g.
#
# Makefile for a library
#
include $(POCO_BASE)/build/rules/global
objects = MyClass ...
target = MyLib
target_libs = PocoFoundation ...
postbuild = echo "The build is done."
include $(POCO_BASE)/build/rules/exec
----
!!Make Targets
Independently of which kind of product (library, executable, plugin) is
being built, there are always five make targets available:
Note that these targets are only available in project-level Makefiles, not
the global Makefile.
!clean
The <*clean*> target will remove all executable and intermediate object files,
forcing a full rebuild with the next make.
!all
<*all*> is the default target, used if no other target is specified.
Depending on the current configuration, it will either build a statically linked or
dynamically linked library/executable, or both.
!static_debug
The <*static_debug*> target will build a statically linked debug version of
the library or executable. Statically linked executables will be linked
in the <*static*> subdirectory within the <*bin/<OSNAME>/<OSARCH>*> directory.
Debug libraries and executables have a 'd' appended to their basename
(e.g., MyLibd.so).
!static_release
The <*static_release*> target will build a statically linked release
version of the library or executable.
!shared_debug
The <*shared_debug*> target will build a dynamically linked debug version
of the library or executable. The library or executable will
have the suffix <*d*> appended to its name (e.g., if target is MyExec,
the actual name of the executable will be MyExecd).
!shared_release
The <*shared_release*> target will build a dynamically linked release
version of the library or executable.
!!Environment Variables
The POCO build system requires or uses certain environment variables to work properly.
!POCO_BASE
<*POCO_BASE*> is required and specifies the directory where the POCO
source tree is located.
!POCO_BUILD
<*POCO_BUILD*> specifies the directory where the build system puts all
intermediate build files (object files, dependency files) and build
products (libraries and executables). Normally, these files are located
within the POCO source tree. Setting POCO_BUILD allows to keep the POCO
source tree clean and free of binaries.
!POCO_CONFIG
<*POCO_CONFIG*> specifies the build configuration file (located in build/config)
to use. Defaults to the output of <*uname*> if not specified.
!POCO_TARGET_OSNAME and POCO_TARGET_OSARCH
<*POCO_TARGET_OSNAME*> and >*POCO_TARGET_OSARCH*> are used in
cross builds, to specify the operating system name and hardware
architecture of the target. These names is used to find the directory
where intermediate object files and final build products are put.
Intermediate files are always put into <*obj/<OSNAME>/<OSARCH>*>
and final build products are put into <*lib/<OSNAME>/<OSARCH>*>, or
<*bin/<OSNAME>/<OSARCH>*>, respectively.
If <*POCO_TARGET_OSNAME*> is specified, its value becomes the
value for <*<OSNAME>*>. If <*POCO_TARGET_OSARCH*> is specified, its value
likewise becomes the value for <*<OSARCH>*>
The default value for <*<OSNAME>*> is the output of <*uname*> or a
similar command.
The default value for <*<OSARCH>*> is the output of <*uname -m*> or a
similar command.
!OSARCH_64BITS
If defined to 1, will force a 64 bit build on platforms that support 64 bit builds.
!PROJECT_BASE
Setting this environment variable allows you to use the build system to
build POCO-based libraries and executables outside the POCO_BASE directory
hierarchy. Given a directory <*/projects*> containing a project directory
<*MyProject*> (that is, <*/projects/MyProject*>), <*PROJECT_BASE*>
must be set to <*/projects*>. Assuming <*/projects/MyProject/Makefile*>
is available, you can change to the <*/projects/MyProject*> directory and
invoke <*gmake*> to build your project. <*POCO_BASE*> must still be set
and point to the POCO source tree, as usual.
!!Special Files
!components
The build system requires a file named <*components*> being located in
<*$(POCO_BASE)*>. This file contains a list of project names, one per line.
The contents of this file are used by the build system to automatically
build include search paths. For example, if <*components*> has the following content:
Foundation
XML
Util
Net
----
the following include search path options will be used for compiling:
-I$(POCO_BASE)/Foundation/include -I$(POCO_BASE)/XML/include -I$(POCO_BASE)/Util/include -I$(POCO_BASE)/Net/include
----
If a new library is being added to POCO, a corresponding entry should be made in the <*components*> file, so that the compiler can find its header files.
!libversion
The content of the file <*libversion*>, located in <*$(POCO_BASE)*>,
will be stored in the variable <*$(LIBVERSION)*>. This variable can be used
in a Makefile as the value for the <*target_version*> variable.
!Configuring the Build Process
The build process is configured by build configuration files,
located in the <*build/config*> directory.
Unless specified otherwise, by setting the <*POCO_CONFIG*>
environment variable accordingly, the build system selects the
build configuration file with the same name as the host's
operating system (output of <*uname*>). If you need support for a
new operating system, or just need to customize an existing configuration,
you'll usually create a new build configuration file (by copying an existing one).
A typical build configuration file looks like this:
#
# Linux
#
# Make settings for Linux 2.6/gcc 3.3
#
#
#
# General Settings
#
LINKMODE = SHARED
#
# Define Tools
#
CC = gcc
CXX = g++
LINK = $(CXX)
LIB = ar -cr
RANLIB = ranlib
SHLIB = $(CXX) -shared -Wl,-soname,$(notdir $@) -o $@
SHLIBLN = $(POCO_BASE)/build/script/shlibln
STRIP = strip
DEP = $(POCO_BASE)/build/script/makedepend.gcc
SHELL = sh
RM = rm -rf
CP = cp
MKDIR = mkdir -p
#
# Extension for Shared Libraries
#
SHAREDLIBEXT = .so.$(target_version)
SHAREDLIBLINKEXT = .so
#
# Compiler and Linker Flags
#
CFLAGS =
CFLAGS32 =
CFLAGS64 =
CXXFLAGS = -Wall -Wno-sign-compare
CXXFLAGS32 =
CXXFLAGS64 =
LINKFLAGS =
LINKFLAGS32 =
LINKFLAGS64 =
STATICOPT_CC =
STATICOPT_CXX =
STATICOPT_LINK = -static
SHAREDOPT_CC = -fPIC
SHAREDOPT_CXX = -fPIC
SHAREDOPT_LINK = -Wl,-rpath,$(LIBPATH)
DEBUGOPT_CC = -g -D_DEBUG
DEBUGOPT_CXX = -g -D_DEBUG
DEBUGOPT_LINK = -g
RELEASEOPT_CC = -O2 -DNDEBUG
RELEASEOPT_CXX = -O2 -DNDEBUG
RELEASEOPT_LINK = -O2
#
# System Specific Flags
#
SYSFLAGS = -D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DPOCO_HAVE_FD_EPOLL
#
# System Specific Libraries
#
SYSLIBS = -lpthread -ldl -lrt
----
The various settings in the build configuration file are described below.
!!General Settings
!LINKMODE
This specifies the default link mode, which can have the values
<*STATIC*>, <*SHARED*> or <*BOTH*>.
!TOOL
For cross builds, <*TOOL*> specifies the prefix for the toolchain executables, e.g.
TOOL = arm-unknown-linux-gnu
----
<*TOOL*> can later be used in the tool section, as in:
CC = $(TOOL)-gcc
CXX = $(TOOL)-g++
...
----
!POCO_TARGET_OSNAME and POCO_TARGET_OSARCH
The general settings section is also the right place to define
<*POCO_TARGET_OSNAME*> and <*POCO_TARGET_OSARCH*> for cross builds.
!!Tool Definition
!CC
<*CC*> specifies the command for invoking the C compiler.
!CXX
<*CXX*> specifies the command for invoking the C++ compiler.
!LINK
<*LINK*> specifies the command for invoking the link editor.
!STRIP
<*STRIP*> specifies the command for invoking the strip utility.
!LIB
<*LIB*> specifies the command for invoking the library archiver utility.
!RANLIB
<*RANLIB*> specifies the command for invoking the library table of contents updater
utility.
!SHLIB
<*SHLIB*> specifies the command for creating shared libraries.
!SHLIBLN
<*SHLIBLN*> specifies the command for creating shared library
symbolic links (e.g. <*libPocoFoundation.so*> -> <*libPocoFoundation.so.1*>)
!DEP
<*DEP*> specifies the command for creating or updating the dependencies. This
is usually a shell script invoking the C/C++ compiler in a special way to generate
a list of dependencies.
!SHELL
<*SHELL*> specifies the command for invoking the POSIX shell.
!RM
<*RM*> specifies the command for deleting files and directories.
!CP
<*CP*> specifies the command for copying files.
!MKDIR
<*MKDIR*> specifies the command for creating directories.
!!Shared Library Extensions
!SHAREDLIBEXT
<*SHAREDLIBEXT*> specifies the extension for shared libraries.
This usually includes a version number (e.g. <*.so.1*>).
!SHAREDLIBLINKEXT
<*SHAREDLIBLINKEXT*> specifies the extension for shared library
symbolic links. (e.g., <*.so*>)
!!Compiler and Linker Flags
!CFLAGS
<*CFLAGS*> specifies additional flags passed to the C compiler.
!CFLAGS32
<*CFLAGS32*> specifies additional flags passed to the C compiler
if compiling in 32 bit mode.
!CFLAGS64
<*CFLAGS64*> specifies additional flags passed to the C compiler
if compiling in 64 bit mode.
!CXXFLAGS
<*CXXFLAGS*> specifies additional flags passed to the C++ compiler.
!CXXFLAGS32
<*CXXFLAGS32*> specifies additional flags passed to the C++ compiler if
compiling in 32 bit mode.
!CXXFLAGS64
<*CXXFLAGS64*> specifies additional flags passed to the C++ compiler if
compiling in 64 bit mode.
!LINKFLAGS
<*LINKFLAGS*> specifies additional flags passed to the linker.
!LINKFLAGS32
<*LINKFLAGS32*> specifies additional flags passed to the linker if
compiling in 32 bit mode.
!LINKFLAGS64
<*LINKFLAGS64*> specifies additional flags passed to the linker if
compiling in 64 bit mode.
!STATICOPT_CC
<*STATICOPT_CC*> specifies additonal flags passed to the C compiler
if compiling for static linking.
!STATICOPT_CXX
<*STATICOPT_CXX*> specifies additonal flags passed to the C++ compiler if
compiling for static linking.
!STATICOPT_LINK
<*STATICOPT_LINK*> specifies additonal flags passed to the linker for
static linking.
!SHAREDOPT_CC
<*SHAREDOPT_CC*> specifies additonal flags passed to the C compiler if
compiling for dynamic linking.
!SHAREDOPT_CXX
<*SHAREDOPT_CXX*> specifies additonal flags passed to the C++ compiler if
compiling for dynamic linking.
!SHAREDOPT_LINK
<*SHAREDOPT_LINK*> specifies additonal flags passed to the linker for dynamic linking.
!DEBUGOPT_CC
<*DEBUGOPT_CC*> specifies additional flags passed to the C compiler if compiling in debug mode.
!DEBUGOPT_CXX
<*DEBUGOPT_CXX*> specifies additional flags passed to the C++ compiler if compiling in debug mode.
!DEBUGOPT_LINK
<*DEBUGOPT_LINK*> specifies additional flags passed to the linker if linking in debug mode.
!RELEASEOPT_CC
<*RELEASEOPT_CC*> specifies additional flags passed to the C compiler if compiling in release mode.
!RELEASEOPT_CXX
<*RELEASEOPT_CXX*> specifies additional flags passed to the C++ compiler if compiling in release mode.
!RELEASEOPT_LINK
<*RELEASEOPT_LINK*> specifies additional flags passed to the linker if linking in release mode.
!!System Specific Flags
!SYSFLAGS
<*SYSFLAGS*> specifies flags passed to both the C and C++ compiler. This usually contains system-specific include paths and settings such as -D_XOPEN_SOURCE=500 or -D_THREAD_SAFE.
!SYSLIBS
<*SYSLIBS*> specifies flags passed to the linker. Usually, this flags specify system-specific libraries, such as -lpthread or -ldl.
|