blob: 47856fa1d559ba52699c130cd8c94e5fe14e28bc [file] [log] [blame]
yaberauneyaef772532009-10-09 17:55:43 +00001==============================
2Introduction
3==============================
4
5The following document briefly describes the steps and methodologies used for
6the new and improved Makefile system.
7
8==============================
9The Problem
10==============================
11
12The problem with the old Makefile system is that it was very difficult to
13maintain and it lacked any sense of formal structure, thus developing for LTP
yaberauneya2f27b052009-11-07 01:23:20 +000014and including new targets was more difficult than it should have been
yaberauneyaef772532009-10-09 17:55:43 +000015(maintenance). Furthermore, proper option-based cross-compilation was
16impossible due to the fact that the Makefiles didn't support a prefixing
17system, and the appropriate implicit / static rules hadn't been configured to
yaberauneya2f27b052009-11-07 01:23:20 +000018compile into multiple object directories for out-of-tree build support (ease of
yaberauneyaef772532009-10-09 17:55:43 +000019use / functionality). Finally, there wasn't a means to setup dependencies
20between components, such that if a component required libltp.a in order to
yaberauneya2f27b052009-11-07 01:23:20 +000021compile, it would go off and compile libltp.a first (ease of use).
yaberauneyaef772532009-10-09 17:55:43 +000022
23These items needed to be fixed to reduce maintenance nightmares for the
yaberauneya2f27b052009-11-07 01:23:20 +000024development community contributing to LTP, and the project maintainers.
yaberauneyaef772532009-10-09 17:55:43 +000025
26==============================
27Design
28==============================
29
30The system was designed such that including a single GNU Makefile compatible
31set in each new directory component is all that's essentially required to
32build the system.
33
34Say you had a directory like the following (with .c files in them which
35directly tie into applications, e.g. baz.c -> baz):
36
37 .../foo/
38 |--> Makefile
39 |
40 --> bar/
41 |
42 --> Makefile
43 |
44 --> baz.c
45
46Here's an example of how one would accomplish that:
47
48.../foo/Makefile:
49#
50# Copyright disclaimer goes here -- please use GPLv2.
51#
52
53top_srcdir ?= ..
54
55include $(top_srcdir)/include/mk/env_pre.mk
56include $(top_srcdir)/include/mk/generic_trunk_target.mk
57
58.../foo/bar/Makefile:
59#
60# Copyright disclaimer goes here -- please use GPLv2.
61#
62
63top_srcdir ?= ..
64
65include $(top_srcdir)/include/mk/env_pre.mk
66include $(top_srcdir)/include/mk/generic_leaf_target.mk
67
68==============================
69Make Rules and Make Variables
70==============================
71
yaberauneya2f27b052009-11-07 01:23:20 +000072When using make rules, avoid writing ad hoc rules like:
yaberauneyaef772532009-10-09 17:55:43 +000073
74[prog]: [dependencies]
75 cc -I../../include $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LDLIBS) \
76 -o [prog] [dependencies]
77
78etc. This makes cross-compilation and determinism difficult, if not impossible.
79Besides, implicit rules are your friends and as long as you use `MAKEOPTS=;' in
80the top-level caller (or do $(subst r,$(MAKEOPTS)) to remove -r), the compile
81will complete successfully, assuming all other prerequisites have been
82fulfilled (libraries, headers, etc).
83
84$(AR) : The library archiver.
85
86$(CC) : The system C compiler.
87
88$(CXX) : The system C++ compiler.
89
90$(CPP) : The system C preprocessor.
91
92$(CFLAGS) : C compiler flags.
93
94$(CPPFLAGS) : Preprocessor flags, e.g. -I arguments.
95
96$(CXXFLAGS) : C++ compiler flags, e.g. -I arguments.
97
98$(DEBUG_CFLAGS) : Debug flags to pass to $(CC), -g, etc.
99
100$(DEBUG_CXXFLAGS) : Debug flags to pass to $(CXX).
101
102$(LD) : The system linker (typically $(CC), but not
103 necessarily).
104
105$(LDFLAGS) : What to pass in to the linker, including -L arguments
106 and other ld arguments, apart from -l library
107 includes (see $(LDLIBS)).
108
109 This should be done in the $(CC) args passing style
110 when LD := $(CC), e.g. `-Wl,-foo', as opposed to
111 `-foo'.
112
113$(LDLIBS) : Libraries to pass to the linker (e.g. -lltp, etc).
114
115$(OPT_CFLAGS) : Optimization flags to pass into the C compiler, -O2,
116 etc. If you specify -O2 or higher, you should also
117 specify -fno-strict-aliasing, because of gcc
118 fstrict-aliasing optimization bugs in the tree
119 optimizer. Search for `fstrict-aliasing optimization
120 bug' with your favorite search engine.
121
122 Examples of more recent bugs:
123 1. tree-optimization/17510
124 2. tree-optimization/39100
125
126 Various bugs have occurred in the past due to buggy
127 logic in the tree-optimization portion of the gcc
128 compiler, from 3.3.x to 4.4.
129
130$(OPT_CXXFLAGS) : Optimization flags to pass to the C++ compiler.
131
132$(RANLIB) : What to run after archiving a library.
133
134$(WCFLAGS) : Warning flags to pass to $(CC), e.g. -Werror,
135 -Wall, etc.
136
137$(WCXXFLAGS) : Same as $(WCFLAGS), but for $(CXX).
138
139==============================
140Make System Variables
141==============================
142
143A series of variables are used within the make system that direct what actions
yaberauneya2d8710f2009-10-25 06:35:08 +0000144need to be taken. Rather than me listing the variables here, please with their
145intended uses, please refer to the comments contained in
146`.../include/mk/env_pre.mk'.
yaberauneyaef772532009-10-09 17:55:43 +0000147
148==============================
149Guidelines and Recommendations
150==============================
151
152Of course, the GNU Make manual is key to understanding the Make system, but
153here are the following sections and chapters I suggest reviewing:
154
155- implicit rules: http://www.gnu.org/software/make/manual/make.html#Implicit-Rules
156- variables and expansion: http://www.gnu.org/software/make/manual/make.html#Using-Variables
157- origin use: http://www.gnu.org/software/make/manual/make.html#Origin-Function
158- vpath use: http://www.gnu.org/software/make/manual/make.html#Directory-Search
159
160==============================
161Before Committing
162==============================
163
yaberauneya2d8710f2009-10-25 06:35:08 +0000164One should rebuild from scratch before committing. Please see INSTALL for more
165details.
yaberauneyaef772532009-10-09 17:55:43 +0000166
167==============================
168Other Errata
169==============================
170
171Please see TODO for any issues related to the Makefile infrastructure, and
172build structure / source tree in general.