]> git.ipfire.org Git - thirdparty/cups.git/blob - CONTRIBUTING.md
Update CONTRIBUTING file to use markdown syntax.
[thirdparty/cups.git] / CONTRIBUTING.md
1 # Contributing to CUPS
2
3 CUPS is developed by Apple Inc. and distributed as open source software under a
4 combination of GNU GPL2 and GNU LGPL2 licenses with exceptions to allow
5 developers on Apple's operating systems to develop CUPS-based software under
6 alternate license terms. Significant contributions to CUPS must be licensed to
7 Apple using the Apple Contributor Agreement:
8
9 https://www.cups.org/AppleContributorAgreement_2011-03-10.pdf
10
11 Contributions should be submitted as attachments to bug reports on the CUPS web
12 site. Changes to existing source files should be submitted as unified diffs
13 (both Subversion and Git produce this format by default) while new source files
14 should be provided as-is or in an archive. Github pull requests can also be
15 used to submit changes.
16
17
18 ## HOW TO CONTACT THE DEVELOPERS
19
20 The CUPS mailing lists are the primary means of asking questions and informally
21 discussing issues and feature requests with the CUPS developers and other
22 experienced CUPS users and developers. The "cups" mailing list is intended for
23 CUPS usage questions and new software announcements while the "cups-devel"
24 mailing list provides a forum for CUPS developers and monitoring new bugs.
25
26
27 ## INTERFACES
28
29 CUPS interfaces, including the C APIs and command-line arguments, environment
30 variables, configuration files, and output format, are stable across patch
31 versions and are generally backwards-compatible with interfaces used in prior
32 major and minor versions. However, program interfaces such as those used by
33 the scheduler to run filter, port monitor, and backend processes for job
34 processing should only be considered stable from the point of view of a
35 filter, port monitor, or backend. Software that simulates the scheduler in
36 order to run those programs outside of CUPS must necessarily be updated when
37 the corresponding interface is changed in a subsequent CUPS release, otherwise
38 undefined behavior can occur.
39
40 CUPS C APIs starting with an underscore (_) are considered to be private to
41 CUPS and are not subject to the normal guarantees of stability between CUPS
42 releases and must never be used in non-CUPS source code. Similarly,
43 configuration and state files written by CUPS are considered private if a
44 corresponding man page is not provided with the CUPS release. Never rely on
45 undocumented files or formats when developing software for CUPS. Always use a
46 published C API to access data stored in a file to avoid compatibility problems
47 in the future.
48
49
50 ## BUILD SYSTEM
51
52 The CUPS build system uses GNU autoconf to tailor the library to the local
53 operating system. Project files for the current release of Microsoft Visual
54 Studio are also provided for Microsoft Windows®. To improve portability,
55 makefiles must not make use of features unique to GNU make. See the MAKEFILE
56 GUIDELINES section for a description of the allowed make features and makefile
57 guidelines.
58
59 Additional GNU build programs such as GNU automake and GNU libtool must not be
60 used. GNU automake produces non-portable makefiles which depend on GNU-
61 specific extensions, and GNU libtool is not portable or reliable enough for
62 CUPS.
63
64
65 ## VERSION NUMBERING
66
67 CUPS uses a three-part version number separated by periods to represent the
68 major, minor, and patch release numbers. Major release numbers indicate large
69 design changes or backwards-incompatible changes to the CUPS API or CUPS
70 Imaging API. Minor release numbers indicate new features and other smaller
71 changes which are backwards-compatible with previous CUPS releases. Patch
72 numbers indicate bug fixes to the previous feature or patch release.
73
74 > Note:
75 >
76 > When we talk about compatibility, we are talking about binary compatibility
77 > for public APIs and output format compatibility for program interfaces.
78 > Changes to configuration file formats or the default behavior of programs
79 > are not generally considered incompatible as the upgrade process can
80 > normally address such changes gracefully.
81
82 Production releases use the plain version numbers:
83
84 MAJOR.MINOR.PATCH
85 1.0.0
86 ...
87 1.1.0
88 ...
89 1.1.23
90 ...
91 2.0.0
92 ...
93 2.1.0
94 2.1.1
95 2.1.2
96 2.1.3
97
98 The first production release in a MAJOR.MINOR series (MAJOR.MINOR.0) is called
99 a feature release. Feature releases are the only releases that may contain new
100 features. Subsequent production releases in a MAJOR.MINOR series may only
101 contain bug fixes.
102
103 Beta-test releases are identified by appending the letter B to the major and
104 minor version numbers followed by the beta release number:
105
106 MAJOR.MINORbNUMBER
107 2.2b1
108
109 Release candidates are identified by appending the letters RC to the major and
110 minor version numbers followed by the release candidate number:
111
112 MAJOR.MINORrcNUMBER
113 2.2rc1
114
115
116 ## CODING GUIDELINES
117
118 Contributed source code must follow the guidelines below. While the examples
119 are for C and C++ source files, source code for other languages should conform
120 to the same guidelines as allowed by the language.
121
122
123 ### SOURCE FILES
124
125 All source files names must be 16 characters or less in length to ensure
126 compatibility with older UNIX filesystems. Source files containing functions
127 have an extension of ".c" for C and ".cxx" for C++ source files. All other
128 "include" files have an extension of ".h". Tabs are set to 8 characters or
129 columns.
130
131 > Note:
132 >
133 > The ".cxx" extension is used because it is the only common C++ extension
134 > between Linux, OS X, UNIX, and Windows.
135
136 The top of each source file contains a header giving the purpose or nature of
137 the source file and the copyright and licensing notice:
138
139 /*
140 * Description of file contents.
141 *
142 * Copyright 2016 by Apple Inc.
143 *
144 * These coded instructions, statements, and computer programs are the
145 * property of Apple Inc. and are protected by Federal copyright
146 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
147 * which should have been included with this file. If this file is
148 * file is missing or damaged, see the license at "http://www.cups.org/".
149 */
150
151 For source files that are subject to the Apple OS-Developed Software exception,
152 the following additional comment appears after the contact information:
153
154 * This file is subject to the Apple OS-Developed Software exception.
155
156
157 ### HEADER FILES
158
159 All public header files must include the "versioning.h" header file, or a header
160 that does so. Function declarations are then "decorated" with the correct
161 _CUPS_API_major_minor macro to define its availability based on the build
162 environment, for example:
163
164 extern int cupsDoThis(int foo, int bar) _CUPS_API_2_2;
165
166 Private API header files must be named with the suffix "-private", for example
167 the "cups.h" header file defines all of the public CUPS APIs while the
168 "cups-private.h" header file defines all of the private CUPS APIs as well.
169 Typically a private API header file will include the corresponding public API
170 header file.
171
172
173 ### COMMENTS
174
175 All source code utilizes block comments within functions to describe the
176 operations being performed by a group of statements; avoid putting a comment
177 per line unless absolutely necessary, and then consider refactoring the code
178 so that it is not necessary. C source files use the block comment format
179 ("/* comment */") since many vendor C compilers still do not support C99/C++
180 comments ("// comment"):
181
182 /*
183 * Clear the state array before we begin...
184 */
185
186 for (i = 0; i < (sizeof(array) / sizeof(sizeof(array[0])); i ++)
187 array[i] = CUPS_STATE_IDLE;
188
189 /*
190 * Wait for state changes on another thread...
191 */
192
193 do
194 {
195 for (i = 0; i < (sizeof(array) / sizeof(sizeof(array[0])); i ++)
196 if (array[i] != CUPS_STATE_IDLE)
197 break;
198
199 if (i == (sizeof(array) / sizeof(array[0])))
200 sleep(1);
201 } while (i == (sizeof(array) / sizeof(array[0])));
202
203
204 ### INDENTATION
205
206 All code blocks enclosed by brackets begin with the opening brace on a new
207 line. The code then follows starting on a new line after the brace and is
208 indented 2 spaces. The closing brace is then placed on a new line following
209 the code at the original indentation:
210
211 {
212 int i; /* Looping var */
213
214 /*
215 * Process foobar values from 0 to 999...
216 */
217
218 for (i = 0; i < 1000; i ++)
219 {
220 do_this(i);
221 do_that(i);
222 }
223 }
224
225 Single-line statements following "do", "else", "for", "if", and "while" are
226 indented 2 spaces as well. Blocks of code in a "switch" block are indented 4
227 spaces after each "case" and "default" case:
228
229 switch (array[i])
230 {
231 case CUPS_STATE_IDLE :
232 do_this(i);
233 do_that(i);
234 break;
235
236 default :
237 do_nothing(i);
238 break;
239 }
240
241
242 ### SPACING
243
244 A space follows each reserved word such as "if", "while", etc. Spaces are not
245 inserted between a function name and the arguments in parenthesis.
246
247
248 ### RETURN VALUES
249
250 Parenthesis surround values returned from a function:
251
252 return (CUPS_STATE_IDLE);
253
254
255 ### FUNCTIONS
256
257 Functions with a global scope have a lowercase prefix followed by capitalized
258 words, e.g., "cupsDoThis", "cupsDoThat", "cupsDoSomethingElse", etc. Private
259 global functions begin with a leading underscore, e.g., "\_cupsDoThis",
260 "\_cupsDoThat", etc.
261
262 Functions with a local scope are declared "static" with lowercase names and
263 underscores between words, e.g., "do\_this", "do\_that", "do\_something\_else", etc.
264
265 Each function begins with a comment header describing what the function does,
266 the possible input limits (if any), the possible output values (if any), and
267 any special information needed:
268
269 /*
270 * 'do_this()' - Compute y = this(x).
271 *
272 * Notes: none.
273 */
274
275 static float /* O - Inverse power value, 0.0 <= y <= 1.1 */
276 do_this(float x) /* I - Power value (0.0 <= x <= 1.1) */
277 {
278 ...
279 return (y);
280 }
281
282 Return/output values are indicated using an "O" prefix, input values are
283 indicated using the "I" prefix, and values that are both input and output use
284 the "IO" prefix for the corresponding in-line comment.
285
286 The Mini-XML documentation generator also understands the following special
287 text in the function description comment:
288
289 @deprecated@ - Marks the function as deprecated (not recommended
290 for new development and scheduled for removal)
291 @since CUPS version@ - Marks the function as new in the specified version
292 of CUPS.
293 @private@ - Marks the function as private (same as starting the
294 function name with an underscore)
295
296
297 ### VARIABLES
298
299 Variables with a global scope are capitalized, e.g., "ThisVariable",
300 "ThatVariable", "ThisStateVariable", etc. Globals in CUPS libraries are either
301 part of the per-thread global values managed by the "\_cupsGlobals()" function
302 or are suitably protected for concurrent access. Global variables should be
303 replaced by function arguments whenever possible.
304
305 Variables with a local scope are lowercase with underscores between words,
306 e.g., "this\_variable", "that\_variable", etc. Any "local global" variables
307 shared by functions within a source file are declared "static". As for global
308 variables, local static variables are suitably protected for concurrent access.
309
310 Each variable is declared on a separate line and is immediately followed by a
311 comment block describing the variable:
312
313 int ThisVariable; /* The current state of this */
314 static int that_variable; /* The current state of that */
315
316
317 ### TYPES
318
319 All type names are lowercase with underscores between words and "\_t" appended
320 to the end of the name, e.g., "cups\_this\_type\_t", "cups\_that\_type\_t", etc.
321 Type names start with a prefix, typically "cups" or the name of the program,
322 to avoid conflicts with system types. Private type names start with an
323 underscore, e.g., "\_cups\_this\_t", "\_cups\_that\_t", etc.
324
325 Each type has a comment block immediately after the typedef:
326
327 typedef int cups_this_type_t; /* This type is for CUPS foobar options. */
328
329
330 ### STRUCTURES
331
332 All structure names are lowercase with underscores between words and "\_s"
333 appended to the end of the name, e.g., "cups\_this\_s", "cups\_that\_s", etc.
334 Structure names start with a prefix, typically "cups" or the name of the
335 program, to avoid conflicts with system types. Private structure names start
336 with an underscore, e.g., "\_cups\_this\_s", "\_cups\_that\_s", etc.
337
338 Each structure has a comment block immediately after the struct and each member
339 is documented similar to the variable naming policy above:
340
341 struct cups_this_struct_s /* This structure is for CUPS foobar options. */
342 {
343 int this_member; /* Current state for this */
344 int that_member; /* Current state for that */
345 };
346
347
348 ### CONSTANTS
349
350 All constant names are uppercase with underscores between words, e.g.,
351 "CUPS\_THIS\_CONSTANT", "CUPS\_THAT\_CONSTANT", etc. Constants begin with an
352 uppercase prefix, typically "CUPS" or the program name. Private constants
353 start with an underscore, e.g., "\_CUPS\_THIS\_CONSTANT", "\_CUPS\_THAT\_CONSTANT",
354 etc.
355
356 Typed enumerations should be used whenever possible to allow for type checking
357 by the compiler.
358
359 Comment blocks immediately follow each constant:
360
361 typedef enum cups_tray_e /* Tray enumerations */
362 {
363 CUPS_TRAY_THIS, /* This tray */
364 CUPS_TRAY_THAT /* That tray */
365 } cups_tray_t;
366
367
368 ## MAKEFILE GUIDELINES
369
370 The following is a guide to the makefile-based build system used by CUPS.
371 These standards have been developed over the years to allow CUPS to be built on
372 as many systems and environments as possible.
373
374
375 ### GENERAL ORGANIZATION
376
377 The CUPS source code is organized functionally into a top-level makefile,
378 include file, and subdirectories each with their own makefile and dependencies
379 files. The ".in" files are template files for the autoconf software and are
380 used to generate a static version of the corresponding file.
381
382
383 ### MAKEFILE DOCUMENTATION
384
385 Each makefile starts with the standard CUPS header containing the description
386 of the file, and CUPS copyright and license notice:
387
388 #
389 # Makefile for ...
390 #
391 # Copyright 2016 by Apple Inc.
392 #
393 # These coded instructions, statements, and computer programs are the
394 # property of Apple Inc. and are protected by Federal copyright
395 # law. Distribution and use rights are outlined in the file "LICENSE.txt"
396 # which should have been included with this file. If this file is
397 # file is missing or damaged, see the license at "http://www.cups.org/".
398 #
399
400
401 ### PORTABLE MAKEFILE CONSTRUCTION
402
403 CUPS uses a common subset of make program syntax to ensure that the software
404 can be compiled "out of the box" on as many systems as possible. The following
405 is a list of assumptions we follow when constructing makefiles:
406
407 - Targets; we assume that the make program supports the notion of simple
408 targets of the form "name:" that perform tab-indented commands that follow
409 the target, e.g.:
410
411 target:
412
413 _TAB_ target commands
414
415 - Dependencies; we assume that the make program supports recursive dependencies
416 on targets, e.g.:
417
418 target: foo bar
419
420 _TAB_ target commands
421
422 foo: bla
423
424 _TAB_ foo commands
425
426 bar:
427
428 _TAB_ bar commands
429
430 bla:
431
432 _TAB_ bla commands
433
434 - Variable Definition; we assume that the make program supports variable
435 definition on the command-line or in the makefile using the following form:
436
437 name=value
438
439 - Variable Substitution; we assume that the make program supports variable
440 substitution using the following forms:
441
442 - $(name); substitutes the value of "name",
443 - $(name:.old=.new); substitutes the value of "name" with the filename
444 extension ".old" changed to ".new",
445 - $(MAKEFLAGS); substitutes the command-line options passed to the
446 program without the leading hyphen (-),
447 - $$; substitutes a single $ character,
448 - $<; substitutes the current source file or dependency, and
449 - $@; substitutes the current target name.
450
451 - Suffixes; we assume that the make program supports filename suffixes with
452 assumed dependencies, e.g.:
453
454 .SUFFIXES: .c .o
455
456 .c.o:
457
458 _TAB_ $(CC) $(CFLAGS) -o $@ -c $<
459
460 - Include Files; we assume that the make program supports the include
461 directive, e.g.:
462
463 include ../Makedefs
464
465 include Dependencies
466
467 - Comments; we assume that comments begin with a # character and proceed to the
468 end of the current line.
469
470 - Line Length; we assume that there is no practical limit to the length of
471 lines.
472
473 - Continuation of long lines; we assume that the \ character may be placed at
474 the end of a line to concatenate two or more lines in a makefile to form a
475 single long line.
476
477 - Shell; we assume a POSIX-compatible shell is present on the build system.
478
479
480 ### STANDARD VARIABLES
481
482 The following variables are defined in the "Makedefs" file generated by the
483 autoconf software:
484
485 - ALL_CFLAGS; the combined C compiler options,
486 - ALL_CXXFLAGS; the combined C++ compiler options,
487 - AMANDIR; the administrative man page installation directory (section 8/1m
488 depending on the platform),
489 - AR; the library archiver command,
490 - ARFLAGS; options for the library archiver command,
491 - AWK; the local awk command,
492 - BINDIR; the binary installation directory,
493 - BUILDROOT; optional installation prefix (defaults to DSTROOT),
494 - CC; the C compiler command,
495 - CFLAGS; options for the C compiler command,
496 - CHMOD; the chmod command,
497 - CXX; the C++ compiler command,
498 - CXXFLAGS; options for the C++ compiler command,
499 - DATADIR; the data file installation directory,
500 - DSO; the C shared library building command,
501 - DSOXX; the C++ shared library building command,
502 - DSOFLAGS; options for the shared library building command,
503 - INCLUDEDIR; the public header file installation directory,
504 - INSTALL; the install command,
505 - INSTALL_BIN; the program installation command,
506 - INSTALL_COMPDATA; the compressed data file installation command,
507 - INSTALL_CONFIG; the configuration file installation command,
508 - INSTALL_DATA; the data file installation command,
509 - INSTALL_DIR; the directory installation command,
510 - INSTALL_LIB; the library installation command,
511 - INSTALL_MAN; the documentation installation command,
512 - INSTALL_SCRIPT; the shell script installation command,
513 - LD; the linker command,
514 - LDFLAGS; options for the linker,
515 - LIBDIR; the library installation directory,
516 - LIBS; libraries for all programs,
517 - LN; the ln command,
518 - MAN1EXT; extension for man pages in section 1,
519 - MAN3EXT; extension for man pages in section 3,
520 - MAN5EXT; extension for man pages in section 5,
521 - MAN7EXT; extension for man pages in section 7,
522 - MAN8DIR; subdirectory for man pages in section 8,
523 - MAN8EXT; extension for man pages in section 8,
524 - MANDIR; the man page installation directory,
525 - OPTIM; common compiler optimization options,
526 - PRIVATEINCLUDE; the private header file installation directory,
527 - RM; the rm command,
528 - SHELL; the sh (POSIX shell) command,
529 - STRIP; the strip command,
530 - srcdir; the source directory.
531
532
533 ### STANDARD TARGETS
534
535 The following standard targets are defined in each makefile:
536
537 - all; creates all target programs, libraries, and documentation files,
538 - clean; removes all target programs libraries, documentation files, and object
539 files,
540 - depend; generates automatic dependencies for any C or C++ source files (also
541 see "DEPENDENCIES"),
542 - distclean; removes autoconf-generated files in addition to those removed by
543 the "clean" target,
544 - install; installs all distribution files in their corresponding locations
545 (also see "INSTALL/UNINSTALL SUPPORT"),
546 - install-data; installs all data files in their corresponding locations (also
547 see "INSTALL/UNINSTALL SUPPORT"),
548 - install-exec; installs all executable files in their corresponding locations
549 (also see "INSTALL/UNINSTALL SUPPORT"),
550 - install-headers; installs all include files in their corresponding locations
551 (also see "INSTALL/UNINSTALL SUPPORT"),
552 - install-libs; installs all library files in their corresponding locations
553 (also see "INSTALL/UNINSTALL SUPPORT"), and
554 - uninstall; removes all distribution files from their corresponding locations
555 (also see "INSTALL/UNINSTALL SUPPORT").
556
557
558 ### OBJECT FILES
559
560 Object files (the result of compiling a C or C++ source file) have the
561 extension ".o".
562
563
564 ### PROGRAMS
565
566 Program files are the result of linking object files and libraries together to
567 form an executable file. A typical program target looks like:
568
569 program: $(OBJS)
570 TAB echo Linking $@...
571 TAB $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
572
573 ### STATIC LIBRARIES
574
575 Static libraries have a prefix of "lib" and the extension ".a". A typical
576 static library target looks like:
577
578 libname.a: $(OBJECTS)
579 TAB echo Creating $@...
580 TAB $(RM) $@
581 TAB $(AR) $(ARFLAGS) $@ $(OBJECTS)
582 TAB $(RANLIB) $@
583
584 ### SHARED LIBRARIES
585
586 Shared libraries have a prefix of "lib" and the extension ".dylib" or ".so"
587 depending on the operating system. A typical shared library is composed of
588 several targets that look like:
589
590 libname.so: $(OBJECTS)
591 TAB echo $(DSOCOMMAND) libname.so.$(DSOVERSION) ...
592 TAB $(DSOCOMMAND) libname.so.$(DSOVERSION) $(OBJECTS)
593 TAB $(RM) libname.so libname.so.$(DSOMAJOR)
594 TAB $(LN) libname.so.$(DSOVERSION) libname.so.$(DSOMAJOR)
595 TAB $(LN) libname.so.$(DSOVERSION) libname.so
596
597 libname.dylib: $(OBJECTS)
598 TAB echo $(DSOCOMMAND) libname.$(DSOVERSION).dylib ...
599 TAB $(DSOCOMMAND) libname.$(DSOVERSION).dylib \
600 TAB TAB -install_name $(libdir)/libname.$(DSOMAJOR).dylib \
601 TAB TAB -current_version libname.$(DSOVERSION).dylib \
602 TAB TAB -compatibility_version $(DSOMAJOR).0 \
603 TAB TAB $(OBJECTS) $(LIBS)
604 TAB $(RM) libname.dylib
605 TAB $(RM) libname.$(DSOMAJOR).dylib
606 TAB $(LN) libname.$(DSOVERSION).dylib libname.$(DSOMAJOR).dylib
607 TAB $(LN) libname.$(DSOVERSION).dylib libname.dylib
608
609 ### DEPENDENCIES
610
611 Static dependencies are expressed in each makefile following the target, for
612 example:
613
614 foo: bar
615
616 Static dependencies are only used when it is not possible to automatically
617 generate them. Automatic dependencies are stored in a file named
618 "Dependencies" and included at the end of the makefile. The following "depend"
619 target rule is used to create the automatic dependencies:
620
621 depend:
622 TAB $(CC) -MM $(ALL_CFLAGS) $(OBJS:.o=.c) >Dependencies
623
624 We regenerate the automatic dependencies on an OS X system and express any
625 non-OS X dependencies statically in the makefile.
626
627
628 ### INSTALL/UNINSTALL SUPPORT
629
630 All makefiles contains install and uninstall rules which install or remove the
631 corresponding software. These rules must use the $(BUILDROOT) variable as a
632 prefix to any installation directory so that CUPS can be installed in a
633 temporary location for packaging by programs like rpmbuild.
634
635 The $(INSTALL\_BIN), $(INSTALL\_COMPDATA), $(INSTALL\_CONFIG), $(INSTALL\_DATA),
636 $(INSTALL\_DIR), $(INSTALL\_LIB), $(INSTALL\_MAN), and $(INSTALL\_SCRIPT) variables
637 must be used when installing files so that the proper ownership and permissions
638 are set on the installed files.
639
640 The $(RANLIB) command must be run on any static libraries after installation
641 since the symbol table is invalidated when the library is copied on some
642 platforms.
643