writing-rules.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. * Assignment: use +=+ preceded and followed by one space:
  39. +
  40. ---------------------
  41. LIBFOO_VERSION = 1.0
  42. LIBFOO_CONF_OPT += --without-python-support
  43. ---------------------
  44. +
  45. It is also possible to align the +=+ signs:
  46. +
  47. ---------------------
  48. LIBFOO_VERSION = 1.0
  49. LIBFOO_SOURCE = foo-$(LIBFOO_VERSION).tar.gz
  50. LIBFOO_CONF_OPT += --without-python-support
  51. ---------------------
  52. * Indentation: use tab only:
  53. +
  54. ---------------------
  55. define LIBFOO_REMOVE_DOC
  56. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/doc \
  57. $(TARGET_DIR)/usr/share/man/man3/libfoo*
  58. endef
  59. ---------------------
  60. +
  61. Note that commands inside a +define+ block should always start with a tab,
  62. so _make_ recognizes them as commands.
  63. * Optional dependency:
  64. ** Prefer multi-line syntax.
  65. +
  66. YES:
  67. +
  68. ---------------------
  69. ifeq ($(BR2_PACKAGE_PYTHON),y)
  70. LIBFOO_CONF_OPT += --with-python-support
  71. LIBFOO_DEPENDENCIES += python
  72. else
  73. LIBFOO_CONF_OPT += --without-python-support
  74. endif
  75. ---------------------
  76. +
  77. NO:
  78. +
  79. ---------------------
  80. LIBFOO_CONF_OPT += --with$(if $(BR2_PACKAGE_PYTHON),,out)-python-support
  81. LIBFOO_DEPENDENCIES += $(if $(BR2_PACKAGE_PYTHON),python,)
  82. ---------------------
  83. ** Keep configure options and dependencies close together.
  84. * Optional hooks: keep hook definition and assignment together in one
  85. if block.
  86. +
  87. YES:
  88. +
  89. ---------------------
  90. ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  91. define LIBFOO_REMOVE_DATA
  92. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
  93. endef
  94. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  95. endif
  96. ---------------------
  97. +
  98. NO:
  99. +
  100. ---------------------
  101. define LIBFOO_REMOVE_DATA
  102. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
  103. endef
  104. ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  105. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  106. endif
  107. ---------------------
  108. The documentation
  109. ~~~~~~~~~~~~~~~~~
  110. The documentation uses the
  111. http://www.methods.co.nz/asciidoc/[asciidoc] format.
  112. For further details about the http://www.methods.co.nz/asciidoc/[asciidoc]
  113. syntax, refer to http://www.methods.co.nz/asciidoc/userguide.html[].