mkconfig.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /****************************************************************************
  2. * tools/mkconfig.c
  3. *
  4. * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <string.h>
  39. #include <stdlib.h>
  40. #include <errno.h>
  41. #include "cfgdefine.h"
  42. /****************************************************************************
  43. * Pre-processor Definitions
  44. ****************************************************************************/
  45. #define DEFCONFIG ".config"
  46. /****************************************************************************
  47. * Private Functions
  48. ****************************************************************************/
  49. static inline char *getfilepath(const char *name)
  50. {
  51. snprintf(line, PATH_MAX, "%s/" DEFCONFIG, name);
  52. line[PATH_MAX] = '\0';
  53. return strdup(line);
  54. }
  55. static void show_usage(const char *progname)
  56. {
  57. fprintf(stderr, "USAGE: %s <abs path to .config>\n", progname);
  58. exit(1);
  59. }
  60. /****************************************************************************
  61. * Public Functions
  62. ****************************************************************************/
  63. int main(int argc, char **argv, char **envp)
  64. {
  65. char *filepath;
  66. FILE *stream;
  67. if (argc != 2)
  68. {
  69. fprintf(stderr, "Unexpected number of arguments\n");
  70. show_usage(argv[0]);
  71. }
  72. filepath = getfilepath(argv[1]);
  73. if (!filepath)
  74. {
  75. fprintf(stderr, "getfilepath failed\n");
  76. exit(2);
  77. }
  78. stream = fopen(filepath, "r");
  79. if (!stream)
  80. {
  81. fprintf(stderr, "open %s failed: %s\n", filepath, strerror(errno));
  82. exit(3);
  83. }
  84. printf("/* config.h -- Autogenerated! Do not edit. */\n\n");
  85. printf("#ifndef __INCLUDE_NUTTX_CONFIG_H\n");
  86. printf("#define __INCLUDE_NUTTX_CONFIG_H\n\n");
  87. printf("/* General Definitions ***********************************/\n");
  88. printf("/* Used to represent the values of tristate options */\n\n");
  89. printf("#define CONFIG_y 1\n");
  90. printf("#define CONFIG_m 2\n\n");
  91. printf("/* Architecture-specific options *************************/\n\n");
  92. generate_definitions(stream);
  93. printf("\n/* Sanity Checks *****************************************/\n\n");
  94. printf("/* If this is an NXFLAT, external build, then make sure that\n");
  95. printf(" * NXFLAT support is enabled in the base code.\n");
  96. printf(" */\n\n");
  97. printf("#if defined(__NXFLAT__) && !defined(CONFIG_NXFLAT)\n");
  98. printf("# error \"NXFLAT support not enabled in this configuration\"\n");
  99. printf("#endif\n\n");
  100. printf("/* NXFLAT requires PIC support in the TCBs. */\n\n");
  101. printf("#if defined(CONFIG_NXFLAT)\n");
  102. printf("# undef CONFIG_PIC\n");
  103. printf("# define CONFIG_PIC 1\n");
  104. printf("#endif\n\n");
  105. printf("/* Binary format support is disabled if no binary formats are\n");
  106. printf(" * configured (at present, NXFLAT is the only supported binary.\n");
  107. printf(" * format).\n");
  108. printf(" */\n\n");
  109. printf("#if !defined(CONFIG_NXFLAT) && !defined(CONFIG_ELF) && !defined(CONFIG_BUILTIN)\n");
  110. printf("# undef CONFIG_BINFMT_DISABLE\n");
  111. printf("# define CONFIG_BINFMT_DISABLE 1\n");
  112. printf("#endif\n\n");
  113. printf("/* The correct way to disable RR scheduling is to set the\n");
  114. printf(" * timeslice to zero.\n");
  115. printf(" */\n\n");
  116. printf("#ifndef CONFIG_RR_INTERVAL\n");
  117. printf("# define CONFIG_RR_INTERVAL 0\n");
  118. printf("#endif\n\n");
  119. printf("/* The correct way to disable stream support is to set the number of\n");
  120. printf(" * streamd to zero.\n");
  121. printf(" */\n\n");
  122. printf("#ifndef CONFIG_NFILE_STREAMS\n");
  123. printf("# define CONFIG_NFILE_STREAMS 0\n");
  124. printf("#endif\n\n");
  125. printf("/* If no file streams are configured, then make certain that buffered I/O\n");
  126. printf(" * support is disabled\n");
  127. printf(" */\n\n");
  128. printf("#if CONFIG_NFILE_STREAMS == 0\n");
  129. printf("# undef CONFIG_STDIO_BUFFER_SIZE\n");
  130. printf("# undef CONFIG_STDIO_LINEBUFFER\n");
  131. printf("# undef CONFIG_STDIO_DISABLE_BUFFERING\n");
  132. printf("# define CONFIG_STDIO_DISABLE_BUFFERING 1\n");
  133. printf("#endif\n\n");
  134. printf("/* If priority inheritance is disabled, then do not allocate any\n");
  135. printf(" * associated resources.\n");
  136. printf(" */\n\n");
  137. printf("#if !defined(CONFIG_PRIORITY_INHERITANCE) || !defined(CONFIG_SEM_PREALLOCHOLDERS)\n");
  138. printf("# undef CONFIG_SEM_PREALLOCHOLDERS\n");
  139. printf("# define CONFIG_SEM_PREALLOCHOLDERS 0\n");
  140. printf("#endif\n\n");
  141. printf("#if !defined(CONFIG_PRIORITY_INHERITANCE) || !defined(CONFIG_SEM_NNESTPRIO)\n");
  142. printf("# undef CONFIG_SEM_NNESTPRIO\n");
  143. printf("# define CONFIG_SEM_NNESTPRIO 0\n");
  144. printf("#endif\n\n");
  145. printf("/* If the end of RAM is not specified then it is assumed to be the beginning\n");
  146. printf(" * of RAM plus the RAM size.\n");
  147. printf(" */\n\n");
  148. printf("#ifndef CONFIG_RAM_END\n");
  149. printf("# define CONFIG_RAM_END (CONFIG_RAM_START+CONFIG_RAM_SIZE)\n");
  150. printf("#endif\n\n");
  151. printf("#ifndef CONFIG_RAM_VEND\n");
  152. printf("# define CONFIG_RAM_VEND (CONFIG_RAM_VSTART+CONFIG_RAM_SIZE)\n");
  153. printf("#endif\n\n");
  154. printf("/* If the end of FLASH is not specified then it is assumed to be the beginning\n");
  155. printf(" * of FLASH plus the FLASH size.\n");
  156. printf(" */\n\n");
  157. printf("#ifndef CONFIG_FLASH_END\n");
  158. printf("# define CONFIG_FLASH_END (CONFIG_FLASH_START+CONFIG_FLASH_SIZE)\n");
  159. printf("#endif\n\n");
  160. printf("/* If the maximum message size is zero, then we assume that message queues\n");
  161. printf(" * support should be disabled\n");
  162. printf(" */\n\n");
  163. printf("#if !defined(CONFIG_MQ_MAXMSGSIZE) || defined(CONFIG_DISABLE_MQUEUE)\n");
  164. printf("# undef CONFIG_MQ_MAXMSGSIZE\n");
  165. printf("# define CONFIG_MQ_MAXMSGSIZE 0\n");
  166. printf("#endif\n\n");
  167. printf("#if CONFIG_MQ_MAXMSGSIZE <= 0 && !defined(CONFIG_DISABLE_MQUEUE)\n");
  168. printf("# define CONFIG_DISABLE_MQUEUE 1\n");
  169. printf("#endif\n\n");
  170. printf("#endif /* __INCLUDE_NUTTX_CONFIG_H */\n");
  171. fclose(stream);
  172. /* Exit (without bothering to clean up allocations) */
  173. free(filepath);
  174. return 0;
  175. }