2
1

writing-rules.txt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // -*- mode:doc; -*-
  2. Coding style
  3. ------------
  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. ~~~~~~~~~~~~~~~~
  14. +Config.in+ files contain entries for almost anything configurable in
  15. Buildroot.
  16. An entry has the following pattern:
  17. ---------------------
  18. config BR2_PACKAGE_LIBFOO
  19. bool "libfoo"
  20. depends on BR2_PACKAGE_LIBBAZ
  21. select BR2_PACKAGE_LIBBAR
  22. help
  23. This is a comment that explains what libfoo is.
  24. http://foosoftware.org/libfoo/
  25. ---------------------
  26. * The +bool+, +depends on+, +select+ and +help+ lines are indented
  27. with one tab.
  28. * The help text itself should be indented with one tab and two
  29. spaces.
  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. ~~~~~~~~~~~~~~
  37. * Assignment: use +=+ preceded and followed by one space:
  38. +
  39. ---------------------
  40. LIBFOO_VERSION = 1.0
  41. LIBFOO_CONF_OPT += --without-python-support
  42. ---------------------
  43. +
  44. It is also possible to align the +=+ signs:
  45. +
  46. ---------------------
  47. LIBFOO_VERSION = 1.0
  48. LIBFOO_SOURCE = foo-$(LIBFOO_VERSION).tar.gz
  49. LIBFOO_CONF_OPT += --without-python-support
  50. ---------------------
  51. * Indentation: use tab only:
  52. +
  53. ---------------------
  54. define LIBFOO_REMOVE_DOC
  55. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/doc \
  56. $(TARGET_DIR)/usr/share/man/man3/libfoo*
  57. endef
  58. ---------------------
  59. +
  60. Note that commands inside a +define+ block should always start with a tab,
  61. so _make_ recognizes them as commands.
  62. * Optional dependency:
  63. ** Prefer multi-line syntax.
  64. +
  65. YES:
  66. +
  67. ---------------------
  68. ifeq ($(BR2_PACKAGE_PYTHON),y)
  69. LIBFOO_CONF_OPT += --with-python-support
  70. LIBFOO_DEPENDENCIES += python
  71. else
  72. LIBFOO_CONF_OPT += --without-python-support
  73. endif
  74. ---------------------
  75. +
  76. NO:
  77. +
  78. ---------------------
  79. LIBFOO_CONF_OPT += --with$(if $(BR2_PACKAGE_PYTHON),,out)-python-support
  80. LIBFOO_DEPENDENCIES += $(if $(BR2_PACKAGE_PYTHON),python,)
  81. ---------------------
  82. ** Keep configure options and dependencies close together.
  83. * Optional hooks: keep hook definition and assignment together in one
  84. if block.
  85. +
  86. YES:
  87. +
  88. ---------------------
  89. ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  90. define LIBFOO_REMOVE_DATA
  91. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
  92. endef
  93. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  94. endif
  95. ---------------------
  96. +
  97. NO:
  98. +
  99. ---------------------
  100. define LIBFOO_REMOVE_DATA
  101. $(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
  102. endef
  103. ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
  104. LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
  105. endif
  106. ---------------------
  107. The documentation
  108. ~~~~~~~~~~~~~~~~~
  109. The documentation uses the
  110. http://www.methods.co.nz/asciidoc/[asciidoc] format.
  111. For further details about the http://www.methods.co.nz/asciidoc/[asciidoc]
  112. syntax, refer to http://www.methods.co.nz/asciidoc/userguide.html[].