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

5
Last change on this file since c8aecf9 was c8aecf9, checked in by Sebastian Huber <sebastian.huber@…>, on 12/20/16 at 12:17:04

Add warnings to basic BSP chapters

Update #2852.

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