menuselect.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2005 - 2010, Digium, Inc.
  5. *
  6. * Russell Bryant <russell@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*!
  19. * \file
  20. *
  21. * \author Russell Bryant <russell@digium.com>
  22. *
  23. * \brief A menu-driven system for Asterisk module selection
  24. */
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <stdarg.h>
  30. #include <getopt.h>
  31. #include <ctype.h>
  32. #include <libxml/parser.h>
  33. #include <libxml/tree.h>
  34. #include "autoconfig.h"
  35. #include "linkedlists.h"
  36. #include "menuselect.h"
  37. #define ARRAY_LEN(a) (size_t) (sizeof(a) / sizeof(0[a]))
  38. #ifdef MENUSELECT_DEBUG
  39. static FILE *debug;
  40. #endif
  41. /*! The list of categories */
  42. struct categories categories = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
  43. /*!
  44. We have to maintain a pointer to the root of the trees generated from reading
  45. the build options XML files so that we can free it when we're done. We don't
  46. copy any of the information over from these trees. Our list is just a
  47. convenient mapping to the information contained in these lists with one
  48. additional piece of information - whether the build option is enabled or not.
  49. */
  50. struct tree {
  51. /*! the root of the tree */
  52. xmlDoc *root;
  53. /*! for linking */
  54. AST_LIST_ENTRY(tree) list;
  55. };
  56. /*! The list of trees from menuselect-tree files */
  57. static AST_LIST_HEAD_NOLOCK_STATIC(trees, tree);
  58. static const char * const tree_files[] = {
  59. "menuselect-tree"
  60. };
  61. static char *output_makeopts = OUTPUT_MAKEOPTS_DEFAULT;
  62. static char *output_makedeps = OUTPUT_MAKEDEPS_DEFAULT;
  63. /*! This is set to 1 if menuselect.makeopts pre-existed the execution of this app */
  64. static int existing_config = 0;
  65. /*! This is set when the --check-deps argument is provided. */
  66. static int check_deps = 0;
  67. /*! These are set when the --list-options or --list-groups arguments are provided. */
  68. static int list_options = 0, list_groups = 0;
  69. /*! This variable is non-zero when any changes are made */
  70. int changes_made = 0;
  71. /*! Menu name */
  72. const char *menu_name = "Menuselect";
  73. enum dep_file_state {
  74. DEP_FILE_UNKNOWN = -2,
  75. DEP_FILE_DISABLED = -1,
  76. DEP_FILE_UNMET = 0,
  77. DEP_FILE_MET = 1,
  78. };
  79. /*! Global list of dependencies that are external to the tree */
  80. struct dep_file {
  81. char name[32];
  82. enum dep_file_state met;
  83. enum dep_file_state previously_met;
  84. AST_LIST_ENTRY(dep_file) list;
  85. };
  86. AST_LIST_HEAD_NOLOCK_STATIC(deps_file, dep_file);
  87. /*! \brief return a pointer to the first non-whitespace character */
  88. static inline char *skip_blanks(char *str)
  89. {
  90. if (!str)
  91. return NULL;
  92. while (*str && *str < 33)
  93. str++;
  94. return str;
  95. }
  96. static int open_debug(void)
  97. {
  98. #ifdef MENUSELECT_DEBUG
  99. if (!(debug = fopen("menuselect_debug.txt", "w"))) {
  100. fprintf(stderr, "Failed to open menuselect_debug.txt for debug output.\n");
  101. return -1;
  102. }
  103. #endif
  104. return 0;
  105. }
  106. #define print_debug(f, ...) __print_debug(__LINE__, f, ## __VA_ARGS__)
  107. static void __attribute__((format(printf, 2, 3))) __print_debug(int line, const char *format, ...)
  108. {
  109. #ifdef MENUSELECT_DEBUG
  110. va_list ap;
  111. fprintf(debug, "%d -", line);
  112. va_start(ap, format);
  113. vfprintf(debug, format, ap);
  114. va_end(ap);
  115. fflush(debug);
  116. #endif
  117. }
  118. static void close_debug(void)
  119. {
  120. #ifdef MENUSELECT_DEBUG
  121. if (debug)
  122. fclose(debug);
  123. #endif
  124. }
  125. /*! \brief Finds a category with the given name or creates it if not found */
  126. static struct category *category_find_or_create(const char *name)
  127. {
  128. struct category *c;
  129. AST_LIST_TRAVERSE(&categories, c, list) {
  130. if (!strcmp(c->name, name)) {
  131. xmlFree((void *) name);
  132. return c;
  133. }
  134. }
  135. if (!(c = calloc(1, sizeof(*c)))) {
  136. return NULL;
  137. }
  138. c->name = name;
  139. AST_LIST_INSERT_TAIL(&categories, c, list);
  140. return c;
  141. }
  142. static void free_reference(struct reference *ref)
  143. {
  144. /* If name and displayname point to the same place, only free one of them */
  145. if (ref->name == ref->displayname) {
  146. xmlFree((void *) ref->name);
  147. } else {
  148. xmlFree((void *) ref->name);
  149. xmlFree((void *) ref->displayname);
  150. }
  151. free(ref);
  152. }
  153. /*! \brief Free a member structure and all of its members */
  154. static void free_member(struct member *mem)
  155. {
  156. struct reference *ref;
  157. if (!mem) {
  158. return;
  159. }
  160. while ((ref = AST_LIST_REMOVE_HEAD(&mem->deps, list)))
  161. free_reference(ref);
  162. while ((ref = AST_LIST_REMOVE_HEAD(&mem->conflicts, list)))
  163. free_reference(ref);
  164. while ((ref = AST_LIST_REMOVE_HEAD(&mem->uses, list)))
  165. free_reference(ref);
  166. if (!mem->is_separator) {
  167. xmlFree((void *) mem->name);
  168. xmlFree((void *) mem->displayname);
  169. xmlFree((void *) mem->touch_on_change);
  170. xmlFree((void *) mem->remove_on_change);
  171. xmlFree((void *) mem->defaultenabled);
  172. xmlFree((void *) mem->support_level);
  173. xmlFree((void *) mem->replacement);
  174. }
  175. free(mem);
  176. }
  177. /*! \assigns values to support level strings */
  178. static enum support_level_values string_to_support_level(const char *support_level)
  179. {
  180. if (!support_level) {
  181. return SUPPORT_UNSPECIFIED;
  182. }
  183. if (!strcasecmp(support_level, "core")) {
  184. return SUPPORT_CORE;
  185. }
  186. if (!strcasecmp(support_level, "extended")) {
  187. return SUPPORT_EXTENDED;
  188. }
  189. if (!strcasecmp(support_level, "deprecated")) {
  190. return SUPPORT_DEPRECATED;
  191. }
  192. if (!strcasecmp(support_level, "external")) {
  193. return SUPPORT_EXTERNAL;
  194. }
  195. if (!strcasecmp(support_level, "option")) {
  196. return SUPPORT_OPTION;
  197. }
  198. return SUPPORT_UNSPECIFIED;
  199. }
  200. /*! \gets const separator strings from support level values */
  201. static const char *support_level_to_string(enum support_level_values support_level)
  202. {
  203. switch (support_level) {
  204. case SUPPORT_CORE:
  205. return "Core";
  206. case SUPPORT_EXTENDED:
  207. return "Extended";
  208. case SUPPORT_DEPRECATED:
  209. return "Deprecated";
  210. case SUPPORT_EXTERNAL:
  211. return "External";
  212. case SUPPORT_OPTION:
  213. return "Module Options";
  214. default:
  215. return "Unspecified";
  216. }
  217. }
  218. static void categories_flatten()
  219. {
  220. int idx;
  221. struct category *c;
  222. struct member *m;
  223. AST_LIST_TRAVERSE(&categories, c, list) {
  224. for (idx = 0; idx < SUPPORT_COUNT; idx++) {
  225. struct support_level_bucket bucket = c->buckets[idx];
  226. while ((m = AST_LIST_REMOVE_HEAD(&bucket, list))) {
  227. AST_LIST_INSERT_TAIL(&c->members, m, list);
  228. }
  229. }
  230. }
  231. }
  232. /*! \sets default values for a given separator */
  233. static struct member *create_separator(enum support_level_values level)
  234. {
  235. struct member *separator = calloc(1, sizeof(*separator));
  236. separator->name = support_level_to_string(level);
  237. separator->displayname = "";
  238. separator->is_separator = 1;
  239. return separator;
  240. }
  241. /*! \adds a member to a category and attaches it to the last element of a particular support level used */
  242. static int add_member_list_order(struct member *mem, struct category *cat)
  243. {
  244. enum support_level_values support_level = string_to_support_level(mem->support_level);
  245. struct support_level_bucket *bucket = &cat->buckets[support_level];
  246. if (AST_LIST_EMPTY(bucket)) {
  247. struct member *sep = create_separator(support_level);
  248. AST_LIST_INSERT_TAIL(bucket, sep, list);
  249. }
  250. AST_LIST_INSERT_TAIL(bucket, mem, list);
  251. return 0;
  252. }
  253. static int process_xml_defaultenabled_node(xmlNode *node, struct member *mem)
  254. {
  255. const char *tmp = (const char *) xmlNodeGetContent(node);
  256. if (tmp && !strlen_zero(tmp)) {
  257. mem->defaultenabled = tmp;
  258. }
  259. return 0;
  260. }
  261. static int process_xml_supportlevel_node(xmlNode *node, struct member *mem)
  262. {
  263. const char *tmp = (const char *) xmlNodeGetContent(node);
  264. if (tmp && !strlen_zero(tmp)) {
  265. xmlFree((void *) mem->support_level);
  266. mem->support_level = tmp;
  267. print_debug("Set support_level for %s to %s\n", mem->name, mem->support_level);
  268. }
  269. return 0;
  270. }
  271. static int process_xml_replacement_node(xmlNode *node, struct member *mem)
  272. {
  273. const char *tmp = (const char *) xmlNodeGetContent(node);
  274. if (tmp && !strlen_zero(tmp)) {
  275. mem->replacement = tmp;
  276. }
  277. return 0;
  278. }
  279. static int process_xml_ref_node(xmlNode *node, struct member *mem, struct reference_list *refs)
  280. {
  281. struct reference *ref;
  282. const char *tmp;
  283. if (!(ref = calloc(1, sizeof(*ref)))) {
  284. free_member(mem);
  285. return -1;
  286. }
  287. if ((tmp = (const char *) xmlGetProp(node, BAD_CAST "name"))) {
  288. if (!strlen_zero(tmp)) {
  289. ref->name = tmp;
  290. }
  291. }
  292. if ((tmp = (const char *) xmlGetProp(node, BAD_CAST "autoselect"))) {
  293. ref->autoselect = !strcasecmp(tmp, "yes");
  294. }
  295. tmp = (const char *) xmlNodeGetContent(node);
  296. if (tmp && !strlen_zero(tmp)) {
  297. ref->displayname = tmp;
  298. if (!ref->name) {
  299. ref->name = ref->displayname;
  300. }
  301. AST_LIST_INSERT_TAIL(refs, ref, list);
  302. } else {
  303. free_reference(ref);
  304. }
  305. return 0;
  306. }
  307. static int process_xml_depend_node(xmlNode *node, struct member *mem)
  308. {
  309. return process_xml_ref_node(node, mem, &mem->deps);
  310. }
  311. static int process_xml_conflict_node(xmlNode *node, struct member *mem)
  312. {
  313. return process_xml_ref_node(node, mem, &mem->conflicts);
  314. }
  315. static int process_xml_use_node(xmlNode *node, struct member *mem)
  316. {
  317. return process_xml_ref_node(node, mem, &mem->uses);
  318. }
  319. static int process_xml_member_data_node(xmlNode *node, struct member *mem)
  320. {
  321. return 0;
  322. }
  323. static int process_xml_unknown_node(xmlNode *node, struct member *mem)
  324. {
  325. fprintf(stderr, "Encountered unknown node: %s\n", node->name);
  326. return 0;
  327. }
  328. typedef int (*node_handler)(xmlNode *, struct member *);
  329. static const struct {
  330. const char *name;
  331. node_handler func;
  332. } node_handlers[] = {
  333. { "defaultenabled", process_xml_defaultenabled_node },
  334. { "support_level", process_xml_supportlevel_node },
  335. { "replacement", process_xml_replacement_node },
  336. { "depend", process_xml_depend_node },
  337. { "conflict", process_xml_conflict_node },
  338. { "use", process_xml_use_node },
  339. { "member_data", process_xml_member_data_node },
  340. };
  341. static node_handler lookup_node_handler(xmlNode *node)
  342. {
  343. int i;
  344. for (i = 0; i < ARRAY_LEN(node_handlers); i++) {
  345. if (!strcmp(node_handlers[i].name, (const char *) node->name)) {
  346. return node_handlers[i].func;
  347. }
  348. }
  349. return process_xml_unknown_node;
  350. }
  351. static int process_process_xml_category_child_node(xmlNode *node, struct member *mem)
  352. {
  353. node_handler handler = lookup_node_handler(node);
  354. return handler(node, mem);
  355. }
  356. static int process_xml_member_node(xmlNode *node, struct category *cat)
  357. {
  358. xmlNode *cur;
  359. struct member *mem;
  360. xmlChar *tmp;
  361. if (!(mem = calloc(1, sizeof(*mem)))) {
  362. return -1;
  363. }
  364. mem->name = (const char *) xmlGetProp(node, BAD_CAST "name");
  365. mem->displayname = (const char *) xmlGetProp(node, BAD_CAST "displayname");
  366. mem->touch_on_change = (const char *) xmlGetProp(node, BAD_CAST "touch_on_change");
  367. mem->remove_on_change = (const char *) xmlGetProp(node, BAD_CAST "remove_on_change");
  368. mem->support_level = (const char *) xmlCharStrdup("unspecified");
  369. if ((tmp = xmlGetProp(node, BAD_CAST "explicitly_enabled_only"))) {
  370. mem->explicitly_enabled_only = !xmlStrcasecmp(tmp, BAD_CAST "yes");
  371. xmlFree(tmp);
  372. }
  373. for (cur = node->children; cur; cur = cur->next) {
  374. if (cur->type != XML_ELEMENT_NODE) {
  375. continue;
  376. }
  377. process_process_xml_category_child_node(cur, mem);
  378. }
  379. if (!cat->positive_output && strcasecmp(mem->support_level, "option")) {
  380. mem->enabled = 1;
  381. if (!mem->defaultenabled || strcasecmp(mem->defaultenabled, "no")) {
  382. mem->was_enabled = 1;
  383. print_debug("Enabled %s because the category does not have positive output\n", mem->name);
  384. }
  385. }
  386. if (add_member_list_order(mem, cat)) {
  387. free_member(mem);
  388. }
  389. return 0;
  390. }
  391. static void free_category(struct category *cat)
  392. {
  393. struct member *mem;
  394. xmlFree((void *) cat->name);
  395. xmlFree((void *) cat->displayname);
  396. xmlFree((void *) cat->remove_on_change);
  397. xmlFree((void *) cat->touch_on_change);
  398. while ((mem = AST_LIST_REMOVE_HEAD(&cat->members, list))) {
  399. free_member(mem);
  400. }
  401. free(cat);
  402. }
  403. static int process_xml_category_node(xmlNode *node)
  404. {
  405. struct category *cat;
  406. const char *tmp;
  407. xmlNode *cur;
  408. if (!(tmp = (const char *) xmlGetProp(node, BAD_CAST "name"))) {
  409. fprintf(stderr, "Missing 'name' attribute for 'category' element. Skipping...\n");
  410. /* Return success here so we don't bail on the whole document */
  411. return 0;
  412. }
  413. cat = category_find_or_create(tmp);
  414. if ((tmp = (const char *) xmlGetProp(node, BAD_CAST "displayname"))) {
  415. xmlFree((void *) cat->displayname);
  416. cat->displayname = tmp;
  417. }
  418. if ((tmp = (const char *) xmlGetProp(node, BAD_CAST "remove_on_change"))) {
  419. xmlFree((void *) cat->remove_on_change);
  420. cat->remove_on_change = tmp;
  421. }
  422. if ((tmp = (const char *) xmlGetProp(node, BAD_CAST "touch_on_change"))) {
  423. xmlFree((void *) cat->touch_on_change);
  424. cat->touch_on_change = tmp;
  425. }
  426. if ((tmp = (const char *) xmlGetProp(node, BAD_CAST "positive_output"))) {
  427. cat->positive_output = !strcasecmp(tmp, "yes");
  428. xmlFree((void *) tmp);
  429. }
  430. if ((tmp = (const char *) xmlGetProp(node, BAD_CAST "exclusive"))) {
  431. cat->exclusive = !strcasecmp(tmp, "yes");
  432. xmlFree((void *) tmp);
  433. }
  434. for (cur = node->children; cur; cur = cur->next) {
  435. if (cur->type != XML_ELEMENT_NODE) {
  436. continue;
  437. }
  438. if (xmlStrcmp(cur->name, BAD_CAST "member")) {
  439. fprintf(stderr, "Ignoring unknown element: %s\n", cur->name);
  440. continue;
  441. }
  442. process_xml_member_node(cur, cat);
  443. }
  444. return 0;
  445. }
  446. static int process_xml_menu_node(struct tree *tree, xmlNode *node)
  447. {
  448. xmlNode *cur;
  449. xmlChar *tmp;
  450. if (strcmp((const char *) node->name, "menu")) {
  451. fprintf(stderr, "Invalid document: Expected \"menu\" element.\n");
  452. return -1;
  453. }
  454. AST_LIST_INSERT_HEAD(&trees, tree, list);
  455. if ((tmp = xmlGetProp(node, BAD_CAST "name"))) {
  456. menu_name = (const char *) tmp;
  457. }
  458. for (cur = node->children; cur; cur = cur->next) {
  459. if (cur->type != XML_ELEMENT_NODE) {
  460. continue;
  461. }
  462. if (xmlStrcmp(cur->name, BAD_CAST "category")) {
  463. fprintf(stderr, "Ignoring unknown element: %s\n", cur->name);
  464. continue;
  465. }
  466. if (process_xml_category_node(cur)) {
  467. return -1;
  468. }
  469. }
  470. categories_flatten();
  471. return 0;
  472. }
  473. /*! \brief Parse an input makeopts file */
  474. static int parse_tree(const char *tree_file)
  475. {
  476. struct tree *tree;
  477. xmlNode *menu;
  478. if (!(tree = calloc(1, sizeof(*tree)))) {
  479. return -1;
  480. }
  481. if (!(tree->root = xmlParseFile(tree_file))) {
  482. free(tree);
  483. return -1;
  484. }
  485. if (!(menu = xmlDocGetRootElement(tree->root))) {
  486. fprintf(stderr, "Invalid document: No root element\n");
  487. xmlFreeDoc(tree->root);
  488. free(tree);
  489. return -1;
  490. }
  491. if (process_xml_menu_node(tree, menu)) {
  492. xmlFreeDoc(tree->root);
  493. free(tree);
  494. return -1;
  495. }
  496. return 0;
  497. }
  498. /*!
  499. * \arg interactive Set to non-zero if being called while user is making changes
  500. */
  501. static unsigned int calc_dep_failures(int interactive, int pre_confload)
  502. {
  503. unsigned int result = 0;
  504. struct category *cat;
  505. struct member *mem;
  506. struct reference *dep;
  507. struct dep_file *dep_file;
  508. unsigned int changed, old_failure;
  509. AST_LIST_TRAVERSE(&categories, cat, list) {
  510. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  511. if (mem->is_separator) {
  512. continue;
  513. }
  514. old_failure = mem->depsfailed;
  515. AST_LIST_TRAVERSE(&mem->deps, dep, list) {
  516. if (dep->member)
  517. continue;
  518. mem->depsfailed = HARD_FAILURE;
  519. AST_LIST_TRAVERSE(&deps_file, dep_file, list) {
  520. if (!strcasecmp(dep_file->name, dep->name)) {
  521. if (dep_file->met == DEP_FILE_MET) {
  522. mem->depsfailed = NO_FAILURE;
  523. }
  524. break;
  525. }
  526. }
  527. if (mem->depsfailed != NO_FAILURE) {
  528. break; /* This dependency is not met, so we can stop now */
  529. }
  530. }
  531. if (old_failure == SOFT_FAILURE && mem->depsfailed != HARD_FAILURE)
  532. mem->depsfailed = SOFT_FAILURE;
  533. }
  534. }
  535. if (pre_confload) {
  536. return 0;
  537. }
  538. do {
  539. changed = 0;
  540. AST_LIST_TRAVERSE(&categories, cat, list) {
  541. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  542. if (mem->is_separator) {
  543. continue;
  544. }
  545. old_failure = mem->depsfailed;
  546. if (mem->depsfailed == HARD_FAILURE)
  547. continue;
  548. mem->depsfailed = NO_FAILURE;
  549. AST_LIST_TRAVERSE(&mem->deps, dep, list) {
  550. if (!dep->member)
  551. continue;
  552. if (dep->member->depsfailed == HARD_FAILURE) {
  553. mem->depsfailed = HARD_FAILURE;
  554. break;
  555. } else if (dep->member->depsfailed == SOFT_FAILURE) {
  556. mem->depsfailed = SOFT_FAILURE;
  557. } else if (!dep->member->enabled) {
  558. mem->depsfailed = SOFT_FAILURE;
  559. }
  560. }
  561. if (mem->depsfailed != old_failure) {
  562. if ((mem->depsfailed == NO_FAILURE) && mem->was_defaulted) {
  563. mem->enabled = !strcasecmp(mem->defaultenabled, "yes");
  564. print_debug("Just set %s enabled to %d\n", mem->name, mem->enabled);
  565. } else {
  566. mem->enabled = interactive ? 0 : mem->was_enabled;
  567. print_debug("Just set %s enabled to %d\n", mem->name, mem->enabled);
  568. }
  569. changed = 1;
  570. break; /* This dependency is not met, so we can stop now */
  571. }
  572. }
  573. if (changed)
  574. break;
  575. }
  576. if (changed)
  577. result = 1;
  578. } while (changed);
  579. return result;
  580. }
  581. static unsigned int calc_conflict_failures(int interactive, int pre_confload)
  582. {
  583. unsigned int result = 0;
  584. struct category *cat;
  585. struct member *mem;
  586. struct reference *cnf;
  587. struct dep_file *dep_file;
  588. unsigned int changed, old_failure;
  589. AST_LIST_TRAVERSE(&categories, cat, list) {
  590. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  591. if (mem->is_separator) {
  592. continue;
  593. }
  594. old_failure = mem->conflictsfailed;
  595. AST_LIST_TRAVERSE(&mem->conflicts, cnf, list) {
  596. if (cnf->member)
  597. continue;
  598. mem->conflictsfailed = NO_FAILURE;
  599. AST_LIST_TRAVERSE(&deps_file, dep_file, list) {
  600. if (!strcasecmp(dep_file->name, cnf->name)) {
  601. if (dep_file->met == DEP_FILE_MET) {
  602. mem->conflictsfailed = HARD_FAILURE;
  603. print_debug("Setting %s conflictsfailed to HARD_FAILURE\n", mem->name);
  604. }
  605. break;
  606. }
  607. }
  608. if (mem->conflictsfailed != NO_FAILURE)
  609. break; /* This conflict was found, so we can stop now */
  610. }
  611. if (old_failure == SOFT_FAILURE && mem->conflictsfailed != HARD_FAILURE) {
  612. print_debug("%d - Setting %s conflictsfailed to SOFT_FAILURE\n", __LINE__, mem->name);
  613. mem->conflictsfailed = SOFT_FAILURE;
  614. }
  615. }
  616. }
  617. if (pre_confload) {
  618. return 0;
  619. }
  620. do {
  621. changed = 0;
  622. AST_LIST_TRAVERSE(&categories, cat, list) {
  623. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  624. if (mem->is_separator) {
  625. continue;
  626. }
  627. old_failure = mem->conflictsfailed;
  628. if (mem->conflictsfailed == HARD_FAILURE)
  629. continue;
  630. mem->conflictsfailed = NO_FAILURE;
  631. AST_LIST_TRAVERSE(&mem->conflicts, cnf, list) {
  632. if (!cnf->member)
  633. continue;
  634. if (cnf->member->enabled) {
  635. mem->conflictsfailed = SOFT_FAILURE;
  636. print_debug("%d - Setting %s conflictsfailed to SOFT_FAILURE because %s is enabled\n", __LINE__, mem->name, cnf->member->name);
  637. break;
  638. }
  639. }
  640. if (mem->conflictsfailed != old_failure && mem->conflictsfailed != NO_FAILURE) {
  641. mem->enabled = 0;
  642. print_debug("Just set %s enabled to %d because of conflicts\n", mem->name, mem->enabled);
  643. changed = 1;
  644. break; /* This conflict has been found, so we can stop now */
  645. }
  646. }
  647. if (changed)
  648. break;
  649. }
  650. if (changed)
  651. result = 1;
  652. } while (changed);
  653. return result;
  654. }
  655. /*! \brief Process dependencies against the input dependencies file */
  656. static int process_deps(void)
  657. {
  658. FILE *f;
  659. char buf[80];
  660. int res = 0;
  661. struct dep_file *dep_file;
  662. if (!(f = fopen(MENUSELECT_DEPS, "r"))) {
  663. fprintf(stderr, "Unable to open '%s' for reading! Did you run ./configure ?\n", MENUSELECT_DEPS);
  664. return -1;
  665. }
  666. /* Build a dependency list from the file generated by configure */
  667. while (memset(buf, 0, sizeof(buf)), fgets(buf, sizeof(buf), f)) {
  668. char *name, *cur, *prev, *p;
  669. int val;
  670. /* Strip trailing CR/NL */
  671. while ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) {
  672. *p = '\0';
  673. }
  674. p = buf;
  675. name = strsep(&p, "=");
  676. if (!p)
  677. continue;
  678. cur = strsep(&p, ":");
  679. prev = strsep(&p, ":");
  680. if (!(dep_file = calloc(1, sizeof(*dep_file))))
  681. break;
  682. strncpy(dep_file->name, name, sizeof(dep_file->name) - 1);
  683. dep_file->met = DEP_FILE_UNKNOWN;
  684. dep_file->previously_met = DEP_FILE_UNKNOWN;
  685. if (sscanf(cur, "%d", &val) != 1) {
  686. fprintf(stderr, "Unknown value '%s' found in %s for %s\n", cur, MENUSELECT_DEPS, name);
  687. } else {
  688. switch (val) {
  689. case DEP_FILE_MET:
  690. case DEP_FILE_UNMET:
  691. case DEP_FILE_DISABLED:
  692. dep_file->met = val;
  693. break;
  694. default:
  695. fprintf(stderr, "Unknown value '%s' found in %s for %s\n", cur, MENUSELECT_DEPS, name);
  696. break;
  697. }
  698. }
  699. if (prev) {
  700. if (sscanf(prev, "%d", &val) != 1) {
  701. fprintf(stderr, "Unknown value '%s' found in %s for %s\n", prev, MENUSELECT_DEPS, name);
  702. } else {
  703. switch (val) {
  704. case DEP_FILE_MET:
  705. case DEP_FILE_UNMET:
  706. case DEP_FILE_DISABLED:
  707. dep_file->previously_met = val;
  708. break;
  709. default:
  710. fprintf(stderr, "Unknown value '%s' found in %s for %s\n", prev, MENUSELECT_DEPS, name);
  711. break;
  712. }
  713. }
  714. }
  715. AST_LIST_INSERT_TAIL(&deps_file, dep_file, list);
  716. }
  717. fclose(f);
  718. return res;
  719. }
  720. static void free_deps_file(void)
  721. {
  722. struct dep_file *dep_file;
  723. /* Free the dependency list we built from the file */
  724. while ((dep_file = AST_LIST_REMOVE_HEAD(&deps_file, list)))
  725. free(dep_file);
  726. }
  727. static int match_member_relations(void)
  728. {
  729. struct category *cat, *cat2;
  730. struct member *mem, *mem2;
  731. struct reference *dep;
  732. struct reference *cnf;
  733. struct reference *use;
  734. /* Traverse through each module's dependency list and determine whether each is another module */
  735. AST_LIST_TRAVERSE(&categories, cat, list) {
  736. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  737. if (mem->is_separator) {
  738. continue;
  739. }
  740. AST_LIST_TRAVERSE(&mem->deps, dep, list) {
  741. AST_LIST_TRAVERSE(&cat->members, mem2, list) {
  742. if (mem->is_separator) {
  743. continue;
  744. }
  745. if (strcasecmp(mem2->name, dep->name))
  746. continue;
  747. dep->member = mem2;
  748. break;
  749. }
  750. if (dep->member)
  751. continue;
  752. AST_LIST_TRAVERSE(&categories, cat2, list) {
  753. AST_LIST_TRAVERSE(&cat2->members, mem2, list) {
  754. if (mem->is_separator) {
  755. continue;
  756. }
  757. if (strcasecmp(mem2->name, dep->name))
  758. continue;
  759. dep->member = mem2;
  760. break;
  761. }
  762. if (dep->member)
  763. break;
  764. }
  765. }
  766. }
  767. }
  768. /* Traverse through each module's use list and determine whether each is another module */
  769. AST_LIST_TRAVERSE(&categories, cat, list) {
  770. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  771. if (mem->is_separator) {
  772. continue;
  773. }
  774. AST_LIST_TRAVERSE(&mem->uses, use, list) {
  775. AST_LIST_TRAVERSE(&cat->members, mem2, list) {
  776. if (mem->is_separator) {
  777. continue;
  778. }
  779. if (strcasecmp(mem2->name, use->name))
  780. continue;
  781. use->member = mem2;
  782. break;
  783. }
  784. if (use->member)
  785. continue;
  786. AST_LIST_TRAVERSE(&categories, cat2, list) {
  787. AST_LIST_TRAVERSE(&cat2->members, mem2, list) {
  788. if (mem->is_separator) {
  789. continue;
  790. }
  791. if (strcasecmp(mem2->name, use->name))
  792. continue;
  793. use->member = mem2;
  794. break;
  795. }
  796. if (use->member)
  797. break;
  798. }
  799. }
  800. }
  801. }
  802. /*
  803. * BUGBUG:
  804. * This doesn't work, the only way we can fix this is to remove OPTIONAL_API
  805. * toggle from menuselect and add a command-line argument to ./configure.
  806. */
  807. #if 0
  808. AST_LIST_TRAVERSE(&categories, cat, list) {
  809. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  810. if (mem->is_separator) {
  811. continue;
  812. }
  813. AST_LIST_TRAVERSE_SAFE_BEGIN(&mem->uses, use, list) {
  814. if (use->member) {
  815. AST_LIST_REMOVE_CURRENT(&mem->uses, list);
  816. AST_LIST_INSERT_TAIL(&mem->deps, use, list);
  817. }
  818. }
  819. AST_LIST_TRAVERSE_SAFE_END;
  820. }
  821. }
  822. #endif
  823. /* Traverse through each category marked as exclusive and mark every member as conflicting with every other member */
  824. AST_LIST_TRAVERSE(&categories, cat, list) {
  825. if (!cat->exclusive)
  826. continue;
  827. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  828. if (mem->is_separator) {
  829. continue;
  830. }
  831. AST_LIST_TRAVERSE(&cat->members, mem2, list) {
  832. if (mem->is_separator) {
  833. continue;
  834. }
  835. if (mem2 == mem)
  836. continue;
  837. if (!(cnf = calloc(1, sizeof(*cnf))))
  838. return -1;
  839. cnf->name = mem2->name;
  840. cnf->member = mem2;
  841. AST_LIST_INSERT_TAIL(&mem->conflicts, cnf, list);
  842. }
  843. }
  844. }
  845. /* Traverse through each category and determine whether named conflicts for each module are other modules */
  846. AST_LIST_TRAVERSE(&categories, cat, list) {
  847. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  848. if (mem->is_separator) {
  849. continue;
  850. }
  851. AST_LIST_TRAVERSE(&mem->conflicts, cnf, list) {
  852. AST_LIST_TRAVERSE(&cat->members, mem2, list) {
  853. if (mem->is_separator) {
  854. continue;
  855. }
  856. if (strcasecmp(mem2->name, cnf->name))
  857. continue;
  858. cnf->member = mem2;
  859. break;
  860. }
  861. if (cnf->member)
  862. continue;
  863. AST_LIST_TRAVERSE(&categories, cat2, list) {
  864. AST_LIST_TRAVERSE(&cat2->members, mem2, list) {
  865. if (mem->is_separator) {
  866. continue;
  867. }
  868. if (strcasecmp(mem2->name, cnf->name))
  869. continue;
  870. cnf->member = mem2;
  871. break;
  872. }
  873. if (cnf->member)
  874. break;
  875. }
  876. }
  877. }
  878. }
  879. return 0;
  880. }
  881. /*! \brief Iterate through all of the input tree files and call the parse function on them */
  882. static int build_member_list(void)
  883. {
  884. int i;
  885. int res = -1;
  886. for (i = 0; i < (sizeof(tree_files) / sizeof(tree_files[0])); i++) {
  887. if ((res = parse_tree(tree_files[i]))) {
  888. fprintf(stderr, "Error parsing '%s'!\n", tree_files[i]);
  889. break;
  890. }
  891. }
  892. if (!res)
  893. res = match_member_relations();
  894. return res;
  895. }
  896. /*! \brief Given the string representation of a member and category, mark it as present in a given input file */
  897. static void mark_as_present(const char *member, const char *category)
  898. {
  899. struct category *cat;
  900. struct member *mem;
  901. char negate = 0;
  902. if (*member == '-') {
  903. member++;
  904. negate = 1;
  905. }
  906. print_debug("Marking %s of %s as present\n", member, category);
  907. AST_LIST_TRAVERSE(&categories, cat, list) {
  908. if (strcmp(category, cat->name))
  909. continue;
  910. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  911. if (mem->is_separator) {
  912. continue;
  913. }
  914. if (!strcmp(member, mem->name)) {
  915. mem->was_enabled = mem->enabled = (negate ? !cat->positive_output : cat->positive_output);
  916. print_debug("Just set %s enabled to %d\n", mem->name, mem->enabled);
  917. break;
  918. }
  919. }
  920. if (!mem)
  921. fprintf(stderr, "member '%s' in category '%s' not found, ignoring.\n", member, category);
  922. break;
  923. }
  924. if (!cat)
  925. fprintf(stderr, "category '%s' not found! Can't mark '%s' as disabled.\n", category, member);
  926. }
  927. unsigned int enable_member(struct member *mem)
  928. {
  929. struct reference *dep;
  930. unsigned int can_enable = 1;
  931. AST_LIST_TRAVERSE(&mem->deps, dep, list) {
  932. if (!dep->member)
  933. continue;
  934. if (!dep->member->enabled) {
  935. if (dep->member->conflictsfailed != NO_FAILURE) {
  936. can_enable = 0;
  937. break;
  938. }
  939. if (dep->member->depsfailed == HARD_FAILURE) {
  940. can_enable = 0;
  941. break;
  942. }
  943. if (dep->member->explicitly_enabled_only) {
  944. can_enable = 0;
  945. break;
  946. }
  947. if (!(can_enable = enable_member(dep->member)))
  948. break;
  949. }
  950. }
  951. if ((mem->enabled = can_enable)) {
  952. struct reference *use;
  953. print_debug("Just set %s enabled to %d\n", mem->name, mem->enabled);
  954. while (calc_dep_failures(1, 0) || calc_conflict_failures(1, 0));
  955. AST_LIST_TRAVERSE(&mem->uses, use, list) {
  956. if (use->member && use->autoselect && !use->member->enabled) {
  957. enable_member(use->member);
  958. }
  959. }
  960. }
  961. return can_enable;
  962. }
  963. void toggle_enabled(struct member *mem)
  964. {
  965. if ((mem->depsfailed == HARD_FAILURE) || (mem->conflictsfailed == HARD_FAILURE) || (mem->is_separator))
  966. return;
  967. if (!mem->enabled)
  968. enable_member(mem);
  969. else
  970. mem->enabled = 0;
  971. print_debug("3- changed %s to %d\n", mem->name, mem->enabled);
  972. mem->was_defaulted = 0;
  973. changes_made++;
  974. while (calc_dep_failures(1, 0) || calc_conflict_failures(1, 0));
  975. }
  976. /*! \brief Toggle a member of a category at the specified index to enabled/disabled */
  977. void toggle_enabled_index(struct category *cat, int index)
  978. {
  979. struct member *mem;
  980. int i = 0;
  981. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  982. if (i++ == index)
  983. break;
  984. }
  985. if (!mem)
  986. return;
  987. toggle_enabled(mem);
  988. }
  989. static void set_member_enabled(struct member *mem)
  990. {
  991. if ((mem->depsfailed == HARD_FAILURE) || (mem->conflictsfailed == HARD_FAILURE))
  992. return;
  993. if ((mem->enabled) || (mem->is_separator))
  994. return;
  995. enable_member(mem);
  996. mem->was_defaulted = 0;
  997. changes_made++;
  998. while (calc_dep_failures(1, 0) || calc_conflict_failures(1, 0));
  999. }
  1000. void set_enabled(struct category *cat, int index)
  1001. {
  1002. struct member *mem;
  1003. int i = 0;
  1004. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1005. if (mem->is_separator) {
  1006. continue;
  1007. }
  1008. if (i++ == index)
  1009. break;
  1010. }
  1011. if (!mem)
  1012. return;
  1013. set_member_enabled(mem);
  1014. }
  1015. static void clear_member_enabled(struct member *mem)
  1016. {
  1017. if (!mem->enabled)
  1018. return;
  1019. mem->enabled = 0;
  1020. mem->was_defaulted = 0;
  1021. changes_made++;
  1022. while (calc_dep_failures(1, 0) || calc_conflict_failures(1, 0));
  1023. }
  1024. void clear_enabled(struct category *cat, int index)
  1025. {
  1026. struct member *mem;
  1027. int i = 0;
  1028. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1029. if (mem->is_separator) {
  1030. continue;
  1031. }
  1032. if (i++ == index)
  1033. break;
  1034. }
  1035. if (!mem)
  1036. return;
  1037. clear_member_enabled(mem);
  1038. }
  1039. /*! \brief Process a previously failed dependency
  1040. *
  1041. * If a module was previously disabled because of a failed dependency
  1042. * or a conflict, and not because the user selected it to be that way,
  1043. * then it needs to be re-enabled by default if the problem is no longer present.
  1044. */
  1045. static void process_prev_failed_deps(char *buf)
  1046. {
  1047. const char *cat_name, *mem_name;
  1048. struct category *cat;
  1049. struct member *mem;
  1050. cat_name = strsep(&buf, "=");
  1051. mem_name = strsep(&buf, "\n");
  1052. if (!cat_name || !mem_name)
  1053. return;
  1054. AST_LIST_TRAVERSE(&categories, cat, list) {
  1055. if (strcasecmp(cat->name, cat_name))
  1056. continue;
  1057. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1058. if (mem->is_separator) {
  1059. continue;
  1060. }
  1061. if (strcasecmp(mem->name, mem_name))
  1062. continue;
  1063. if (!mem->depsfailed && !mem->conflictsfailed) {
  1064. mem->enabled = 1;
  1065. print_debug("Just set %s enabled to %d in processing of previously failed deps\n", mem->name, mem->enabled);
  1066. mem->was_defaulted = 0;
  1067. }
  1068. break;
  1069. }
  1070. break;
  1071. }
  1072. if (!cat || !mem)
  1073. fprintf(stderr, "Unable to find '%s' in category '%s'\n", mem_name, cat_name);
  1074. }
  1075. /*! \brief Parse an existing output makeopts file and enable members previously selected */
  1076. static int parse_existing_config(const char *infile)
  1077. {
  1078. FILE *f;
  1079. #define PARSE_BUF_SIZE 8192
  1080. char *buf = NULL;
  1081. char *category, *parse, *member;
  1082. int lineno = 0;
  1083. if (!(f = fopen(infile, "r"))) {
  1084. /* This isn't really an error, so only print the message in debug mode */
  1085. print_debug("Unable to open '%s' for reading existing config.\n", infile);
  1086. return -1;
  1087. }
  1088. buf = malloc(PARSE_BUF_SIZE);
  1089. if (!buf) {
  1090. fprintf(stderr, "Unable to allocate buffer for reading existing config.\n");
  1091. exit(1);
  1092. }
  1093. while (fgets(buf, PARSE_BUF_SIZE, f)) {
  1094. lineno++;
  1095. if (strlen_zero(buf))
  1096. continue;
  1097. /* skip lines that are not for this tool */
  1098. if (strncasecmp(buf, "MENUSELECT_", strlen("MENUSELECT_")))
  1099. continue;
  1100. if (!strncasecmp(buf, "MENUSELECT_DEPENDS_", strlen("MENUSELECT_DEPENDS_")))
  1101. continue;
  1102. if (!strncasecmp(buf, "MENUSELECT_BUILD_DEPS", strlen("MENUSELECT_BUILD_DEPS")))
  1103. continue;
  1104. parse = buf;
  1105. parse = skip_blanks(parse);
  1106. if (strlen_zero(parse))
  1107. continue;
  1108. /* Grab the category name */
  1109. category = strsep(&parse, "=");
  1110. if (!parse) {
  1111. fprintf(stderr, "Invalid string in '%s' at line '%d'!\n", output_makeopts, lineno);
  1112. continue;
  1113. }
  1114. parse = skip_blanks(parse);
  1115. if (!strcasecmp(category, "MENUSELECT_DEPSFAILED")) {
  1116. process_prev_failed_deps(parse);
  1117. continue;
  1118. }
  1119. while ((member = strsep(&parse, " \n"))) {
  1120. member = skip_blanks(member);
  1121. if (strlen_zero(member))
  1122. continue;
  1123. mark_as_present(member, category);
  1124. }
  1125. }
  1126. free(buf);
  1127. fclose(f);
  1128. return 0;
  1129. }
  1130. /*! \brief Create the output dependencies file */
  1131. static int generate_makedeps_file(void)
  1132. {
  1133. FILE *f;
  1134. struct category *cat;
  1135. struct member *mem;
  1136. struct reference *dep;
  1137. struct reference *use;
  1138. struct dep_file *dep_file;
  1139. if (!(f = fopen(output_makedeps, "w"))) {
  1140. fprintf(stderr, "Unable to open dependencies file (%s) for writing!\n", output_makedeps);
  1141. return -1;
  1142. }
  1143. /* Traverse all categories and members and mark which used packages were found,
  1144. * skipping other members
  1145. */
  1146. AST_LIST_TRAVERSE(&categories, cat, list) {
  1147. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1148. if (mem->is_separator) {
  1149. continue;
  1150. }
  1151. AST_LIST_TRAVERSE(&mem->uses, use, list) {
  1152. if (use->member) {
  1153. use->met = 0;
  1154. continue;
  1155. }
  1156. AST_LIST_TRAVERSE(&deps_file, dep_file, list) {
  1157. if ((use->met = !strcasecmp(use->name, dep_file->name))) {
  1158. break;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. }
  1164. /* Traverse all categories and members and output dependencies for each member */
  1165. AST_LIST_TRAVERSE(&categories, cat, list) {
  1166. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1167. if (mem->is_separator) {
  1168. continue;
  1169. }
  1170. unsigned char header_printed = 0;
  1171. if (AST_LIST_EMPTY(&mem->deps) && AST_LIST_EMPTY(&mem->uses))
  1172. continue;
  1173. AST_LIST_TRAVERSE(&mem->deps, dep, list) {
  1174. const char *c;
  1175. if (dep->member) {
  1176. continue;
  1177. }
  1178. if (!header_printed) {
  1179. fprintf(f, "MENUSELECT_DEPENDS_%s=", mem->name);
  1180. header_printed = 1;
  1181. }
  1182. for (c = dep->name; *c; c++)
  1183. fputc(toupper(*c), f);
  1184. fputc(' ', f);
  1185. }
  1186. AST_LIST_TRAVERSE(&mem->uses, use, list) {
  1187. const char *c;
  1188. if (!use->met) {
  1189. continue;
  1190. }
  1191. if (!header_printed) {
  1192. fprintf(f, "MENUSELECT_DEPENDS_%s=", mem->name);
  1193. header_printed = 1;
  1194. }
  1195. for (c = use->name; *c; c++)
  1196. fputc(toupper(*c), f);
  1197. fputc(' ', f);
  1198. }
  1199. if (header_printed) {
  1200. fprintf(f, "\n");
  1201. }
  1202. }
  1203. }
  1204. fclose(f);
  1205. return 0;
  1206. }
  1207. /*! \brief Create the output makeopts file that results from the user's selections */
  1208. static int generate_makeopts_file(void)
  1209. {
  1210. FILE *f;
  1211. struct category *cat;
  1212. struct member *mem;
  1213. struct reference *dep;
  1214. struct reference *use;
  1215. if (!(f = fopen(output_makeopts, "w"))) {
  1216. fprintf(stderr, "Unable to open build configuration file (%s) for writing!\n", output_makeopts);
  1217. return -1;
  1218. }
  1219. /* Traverse all categories and members and output them as var/val pairs */
  1220. AST_LIST_TRAVERSE(&categories, cat, list) {
  1221. fprintf(f, "%s=", cat->name);
  1222. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1223. if (mem->is_separator) {
  1224. continue;
  1225. }
  1226. if ((!cat->positive_output && (!mem->enabled || mem->depsfailed || mem->conflictsfailed)) ||
  1227. (cat->positive_output && mem->enabled && !mem->depsfailed && !mem->conflictsfailed))
  1228. fprintf(f, "%s ", mem->name);
  1229. }
  1230. fprintf(f, "\n");
  1231. }
  1232. /* Traverse all categories and members, and for every member that is not disabled,
  1233. if it has internal dependencies (other members), list those members one time only
  1234. in a special variable */
  1235. fprintf(f, "MENUSELECT_BUILD_DEPS=");
  1236. AST_LIST_TRAVERSE(&categories, cat, list) {
  1237. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1238. if (mem->is_separator) {
  1239. continue;
  1240. }
  1241. if ((!cat->positive_output && (!mem->enabled || mem->depsfailed || mem->conflictsfailed)) ||
  1242. (cat->positive_output && mem->enabled && !mem->depsfailed && !mem->conflictsfailed))
  1243. continue;
  1244. AST_LIST_TRAVERSE(&mem->deps, dep, list) {
  1245. /* we only care about dependencies between members (internal, not external) */
  1246. if (!dep->member)
  1247. continue;
  1248. /* if this has already been output, continue */
  1249. if (dep->member->build_deps_output)
  1250. continue;
  1251. fprintf(f, "%s ", dep->member->name);
  1252. dep->member->build_deps_output = 1;
  1253. }
  1254. AST_LIST_TRAVERSE(&mem->uses, use, list) {
  1255. /* we only care about dependencies between members (internal, not external) */
  1256. if (!use->member)
  1257. continue;
  1258. /* if the dependency module is not going to be built, don't list it */
  1259. if (!use->member->enabled)
  1260. continue;
  1261. /* if this has already been output, continue */
  1262. if (use->member->build_deps_output)
  1263. continue;
  1264. fprintf(f, "%s ", use->member->name);
  1265. use->member->build_deps_output = 1;
  1266. }
  1267. }
  1268. }
  1269. fprintf(f, "\n");
  1270. /* Output which members were disabled because of failed dependencies or conflicts */
  1271. AST_LIST_TRAVERSE(&categories, cat, list) {
  1272. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1273. if (mem->is_separator) {
  1274. continue;
  1275. }
  1276. if (mem->depsfailed != HARD_FAILURE && mem->conflictsfailed != HARD_FAILURE)
  1277. continue;
  1278. if (!mem->defaultenabled || !strcasecmp(mem->defaultenabled, "yes"))
  1279. fprintf(f, "MENUSELECT_DEPSFAILED=%s=%s\n", cat->name, mem->name);
  1280. }
  1281. }
  1282. fclose(f);
  1283. /* there is no need to process remove_on_change rules if we did not have
  1284. configuration information to start from
  1285. */
  1286. if (!existing_config)
  1287. return 0;
  1288. /* Traverse all categories and members and remove any files that are supposed
  1289. to be removed when an item has been changed */
  1290. AST_LIST_TRAVERSE(&categories, cat, list) {
  1291. unsigned int had_changes = 0;
  1292. char rmcommand[256] = "rm -rf ";
  1293. char touchcommand[256] = "touch -c ";
  1294. char *file, *buf;
  1295. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1296. if (mem->is_separator) {
  1297. continue;
  1298. }
  1299. if ((mem->enabled == mem->was_enabled) && !mem->was_defaulted)
  1300. continue;
  1301. had_changes = 1;
  1302. if (mem->touch_on_change) {
  1303. for (buf = ast_strdupa(mem->touch_on_change), file = strsep(&buf, " ");
  1304. file;
  1305. file = strsep(&buf, " ")) {
  1306. strcpy(&touchcommand[9], file);
  1307. system(touchcommand);
  1308. }
  1309. }
  1310. if (mem->remove_on_change) {
  1311. for (buf = ast_strdupa(mem->remove_on_change), file = strsep(&buf, " ");
  1312. file;
  1313. file = strsep(&buf, " ")) {
  1314. strcpy(&rmcommand[7], file);
  1315. system(rmcommand);
  1316. }
  1317. }
  1318. }
  1319. if (cat->touch_on_change && had_changes) {
  1320. for (buf = ast_strdupa(cat->touch_on_change), file = strsep(&buf, " ");
  1321. file;
  1322. file = strsep(&buf, " ")) {
  1323. strcpy(&touchcommand[9], file);
  1324. system(touchcommand);
  1325. }
  1326. }
  1327. if (cat->remove_on_change && had_changes) {
  1328. for (buf = ast_strdupa(cat->remove_on_change), file = strsep(&buf, " ");
  1329. file;
  1330. file = strsep(&buf, " ")) {
  1331. strcpy(&rmcommand[7], file);
  1332. system(rmcommand);
  1333. }
  1334. }
  1335. }
  1336. return 0;
  1337. }
  1338. /*! \brief Print out all of the information contained in our tree */
  1339. static void dump_member_list(void)
  1340. {
  1341. #ifdef MENUSELECT_DEBUG
  1342. struct category *cat;
  1343. struct member *mem;
  1344. struct reference *dep;
  1345. struct reference *cnf;
  1346. AST_LIST_TRAVERSE(&categories, cat, list) {
  1347. fprintf(stderr, "Category: '%s'\n", cat->name);
  1348. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1349. if (mem->is_separator) {
  1350. continue;
  1351. }
  1352. fprintf(stderr, " ==>> Member: '%s' (%s)", mem->name, mem->enabled ? "Enabled" : "Disabled");
  1353. fprintf(stderr, " Was %s\n", mem->was_enabled ? "Enabled" : "Disabled");
  1354. if (mem->defaultenabled)
  1355. fprintf(stderr, " Defaults to %s\n", !strcasecmp(mem->defaultenabled, "yes") ? "Enabled" : "Disabled");
  1356. AST_LIST_TRAVERSE(&mem->deps, dep, list)
  1357. fprintf(stderr, " --> Depends on: '%s'\n", dep->name);
  1358. if (!AST_LIST_EMPTY(&mem->deps))
  1359. fprintf(stderr, " --> Dependencies Met: %s\n", mem->depsfailed ? "No" : "Yes");
  1360. AST_LIST_TRAVERSE(&mem->conflicts, cnf, list)
  1361. fprintf(stderr, " --> Conflicts with: '%s'\n", cnf->name);
  1362. if (!AST_LIST_EMPTY(&mem->conflicts))
  1363. fprintf(stderr, " --> Conflicts Found: %s\n", mem->conflictsfailed ? "Yes" : "No");
  1364. }
  1365. }
  1366. #endif
  1367. }
  1368. /*! \brief Free all categories and their members */
  1369. static void free_member_list(void)
  1370. {
  1371. struct category *cat;
  1372. while ((cat = AST_LIST_REMOVE_HEAD(&categories, list))) {
  1373. free_category(cat);
  1374. }
  1375. }
  1376. /*! \brief Free all of the XML trees */
  1377. static void free_trees(void)
  1378. {
  1379. struct tree *tree;
  1380. while ((tree = AST_LIST_REMOVE_HEAD(&trees, list))) {
  1381. xmlFreeDoc(tree->root);
  1382. free(tree);
  1383. }
  1384. }
  1385. /*! \brief Enable/Disable all members of a category as long as dependencies have been met and no conflicts are found */
  1386. void set_all(struct category *cat, int val)
  1387. {
  1388. struct member *mem;
  1389. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1390. if (mem->enabled == val)
  1391. continue;
  1392. if (mem->is_separator)
  1393. continue;
  1394. if ((mem->depsfailed == HARD_FAILURE) || (mem->conflictsfailed == HARD_FAILURE))
  1395. continue;
  1396. if (val) {
  1397. enable_member(mem);
  1398. } else {
  1399. mem->enabled = 0;
  1400. }
  1401. mem->was_defaulted = 0;
  1402. changes_made++;
  1403. }
  1404. while (calc_dep_failures(1, 0) || calc_conflict_failures(1, 0));
  1405. }
  1406. int count_categories(void)
  1407. {
  1408. struct category *cat;
  1409. int count = 0;
  1410. AST_LIST_TRAVERSE(&categories, cat, list)
  1411. count++;
  1412. return count;
  1413. }
  1414. int count_members(struct category *cat)
  1415. {
  1416. struct member *mem;
  1417. int count = 0;
  1418. AST_LIST_TRAVERSE(&cat->members, mem, list)
  1419. count++;
  1420. return count;
  1421. }
  1422. static void print_sanity_dep_header(struct dep_file *dep_file, unsigned int *flag)
  1423. {
  1424. fprintf(stderr, "\n"
  1425. "***********************************************************\n"
  1426. " The '%s' dependency was previously satisfied but \n"
  1427. " is now unsatisfied. \n",
  1428. dep_file->name);
  1429. *flag = 1;
  1430. }
  1431. /*! \brief Make sure an existing menuselect.makeopts disabled everything it should have */
  1432. static int sanity_check(void)
  1433. {
  1434. unsigned int insane = 0;
  1435. struct category *cat;
  1436. struct member *mem;
  1437. struct reference *dep;
  1438. struct reference *use;
  1439. struct dep_file *dep_file;
  1440. unsigned int dep_header_printed;
  1441. unsigned int group_header_printed;
  1442. AST_LIST_TRAVERSE(&deps_file, dep_file, list) {
  1443. if (!((dep_file->previously_met == DEP_FILE_MET) &&
  1444. (dep_file->met == DEP_FILE_UNMET))) {
  1445. continue;
  1446. }
  1447. /* this dependency was previously met, but now is not, so
  1448. warn the user about members that could be affected by it
  1449. */
  1450. dep_header_printed = 0;
  1451. group_header_printed = 0;
  1452. AST_LIST_TRAVERSE(&categories, cat, list) {
  1453. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1454. if (mem->is_separator) {
  1455. continue;
  1456. }
  1457. if (!mem->enabled) {
  1458. continue;
  1459. }
  1460. AST_LIST_TRAVERSE(&mem->deps, dep, list) {
  1461. if (strcasecmp(dep->name, dep_file->name)) {
  1462. continue;
  1463. }
  1464. if (!group_header_printed) {
  1465. if (!dep_header_printed) {
  1466. print_sanity_dep_header(dep_file, &dep_header_printed);
  1467. }
  1468. fprintf(stderr, "\n"
  1469. " The following modules will no longer be available:\n");
  1470. group_header_printed = 1;
  1471. }
  1472. fprintf(stderr, " %s\n", mem->name);
  1473. insane = 1;
  1474. }
  1475. }
  1476. }
  1477. group_header_printed = 0;
  1478. AST_LIST_TRAVERSE(&categories, cat, list) {
  1479. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1480. if (mem->is_separator) {
  1481. continue;
  1482. }
  1483. if (!mem->enabled) {
  1484. continue;
  1485. }
  1486. AST_LIST_TRAVERSE(&mem->uses, use, list) {
  1487. if (strcasecmp(use->name, dep_file->name)) {
  1488. continue;
  1489. }
  1490. if (!group_header_printed) {
  1491. if (!dep_header_printed) {
  1492. print_sanity_dep_header(dep_file, &dep_header_printed);
  1493. }
  1494. fprintf(stderr, "\n"
  1495. " The functionality of the following modules will\n"
  1496. " be affected:\n");
  1497. group_header_printed = 1;
  1498. }
  1499. fprintf(stderr, " %s\n", mem->name);
  1500. insane = 1;
  1501. }
  1502. }
  1503. }
  1504. if (dep_header_printed) {
  1505. fprintf(stderr,
  1506. "***********************************************************\n");
  1507. }
  1508. }
  1509. AST_LIST_TRAVERSE(&categories, cat, list) {
  1510. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1511. if (mem->is_separator) {
  1512. continue;
  1513. }
  1514. if ((mem->depsfailed || mem->conflictsfailed) && mem->enabled) {
  1515. fprintf(stderr, "\n"
  1516. "***********************************************************\n"
  1517. " The existing menuselect.makeopts file did not specify \n"
  1518. " that '%s' should not be included. However, either some \n"
  1519. " dependencies for this module were not found or a \n"
  1520. " conflict exists. \n"
  1521. " \n"
  1522. " Either run 'make menuselect' or remove the existing \n"
  1523. " menuselect.makeopts file to resolve this issue. \n"
  1524. "***********************************************************\n"
  1525. "\n", mem->name);
  1526. insane = 1;
  1527. }
  1528. }
  1529. }
  1530. return insane ? -1 : 0;
  1531. }
  1532. /* \brief Set the forced default values if they exist */
  1533. static void process_defaults(void)
  1534. {
  1535. struct category *cat;
  1536. struct member *mem;
  1537. print_debug("Processing default values since config was not present\n");
  1538. AST_LIST_TRAVERSE(&categories, cat, list) {
  1539. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1540. if (mem->is_separator) {
  1541. continue;
  1542. }
  1543. if (!mem->defaultenabled)
  1544. continue;
  1545. if (mem->depsfailed == HARD_FAILURE)
  1546. continue;
  1547. if (mem->conflictsfailed == HARD_FAILURE)
  1548. continue;
  1549. if (!strcasecmp(mem->defaultenabled, "yes")) {
  1550. mem->enabled = 1;
  1551. mem->was_defaulted = 1;
  1552. } else if (!strcasecmp(mem->defaultenabled, "no")) {
  1553. mem->enabled = 0;
  1554. mem->was_defaulted = 1;
  1555. } else
  1556. fprintf(stderr, "Invalid defaultenabled value for '%s' in category '%s'\n", mem->name, cat->name);
  1557. }
  1558. }
  1559. }
  1560. struct member *find_member(const char *name)
  1561. {
  1562. struct category *cat;
  1563. struct member *mem;
  1564. AST_LIST_TRAVERSE(&categories, cat, list) {
  1565. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1566. if (mem->is_separator) {
  1567. continue;
  1568. }
  1569. if (!strcasecmp(name, mem->name)) {
  1570. return mem;
  1571. }
  1572. }
  1573. }
  1574. return NULL;
  1575. }
  1576. struct category *find_category(const char *name)
  1577. {
  1578. struct category *cat;
  1579. AST_LIST_TRAVERSE(&categories, cat, list) {
  1580. if (!strcasecmp(name, cat->name)) {
  1581. return cat;
  1582. }
  1583. }
  1584. return NULL;
  1585. }
  1586. static int usage(const char *argv0)
  1587. {
  1588. fprintf(stderr, "Usage: %s [--enable <option>] [--disable <option>]\n", argv0);
  1589. fprintf(stderr, " [--enable-category <category>] [--enable-all]\n");
  1590. fprintf(stderr, " [--disable-category <category>] [--disable-all] [...]\n");
  1591. fprintf(stderr, " [<config-file> [...]]\n");
  1592. fprintf(stderr, "Usage: %s { --check-deps | --list-options\n", argv0);
  1593. fprintf(stderr, " | --list-category <category> | --category-list | --help }\n");
  1594. fprintf(stderr, " [<config-file> [...]]\n");
  1595. return 0;
  1596. }
  1597. int main(int argc, char *argv[])
  1598. {
  1599. int res = 0;
  1600. const char *list_group = NULL;
  1601. unsigned int x;
  1602. static struct option long_options[] = {
  1603. /*
  1604. * The --check-deps option is used to ask this application to check to
  1605. * see if that an existing menuselect.makeopts file contains all of the
  1606. * modules that have dependencies that have not been met. If this
  1607. * is not the case, an informative message will be printed to the
  1608. * user and the build will fail.
  1609. */
  1610. { "check-deps", no_argument, &check_deps, 1 },
  1611. { "enable", required_argument, 0, 'e' },
  1612. { "enable-category", required_argument, 0, 'E' },
  1613. { "enable-all", no_argument, 0, 'a' },
  1614. { "disable", required_argument, 0, 'd' },
  1615. { "disable-category", required_argument, 0, 'D' },
  1616. { "disable-all", no_argument, 0, 'A' },
  1617. { "list-options", no_argument, &list_options, 1 },
  1618. { "list-category", required_argument, 0, 'L' },
  1619. { "category-list", no_argument, &list_groups, 1 },
  1620. { "help", no_argument, 0, 'h' },
  1621. { 0, 0, 0, 0 },
  1622. };
  1623. int do_menu = 1, do_settings = 1;
  1624. int c, option_index = 0;
  1625. if (open_debug()) {
  1626. exit(1);
  1627. }
  1628. LIBXML_TEST_VERSION;
  1629. /* Parse the input XML files to build the list of available options */
  1630. if ((res = build_member_list()))
  1631. exit(res);
  1632. /* Load module dependencies */
  1633. if ((res = process_deps()))
  1634. exit(res);
  1635. while (calc_dep_failures(0, 1) || calc_conflict_failures(0, 1));
  1636. while ((c = getopt_long(argc, argv, "", long_options, &option_index)) != -1) {
  1637. switch (c) {
  1638. case 'L':
  1639. list_group = optarg;
  1640. do_settings = 0;
  1641. /* Fall-through */
  1642. case 'a':
  1643. case 'A':
  1644. case 'e':
  1645. case 'E':
  1646. case 'd':
  1647. case 'D':
  1648. do_menu = 0;
  1649. break;
  1650. case 'h':
  1651. return usage(argv[0]);
  1652. break;
  1653. default:
  1654. break;
  1655. }
  1656. }
  1657. if (check_deps || list_options || list_groups) {
  1658. do_menu = 0;
  1659. do_settings = 0;
  1660. }
  1661. if (optind < argc) {
  1662. for (x = optind; x < argc; x++) {
  1663. res = parse_existing_config(argv[x]);
  1664. if (!res && !strcasecmp(argv[x], OUTPUT_MAKEOPTS_DEFAULT))
  1665. existing_config = 1;
  1666. res = 0;
  1667. }
  1668. }
  1669. /* Dump the list produced by parsing the various input files */
  1670. dump_member_list();
  1671. while (calc_dep_failures(0, 0) || calc_conflict_failures(0, 0));
  1672. if (!existing_config)
  1673. process_defaults();
  1674. else if (check_deps)
  1675. res = sanity_check();
  1676. while (calc_dep_failures(0, 0) || calc_conflict_failures(0, 0));
  1677. print_debug("do_menu=%d, do_settings=%d\n", do_menu, do_settings);
  1678. if (do_menu && !res) {
  1679. res = run_menu();
  1680. } else if (!do_settings) {
  1681. if (list_groups) {
  1682. struct category *cat;
  1683. AST_LIST_TRAVERSE(&categories, cat, list) {
  1684. fprintf(stdout, "%s\n", cat->name);
  1685. }
  1686. } else if (list_options) {
  1687. struct category *cat;
  1688. struct member *mem;
  1689. AST_LIST_TRAVERSE(&categories, cat, list) {
  1690. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1691. if (mem->is_separator) {
  1692. continue;
  1693. }
  1694. fprintf(stdout, "%c %-30.30s %s\n", mem->enabled ? '+' : '-', mem->name, cat->name);
  1695. }
  1696. }
  1697. } else if (!strlen_zero(list_group)) {
  1698. struct category *cat;
  1699. struct member *mem;
  1700. if ((cat = find_category(list_group))) {
  1701. AST_LIST_TRAVERSE(&cat->members, mem, list) {
  1702. if (mem->is_separator) {
  1703. continue;
  1704. }
  1705. fprintf(stdout, "%c %s\n", mem->enabled ? '+' : '-', mem->name);
  1706. }
  1707. }
  1708. }
  1709. } else if (!do_menu && do_settings) {
  1710. struct member *mem;
  1711. struct category *cat;
  1712. print_debug("Doing settings with argc=%d\n", argc);
  1713. /* Reset options processing */
  1714. option_index = 0;
  1715. optind = 1;
  1716. while ((c = getopt_long(argc, argv, "", long_options, &option_index)) != -1) {
  1717. print_debug("Got option %c\n", c);
  1718. switch (c) {
  1719. case 'e':
  1720. if (!strlen_zero(optarg)) {
  1721. if ((mem = find_member(optarg))) {
  1722. set_member_enabled(mem);
  1723. } else {
  1724. fprintf(stderr, "'%s' not found\n", optarg);
  1725. }
  1726. }
  1727. break;
  1728. case 'E':
  1729. if (!strlen_zero(optarg)) {
  1730. if ((cat = find_category(optarg))) {
  1731. set_all(cat, 1);
  1732. } else {
  1733. fprintf(stderr, "'%s' not found\n", optarg);
  1734. }
  1735. }
  1736. break;
  1737. case 'a': /* enable-all */
  1738. AST_LIST_TRAVERSE(&categories, cat, list) {
  1739. set_all(cat, 1);
  1740. }
  1741. break;
  1742. case 'd':
  1743. if (!strlen_zero(optarg)) {
  1744. if ((mem = find_member(optarg))) {
  1745. clear_member_enabled(mem);
  1746. } else {
  1747. fprintf(stderr, "'%s' not found\n", optarg);
  1748. }
  1749. }
  1750. break;
  1751. case 'D':
  1752. if (!strlen_zero(optarg)) {
  1753. if ((cat = find_category(optarg))) {
  1754. set_all(cat, 0);
  1755. } else {
  1756. fprintf(stderr, "'%s' not found\n", optarg);
  1757. }
  1758. }
  1759. break;
  1760. case 'A': /* disable-all */
  1761. AST_LIST_TRAVERSE(&categories, cat, list) {
  1762. set_all(cat, 0);
  1763. }
  1764. break;
  1765. case '?':
  1766. break;
  1767. default:
  1768. break;
  1769. }
  1770. }
  1771. res = 0;
  1772. }
  1773. if (!res) {
  1774. res = generate_makeopts_file();
  1775. }
  1776. /* Always generate the dependencies file */
  1777. if (!res) {
  1778. generate_makedeps_file();
  1779. }
  1780. /* free everything we allocated */
  1781. free_deps_file();
  1782. free_trees();
  1783. free_member_list();
  1784. close_debug();
  1785. xmlCleanupParser();
  1786. exit(res);
  1787. }