mkconfig.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /****************************************************************************
  2. * tools/mkconfig.c
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <errno.h>
  26. #include "cfgdefine.h"
  27. /****************************************************************************
  28. * Pre-processor Definitions
  29. ****************************************************************************/
  30. #define DEFCONFIG ".config"
  31. /****************************************************************************
  32. * Private Functions
  33. ****************************************************************************/
  34. static inline char *getfilepath(const char *name)
  35. {
  36. snprintf(line, PATH_MAX, "%s/" DEFCONFIG, name);
  37. line[PATH_MAX] = '\0';
  38. return strdup(line);
  39. }
  40. static void show_usage(const char *progname)
  41. {
  42. fprintf(stderr, "USAGE: %s <abs path to .config>\n", progname);
  43. exit(1);
  44. }
  45. /****************************************************************************
  46. * Public Functions
  47. ****************************************************************************/
  48. int main(int argc, char **argv, char **envp)
  49. {
  50. char *filepath;
  51. FILE *stream;
  52. if (argc != 2)
  53. {
  54. fprintf(stderr, "Unexpected number of arguments\n");
  55. show_usage(argv[0]);
  56. }
  57. filepath = getfilepath(argv[1]);
  58. if (!filepath)
  59. {
  60. fprintf(stderr, "getfilepath failed\n");
  61. exit(2);
  62. }
  63. stream = fopen(filepath, "r");
  64. if (!stream)
  65. {
  66. fprintf(stderr, "open %s failed: %s\n", filepath, strerror(errno));
  67. exit(3);
  68. }
  69. printf(
  70. "/* config.h -- Autogenerated! Do not edit. */\n\n"
  71. "#ifndef __INCLUDE_NUTTX_CONFIG_H\n"
  72. "#define __INCLUDE_NUTTX_CONFIG_H\n\n"
  73. "/* General Definitions ***********************************/\n"
  74. "/* Used to represent the values of tristate options */\n\n"
  75. "#define CONFIG_y 1\n"
  76. "#define CONFIG_m 2\n\n"
  77. "/* Architecture-specific options *************************/\n\n");
  78. generate_definitions(stream);
  79. printf(
  80. "\n/* Sanity Checks *****************************************/\n\n"
  81. "/* If this is an NXFLAT, external build, then make sure that\n"
  82. " * NXFLAT support is enabled in the base code.\n"
  83. " */\n\n"
  84. "#if defined(__NXFLAT__) && !defined(CONFIG_NXFLAT)\n"
  85. "# error \"NXFLAT support not enabled in this configuration\"\n"
  86. "#endif\n\n"
  87. "/* NXFLAT requires PIC support in the TCBs. */\n\n"
  88. "#if defined(CONFIG_NXFLAT)\n"
  89. "# undef CONFIG_PIC\n"
  90. "# define CONFIG_PIC 1\n"
  91. "#endif\n\n"
  92. "/* Binary format support is disabled if no binary formats are\n"
  93. " * configured (at present, NXFLAT is the only supported binary.\n"
  94. " * format).\n"
  95. " */\n\n"
  96. "#if !defined(CONFIG_NXFLAT) && !defined(CONFIG_ELF) \\\n"
  97. " && !defined(CONFIG_BUILTIN)\n"
  98. "# undef CONFIG_BINFMT_DISABLE\n"
  99. "# define CONFIG_BINFMT_DISABLE 1\n"
  100. "#endif\n\n"
  101. "/* The correct way to disable RR scheduling is to set the\n"
  102. " * timeslice to zero.\n"
  103. " */\n\n"
  104. "#ifndef CONFIG_RR_INTERVAL\n"
  105. "# define CONFIG_RR_INTERVAL 0\n"
  106. "#endif\n\n"
  107. "/* If no file streams are configured, then make certain that\n"
  108. " * buffered I/O support is disabled\n"
  109. " */\n\n"
  110. "#ifndef CONFIG_FILE_STREAM\n"
  111. "# undef CONFIG_STDIO_BUFFER_SIZE\n"
  112. "# undef CONFIG_STDIO_LINEBUFFER\n"
  113. "# undef CONFIG_STDIO_DISABLE_BUFFERING\n"
  114. "# define CONFIG_STDIO_DISABLE_BUFFERING 1\n"
  115. "#endif\n\n"
  116. "/* If priority inheritance is disabled, then do not allocate any\n"
  117. " * associated resources.\n"
  118. " */\n\n"
  119. "#if !defined(CONFIG_PRIORITY_INHERITANCE) \\\n"
  120. " || !defined(CONFIG_SEM_PREALLOCHOLDERS)\n"
  121. "# undef CONFIG_SEM_PREALLOCHOLDERS\n"
  122. "# define CONFIG_SEM_PREALLOCHOLDERS 0\n"
  123. "#endif\n\n"
  124. "#if !defined(CONFIG_PRIORITY_INHERITANCE) \\\n"
  125. " || !defined(CONFIG_SEM_NNESTPRIO)\n"
  126. "# undef CONFIG_SEM_NNESTPRIO\n"
  127. "# define CONFIG_SEM_NNESTPRIO 0\n"
  128. "#endif\n\n"
  129. "/* If the end of RAM is not specified then it is assumed to be\n"
  130. " * the beginning of RAM plus the RAM size.\n"
  131. " */\n\n"
  132. "#ifndef CONFIG_RAM_END\n"
  133. "# define CONFIG_RAM_END (CONFIG_RAM_START+CONFIG_RAM_SIZE)\n"
  134. "#endif\n\n"
  135. "#ifndef CONFIG_RAM_VEND\n"
  136. "# define CONFIG_RAM_VEND (CONFIG_RAM_VSTART+CONFIG_RAM_SIZE)\n"
  137. "#endif\n\n"
  138. "/* If the end of FLASH is not specified then it is assumed to be\n"
  139. " * the beginning of FLASH plus the FLASH size.\n"
  140. " */\n\n"
  141. "#ifndef CONFIG_FLASH_END\n"
  142. "# define CONFIG_FLASH_END (CONFIG_FLASH_START+CONFIG_FLASH_SIZE)\n"
  143. "#endif\n\n"
  144. "/* If the maximum message size is zero, then we assume that\n"
  145. " * message queues support should be disabled\n"
  146. " */\n\n"
  147. "#if !defined(CONFIG_MQ_MAXMSGSIZE) || defined(CONFIG_DISABLE_MQUEUE)\n"
  148. "# undef CONFIG_MQ_MAXMSGSIZE\n"
  149. "# define CONFIG_MQ_MAXMSGSIZE 0\n"
  150. "#endif\n\n"
  151. "#if CONFIG_MQ_MAXMSGSIZE <= 0 && !defined(CONFIG_DISABLE_MQUEUE)\n"
  152. "# define CONFIG_DISABLE_MQUEUE 1\n"
  153. "#endif\n\n"
  154. "#endif /* __INCLUDE_NUTTX_CONFIG_H */\n");
  155. fclose(stream);
  156. /* Exit (without bothering to clean up allocations) */
  157. free(filepath);
  158. return 0;
  159. }