source: rtems-docs/bsp_howto/makefiles.rst @ 9aafb39

4.115
Last change on this file since 9aafb39 was 6d7a4d2, checked in by Chris Johns <chrisj@…>, on 06/17/16 at 05:05:41

Update the BSP howto.

Closes #2590.

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