writing-rules.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 +Config.in+ files are the input for the configuration tool
  30. used in Buildroot, which is the regular _Kconfig_. For further
  31. details about the _Kconfig_ language, refer to
  32. http://kernel.org/doc/Documentation/kbuild/kconfig-language.txt[].
  33. [[writing-rules-mk]]
  34. === The +.mk+ file
  35. * Header: The file starts with a header. It contains the module name,
  36. preferably in lowercase, enclosed between separators made of 80 hashes. A
  37. blank line is mandatory after the header:
  38. +
  39. ---------------------
  40. ################################################################################
  41. #
  42. # libfoo
  43. #
  44. ################################################################################
  45. ---------------------
  46. +
  47. * Assignment: use +=+ preceded and followed by one space:
  48. +
  49. ---------------------
  50. LIBFOO_VERSION = 1.0
  51. LIBFOO_CONF_OPTS += --without-python-support
  52. ---------------------
  53. +
  54. Do not align the +=+ signs.
  55. * Indentation: use tab only:
  56. +
  57. ---------------------
  58. define LIBFOO_REMOVE_DOC
  59. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/doc \
  60. $(TARGET_DIR)/usr/share/man/man3/libfoo*
  61. endef
  62. ---------------------
  63. +
  64. Note that commands inside a +define+ block should always start with a tab,
  65. so _make_ recognizes them as commands.
  66. * Optional dependency:
  67. ** Prefer multi-line syntax.
  68. +
  69. YES:
  70. +
  71. ---------------------
  72. ifeq ($(BR2_PACKAGE_PYTHON),y)
  73. LIBFOO_CONF_OPTS += --with-python-support
  74. LIBFOO_DEPENDENCIES += python
  75. else
  76. LIBFOO_CONF_OPTS += --without-python-support
  77. endif
  78. ---------------------
  79. +
  80. NO:
  81. +
  82. ---------------------
  83. LIBFOO_CONF_OPTS += --with$(if $(BR2_PACKAGE_PYTHON),,out)-python-support
  84. LIBFOO_DEPENDENCIES += $(if $(BR2_PACKAGE_PYTHON),python,)
  85. ---------------------
  86. ** Keep configure options and dependencies close together.
  87. * Optional hooks: keep hook definition and assignment together in one
  88. if block.
  89. +
  90. YES:
  91. +
  92. ---------------------
  93. ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  94. define LIBFOO_REMOVE_DATA
  95. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
  96. endef
  97. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  98. endif
  99. ---------------------
  100. +
  101. NO:
  102. +
  103. ---------------------
  104. define LIBFOO_REMOVE_DATA
  105. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
  106. endef
  107. ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  108. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  109. endif
  110. ---------------------
  111. === The documentation
  112. The documentation uses the
  113. http://www.methods.co.nz/asciidoc/[asciidoc] format.
  114. For further details about the http://www.methods.co.nz/asciidoc/[asciidoc]
  115. syntax, refer to http://www.methods.co.nz/asciidoc/userguide.html[].