New build path variable
[freeradius.git] / doc / DIFFS.rst
1 Submitting patches or diff's to the FreeRADIUS project
2 ======================================================
3
4 For a person or company wishing to submit a change to the
5 FreeRADIUS project, the process can sometimes be daunting if you're
6 not familiar with "the system." This text is a collection of
7 suggestions which can greatly increase the chances of your change
8 being accepted.
9
10 Creating and Sending Your Change 
11 --------------------------------
12
13    1. "diff -u" 
14
15       Use "diff -u" or "diff -urN" to create patches. 
16
17       All changes to the source occur in the form of patches, as
18       generated by diff(1).  When creating your patch, make sure to
19       create it in "unified diff" format, as supplied by the '-u'
20       argument to diff(1). Patches should be based in the root source
21       directory, not in any lower subdirectory.
22
23       To create a patch for a single file, it is often sufficient to do: 
24
25            SRCTREE=/home/user/src/freeradiusd/
26            MYFILE=src/modules/rlm_foo/foo.c
27             
28            cd $SRCTREE
29            cp $MYFILE $MYFILE.orig
30            vi $MYFILE # make your change
31            diff -u $MYFILE.orig $MYFILE > /tmp/patch 
32
33       To create a patch for multiple files, you should unpack a
34       "vanilla", or unmodified source tree, and generate a diff
35       against your own source tree. For example:
36
37            MYSRC=/home/user/src/freeradiusd-feature/
38             
39            gunzip freeradiusd-version.tar.gz
40            tar xvf freeradiusd-version.tar
41            diff -urN freeradiusd-version $MYSRC > ~/feature-version.patch
42
43    2. Describe your changes. 
44
45       Describe the technical detail of the change(s) your patch includes. 
46
47       Be as specific as possible. The WORST descriptions possible
48       include things like "update file X", "bug fix for file X",
49       or "this patch includes updates for subsystem X. Please apply."
50
51       If your description starts to get long, that's a sign that you
52       probably need to split up your patch. See #3, next.
53
54    3. Separate your changes. 
55
56       Separate each logical change into its own patch.
57
58       For example, if your changes include both bug fixes and
59       performance enhancements for a single module, separate those
60       changes into two or more patches.
61
62       On the other hand, if you make a single change to numerous
63       files, group those changes into a single patch. Thus a single
64       LOGICAL change is contained within a single patch.
65
66       If one patch depends on another patch in order for a change to
67       be complete, that is OK. Simply note "this patch depends on
68       patch X" in your patch description.
69
70    4. Select e-mail destination. 
71
72       If you are on the developers mailing list, send the patch there.
73       freeradius-devel@lists.freeradius.org
74
75       Otherwise, send the patch to 'patches@freeradius.org'
76
77    5. No MIME, no links, no compression, no attachments. Just plain text. 
78
79       The developers need to be able to read and comment on the
80       changes you are submitting. It is important for a developer to
81       be able to "quote" your changes, using standard e-mail tools, so
82       that they may comment on specific portions of your code.
83
84       For this reason, all patches should be submitting e-mail
85       "inline".
86
87       Do not attach the patch as a MIME attachment, compressed or
88       not. Many popular e-mail applications will not always transmit a
89       MIME attachment as plain text, making it impossible to comment
90       on your code. A MIME attachment also takes a bit more time to
91       process, decreasing the likelihood of your MIME-attached change
92       being accepted.
93
94       Compressed patches are generally rejected outright.  If the
95       developer has to do additional work to read your patch, the odds
96       are that it will be ignored completely.
97
98    6. E-mail size. 
99
100       When sending patches, always follow step #5. 
101
102       Large changes are not appropriate for mailing lists, and some
103       maintainers. If your patch, exceeds 40Kb in size, it is
104       preferred that you store your patch on an Internet-accessible
105       server, and provide instead a URL (link) pointing to your patch.
106
107    7. Name the version of the server.
108
109       It is important to note, either in the subject line or in the
110       patch description, the server version to which this patch
111       applies.
112
113    8. Don't get discouraged. Re-submit. 
114
115       After you have submitted your change, be patient and wait. If
116       the patch is approved and applied, it will appear in the next
117       version of the server.
118
119       However, if your change doesn't appear in the next version of
120       the server, there could be any number of reasons. It's YOUR job
121       to narrow down those reasons, correct what was wrong, and submit
122       your updated change.
123
124       It is quite common a patch to be "dropped" without
125       comment. That's the nature of the system. If your patch is
126       dropped, it could be due to
127
128            A style issue (see section 2, below),
129            An e-mail formatting issue (see section item 5, above)
130            A technical problem with your change 
131            Your patch got lost among other patches
132
133       When in doubt, re-submit.
134
135 Hints, Tips, and Tricks 
136 -----------------------
137
138 This section lists many of the common "rules" associated with code
139 submitted to the project. There are always exceptions... but you must
140 have a really good reason for doing so.
141
142    1. Read the Documentation and follow the CodingStyle 
143
144       The FreeRADIUS server has a common coding style.  Use real tabs
145       to indent.  There is whitespace in variable assignments.
146       (i = 1, NOT i=1).
147
148       When in doubt, format your code to look the same as code already
149       in the server.  If your code deviates too much from the current
150       style, it is likely to be rejected without further review, and
151       without comment.
152
153    2. #ifdefs are ugly 
154
155       Code cluttered with ifdefs is difficult to read and
156       maintain. Don't do it. Instead, put your ifdefs in a header, and
157       conditionally define 'static inline' functions, or macros, which
158       are used in the code. Let the compiler optimize away the "no-op"
159       case.
160
161       Simple example, of poor code:: 
162
163            #ifdef CONFIG_MY_FUNKINESS 
164                  init_my_stuff(foo);
165            #endif 
166
167       Cleaned-up example: 
168
169       (in header):: 
170
171            #ifndef CONFIG_MY_FUNKINESS
172            static inline void init_my_stuff(char *foo) {}
173            #endif 
174
175       (in the code itself):: 
176
177            init_my_stuff(dev); 
178
179    3. 'static inline' is better than a macro 
180
181       Static inline functions are greatly preferred over macros. They
182       provide type safety, have no length limitations, no formatting
183       limitations, and under gcc they are as cheap as macros.
184
185       Macros should only be used for cases where a static inline is
186       clearly suboptimal [there a few, isolated cases of this in fast
187       paths], or where it is impossible to use a static inline
188       function [such as string-izing].
189
190       'static inline' is preferred over 'static __inline__', 'extern
191       inline', and 'extern __inline__'.
192
193    4. Don't over-design. 
194
195       Don't try to anticipate nebulous future cases which may or may
196       not be useful: "Make it as simple as you can, and no simpler"
197
198       Split up functionality as much as possible.  If your code needs
199       to do two unrelated things, write two functions.  Mashing two
200       kinds of work into one function makes the server difficult to
201       debug and maintain.
202
203       See the 'coding-methods.txt' document in this directory for
204       further description of coding methods.