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 | |
---|
9 | Makefiles |
---|
10 | ********* |
---|
11 | |
---|
12 | This chapter discusses the Makefiles associated with a BSP. It does not |
---|
13 | describe the process of configuring, building, and installing RTEMS. This |
---|
14 | chapter will not provide detailed information about this process. Nonetheless, |
---|
15 | it is important to remember that the general process consists of four phases as |
---|
16 | shown here: |
---|
17 | |
---|
18 | - ``bootstrap`` |
---|
19 | |
---|
20 | - ``configure`` |
---|
21 | |
---|
22 | - ``build`` |
---|
23 | |
---|
24 | - ``install`` |
---|
25 | |
---|
26 | During the bootstrap phase, you are using the ``configure.ac`` and |
---|
27 | ``Makefile.am`` files as input to GNU autoconf and automake to generate a |
---|
28 | variety of files. This is done by running the ``bootstrap`` script found at |
---|
29 | the top of the RTEMS source tree. |
---|
30 | |
---|
31 | During the configure phase, a number of files are generated. These generated |
---|
32 | files are tailored for the specific host/target combination by the configure |
---|
33 | script. This set of files includes the Makefiles used to actually compile and |
---|
34 | install RTEMS. |
---|
35 | |
---|
36 | During the build phase, the source files are compiled into object files and |
---|
37 | libraries are built. |
---|
38 | |
---|
39 | During the install phase, the libraries, header files, and other support files |
---|
40 | are copied to the BSP specific installation point. After installation is |
---|
41 | successfully completed, the files generated by the configure and build phases |
---|
42 | may be removed. |
---|
43 | |
---|
44 | Makefiles Used During The BSP Building Process |
---|
45 | ============================================== |
---|
46 | |
---|
47 | RTEMS uses the *GNU automake* and *GNU autoconf* automatic configuration |
---|
48 | package. Consequently, there are a number of automatically generated files in |
---|
49 | each directory in the RTEMS source tree. The ``bootstrap`` script found in the |
---|
50 | top level directory of the RTEMS source tree is executed to produce the |
---|
51 | automatically 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 |
---|
53 | one 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 | |
---|
62 | There is a file named ``Makefile.am`` in each directory of a BSP. This file is |
---|
63 | used by *automake* to produce the file named ``Makefile.in`` which is also |
---|
64 | found in each directory of a BSP. When modifying a ``Makefile.am``, you can |
---|
65 | probably find examples of anything you need to do in one of the BSPs. |
---|
66 | |
---|
67 | The configure process specializes the ``Makefile.in`` files at the time that |
---|
68 | RTEMS is configured for a specific development host and target. Makefiles are |
---|
69 | automatically generated from the ``Makefile.in`` files. It is necessary for |
---|
70 | the 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 | |
---|
74 | The ``Makefile`` files generated are processed when configuring and building |
---|
75 | RTEMS for a given BSP. |
---|
76 | |
---|
77 | The BSP developer is responsible for generating ``Makefile.am`` files which |
---|
78 | properly build all the files associated with their BSP. Most BSPs will only |
---|
79 | have a single ``Makefile.am`` which details the set of source files to build to |
---|
80 | compose the BSP support library along with the set of include files that are to |
---|
81 | be installed. |
---|
82 | |
---|
83 | This single ``Makefile.am`` at the top of the BSP tree specifies the set of |
---|
84 | header files to install. This fragment from the SPARC/ERC32 BSP results in |
---|
85 | four 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 | |
---|
94 | When 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 |
---|
96 | forget to run ``bootstrap -p`` to regenerate the ``preinstall.am``. |
---|
97 | |
---|
98 | The ``Makefile.am`` also specifies which source files to build. By convention, |
---|
99 | logical components within the BSP each assign their source files to a unique |
---|
100 | variable. These variables which define the source files are collected into a |
---|
101 | single variable which instructs the GNU autotools that we are building |
---|
102 | ``libbsp.a``. This fragment from the SPARC/ERC32 BSP shows how the startup |
---|
103 | related, miscellaneous support code, and the console device driver source is |
---|
104 | managed 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 | |
---|
118 | When adding new files to an existing directory, do not forget to add the new |
---|
119 | files to the list of files to be built in the corresponding ``XXX_SOURCES`` |
---|
120 | variable in the ``Makefile.am`` and run``bootstrap``. |
---|
121 | |
---|
122 | Some BSPs use code that is built in ``libcpu``. If you BSP does this, then you |
---|
123 | will need to make sure the objects are pulled into your BSP library. The |
---|
124 | following from the SPARC/ERC32 BSP pulls in the cache, register window |
---|
125 | management 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 | |
---|
136 | The ``Makefile.am`` files are ONLY processed by ``bootstrap`` and the resulting |
---|
137 | ``Makefile.in`` files are only processed during the configure process of a |
---|
138 | RTEMS build. Therefore, when developing a BSP and adding a new file to a |
---|
139 | ``Makefile.am``, the already generated ``Makefile`` will not automatically |
---|
140 | include the new references unless you configured RTEMS with the |
---|
141 | ``--enable-maintainer-mode`` option. Otherwise, the new file will not being be |
---|
142 | taken into account! |
---|
143 | |
---|
144 | Creating a New BSP Make Customization File |
---|
145 | ========================================== |
---|
146 | |
---|
147 | When building a BSP or an application using that BSP, it is necessary to tailor |
---|
148 | the compilation arguments to account for compiler flags, use custom linker |
---|
149 | scripts, include the RTEMS libraries, etc.. The BSP must be built using this |
---|
150 | information. Later, once the BSP is installed with the toolset, this same |
---|
151 | information must be used when building the application. So a BSP must include |
---|
152 | a build configuration file. The configuration file is ``make/custom/BSP.cfg``. |
---|
153 | |
---|
154 | The configuration file is taken into account when building one's application |
---|
155 | using the RTEMS template Makefiles (``make/templates``). These application |
---|
156 | template Makefiles have been included with the RTEMS source distribution since |
---|
157 | the early 1990's. However there is a desire in the RTEMS user community to |
---|
158 | move all provided examples to GNU autoconf. They are included in the 4.9 |
---|
159 | release series and used for all examples provided with RTEMS. There is no |
---|
160 | definite time table for obsoleting them. You are free to use these but be |
---|
161 | warned they have fallen out of favor with many in the RTEMS community and may |
---|
162 | disappear in the future. |
---|
163 | |
---|
164 | The following is a slightly shortened version of the make customization file |
---|
165 | for 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 | |
---|
182 | The make customization files have generally grown simpler and simpler with each |
---|
183 | RTEMS release. Beginning in the 4.9 release series, the rules for linking an |
---|
184 | RTEMS application are shared by all BSPs. Only BSPs which need to perform a |
---|
185 | transformation from linked ELF file to a downloadable format have any |
---|
186 | additional actions for program link time. In 4.8 and older, every BSP specified |
---|
187 | the "make executable" or ``make-exe`` rule and duplicated the same actions. |
---|
188 | |
---|
189 | It is generally easier to copy a ``make/custom`` file from a BSP similar to the |
---|
190 | one being developed. |
---|