HACKING 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. -*-text-*-
  2. Guile Hacking Guide
  3. Copyright (c) 1996-2002,2008,2012,2015,2017,2024 Free Software Foundation, Inc.
  4. Permission is granted to anyone to make or distribute verbatim copies
  5. of this document as received, in any medium, provided that the
  6. copyright notice and permission notice are preserved,
  7. and that the distributor grants the recipient permission
  8. for further redistribution as permitted by this notice.
  9. Permission is granted to distribute modified versions
  10. of this document, or of portions of it,
  11. under the above conditions, provided also that they
  12. carry prominent notices stating who last changed them,
  13. and that any new or changed statements about the activities
  14. of the Free Software Foundation are approved by the Foundation.
  15. What to Hack =========================================================
  16. You can hack whatever you want, thank GNU.
  17. It's a good idea to join the guile-devel@gnu.org mailing list. See
  18. http://www.gnu.org/software/guile/mail/mail.html for more info.
  19. Hacking It Yourself ==================================================
  20. You can spawn a shell with all the required dependencies using GNU Guix
  21. by running the following command:
  22. guix shell -D -f guix.scm --pure
  23. In this way, you can effortlessly compile Guile from the Git checkout
  24. with just these three lines:
  25. guix shell -CP -D -f guix.scm -- ./autogen.sh
  26. guix shell -CP -D -f guix.scm -- ./configure \
  27. --enable-mini-gmp --disable-static
  28. guix shell -CP -D -f guix.scm -- make
  29. Disabling of the static libraries is optional, but it does speed up the
  30. builds, and you are unlikely to need them for local development.
  31. Note: Currently JIT causes Guile to crash in obscure ways on GNU Hurd,
  32. so on that platform you want to also pass the --disable-jit flag
  33. to the configure script.
  34. Note: On any i*86 architecture, you also need to pass in the compiler
  35. flag -fexcess-precision=standard in order to get the test suite
  36. to pass. That can be done by passing an additional argument to
  37. the configure script:
  38. CFLAGS='-g -O2 -fexcess-precision=standard'
  39. Once that finishes, you can execute your newly compiled Guile using the
  40. ./meta/guile script:
  41. $ guix shell -CP -D -f guix.scm -- ./meta/guile -v | head -n1
  42. guile (GNU Guile) 3.0.9.139-d7cf5-dirty
  43. For more manual approach, read on.
  44. When Guile is obtained from Git, a few extra steps must be taken
  45. before the usual configure, make, make install. You will need to have
  46. up-to-date versions of the tools as listed below, correctly installed.
  47. Sometimes older or newer versions will work. (See below for versions
  48. to avoid.)
  49. Then you must run the autogen.sh script, as described below.
  50. The same procedure can be used to regenerate the files in released
  51. versions of Guile. In that case the headers of the original generated
  52. files (e.g., configure, Makefile.in, ltmain.sh) can be used to
  53. identify which tool versions may be required.
  54. Autoconf --- a system for automatically generating `configure'
  55. scripts from templates which list the non-portable features a
  56. program would like to use. Available in
  57. "ftp://ftp.gnu.org/pub/gnu/autoconf"
  58. Automake --- a system for automatically generating Makefiles that
  59. conform to the (rather Byzantine) GNU coding standards. The
  60. nice thing is that it takes care of hairy targets like 'make
  61. dist' and 'make distclean', and automatically generates
  62. Makefile dependencies. Automake is available in
  63. "ftp://ftp.gnu.org/pub/gnu/automake"
  64. libtool --- a system for managing the zillion hairy options needed
  65. on various systems to produce shared libraries. Available in
  66. "ftp://ftp.gnu.org/pub/gnu/libtool". Version 2.2 (or
  67. later) is recommended (for correct AIX support, and correct
  68. interaction with the Gnulib module for using libunistring).
  69. gettext --- a system for rigging a program so that it can output its
  70. messages in the local tongue. Guile presently only exports
  71. the gettext functionality to Scheme, it does not use it
  72. itself.
  73. flex --- a scanner generator. It's probably not essential to have the
  74. latest version; Flex 2.5.37 is known to work.
  75. One false move and you will be lost in a little maze of automatically
  76. generated files, all different.
  77. Here is the authoritative list of tool/version/platform tuples that
  78. have been known to cause problems, and a short description of the problem.
  79. Sample GDB Initialization File =======================================
  80. In GDB, you probably want to load the gdbinit file included with Guile,
  81. which defines a number of GDB helpers to inspect Scheme values.
  82. Contributing Your Changes ============================================
  83. - If you have put together a change that meets the coding standards
  84. described below, we encourage you to submit it to Guile. Post your
  85. patch to guile-devel@gnu.org or bug-guile@gnu.org; the latter is
  86. tracked at <https://bugs.gnu.org/guile>, which can be browsed from
  87. Emacs with debbugs.el, and is thus less likely to be lost.
  88. - We prefer patches generated using 'git format-patch'.
  89. - Provide a description in the commit message, like so:
  90. 1-line description of change
  91. More extensive discussion of your change. Document why you are
  92. changing things.
  93. * filename (function name): file specific change comments.
  94. - For proper credit, also make sure you update the AUTHORS file
  95. (for new files for which you've assigned copyright to the FSF), or
  96. the THANKS file (for everything else).
  97. Coding standards =====================================================
  98. - As for any part of Project GNU, changes to Guile should follow the
  99. GNU coding standards, available at
  100. https://www.gnu.org/prep/standards/standards.html.
  101. - The Guile tree should compile without warnings under the following
  102. GCC switches, which are the default in the current configure script:
  103. -O2 -Wall -Wpointer-arith -Wmissing-prototypes
  104. To make sure of this, you can use the --enable-error-on-warning option
  105. to configure. This option will make GCC fail if it hits a warning.
  106. Note that the warnings generated vary from one version of GCC to the
  107. next, and from one architecture to the next. For this reason,
  108. --enable-error-on-warning is not enabled by default.
  109. - If you add code which uses functions or other features that are not
  110. entirely portable, please make sure the rest of Guile will still
  111. function properly on systems where they are missing. This usually
  112. entails adding a test to configure.in, and then adding #ifdefs to your
  113. code to disable it if the system's features are missing. Do check first
  114. if the function has a Gnulib wrapper, though.
  115. - The normal way of removing a function, macro or variable is to mark
  116. it as "deprecated", keep it for a while, and remove it in a later
  117. release. If a function or macro is marked as "deprecated" it
  118. indicates that people shouldn't use it in new programs, and should try
  119. to remove it in old. Make sure that an alternative exists unless it
  120. is our purpose to remove functionality. Don't deprecate definitions
  121. if it is unclear when they will be removed. (This is to ensure that a
  122. valid way of implementing some functionality always exists.)
  123. When deprecating a definition, always follow this procedure:
  124. 1. Mark the definition using
  125. #if (SCM_DEBUG_DEPRECATED == 0)
  126. ...
  127. #endif
  128. or, for Scheme code, wrap it using
  129. (begin-deprecated
  130. ...)
  131. 2. Make the deprecated code issue a warning when it is used, by using
  132. scm_c_issue_deprecation_warning (in C) or issue-deprecation-warning
  133. (in Scheme).
  134. 3. Write a comment at the definition explaining how a programmer can
  135. manage without the deprecated definition.
  136. 4. Add an entry that the definition has been deprecated in NEWS and
  137. explain what to do instead.
  138. - Write commit messages for functions written in C using the
  139. functions' C names, and write entries for functions written in Scheme
  140. using the functions' Scheme names. For example,
  141. * foo.c: Moved scm_procedure_documentation from eval.c.
  142. is preferred over
  143. * foo.c: Moved procedure-documentation from eval.c.
  144. Changes like adding this line are special:
  145. SCM_PROC (s_map_in_order, "map-in-order", 2, 0, 1, scm_map);
  146. Since the change here is about the name itself --- we're adding a new
  147. alias for scm_map that guarantees the order in which we process list
  148. elements, but we're not changing scm_map at all --- it's appropriate
  149. to use the Scheme name in the commit message.
  150. - Make sure you have papers from people before integrating their
  151. changes or contributions. This is very frustrating, but very
  152. important to do right. From maintain.texi, "Information for
  153. Maintainers of GNU Software":
  154. When incorporating changes from other people, make sure to follow the
  155. correct procedures. Doing this ensures that the FSF has the legal
  156. right to distribute and defend GNU software.
  157. For the sake of registering the copyright on later versions ofthe
  158. software you need to keep track of each person who makes significant
  159. changes. A change of ten lines or so, or a few such changes, in a
  160. large program is not significant.
  161. *Before* incorporating significant changes, make sure that the person
  162. has signed copyright papers, and that the Free Software Foundation has
  163. received them.
  164. If you receive contributions you want to use from someone, let a
  165. maintainer know and they will take care of the administrivia. Put the
  166. contributions aside until we have the necessary papers.
  167. Once you accept a contribution, be sure to keep the files AUTHORS and
  168. THANKS up-to-date.
  169. - When you make substantial changes to a file, add the current year to
  170. the list of years in the copyright notice at the top of the file.
  171. - When you get bug reports or patches from people, be sure to list
  172. them in THANKS.
  173. - Do not introduce trailing whitespace (and feel free to clean it up
  174. opportunistically, that is, if doing so is part of some other change).
  175. The goal is to reduce (and over time, eliminate) spurious diffs.
  176. For Emacs users:
  177. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  178. Naming conventions ===================================================
  179. We use certain naming conventions to structure the considerable number
  180. of global identifiers. All identifiers should be either all lower
  181. case or all upper case. Syllables are separated by underscores `_'.
  182. All non-static identifiers should start with scm_ or SCM_. Then might
  183. follow zero or more syllables giving the category of the identifier.
  184. The currently used category identifiers are
  185. t - type name
  186. c,C - something with a interface suited for C use. This is used
  187. to name functions that behave like Scheme primitives but
  188. have a more C friendly calling convention.
  189. i,I - internal to libguile. It is global, but not considered part
  190. of the libguile API.
  191. f - a SCM variable pointing to a Scheme function object.
  192. F - a bit mask for a flag.
  193. m - a macro transformer procedure
  194. n,N - a count of something
  195. s - a constant C string
  196. k - a SCM variable pointing to a keyword.
  197. sym - a SCM variable pointing to a symbol.
  198. var - a SCM variable pointing to a variable object.
  199. The follwing syllables also have a technical meaning:
  200. str - this denotes a zero terminated C string
  201. mem - a C string with an explicit count