pico]OS
1.0.4
|
<h3> Introduction </h3>
pico]OS comes with a powerful make environment based on GNU Make. The make files are universal to all target platforms and most compilers. They are the first step to platform independent software developement.
The core files of the make environment are located in the subdirectory picoos/make
. The main makefile for pico]OS is stored in the pico]OS root directory, and every platform port comes with a makefile that teaches the platform dependent environment to the make system.
The makefiles were tested with GNU make 3.80
For MS Windows platforms, you can download a Windows version of make from http://mingw.sourceforge.net/download.shtml
To compile the pico]OS library, you need to execute the makefile in the pico]OS root directory. The makefile knows three targets, that are:
all
builds the pico]OS libraryclean
deletes all binaries generated by previous make rundocu
builds the documentation using the doxygen toolThe targets all
and clean
need the additional parameter PORT
that specifies the destination port. For example, a valid make call would look like this (at the DOS prompt):
This will build pico]OS for the 6502 processor family. After the successful execution of make you will find two new subdirectories: The obj
directory contains all generated object files, and the lib
directory the final library.
There is a second option available on the command line: BUILD=DEBUG
will build a debug version of the operating system, and a BUILD=RELEASE
will build a release version. Note that the debug version is the default when this option is not given.
Note: The name of the port is the name of its subdirectory in the ports
directory.
Usually you will have more than one project that uses pico]OS. pico]OS is only installed one time on the harddisk, and you have several projects that link against the pico]OS library. Every project has different requirements on the RTOS, thus each project has its own configuration files for pico]OS. To avoid binary clashes with the other projects, it is required to tell make where the configuration files are located and where the generated pico]OS library shall be stored. This is done by two additional arguments in the command line of the make call:
The parameter RTOS_OUTPUTDIR
tells make where to store the generated pico]OS library. DIR_CONFIG
specifies the directory where the configuration files can be found. Note that the paths should be absolute paths, or, relative paths from the view of pico]OS (and that is mostly impracticable).
The pico]OS library is only the first step to an executable. The make environment supports also the linking of object files and libraries to get an executable. For example, you have written a 'hello world' program that uses pico]OS. To compile and link the file hello.c
you need to perform the following steps:
picoos
directory treehello.c
in this directoryoutfile.mak
from the examples directory) in the same directory. The makefile should look like this:The lines 6, 20, 32, 38 and 85 are mandatory. The PORT
variable may also be set at the command line when make is invoked, even like the BUILD
mode. RELROOT
sets the relative way to the pico]OS root directory. Line 20 includes the main makefile of the make environment. In line 29 you can enable the nano layer of pico]OS that is available with pico]OS 0.8.0. Line 32 sets the name of the executable to generate. Note that only the basename must be specified, the file extension is added automatically. Lines 37 to 47 set the source files that shall be linked to the pico]OS library. SRC_TXT
specifies a list of sourcecode files (in textual form). SRC_OBJ
and SRC_LIB
specify a list of existing object files and libraries that shall be linked to the executable. SRC_HDR
is a list of the header files that are used by your project. In line 51 you can set preprocessor defines to control the compilation of your software. The defines are passed to the compiler and can be checked with the #if / #endif preprocessor command in the C source files. Additional include paths for header files can be set in line 54. Please use the preprocessor command #include
<header.h>
to include a header file that is located in the global include path. If your application uses an other configuration than the default, you can place your own configuration files poscfg.h
and noscfg.h
into your project directory. You must then set DIR_CONFIG
(line 61) to the place where the configuration files are located. Note that this path is absolute to the pico]OS root, so if your project directory is picoos-1.0.0/myproject
, you would set DIR_CONFIG = myproject
. To make things easier, the pre-defined variable CURRENTDIR
points always to the current directory. In line 66 you may specify your own output directory for the generated binaries. If you do not set this variable, the binaries will be saved in the directory picoos-1.0.0/out/portname/rel_or_deb/
. Finally, the line 85 includes the makefile that starts the build process.
There is something special you should notice: You can tell the makefile to execute other, external makefiles. For example, this is useful to start a makefile that shall compile a library that is used by your program. Usually, you would add the library to the SRC_LIB
variable in line 47. The corresponding library makefile can be added to the variable EXEC_MAKEFILES
in line 77. Every time this makefile is executed, also the library makefile will be executed, ensuring the library is up to date.
And there is another special thing: You can divide your project into smaller modules. The modules are compiled to libraries and the libraries are then linked to the main program. For your own libraries, you should use the template makefile 'library.mak' in the examples directory. A description of this file you will find in the next section, see below. If you are using this modularized architecture, you can simply add the modules you wish to link to your main program to the variable MODULES
in line 73. You do not need to set also the library name in line 47, this does the pico]OS make for you.
To build your application, simply invoke make with the target all
to generate the executable. The makefile supports also the target clean
that cleans your last build again. Note: If you do not have set the PORT
and the BUILD
mode in the makefile, you need to specify them on the make command line. In this case, a valid make call would look like this: " make all PORT=x86w32 BUILD=DEBUG "
As described above, sometimes it is useful (or maybe necessary) to divide a project into some smaller modules or so called libraries. For this purpose pico]OS provides an example makefile (see examples directory, file library.mak
) that looks like this:
Like above, the lines 6, 14, 23, 29 and 59 are mandatory. RELROOT
sets the relative way to the pico]OS root directory. Line 14 includes the main makefile of the make environment. Line 23 sets the name of the generated library. Note that only the basename must be specified, the file extension is added automatically. Lines 28 to 35 set the source files that shall be added to the library. SRC_TXT
specifies a list of sourcecode files (in textual form), and SRC_HDR
is set to a list of C header files that are referenced by the C source files. The variable SRC_OBJ
can be filled with some precompiled object files (but this feature you won't really use). In line 39 you can set preprocessor defines to control the compilation of your software. The defines are passed to the compiler and can be checked with the #if / #endif preprocessor command in the C source files. Additional include paths for header files can be set in line 42. Please use the preprocessor command #include
<header.h>
to include a header file that is located in the global include path. In line 50 you may specify your own output directory for the generated binaries. If you do not set this variable, the binaries will be saved in the directory picoos-1.0.0/out/portname/rel_or_deb/
. Finally, the line 59 includes the makefile that starts the build process.
To generate the library manually, you can call the makefile with the port and build mode parameter: " make all PORT=x86w32 BUILD=DEBUG "
. As an option, you may also set the NANO flag to 1 (NANO=1
) if the library uses the nano layer of pico]OS.
But in most cases you will start the makefile from within a main makefile that is used to compile the whole project. Take the file outfile.mak
from the examples directory as a template for such a main makefile. When you add this library makefile (that means, the name and path of the directory where this library makefile is located) to the MODULES=
variable in the main makefile, the library makefile will be automatically executed when the project is built. All command line parameters that are set to execute the main makefile will also be passed to the library makefiles.
Each platform port need to have a special version of the file port.mak. This file is used to tell the make environment the settings needed to compile files for the platform. This settings include: The compiler / linker / archiver to use, runtime libraries to link to the exectuable, file extension names, and various port specific settings. Here is an example how the file port.mak
may look like:
The lines 12, 15 - 19, 22 - 25, 28, 31 - 40, 54 - 55, 57 - 58, 62, 65, 68 and 71 are mandatory. If GENERIC_FINDBIT
(line 12) is enabled (= set to 1), the file fbit_gen.c is compiled and linked to the pico]OS library. Some compilers need a special handling to compile C-files. If CC2ASM
is set to 1, the make system will first generate assembly files from C source files before generating the final object file from the intermediate assembly file.