source: rtems-docs/bsp-howto/makefiles.rst @ cc1d3fa

4.115
Last change on this file since cc1d3fa was cc1d3fa, checked in by Chris Johns <chrisj@…>, on 11/09/16 at 01:33:08

bsp-howto: Fix header levels.

  • Property mode set to 100644
File size: 8.4 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2002.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7.. _Makefiles:
8
9Makefiles
10*********
11
12This chapter discusses the Makefiles associated with a BSP.  It does not
13describe the process of configuring, building, and installing RTEMS.  This
14chapter will not provide detailed information about this process.  Nonetheless,
15it is important to remember that the general process consists of four phases as
16shown here:
17
18- ``bootstrap``
19
20- ``configure``
21
22- ``build``
23
24- ``install``
25
26During the bootstrap phase, you are using the ``configure.ac`` and
27``Makefile.am`` files as input to GNU autoconf and automake to generate a
28variety of files.  This is done by running the ``bootstrap`` script found at
29the top of the RTEMS source tree.
30
31During the configure phase, a number of files are generated.  These generated
32files are tailored for the specific host/target combination by the configure
33script.  This set of files includes the Makefiles used to actually compile and
34install RTEMS.
35
36During the build phase, the source files are compiled into object files and
37libraries are built.
38
39During the install phase, the libraries, header files, and other support files
40are copied to the BSP specific installation point.  After installation is
41successfully completed, the files generated by the configure and build phases
42may be removed.
43
44Makefiles Used During The BSP Building Process
45==============================================
46
47RTEMS uses the *GNU automake* and *GNU autoconf* automatic configuration
48package.  Consequently, there are a number of automatically generated files in
49each directory in the RTEMS source tree.  The ``bootstrap`` script found in the
50top level directory of the RTEMS source tree is executed to produce the
51automatically generated files.  That script must be run from a directory with a
52``configure.ac`` file in it.  The ``bootstrap`` command is usually invoked in
53one of the following manners:
54
55- ``bootstrap`` to regenerate all files that are generated by autoconf and
56  automake.
57
58- ``bootstrap -c`` to remove all files generated by autoconf and automake.
59
60- ``bootstrap -p`` to regenerate ``preinstall.am`` files.
61
62There is a file named ``Makefile.am`` in each directory of a BSP.  This file is
63used by *automake* to produce the file named ``Makefile.in`` which is also
64found in each directory of a BSP.  When modifying a ``Makefile.am``, you can
65probably find examples of anything you need to do in one of the BSPs.
66
67The configure process specializes the ``Makefile.in`` files at the time that
68RTEMS is configured for a specific development host and target.  Makefiles are
69automatically generated from the ``Makefile.in`` files.  It is necessary for
70the BSP developer to provide the ``Makefile.am`` files and generate the
71``Makefile.in`` files.  Most of the time, it is possible to copy the
72``Makefile.am`` from another similar directory and edit it.
73
74The ``Makefile`` files generated are processed when configuring and building
75RTEMS for a given BSP.
76
77The BSP developer is responsible for generating ``Makefile.am`` files which
78properly build all the files associated with their BSP.  Most BSPs will only
79have a single ``Makefile.am`` which details the set of source files to build to
80compose the BSP support library along with the set of include files that are to
81be installed.
82
83This single ``Makefile.am`` at the top of the BSP tree specifies the set of
84header files to install.  This fragment from the SPARC/ERC32 BSP results in
85four header files being installed.
86
87.. code-block:: makefile
88
89    include_HEADERS = include/bsp.h
90    include_HEADERS += include/tm27.h
91    include_HEADERS += include/erc32.h
92    include_HEADERS += include/coverhd.h
93
94When adding new include files, you will be adding to the set of
95``include_HEADERS``.  When you finish editing the ``Makefile.am`` file, do not
96forget to run ``bootstrap -p`` to regenerate the ``preinstall.am``.
97
98The ``Makefile.am`` also specifies which source files to build.  By convention,
99logical components within the BSP each assign their source files to a unique
100variable.  These variables which define the source files are collected into a
101single variable which instructs the GNU autotools that we are building
102``libbsp.a``.  This fragment from the SPARC/ERC32 BSP shows how the startup
103related, miscellaneous support code, and the console device driver source is
104managed in the ``Makefile.am``.
105
106.. code-block:: makefile
107
108    startup_SOURCES = ../../sparc/shared/bspclean.c ../../shared/bsplibc.c \
109    ../../shared/bsppredriverhook.c \
110    ../../shared/bsppost.c ../../sparc/shared/bspstart.c \
111    ../../shared/bootcard.c ../../shared/sbrk.c startup/setvec.c \
112    startup/spurious.c startup/erc32mec.c startup/boardinit.S
113    clock_SOURCES = clock/ckinit.c
114    ...
115    noinst_LIBRARIES = libbsp.a
116    libbsp_a_SOURCES = $(startup_SOURCES) $(console_SOURCES) ...
117
118When adding new files to an existing directory, do not forget to add the new
119files to the list of files to be built in the corresponding ``XXX_SOURCES``
120variable in the ``Makefile.am`` and run``bootstrap``.
121
122Some BSPs use code that is built in ``libcpu``.  If you BSP does this, then you
123will need to make sure the objects are pulled into your BSP library.  The
124following from the SPARC/ERC32 BSP pulls in the cache, register window
125management and system call support code from the directory corresponding to its
126``RTEMS_CPU`` model.
127
128.. code-block:: makefile
129
130    libbsp_a_LIBADD  = ../../../libcpu/@RTEMS_CPU@/cache.rel \
131    ../../../libcpu/@RTEMS_CPU@/reg_win.rel \
132    ../../../libcpu/@RTEMS_CPU@/syscall.rel
133
134.. note:
135
136The ``Makefile.am`` files are ONLY processed by ``bootstrap`` and the resulting
137``Makefile.in`` files are only processed during the configure process of a
138RTEMS build. Therefore, when developing a BSP and adding a new file to a
139``Makefile.am``, the already generated ``Makefile`` will not automatically
140include the new references unless you configured RTEMS with the
141``--enable-maintainer-mode`` option.  Otherwise, the new file will not being be
142taken into account!
143
144Creating a New BSP Make Customization File
145==========================================
146
147When building a BSP or an application using that BSP, it is necessary to tailor
148the compilation arguments to account for compiler flags, use custom linker
149scripts, include the RTEMS libraries, etc..  The BSP must be built using this
150information.  Later, once the BSP is installed with the toolset, this same
151information must be used when building the application.  So a BSP must include
152a build configuration file.  The configuration file is ``make/custom/BSP.cfg``.
153
154The configuration file is taken into account when building one's application
155using the RTEMS template Makefiles (``make/templates``).  These application
156template Makefiles have been included with the RTEMS source distribution since
157the early 1990's.  However there is a desire in the RTEMS user community to
158move all provided examples to GNU autoconf. They are included in the 4.9
159release series and used for all examples provided with RTEMS. There is no
160definite time table for obsoleting them.  You are free to use these but be
161warned they have fallen out of favor with many in the RTEMS community and may
162disappear in the future.
163
164The following is a slightly shortened version of the make customization file
165for the gen68340 BSP.  The original source for this file can be found in the
166``make/custom`` directory.
167
168.. code-block:: makefile
169
170    # The RTEMS CPU Family and Model
171    RTEMS_CPU=m68k
172    RTEMS_CPU_MODEL=m68340
173    include $(RTEMS_ROOT)/make/custom/default.cfg
174    # This is the actual bsp directory used during the build process.
175    RTEMS_BSP_FAMILY=gen68340
176    # This contains the compiler options necessary to select the CPU model
177    # and (hopefully) optimize for it.
178    CPU_CFLAGS = -mcpu=cpu32
179    # optimize flag: typically -O2
180    CFLAGS_OPTIMIZE_V = -O2 -g -fomit-frame-pointer
181
182The make customization files have generally grown simpler and simpler with each
183RTEMS release.  Beginning in the 4.9 release series, the rules for linking an
184RTEMS application are shared by all BSPs.  Only BSPs which need to perform a
185transformation from linked ELF file to a downloadable format have any
186additional actions for program link time. In 4.8 and older, every BSP specified
187the "make executable" or ``make-exe`` rule and duplicated the same actions.
188
189It is generally easier to copy a ``make/custom`` file from a BSP similar to the
190one being developed.
Note: See TracBrowser for help on using the repository browser.