1 | @c |
---|
2 | @c COPYRIGHT (c) 1988-1998. |
---|
3 | @c On-Line Applications Research Corporation (OAR). |
---|
4 | @c All rights reserved. |
---|
5 | @c |
---|
6 | @c $Id$ |
---|
7 | @c |
---|
8 | |
---|
9 | @chapter Makefiles |
---|
10 | |
---|
11 | @section Makefiles Used During The BSP Building Process |
---|
12 | |
---|
13 | There is a file named @code{Makefile.in} in each directory of a BSP. |
---|
14 | RTEMS uses the @b{GNU autoconf} automatic configuration package. |
---|
15 | This tool specializes the @code{Makefile.in} files at the time that RTEMS |
---|
16 | is configured for a specific development host and target. Makefiles |
---|
17 | are automatically generated from the @code{Makefile.in} files. It is |
---|
18 | necessary for the BSP developer to provide these files. Most of the |
---|
19 | time, it is possible to copy the @code{Makefile.in} from another |
---|
20 | similar directory and edit it. |
---|
21 | |
---|
22 | The @code{Makefile} files generated are processed when building |
---|
23 | RTEMS for a given BSP. |
---|
24 | |
---|
25 | The BSP developer is responsible for generating @code{Makefile.in} |
---|
26 | files which properly build all the files associated with their BSP. |
---|
27 | There are generally three types of Makefiles in a BSP source tree: |
---|
28 | |
---|
29 | |
---|
30 | @itemize @bullet |
---|
31 | @item Directory Makefiles |
---|
32 | @item Source Directory Makefiles |
---|
33 | @item Wrapup Makefile |
---|
34 | @end itemize |
---|
35 | |
---|
36 | @subsection Directory Makefiles |
---|
37 | |
---|
38 | The Directory class of Makefiles directs the build process through |
---|
39 | a set of subdirectories in a particular order. This order is usually |
---|
40 | chosen to insure that build dependencies are properly processed. |
---|
41 | Most BSPs only have one Directory class Makefile. The @code{Makefile.in} |
---|
42 | in the BSP root directory (@code{c/src/lib/libbsp/CPU/BSP}) specifies |
---|
43 | which directories are to be built for this BSP. For example, the |
---|
44 | following Makefile fragment shows how a BSP would only build the |
---|
45 | networking device driver if HAS_NETWORKING was defined: |
---|
46 | |
---|
47 | @example |
---|
48 | NETWORKING_DRIVER_yes_V = network |
---|
49 | NETWORKING_DRIVER = $(NETWORKING_DRIVER_$(HAS_NETWORKING)_V) |
---|
50 | |
---|
51 | [...] |
---|
52 | |
---|
53 | SUB_DIRS=include start340 startup clock console timer \ |
---|
54 | $(NETWORKING_DRIVER) wrapup |
---|
55 | @end example |
---|
56 | |
---|
57 | This fragment states that all the directories have to be processed, |
---|
58 | except for the @code{network} directory which is included only if the |
---|
59 | user configured networking. |
---|
60 | |
---|
61 | @subsection Source Directory Makefiles |
---|
62 | |
---|
63 | There is a @code{Makefile.in} in most of the directories in a BSP. This |
---|
64 | class of Makefile lists the files to be built as part of the driver. |
---|
65 | Do not forget to add the reference to a new file in the @code{Makefile.in} |
---|
66 | it is created! |
---|
67 | |
---|
68 | @b{NOTE:} The @code{Makefile.in} files are ONLY processed during the configure |
---|
69 | process of a RTEMS build. It means that, when you're working on the design |
---|
70 | of your BSP, and that you're adding a file to a folder and to the |
---|
71 | corresponding makefile.in, it will not be taken into account! You have to |
---|
72 | run configure again or modify the @code{Makefile} (the result of the |
---|
73 | configure process) by hand. This file will be in a directory such as |
---|
74 | the following: |
---|
75 | |
---|
76 | @example |
---|
77 | MY_BUILD_DIR/c/src/lib/libbsp/CPU/BSP/DRIVER |
---|
78 | @end example |
---|
79 | |
---|
80 | @subsection Wrapup Makefile |
---|
81 | |
---|
82 | This class of Makefiles produces a library. The BSP wrapup Makefile |
---|
83 | is responsible for producing the library @code{libbsp.a} which is later |
---|
84 | merged into the @code{librtemsall.a} library. This Makefile specifies |
---|
85 | which BSP components are to be placed into the library as well as which |
---|
86 | components from the CPU dependent support code library. For example, |
---|
87 | this component may choose to use a default exception handler from the |
---|
88 | CPU dependent support code or provide its own. |
---|
89 | |
---|
90 | This Makefile makes use of a neat construct in @b{GNU make} to pick |
---|
91 | up the required components: |
---|
92 | |
---|
93 | @example |
---|
94 | BSP_PIECES=startup clock console timer |
---|
95 | CPU_PIECES= |
---|
96 | GENERIC_PIECES= |
---|
97 | |
---|
98 | # bummer; have to use $foreach since % pattern subst rules only replace 1x |
---|
99 | OBJS=$(foreach piece, $(BSP_PIECES), ../$(piece)/$(ARCH)/$(piece).rel) \ |
---|
100 | $(foreach piece, $(CPU_PIECES), \ |
---|
101 | ../../../../libcpu/$(RTEMS_CPU)/$(piece)/$(ARCH)/$(piece).rel) \ |
---|
102 | $(wildcard \ |
---|
103 | ../../../../libcpu/$(RTEMS_CPU)/$(RTEMS_CPU_MODEL)/fpsp/$(ARCH)/fpsp.rel) \ |
---|
104 | $(foreach piece, $(GENERIC_PIECES), ../../../$(piece)/$(ARCH)/$(piece).rel) |
---|
105 | @end example |
---|
106 | |
---|
107 | The variable @code{OBJS} is the list of "pieces" expanded to include |
---|
108 | path information to the appropriate object files. The @code{wildcard} |
---|
109 | function is used on pieces of @code{libbsp.a} which are optional and |
---|
110 | may not be present based upon the configuration options. |
---|
111 | |
---|
112 | @section Makefiles Used Both During The BSP Design and its Use |
---|
113 | |
---|
114 | When building a BSP or an application using that BSP, it is necessary |
---|
115 | to tailor the compilation arguments to account for compiler flags, use |
---|
116 | custom linker scripts, include the RTEMS libraries, etc.. The BSP |
---|
117 | must be built using this information. Later, once the BSP is installed |
---|
118 | with the toolset, this same information must be used when building the |
---|
119 | application. So a BSP must include a build configuration file. The |
---|
120 | configuration file is @code{make/custom/BSP.cfg}. |
---|
121 | |
---|
122 | The configuration file is taken into account when building one's |
---|
123 | application using the RTEMS template Makefiles (@code{make/templates}). |
---|
124 | It is strongly advised to use these template Makefiles since they |
---|
125 | encapsulate a number of build rules along with the compile and link |
---|
126 | time options necessary to execute on the target board. |
---|
127 | |
---|
128 | There are template Makefiles provided for each of the classes of RTEMS |
---|
129 | Makefiles. This include Makefiles to: |
---|
130 | |
---|
131 | @itemize @bullet |
---|
132 | @item call recursively the makefiles in the directories beneath |
---|
133 | the current one, |
---|
134 | |
---|
135 | @item build a library, or |
---|
136 | |
---|
137 | @item build an executable. |
---|
138 | |
---|
139 | @end itemize |
---|
140 | |
---|
141 | The following is a shortened and heavily commented version of the |
---|
142 | make customization file for the gen68340 BSP. The original source |
---|
143 | for this file can be found in the @code{make/custom} directory. |
---|
144 | |
---|
145 | @example |
---|
146 | |
---|
147 | # The RTEMS CPU Family and Model |
---|
148 | RTEMS_CPU=m68k |
---|
149 | RTEMS_CPU_MODEL=mcpu32 |
---|
150 | |
---|
151 | include $(RTEMS_ROOT)/make/custom/default.cfg |
---|
152 | |
---|
153 | # The name of the BSP directory used for the actual source code. |
---|
154 | # This allows for build variants of the same BSP source. |
---|
155 | RTEMS_BSP_FAMILY=gen68340 |
---|
156 | |
---|
157 | # CPU flag to pass to GCC |
---|
158 | CPU_CFLAGS = -mcpu32 |
---|
159 | |
---|
160 | # optimisation flag to pass to GCC |
---|
161 | CFLAGS_OPTIMIZE_V=-O4 -fomit-frame-pointer |
---|
162 | |
---|
163 | # The name of the start file to be linked with. This file is the first |
---|
164 | # part of the BSP which executes. |
---|
165 | START_BASE=start340 |
---|
166 | |
---|
167 | [...] |
---|
168 | |
---|
169 | # This make-exe macro is used in template makefiles to build the |
---|
170 | # final executable. Any other commands to follow, just as using |
---|
171 | # objcopy to build a PROM image or converting the executable to binary. |
---|
172 | |
---|
173 | ifeq ($(RTEMS_USE_GCC272),yes) |
---|
174 | # This has rules to link an application if an older version of GCC is |
---|
175 | # to be used with this BSP. It is not required for a BSP to support |
---|
176 | # older versions of GCC. This option is supported in some of the |
---|
177 | # BSPs which already had this support. |
---|
178 | [...] |
---|
179 | else |
---|
180 | # This has rules to link an application using gcc 2.8 or newer or any |
---|
181 | # egcs version. All BSPs should support this. This version is required |
---|
182 | # to support GNAT/RTEMS. |
---|
183 | define make-exe |
---|
184 | $(CC) $(CFLAGS) $(CFLAGS_LD) -o $(basename $@@).exe $(LINK_OBJS) |
---|
185 | $(NM) -g -n $(basename $@@).exe > $(basename $@@).num |
---|
186 | $(SIZE) $(basename $@@).exe |
---|
187 | endif |
---|
188 | @end example |
---|
189 | |
---|
190 | @subsection Creating a New BSP Make Customization File |
---|
191 | |
---|
192 | The basic steps for creating a @code{make/custom} file for a new BSP |
---|
193 | is as follows: |
---|
194 | |
---|
195 | @itemize @bullet |
---|
196 | |
---|
197 | @item copy any @code{.cfg} file to @code{BSP.cfg} |
---|
198 | |
---|
199 | @item modify RTEMS_CPU, RTEMS_CPU_MODEL, RTEMS_BSP_FAMILY, |
---|
200 | RTEMS_BSP, CPU_CFLAGS, START_BASE, and make-exe rules. |
---|
201 | |
---|
202 | @end itemize |
---|
203 | |
---|
204 | It is generally easier to copy a @code{make/custom} file which is for a |
---|
205 | BSP close to your own. |
---|
206 | |
---|
207 | |
---|