writing-rules.txt 3.5 KB

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