source: rtems/doc/bsp_howto/makefiles.t @ 051ab3b

4.104.114.84.95
Last change on this file since 051ab3b was 051ab3b, checked in by Joel Sherrill <joel.sherrill@…>, on 10/20/98 at 19:27:13

Links between chapters up to Linker Script in place.

First draft of chapters up to and include Makefiles written.

  • Property mode set to 100644
File size: 7.2 KB
Line 
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
13There is a file named @code{Makefile.in} in each directory of a BSP.
14RTEMS uses the @b{GNU autoconf} automatic configuration package.
15This tool specializes the @code{Makefile.in} files at the time that RTEMS
16is configured for a specific development host and target.  Makefiles
17are automatically generated from the @code{Makefile.in} files.  It is
18necessary for the BSP developer to provide these files.  Most of the
19time, it is possible to copy the @code{Makefile.in} from another
20similar directory and edit it.
21
22The @code{Makefile} files generated are processed when building
23RTEMS for a given BSP.
24
25The BSP developer is responsible for generating @code{Makefile.in}
26files which properly build all the files associated with their BSP.
27There 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
38The Directory class of Makefiles directs the build process through
39a set of subdirectories in a particular order.  This order is usually
40chosen to insure that build dependencies are properly processed.
41Most BSPs only have one Directory class Makefile.  The @code{Makefile.in}
42in the BSP root directory (@code{c/src/lib/libbsp/CPU/BSP}) specifies
43which directories are to be built for this BSP. For example, the
44following Makefile fragment shows how a BSP would only build the
45networking device driver if HAS_NETWORKING was defined:
46
47@example
48NETWORKING_DRIVER_yes_V = network
49NETWORKING_DRIVER = $(NETWORKING_DRIVER_$(HAS_NETWORKING)_V)
50
51[...]
52
53SUB_DIRS=include start340 startup clock console timer \
54    $(NETWORKING_DRIVER) wrapup
55@end example
56
57This fragment states that all the directories have to be processed,
58except for the @code{network} directory which is included only if the
59user configured networking.
60
61@subsection Source Directory Makefiles
62
63There is a @code{Makefile.in} in most of the directories in a BSP. This
64class of Makefile lists the files to be built as part of the driver.
65Do not forget to add the reference to a new file in the @code{Makefile.in}
66it is created!
67
68@b{NOTE:} The @code{Makefile.in} files are ONLY processed during the configure
69process of a RTEMS build. It means that, when you're working on the design
70of your BSP, and that you're adding a file to a folder and to the
71corresponding makefile.in, it will not be taken into account! You have to
72run configure again or modify the @code{Makefile} (the result of the
73configure process) by hand.  This file will be in a directory such as
74the following:
75
76@example
77MY_BUILD_DIR/c/src/lib/libbsp/CPU/BSP/DRIVER
78@end example
79
80@subsection Wrapup Makefile
81
82This class of Makefiles produces a library.  The BSP wrapup Makefile
83is responsible for producing the library @code{libbsp.a} which is later
84merged into the @code{librtemsall.a} library.  This Makefile specifies
85which BSP components are to be placed into the library as well as which
86components from the CPU dependent support code library.  For example,
87this component may choose to use a default exception handler from the
88CPU dependent support code or provide its own.
89
90This Makefile makes use of a neat construct in @b{GNU make} to pick
91up the required components:
92
93@example
94BSP_PIECES=startup clock console timer
95CPU_PIECES=
96GENERIC_PIECES=
97
98# bummer; have to use $foreach since % pattern subst rules only replace 1x
99OBJS=$(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
107The variable @code{OBJS} is the list of "pieces" expanded to include
108path information to the appropriate object files.  The @code{wildcard}
109function is used on pieces of @code{libbsp.a} which are optional and
110may not be present based upon the configuration options.
111
112@section Makefiles Used Both During The BSP Design and its Use
113
114When building a BSP or an application using that BSP, it is necessary
115to tailor the compilation arguments to account for compiler flags, use
116custom linker scripts, include the RTEMS libraries, etc..  The BSP
117must be built using this information.  Later, once the BSP is installed
118with the toolset, this same information must be used when building the
119application.  So a BSP must include a build configuration file.  The
120configuration file is @code{make/custom/BSP.cfg}.
121
122The configuration file is taken into account when building one's
123application using the RTEMS template Makefiles (@code{make/templates}).
124It is strongly advised to use these template Makefiles since they
125encapsulate a number of build rules along with the compile and link
126time options necessary to execute on the target board.
127
128There are template Makefiles provided for each of the classes of RTEMS
129Makefiles.  This include Makefiles to:
130
131@itemize @bullet
132@item call recursively the makefiles in the directories beneath
133the current one,
134
135@item build a library, or
136
137@item build an executable.
138
139@end itemize
140
141The following is a shortened and heavily commented version of the
142make customization file for the gen68340 BSP.  The original source
143for this file can be found in the @code{make/custom} directory.
144
145@example
146
147# The RTEMS CPU Family and Model
148RTEMS_CPU=m68k
149RTEMS_CPU_MODEL=mcpu32
150
151include $(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.
155RTEMS_BSP_FAMILY=gen68340
156
157# CPU flag to pass to GCC
158CPU_CFLAGS = -mcpu32
159
160# optimisation flag to pass to GCC
161CFLAGS_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.
165START_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
173ifeq ($(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[...]
179else
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.
183define make-exe
184        $(CC) $(CFLAGS) $(CFLAGS_LD) -o $(basename $@@).exe $(LINK_OBJS)
185        $(NM) -g -n $(basename $@@).exe > $(basename $@@).num
186        $(SIZE) $(basename $@@).exe
187endif
188@end example
189
190@subsection Creating a New BSP Make Customization File
191
192The basic steps for creating a @code{make/custom} file for a new BSP
193is 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,
200RTEMS_BSP, CPU_CFLAGS, START_BASE, and make-exe rules.
201
202@end itemize
203
204It is generally easier to copy a @code{make/custom} file which is for a
205BSP close to your own.
206
207
Note: See TracBrowser for help on using the repository browser.