source: rtems-docs/bsp_howto/makefiles.rst @ 489740f

4.115
Last change on this file since 489740f was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

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