writing-rules.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // -*- mode:doc; -*-
  2. // vim: set syntax=asciidoc:
  3. Coding style
  4. ------------
  5. Overall, these coding style rules are here to help you to add new files in
  6. Buildroot or refactor existing ones.
  7. If you slightly modify some existing file, the important thing is
  8. to keep the consistency of the whole file, so you can:
  9. * either follow the potentially deprecated coding style used in this
  10. file,
  11. * or entirely rework it in order to make it comply with these rules.
  12. [[writing-rules-config-in]]
  13. +Config.in+ file
  14. ~~~~~~~~~~~~~~~~
  15. +Config.in+ files contain entries for almost anything configurable in
  16. Buildroot.
  17. An entry has the following pattern:
  18. ---------------------
  19. config BR2_PACKAGE_LIBFOO
  20. bool "libfoo"
  21. depends on BR2_PACKAGE_LIBBAZ
  22. select BR2_PACKAGE_LIBBAR
  23. help
  24. This is a comment that explains what libfoo is.
  25. http://foosoftware.org/libfoo/
  26. ---------------------
  27. * The +bool+, +depends on+, +select+ and +help+ lines are indented
  28. with one tab.
  29. * The help text itself should be indented with one tab and two
  30. spaces.
  31. The +Config.in+ files are the input for the configuration tool
  32. used in Buildroot, which is the regular _Kconfig_. For further
  33. details about the _Kconfig_ language, refer to
  34. http://kernel.org/doc/Documentation/kbuild/kconfig-language.txt[].
  35. [[writing-rules-mk]]
  36. The +.mk+ file
  37. ~~~~~~~~~~~~~~
  38. * Header: The file starts with a header. It contains the module name,
  39. preferably in lowercase, enclosed between separators made of 80 hashes. A
  40. blank line is mandatory after the header:
  41. +
  42. ---------------------
  43. ################################################################################
  44. #
  45. # libfoo
  46. #
  47. ################################################################################
  48. ---------------------
  49. +
  50. * Assignment: use +=+ preceded and followed by one space:
  51. +
  52. ---------------------
  53. LIBFOO_VERSION = 1.0
  54. LIBFOO_CONF_OPT += --without-python-support
  55. ---------------------
  56. +
  57. It is also possible to align the +=+ signs:
  58. +
  59. ---------------------
  60. LIBFOO_VERSION = 1.0
  61. LIBFOO_SOURCE = foo-$(LIBFOO_VERSION).tar.gz
  62. LIBFOO_CONF_OPT += --without-python-support
  63. ---------------------
  64. * Indentation: use tab only:
  65. +
  66. ---------------------
  67. define LIBFOO_REMOVE_DOC
  68. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/doc \
  69. $(TARGET_DIR)/usr/share/man/man3/libfoo*
  70. endef
  71. ---------------------
  72. +
  73. Note that commands inside a +define+ block should always start with a tab,
  74. so _make_ recognizes them as commands.
  75. * Optional dependency:
  76. ** Prefer multi-line syntax.
  77. +
  78. YES:
  79. +
  80. ---------------------
  81. ifeq ($(BR2_PACKAGE_PYTHON),y)
  82. LIBFOO_CONF_OPT += --with-python-support
  83. LIBFOO_DEPENDENCIES += python
  84. else
  85. LIBFOO_CONF_OPT += --without-python-support
  86. endif
  87. ---------------------
  88. +
  89. NO:
  90. +
  91. ---------------------
  92. LIBFOO_CONF_OPT += --with$(if $(BR2_PACKAGE_PYTHON),,out)-python-support
  93. LIBFOO_DEPENDENCIES += $(if $(BR2_PACKAGE_PYTHON),python,)
  94. ---------------------
  95. ** Keep configure options and dependencies close together.
  96. * Optional hooks: keep hook definition and assignment together in one
  97. if block.
  98. +
  99. YES:
  100. +
  101. ---------------------
  102. ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  103. define LIBFOO_REMOVE_DATA
  104. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
  105. endef
  106. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  107. endif
  108. ---------------------
  109. +
  110. NO:
  111. +
  112. ---------------------
  113. define LIBFOO_REMOVE_DATA
  114. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
  115. endef
  116. ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  117. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  118. endif
  119. ---------------------
  120. The documentation
  121. ~~~~~~~~~~~~~~~~~
  122. The documentation uses the
  123. http://www.methods.co.nz/asciidoc/[asciidoc] format.
  124. For further details about the http://www.methods.co.nz/asciidoc/[asciidoc]
  125. syntax, refer to http://www.methods.co.nz/asciidoc/userguide.html[].