1
0

pkgmaker.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. /*
  2. * pkgmaker - create package meta-data for OpenADK buildsystem
  3. *
  4. * Copyright (C) 2010-2014 Waldemar Brodkorb <wbx@openadk.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <ctype.h>
  20. #include <dirent.h>
  21. #include <fcntl.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <unistd.h>
  26. #include <sys/stat.h>
  27. #include <sys/types.h>
  28. #include "sortfile.h"
  29. #include "strmap.h"
  30. #define MAXLINE 4096
  31. #define MAXVALUE 168
  32. #define MAXVAR 64
  33. #define MAXPATH 320
  34. #define HASHSZ 96
  35. static int nobinpkgs;
  36. #define fatal_error(...) { \
  37. fprintf(stderr, "Fatal error. "); \
  38. fprintf(stderr, __VA_ARGS__); \
  39. fprintf(stderr, "\n"); \
  40. exit(1); \
  41. }
  42. static int parse_var_hash(char *buf, const char *varname, StrMap *strmap) {
  43. char *key, *value, *string;
  44. string = strstr(buf, varname);
  45. if (string != NULL) {
  46. string[strlen(string)-1] = '\0';
  47. key = strtok(string, ":=");
  48. value = strtok(NULL, "=\t");
  49. if (value != NULL)
  50. strmap_put(strmap, key, value);
  51. return(0);
  52. }
  53. return(1);
  54. }
  55. static int parse_var(char *buf, const char *varname, char *pvalue, char **result) {
  56. char *pkg_var;
  57. char *key, *value, *string;
  58. char pkg_str[MAXVAR];
  59. if ((pkg_var = malloc(MAXLINE)) != NULL)
  60. memset(pkg_var, 0, MAXLINE);
  61. else {
  62. perror("Can not allocate memory");
  63. exit(EXIT_FAILURE);
  64. }
  65. if (snprintf(pkg_str, MAXVAR, "%s:=", varname) < 0)
  66. perror("can not create path variable.");
  67. string = strstr(buf, pkg_str);
  68. if (string != NULL) {
  69. string[strlen(string)-1] = '\0';
  70. key = strtok(string, ":=");
  71. value = strtok(NULL, "=\t");
  72. if (value != NULL) {
  73. strncat(pkg_var, value, strlen(value));
  74. *result = strdup(pkg_var);
  75. } else {
  76. nobinpkgs = 1;
  77. *result = NULL;
  78. }
  79. free(pkg_var);
  80. return(0);
  81. } else {
  82. if (snprintf(pkg_str, MAXVAR, "%s+=", varname) < 0)
  83. perror("can not create path variable.");
  84. string = strstr(buf, pkg_str);
  85. if (string != NULL) {
  86. string[strlen(string)-1] = '\0';
  87. key = strtok(string, "+=");
  88. value = strtok(NULL, "=\t");
  89. if (pvalue != NULL)
  90. strncat(pkg_var, pvalue, strlen(pvalue));
  91. strncat(pkg_var, " ", 1);
  92. if (value != NULL)
  93. strncat(pkg_var, value, strlen(value));
  94. *result = strdup(pkg_var);
  95. free(pkg_var);
  96. return(0);
  97. }
  98. }
  99. free(pkg_var);
  100. return(1);
  101. }
  102. static int parse_var_with_system(char *buf, const char *varname, char *pvalue, char **result, char **sysname, int varlen) {
  103. char *pkg_var, *check;
  104. char *key, *value, *string;
  105. if ((pkg_var = malloc(MAXLINE)) != NULL)
  106. memset(pkg_var, 0, MAXLINE);
  107. else {
  108. perror("Can not allocate memory");
  109. exit(EXIT_FAILURE);
  110. }
  111. check = strstr(buf, ":=");
  112. if (check != NULL) {
  113. string = strstr(buf, varname);
  114. if (string != NULL) {
  115. string[strlen(string)-1] = '\0';
  116. key = strtok(string, ":=");
  117. *sysname = strdup(key+varlen);
  118. value = strtok(NULL, "=\t");
  119. if (value != NULL) {
  120. strncat(pkg_var, value, strlen(value));
  121. *result = strdup(pkg_var);
  122. }
  123. free(pkg_var);
  124. return(0);
  125. }
  126. } else {
  127. string = strstr(buf, varname);
  128. if (string != NULL) {
  129. string[strlen(string)-1] = '\0';
  130. key = strtok(string, "+=");
  131. value = strtok(NULL, "=\t");
  132. if (pvalue != NULL)
  133. strncat(pkg_var, pvalue, strlen(pvalue));
  134. strncat(pkg_var, " ", 1);
  135. if (value != NULL)
  136. strncat(pkg_var, value, strlen(value));
  137. *result = strdup(pkg_var);
  138. free(pkg_var);
  139. return(0);
  140. }
  141. }
  142. free(pkg_var);
  143. return(1);
  144. }
  145. static int parse_var_with_pkg(char *buf, const char *varname, char *pvalue, char **result, char **pkgname, int varlen) {
  146. char *pkg_var, *check;
  147. char *key, *value, *string;
  148. if ((pkg_var = malloc(MAXLINE)) != NULL)
  149. memset(pkg_var, 0, MAXLINE);
  150. else {
  151. perror("Can not allocate memory");
  152. exit(EXIT_FAILURE);
  153. }
  154. check = strstr(buf, ":=");
  155. if (check != NULL) {
  156. string = strstr(buf, varname);
  157. if (string != NULL) {
  158. string[strlen(string)-1] = '\0';
  159. key = strtok(string, ":=");
  160. *pkgname = strdup(key+varlen);
  161. value = strtok(NULL, "=\t");
  162. if (value != NULL) {
  163. strncat(pkg_var, value, strlen(value));
  164. *result = strdup(pkg_var);
  165. }
  166. free(pkg_var);
  167. return(0);
  168. }
  169. } else {
  170. string = strstr(buf, varname);
  171. if (string != NULL) {
  172. string[strlen(string)-1] = '\0';
  173. key = strtok(string, "+=");
  174. value = strtok(NULL, "=\t");
  175. if (pvalue != NULL)
  176. strncat(pkg_var, pvalue, strlen(pvalue));
  177. strncat(pkg_var, " ", 1);
  178. if (value != NULL)
  179. strncat(pkg_var, value, strlen(value));
  180. *result = strdup(pkg_var);
  181. free(pkg_var);
  182. return(0);
  183. }
  184. }
  185. free(pkg_var);
  186. return(1);
  187. }
  188. #if 0
  189. static void iter_debug(const char *key, const char *value, const void *obj) {
  190. fprintf(stderr, "HASHMAP key: %s value: %s\n", key, value);
  191. }
  192. #endif
  193. static int hash_str(char *string) {
  194. int i;
  195. int hash;
  196. hash = 0;
  197. for (i=0; i<(int)strlen(string); i++) {
  198. hash += string[i];
  199. }
  200. return(hash);
  201. }
  202. static void iter(const char *key, const char *value, const void *obj) {
  203. FILE *config, *section;
  204. int hash;
  205. char *valuestr, *pkg, *subpkg;
  206. char buf[MAXPATH];
  207. char infile[MAXPATH];
  208. char outfile[MAXPATH];
  209. valuestr = strdup(value);
  210. config = fopen("package/Config.in.auto", "a");
  211. if (config == NULL)
  212. fatal_error("Can not open file package/Config.in.auto");
  213. hash = hash_str(valuestr);
  214. snprintf(infile, MAXPATH, "package/pkglist.d/sectionlst.%d", hash);
  215. snprintf(outfile, MAXPATH, "package/pkglist.d/sectionlst.%d.sorted", hash);
  216. if (access(infile, F_OK) == 0) {
  217. valuestr[strlen(valuestr)-1] = '\0';
  218. fprintf(config, "menu \"%s\"\n", valuestr);
  219. sortfile(infile, outfile);
  220. /* avoid duplicate section entries */
  221. unlink(infile);
  222. section = fopen(outfile, "r");
  223. while (fgets(buf, MAXPATH, section) != NULL) {
  224. buf[strlen(buf)-1] = '\0';
  225. if (buf[strlen(buf)-1] == '@') {
  226. buf[strlen(buf)-1] = '\0';
  227. fprintf(config, "source \"package/%s/Config.in.manual\"\n", buf);
  228. } else {
  229. subpkg = strtok(buf, "|");
  230. subpkg[strlen(subpkg)-1] = '\0';
  231. pkg = strtok(NULL, "|");
  232. fprintf(config, "source \"package/pkgconfigs.d/%s/Config.in.%s\"\n", pkg, subpkg);
  233. }
  234. }
  235. fprintf(config, "endmenu\n\n");
  236. fclose(section);
  237. }
  238. fclose(config);
  239. }
  240. static char *tolowerstr(char *string) {
  241. int i;
  242. char *str;
  243. /* transform to lowercase variable name */
  244. str = strdup(string);
  245. for (i=0; i<(int)strlen(str); i++) {
  246. if (str[i] == '_')
  247. str[i] = '-';
  248. str[i] = tolower(str[i]);
  249. }
  250. return(str);
  251. }
  252. static char *toupperstr(char *string) {
  253. int i;
  254. char *str;
  255. /* transform to uppercase variable name */
  256. str = strdup(string);
  257. for (i=0; i<(int)strlen(str); i++) {
  258. if (str[i] == '+')
  259. str[i] = 'X';
  260. if (str[i] == '-')
  261. str[i] = '_';
  262. /* remove negation here, useful for package host depends */
  263. if (str[i] == '!')
  264. str[i] = '_';
  265. str[i] = toupper(str[i]);
  266. }
  267. return(str);
  268. }
  269. int main() {
  270. DIR *pkgdir, *pkglistdir;
  271. struct dirent *pkgdirp;
  272. FILE *pkg, *cfg, *menuglobal, *section;
  273. char hvalue[MAXVALUE];
  274. char buf[MAXPATH];
  275. char tbuf[MAXPATH];
  276. char path[MAXPATH];
  277. char spath[MAXPATH];
  278. char dir[MAXPATH];
  279. char variable[2*MAXVAR];
  280. char *key, *value, *token, *cftoken, *sp, *hkey, *val, *pkg_fd;
  281. char *pkg_name, *pkg_depends, *pkg_depends_system, *pkg_section, *pkg_descr, *pkg_url;
  282. char *pkg_cxx, *pkg_subpkgs, *pkg_cfline, *pkg_dflt, *pkg_multi;
  283. char *pkg_need_cxx, *pkg_need_java, *pkgname, *sysname, *pkg_debug;
  284. char *pkg_libc_depends, *pkg_host_depends, *pkg_system_depends, *pkg_arch_depends, *pkg_flavours, *pkg_flavours_string, *pkg_choices, *pseudo_name;
  285. char *packages, *pkg_name_u, *pkgs, *pkg_opts, *pkg_libname;
  286. char *saveptr, *p_ptr, *s_ptr, *pkg_helper;
  287. int result;
  288. StrMap *pkgmap, *sectionmap;
  289. pkg_name = NULL;
  290. pkg_descr = NULL;
  291. pkg_section = NULL;
  292. pkg_url = NULL;
  293. pkg_depends = NULL;
  294. pkg_depends_system = NULL;
  295. pkg_opts = NULL;
  296. pkg_libname = NULL;
  297. pkg_flavours = NULL;
  298. pkg_flavours_string = NULL;
  299. pkg_choices = NULL;
  300. pkg_subpkgs = NULL;
  301. pkg_arch_depends = NULL;
  302. pkg_system_depends = NULL;
  303. pkg_host_depends = NULL;
  304. pkg_libc_depends = NULL;
  305. pkg_cxx = NULL;
  306. pkg_dflt = NULL;
  307. pkg_cfline = NULL;
  308. pkg_multi = NULL;
  309. pkg_need_cxx = NULL;
  310. pkg_need_java = NULL;
  311. pkgname = NULL;
  312. sysname = NULL;
  313. pkg_helper = NULL;
  314. pkg_debug = NULL;
  315. p_ptr = NULL;
  316. s_ptr = NULL;
  317. unlink("package/Config.in.auto");
  318. /* open global sectionfile */
  319. menuglobal = fopen("package/Config.in.auto.global", "w");
  320. if (menuglobal == NULL)
  321. fatal_error("global section file not writable.");
  322. /* read section list and create a hash table */
  323. section = fopen("package/section.lst", "r");
  324. if (section == NULL)
  325. fatal_error("section listfile is missing");
  326. sectionmap = strmap_new(HASHSZ);
  327. while (fgets(tbuf, MAXPATH, section) != NULL) {
  328. key = strtok(tbuf, "\t");
  329. value = strtok(NULL, "\t");
  330. strmap_put(sectionmap, key, value);
  331. }
  332. fclose(section);
  333. if (mkdir("package/pkgconfigs.d", S_IRWXU) > 0)
  334. fatal_error("creation of package/pkgconfigs.d failed.");
  335. if (mkdir("package/pkgconfigs.d/gcc", S_IRWXU) > 0)
  336. fatal_error("creation of package/pkgconfigs.d/gcc failed.");
  337. if (mkdir("package/pkglist.d", S_IRWXU) > 0)
  338. fatal_error("creation of package/pkglist.d failed.");
  339. /* delete Config.in.dev */
  340. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
  341. fatal_error("failed to create path variable.");
  342. unlink(path);
  343. cfg = fopen(path, "w");
  344. if (cfg == NULL)
  345. fatal_error("Config.in.dev can not be opened");
  346. fprintf(cfg, "config ADK_PACKAGE_GLIBC_DEV\n");
  347. fprintf(cfg, "\tprompt \"glibc-dev............ development files for glibc\"\n");
  348. fprintf(cfg, "\ttristate\n");
  349. fprintf(cfg, "\tdefault n\n");
  350. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_GLIBC\n");
  351. fprintf(cfg, "\thelp\n");
  352. fprintf(cfg, "\t GNU C library header files.\n\n");
  353. fprintf(cfg, "config ADK_PACKAGE_UCLIBC_DEV\n");
  354. fprintf(cfg, "\tprompt \"uclibc-dev........... development files for uclibc\"\n");
  355. fprintf(cfg, "\ttristate\n");
  356. fprintf(cfg, "\tdefault n\n");
  357. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_UCLIBC\n");
  358. fprintf(cfg, "\thelp\n");
  359. fprintf(cfg, "\t C library header files.\n\n");
  360. fprintf(cfg, "config ADK_PACKAGE_MUSL_DEV\n");
  361. fprintf(cfg, "\tprompt \"musl-dev............. development files for musl\"\n");
  362. fprintf(cfg, "\ttristate\n");
  363. fprintf(cfg, "\tdefault n\n");
  364. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_MUSL\n");
  365. fprintf(cfg, "\thelp\n");
  366. fprintf(cfg, "\t C library header files.\n\n");
  367. fclose(cfg);
  368. /* read Makefile's for all packages */
  369. pkgdir = opendir("package");
  370. while ((pkgdirp = readdir(pkgdir)) != NULL) {
  371. /* skip dotfiles */
  372. if (strncmp(pkgdirp->d_name, ".", 1) > 0) {
  373. if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0)
  374. fatal_error("can not create path variable.");
  375. pkg = fopen(path, "r");
  376. if (pkg == NULL)
  377. continue;
  378. /* skip manually maintained packages */
  379. if (snprintf(path, MAXPATH, "package/%s/Config.in.manual", pkgdirp->d_name) < 0)
  380. fatal_error("can not create path variable.");
  381. if (!access(path, F_OK)) {
  382. while (fgets(buf, MAXPATH, pkg) != NULL) {
  383. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  384. continue;
  385. }
  386. memset(hvalue, 0 , MAXVALUE);
  387. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  388. if (result == 1) {
  389. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  390. fatal_error("can not create path variable.");
  391. section = fopen(spath, "a");
  392. if (section != NULL) {
  393. fprintf(section, "%s@\n", pkgdirp->d_name);
  394. fclose(section);
  395. }
  396. } else
  397. fatal_error("Can not find section description for package %s.",
  398. pkgdirp->d_name);
  399. fclose(pkg);
  400. continue;
  401. }
  402. nobinpkgs = 0;
  403. /* create output directories */
  404. if (snprintf(dir, MAXPATH, "package/pkgconfigs.d/%s", pkgdirp->d_name) < 0)
  405. fatal_error("can not create dir variable.");
  406. if (mkdir(dir, S_IRWXU) > 0)
  407. fatal_error("can not create directory.");
  408. /* allocate memory */
  409. hkey = malloc(MAXVAR);
  410. memset(hkey, 0, MAXVAR);
  411. memset(variable, 0, 2*MAXVAR);
  412. pkgmap = strmap_new(HASHSZ);
  413. /* parse package Makefile */
  414. while (fgets(buf, MAXPATH, pkg) != NULL) {
  415. /* just read variables prefixed with PKG */
  416. if (strncmp(buf, "PKG", 3) == 0) {
  417. if ((parse_var(buf, "PKG_NAME", NULL, &pkg_name)) == 0)
  418. continue;
  419. if (pkg_name != NULL)
  420. pkg_name_u = toupperstr(pkg_name);
  421. else
  422. pkg_name_u = toupperstr(pkgdirp->d_name);
  423. snprintf(variable, MAXVAR, "PKG_CFLINE_%s", pkg_name_u);
  424. if ((parse_var(buf, variable, pkg_cfline, &pkg_cfline)) == 0)
  425. continue;
  426. snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
  427. if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
  428. continue;
  429. if ((parse_var(buf, "PKG_LIBC_DEPENDS", NULL, &pkg_libc_depends)) == 0)
  430. continue;
  431. if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
  432. continue;
  433. if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
  434. continue;
  435. if ((parse_var(buf, "PKG_SYSTEM_DEPENDS", NULL, &pkg_system_depends)) == 0)
  436. continue;
  437. if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
  438. continue;
  439. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  440. continue;
  441. if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
  442. continue;
  443. if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0)
  444. continue;
  445. if ((parse_var(buf, "PKG_NEED_CXX", NULL, &pkg_need_cxx)) == 0)
  446. continue;
  447. if ((parse_var(buf, "PKG_NEED_JAVA", NULL, &pkg_need_java)) == 0)
  448. continue;
  449. if ((parse_var(buf, "PKG_MULTI", NULL, &pkg_multi)) == 0)
  450. continue;
  451. if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
  452. continue;
  453. if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_system, &pkg_depends_system, &sysname, 12)) == 0)
  454. continue;
  455. if ((parse_var(buf, "PKG_LIBNAME", pkg_libname, &pkg_libname)) == 0)
  456. continue;
  457. if ((parse_var(buf, "PKG_OPTS", pkg_opts, &pkg_opts)) == 0)
  458. continue;
  459. if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_STRING_", pkg_flavours_string, &pkg_flavours_string, &pkgname, 20)) == 0)
  460. continue;
  461. if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_", pkg_flavours, &pkg_flavours, &pkgname, 13)) == 0)
  462. continue;
  463. if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
  464. continue;
  465. if ((parse_var_hash(buf, "PKGFX_", pkgmap)) == 0)
  466. continue;
  467. if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
  468. continue;
  469. if ((parse_var_hash(buf, "PKGFC_", pkgmap)) == 0)
  470. continue;
  471. if ((parse_var_with_pkg(buf, "PKG_CHOICES_", pkg_choices, &pkg_choices, &pkgname, 12)) == 0)
  472. continue;
  473. if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
  474. continue;
  475. if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
  476. continue;
  477. if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
  478. continue;
  479. if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
  480. continue;
  481. if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
  482. continue;
  483. if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
  484. continue;
  485. }
  486. }
  487. /* when PKG_LIBNAME exist use this instead of PKG_NAME, but only for !libmix */
  488. if (pkg_libname != NULL)
  489. if (pkg_opts != NULL)
  490. if (strstr(pkg_opts, "libmix") == NULL)
  491. pkg_name = strdup(pkg_libname);
  492. /* end of package Makefile parsing */
  493. if (fclose(pkg) != 0)
  494. perror("Failed to close file stream for Makefile");
  495. #if 0
  496. if (pkg_name != NULL)
  497. fprintf(stderr, "Package name is %s\n", pkg_name);
  498. if (pkg_libname != NULL)
  499. fprintf(stderr, "Package library name is %s\n", pkg_libname);
  500. if (pkg_section != NULL)
  501. fprintf(stderr, "Package section is %s\n", pkg_section);
  502. if (pkg_descr != NULL)
  503. fprintf(stderr, "Package description is %s\n", pkg_descr);
  504. if (pkg_depends != NULL)
  505. fprintf(stderr, "Package dependencies are %s\n", pkg_depends);
  506. if (pkg_depends_system != NULL)
  507. fprintf(stderr, "Package systemspecific dependencies are %s\n", pkg_depends_system);
  508. if (pkg_subpkgs != NULL)
  509. fprintf(stderr, "Package subpackages are %s\n", pkg_subpkgs);
  510. if (pkg_flavours != NULL && pkgname != NULL)
  511. fprintf(stderr, "Package flavours for %s are %s\n", pkgname, pkg_flavours);
  512. if (pkg_flavours_string != NULL && pkgname != NULL)
  513. fprintf(stderr, "Package string flavours for %s are %s\n", pkgname, pkg_flavours_string);
  514. if (pkg_choices != NULL && pkgname != NULL)
  515. fprintf(stderr, "Package choices for %s are %s\n", pkgname, pkg_choices);
  516. if (pkg_url != NULL)
  517. fprintf(stderr, "Package homepage is %s\n", pkg_url);
  518. if (pkg_cfline != NULL)
  519. fprintf(stderr, "Package cfline is %s\n", pkg_cfline);
  520. if (pkg_multi != NULL)
  521. fprintf(stderr, "Package multi is %s\n", pkg_multi);
  522. if (pkg_opts != NULL)
  523. fprintf(stderr, "Package options are %s\n", pkg_opts);
  524. strmap_enum(pkgmap, iter_debug, NULL);
  525. #endif
  526. /* generate master source Config.in file */
  527. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in", pkgdirp->d_name) < 0)
  528. fatal_error("path variable creation failed.");
  529. fprintf(menuglobal, "source \"%s\"\n", path);
  530. /* recreating file is faster than truncating with w+ */
  531. unlink(path);
  532. cfg = fopen(path, "w");
  533. if (cfg == NULL)
  534. continue;
  535. pkgs = NULL;
  536. if (pkg_subpkgs != NULL)
  537. pkgs = strdup(pkg_subpkgs);
  538. fprintf(cfg, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  539. fprintf(cfg, "\ttristate\n");
  540. if (nobinpkgs == 0) {
  541. fprintf(cfg, "\tdepends on ");
  542. if (pkgs != NULL) {
  543. if (pkg_multi != NULL)
  544. if (strncmp(pkg_multi, "1", 1) == 0)
  545. fprintf(cfg, "ADK_HAVE_DOT_CONFIG || ");
  546. token = strtok(pkgs, " ");
  547. fprintf(cfg, "ADK_PACKAGE_%s", token);
  548. token = strtok(NULL, " ");
  549. while (token != NULL) {
  550. fprintf(cfg, " || ADK_PACKAGE_%s", token);
  551. token = strtok(NULL, " ");
  552. }
  553. fprintf(cfg, "\n");
  554. } else {
  555. fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkg_name));
  556. }
  557. }
  558. fprintf(cfg, "\tdefault n\n");
  559. fclose(cfg);
  560. free(pkgs);
  561. /* skip packages without binary package output */
  562. if (nobinpkgs == 1)
  563. continue;
  564. /* generate binary package specific Config.in files */
  565. if (pkg_subpkgs != NULL)
  566. packages = tolowerstr(pkg_subpkgs);
  567. else
  568. packages = strdup(pkg_name);
  569. token = strtok_r(packages, " ", &p_ptr);
  570. while (token != NULL) {
  571. strncat(hkey, "PKGSC_", 6);
  572. strncat(hkey, toupperstr(token), strlen(token));
  573. memset(hvalue, 0 , MAXVALUE);
  574. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  575. memset(hkey, 0 , MAXVAR);
  576. if (result == 1)
  577. pkg_section = strdup(hvalue);
  578. strncat(hkey, "PKGSD_", 6);
  579. strncat(hkey, toupperstr(token), strlen(token));
  580. memset(hvalue, 0 , MAXVALUE);
  581. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  582. memset(hkey, 0 , MAXVAR);
  583. if (result == 1)
  584. pkg_descr = strdup(hvalue);
  585. pseudo_name = malloc(MAXLINE);
  586. memset(pseudo_name, 0, MAXLINE);
  587. strncat(pseudo_name, token, strlen(token));
  588. while (strlen(pseudo_name) < 20)
  589. strncat(pseudo_name, ".", 1);
  590. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp->d_name, token) < 0)
  591. fatal_error("failed to create path variable.");
  592. /* create temporary section files */
  593. memset(hvalue, 0 , MAXVALUE);
  594. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  595. if (result == 1) {
  596. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  597. fatal_error("failed to create path variable.");
  598. section = fopen(spath, "a");
  599. if (section != NULL) {
  600. fprintf(section, "%s |%s\n", token, pkgdirp->d_name);
  601. fclose(section);
  602. }
  603. } else
  604. fatal_error("Can not find section description for package %s.", pkgdirp->d_name);
  605. unlink(path);
  606. cfg = fopen(path, "w");
  607. if (cfg == NULL)
  608. perror("Can not open Config.in file");
  609. if (pkg_need_cxx != NULL) {
  610. fprintf(cfg, "comment \"%s... %s (disabled, c++ missing)\"\n", token, pkg_descr);
  611. fprintf(cfg, "depends on !ADK_TOOLCHAIN_GCC_CXX\n\n");
  612. }
  613. /* save token in pkg_debug */
  614. pkg_debug = strdup(token);
  615. fprintf(cfg, "config ADK_PACKAGE_%s\n", toupperstr(token));
  616. /* no prompt for devonly packages */
  617. if (pkg_opts != NULL) {
  618. if (strstr(pkg_opts, "devonly") != NULL) {
  619. fprintf(cfg, "\t#prompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  620. } else {
  621. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  622. }
  623. } else {
  624. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  625. }
  626. fprintf(cfg, "\ttristate\n");
  627. if (pkg_multi != NULL)
  628. if (strncmp(pkg_multi, "1", 1) == 0)
  629. if (strncmp(toupperstr(token), toupperstr(pkgdirp->d_name), strlen(token)) != 0)
  630. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkgdirp->d_name));
  631. free(pseudo_name);
  632. /* print custom cf line */
  633. if (pkg_cfline != NULL) {
  634. cftoken = strtok_r(pkg_cfline, "@", &saveptr);
  635. while (cftoken != NULL) {
  636. fprintf(cfg, "\t%s\n", cftoken);
  637. cftoken = strtok_r(NULL, "@", &saveptr);
  638. }
  639. free(pkg_cfline);
  640. pkg_cfline = NULL;
  641. }
  642. /* add sub package dependencies */
  643. strncat(hkey, "PKGSS_", 6);
  644. strncat(hkey, toupperstr(token), strlen(token));
  645. memset(hvalue, 0, MAXVALUE);
  646. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  647. if (result == 1) {
  648. val = strtok_r(hvalue, " ", &saveptr);
  649. while (val != NULL) {
  650. if (strncmp(val, "kmod", 4) == 0)
  651. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  652. else
  653. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  654. val = strtok_r(NULL, " ", &saveptr);
  655. }
  656. }
  657. memset(hkey, 0, MAXVAR);
  658. /* create package target system dependency information */
  659. if (pkg_system_depends != NULL) {
  660. pkg_helper = strdup(pkg_system_depends);
  661. token = strtok(pkg_helper, " ");
  662. fprintf(cfg, "\tdepends on ");
  663. sp = "";
  664. while (token != NULL) {
  665. if(strncmp(token, "!", 1) == 0) {
  666. fprintf(cfg, "%s!ADK_TARGET_SYSTEM%s", sp, toupperstr(token));
  667. sp = " && ";
  668. } else {
  669. fprintf(cfg, "%sADK_TARGET_SYSTEM_%s", sp, toupperstr(token));
  670. sp = " || ";
  671. }
  672. token = strtok(NULL, " ");
  673. }
  674. fprintf(cfg, "\n");
  675. free(pkg_helper);
  676. pkg_helper = NULL;
  677. }
  678. /* create package host dependency information */
  679. if (pkg_host_depends != NULL) {
  680. pkg_helper = strdup(pkg_host_depends);
  681. token = strtok(pkg_helper, " ");
  682. fprintf(cfg, "\tdepends on ");
  683. sp = "";
  684. while (token != NULL) {
  685. if(strncmp(token, "!", 1) == 0) {
  686. fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
  687. sp = " && ";
  688. } else {
  689. fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
  690. sp = " || ";
  691. }
  692. token = strtok(NULL, " ");
  693. }
  694. fprintf(cfg, "\n");
  695. free(pkg_helper);
  696. pkg_helper = NULL;
  697. }
  698. /* create package libc dependency information */
  699. if (pkg_libc_depends != NULL) {
  700. pkg_helper = strdup(pkg_libc_depends);
  701. token = strtok(pkg_helper, " ");
  702. fprintf(cfg, "\tdepends on ");
  703. sp = "";
  704. while (token != NULL) {
  705. if(strncmp(token, "!", 1) == 0) {
  706. fprintf(cfg, "%s!ADK_TARGET_LIB_%s", sp, toupperstr(token));
  707. sp = " && ";
  708. } else {
  709. fprintf(cfg, "%sADK_TARGET_LIB_%s", sp, toupperstr(token));
  710. sp = " || ";
  711. }
  712. token = strtok(NULL, " ");
  713. }
  714. fprintf(cfg, "\n");
  715. free(pkg_helper);
  716. pkg_helper = NULL;
  717. }
  718. /* create package target architecture dependency information */
  719. if (pkg_arch_depends != NULL) {
  720. pkg_helper = strdup(pkg_arch_depends);
  721. token = strtok(pkg_helper, " ");
  722. fprintf(cfg, "\tdepends on ");
  723. sp = "";
  724. while (token != NULL) {
  725. if(strncmp(token, "!", 1) == 0) {
  726. fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
  727. sp = " && ";
  728. } else {
  729. fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
  730. sp = " || ";
  731. }
  732. token = strtok(NULL, " ");
  733. }
  734. fprintf(cfg, "\n");
  735. free(pkg_helper);
  736. pkg_helper = NULL;
  737. }
  738. /* create package dependency information */
  739. if (pkg_depends != NULL) {
  740. token = strtok(pkg_depends, " ");
  741. while (token != NULL) {
  742. if (strncmp(token, "kmod", 4) == 0)
  743. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(token));
  744. else
  745. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
  746. token = strtok(NULL, " ");
  747. }
  748. free(pkg_depends);
  749. pkg_depends = NULL;
  750. }
  751. /* create system specific package dependency information */
  752. if (pkg_depends_system != NULL) {
  753. token = strtok(pkg_depends_system, " ");
  754. while (token != NULL) {
  755. fprintf(cfg, "\tselect ADK_PACKAGE_%s if ADK_TARGET_SYSTEM_%s\n", toupperstr(token), sysname);
  756. token = strtok(NULL, " ");
  757. }
  758. free(pkg_depends_system);
  759. pkg_depends_system = NULL;
  760. }
  761. if (pkg_need_cxx != NULL) {
  762. fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_CXX\n");
  763. }
  764. if (pkg_need_java != NULL) {
  765. fprintf(cfg, "\tdepends on ADK_TOOLCHAIN_GCC_JAVA\n");
  766. pkg_need_java = NULL;
  767. }
  768. fprintf(cfg, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  769. if (pkg_dflt != NULL) {
  770. fprintf(cfg, "\tdefault %s\n", pkg_dflt);
  771. pkg_dflt = NULL;
  772. } else {
  773. fprintf(cfg, "\tdefault n\n");
  774. }
  775. fprintf(cfg, "\thelp\n");
  776. fprintf(cfg, "\t %s\n\n", pkg_descr);
  777. if (pkg_url != NULL)
  778. fprintf(cfg, "\t WWW: %s\n", pkg_url);
  779. /* handle special C++ packages */
  780. if (pkg_cxx != NULL) {
  781. fprintf(cfg, "\nchoice\n");
  782. fprintf(cfg, "prompt \"C++ library to use\"\n");
  783. fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
  784. fprintf(cfg, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC\n", pkg_cxx);
  785. fprintf(cfg, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx);
  786. fprintf(cfg, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx);
  787. fprintf(cfg, "\tbool \"GNU C++ library\"\n");
  788. fprintf(cfg, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
  789. fprintf(cfg, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx);
  790. fprintf(cfg, "\tbool \"uClibc++ library\"\n");
  791. fprintf(cfg, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
  792. fprintf(cfg, "endchoice\n");
  793. free(pkg_cxx);
  794. pkg_cxx = NULL;
  795. }
  796. /* handle debug subpackages */
  797. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_DBG\n", toupperstr(pkg_debug));
  798. fprintf(cfg, "\tprompt \"add debug symbols package\"\n");
  799. fprintf(cfg, "\ttristate\n");
  800. fprintf(cfg, "\tdepends on ADK_PACKAGE_GDB\n");
  801. fprintf(cfg, "\tdepends on !ADK_DEBUG\n");
  802. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkg_debug));
  803. fprintf(cfg, "\tdefault n\n");
  804. fprintf(cfg, "\thelp\n\n");
  805. /* package flavours */
  806. if (pkg_flavours != NULL) {
  807. token = strtok(pkg_flavours, " ");
  808. while (token != NULL) {
  809. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  810. // process default value
  811. strncat(hkey, "PKGFX_", 6);
  812. strncat(hkey, token, strlen(token));
  813. memset(hvalue, 0 , MAXVALUE);
  814. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  815. memset(hkey, 0 , MAXVAR);
  816. pkg_fd = strdup(hvalue);
  817. if (strlen(pkg_fd) > 0)
  818. fprintf(cfg, "\tdefault %s\n", pkg_fd);
  819. else
  820. fprintf(cfg, "\tdefault n\n");
  821. // process flavour cfline
  822. strncat(hkey, "PKGFC_", 6);
  823. strncat(hkey, token, strlen(token));
  824. memset(hvalue, 0 , MAXVALUE);
  825. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  826. memset(hkey, 0 , MAXVAR);
  827. pkg_fd = strdup(hvalue);
  828. if (strlen(pkg_fd) > 0)
  829. fprintf(cfg, "\t%s\n", pkg_fd);
  830. fprintf(cfg, "\tboolean ");
  831. strncat(hkey, "PKGFD_", 6);
  832. strncat(hkey, token, strlen(token));
  833. memset(hvalue, 0 , MAXVALUE);
  834. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  835. memset(hkey, 0 , MAXVAR);
  836. pkg_fd = strdup(hvalue);
  837. fprintf(cfg, "\"%s\"\n", pkg_fd);
  838. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
  839. strncat(hkey, "PKGFS_", 6);
  840. strncat(hkey, token, strlen(token));
  841. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  842. if (result == 1) {
  843. val = strtok_r(hvalue, " ", &saveptr);
  844. while (val != NULL) {
  845. if (strncmp(val, "kmod", 4) == 0)
  846. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  847. else
  848. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  849. val = strtok_r(NULL, " ", &saveptr);
  850. }
  851. }
  852. memset(hkey, 0, MAXVAR);
  853. fprintf(cfg, "\thelp\n");
  854. fprintf(cfg, "\t %s\n", pkg_fd);
  855. token = strtok(NULL, " ");
  856. }
  857. free(pkg_flavours);
  858. pkg_flavours = NULL;
  859. }
  860. /* package flavours string */
  861. if (pkg_flavours_string != NULL) {
  862. token = strtok(pkg_flavours_string, " ");
  863. while (token != NULL) {
  864. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  865. // process default value
  866. strncat(hkey, "PKGFX_", 6);
  867. strncat(hkey, token, strlen(token));
  868. memset(hvalue, 0 , MAXVALUE);
  869. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  870. memset(hkey, 0 , MAXVAR);
  871. pkg_fd = strdup(hvalue);
  872. if (strlen(pkg_fd) > 0)
  873. fprintf(cfg, "\tdefault \"%s\"\n", pkg_fd);
  874. // process flavour cfline
  875. strncat(hkey, "PKGFC_", 6);
  876. strncat(hkey, token, strlen(token));
  877. memset(hvalue, 0 , MAXVALUE);
  878. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  879. memset(hkey, 0 , MAXVAR);
  880. pkg_fd = strdup(hvalue);
  881. if (strlen(pkg_fd) > 0)
  882. fprintf(cfg, "\t%s\n", pkg_fd);
  883. fprintf(cfg, "\tstring ");
  884. strncat(hkey, "PKGFD_", 6);
  885. strncat(hkey, token, strlen(token));
  886. memset(hvalue, 0 , MAXVALUE);
  887. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  888. memset(hkey, 0 , MAXVAR);
  889. pkg_fd = strdup(hvalue);
  890. fprintf(cfg, "\"%s\"\n", pkg_fd);
  891. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
  892. strncat(hkey, "PKGFS_", 6);
  893. strncat(hkey, token, strlen(token));
  894. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  895. if (result == 1) {
  896. val = strtok_r(hvalue, " ", &saveptr);
  897. while (val != NULL) {
  898. if (strncmp(val, "kmod", 4) == 0)
  899. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  900. else
  901. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  902. val = strtok_r(NULL, " ", &saveptr);
  903. }
  904. }
  905. memset(hkey, 0, MAXVAR);
  906. fprintf(cfg, "\thelp\n");
  907. fprintf(cfg, "\t %s\n", pkg_fd);
  908. token = strtok(NULL, " ");
  909. }
  910. free(pkg_flavours_string);
  911. pkg_flavours_string = NULL;
  912. }
  913. /* package choices */
  914. if (pkg_choices != NULL) {
  915. fprintf(cfg, "\nchoice\n");
  916. fprintf(cfg, "prompt \"Package flavour choice\"\n");
  917. fprintf(cfg, "depends on ADK_PACKAGE_%s\n\n", pkgname);
  918. token = strtok(pkg_choices, " ");
  919. while (token != NULL) {
  920. fprintf(cfg, "config ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  921. fprintf(cfg, "\tbool ");
  922. strncat(hkey, "PKGCD_", 6);
  923. strncat(hkey, token, strlen(token));
  924. memset(hvalue, 0 , MAXVALUE);
  925. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  926. memset(hkey, 0 , MAXVAR);
  927. fprintf(cfg, "\"%s\"\n", hvalue);
  928. strncat(hkey, "PKGCS_", 6);
  929. strncat(hkey, token, strlen(token));
  930. memset(hvalue, 0, MAXVALUE);
  931. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  932. if (result == 1) {
  933. val = strtok_r(hvalue, " ", &saveptr);
  934. while (val != NULL) {
  935. if (strncmp(val, "kmod", 4) == 0)
  936. fprintf(cfg, "\tselect ADK_KPACKAGE_%s\n", toupperstr(val));
  937. else
  938. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  939. val = strtok_r(NULL, " ", &saveptr);
  940. }
  941. }
  942. memset(hkey, 0, MAXVAR);
  943. token = strtok(NULL, " ");
  944. }
  945. fprintf(cfg, "\nendchoice\n");
  946. free(pkg_choices);
  947. pkg_choices = NULL;
  948. }
  949. /* close file descriptor for Config.in file */
  950. fclose(cfg);
  951. /* create Config.in files for development packages */
  952. if (pkg_opts != NULL) {
  953. if (strstr(pkg_opts, "dev") != NULL) {
  954. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
  955. fatal_error("failed to create path variable.");
  956. cfg = fopen(path, "a");
  957. if (cfg == NULL)
  958. perror("Can not open Config.in.dev file");
  959. if (pkg_libname == NULL)
  960. pkg_libname = strdup(pkg_name);
  961. fprintf(cfg, "\n");
  962. fprintf(cfg, "config ADK_PACKAGE_%s_DEV\n", toupperstr(pkg_libname));
  963. pseudo_name = malloc(MAXLINE);
  964. memset(pseudo_name, 0, MAXLINE);
  965. strncat(pseudo_name, pkg_libname, strlen(pkg_libname));
  966. strncat(pseudo_name, "-dev", 4);
  967. while (strlen(pseudo_name) < 20)
  968. strncat(pseudo_name, ".", 1);
  969. fprintf(cfg, "\tprompt \"%s. development files for %s\"\n", pseudo_name, pkg_libname);
  970. fprintf(cfg, "\ttristate\n");
  971. /* create package target architecture dependency information */
  972. if (pkg_arch_depends != NULL) {
  973. pkg_helper = strdup(pkg_arch_depends);
  974. token = strtok(pkg_helper, " ");
  975. fprintf(cfg, "\tdepends on ");
  976. sp = "";
  977. while (token != NULL) {
  978. if(strncmp(token, "!", 1) == 0) {
  979. fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
  980. sp = " && ";
  981. } else {
  982. fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
  983. sp = " || ";
  984. }
  985. token = strtok(NULL, " ");
  986. }
  987. fprintf(cfg, "\n");
  988. free(pkg_helper);
  989. pkg_helper = NULL;
  990. }
  991. fprintf(cfg, "\tdepends on ADK_PACKAGE_GCC\n");
  992. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(pkg_libname));
  993. fprintf(cfg, "\tdefault n\n");
  994. fclose(cfg);
  995. free(pseudo_name);
  996. free(pkg_libname);
  997. pkg_libname = NULL;
  998. }
  999. pkg_opts = NULL;
  1000. }
  1001. /* parse next package */
  1002. token = strtok_r(NULL, " ", &p_ptr);
  1003. }
  1004. /* end of package output generation */
  1005. free(packages);
  1006. packages = NULL;
  1007. pkg_need_cxx = NULL;
  1008. pkg_need_java = NULL;
  1009. /* reset flags, free memory */
  1010. free(pkg_name);
  1011. free(pkg_libname);
  1012. free(pkg_descr);
  1013. free(pkg_section);
  1014. free(pkg_url);
  1015. free(pkg_depends);
  1016. free(pkg_flavours);
  1017. free(pkg_flavours_string);
  1018. free(pkg_choices);
  1019. free(pkg_subpkgs);
  1020. free(pkg_arch_depends);
  1021. free(pkg_system_depends);
  1022. free(pkg_host_depends);
  1023. free(pkg_libc_depends);
  1024. free(pkg_cxx);
  1025. free(pkg_dflt);
  1026. free(pkg_cfline);
  1027. free(pkg_multi);
  1028. pkg_name = NULL;
  1029. pkg_libname = NULL;
  1030. pkg_descr = NULL;
  1031. pkg_section = NULL;
  1032. pkg_url = NULL;
  1033. pkg_depends = NULL;
  1034. pkg_flavours = NULL;
  1035. pkg_flavours_string = NULL;
  1036. pkg_choices = NULL;
  1037. pkg_subpkgs = NULL;
  1038. pkg_arch_depends = NULL;
  1039. pkg_system_depends = NULL;
  1040. pkg_host_depends = NULL;
  1041. pkg_libc_depends = NULL;
  1042. pkg_cxx = NULL;
  1043. pkg_dflt = NULL;
  1044. pkg_cfline = NULL;
  1045. pkg_multi = NULL;
  1046. strmap_delete(pkgmap);
  1047. nobinpkgs = 0;
  1048. free(hkey);
  1049. }
  1050. }
  1051. /* add menu to gcc package */
  1052. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.gcc") < 0)
  1053. fatal_error("failed to create path variable.");
  1054. cfg = fopen(path, "a");
  1055. if (cfg == NULL)
  1056. perror("Can not open Config.in.gcc file");
  1057. fprintf(cfg, "menu \"Development packages\"\n");
  1058. fprintf(cfg, "depends on ADK_PACKAGE_GCC\n");
  1059. fprintf(cfg, "source \"package/pkgconfigs.d/gcc/Config.in.dev\"\n");
  1060. fprintf(cfg, "endmenu\n");
  1061. fclose(cfg);
  1062. /* create Config.in.auto */
  1063. strmap_enum(sectionmap, iter, NULL);
  1064. strmap_delete(sectionmap);
  1065. fclose(menuglobal);
  1066. closedir(pkgdir);
  1067. /* remove temporary section files */
  1068. pkglistdir = opendir("package/pkglist.d");
  1069. while ((pkgdirp = readdir(pkglistdir)) != NULL) {
  1070. if (strncmp(pkgdirp->d_name, "sectionlst.", 11) == 0) {
  1071. if (snprintf(path, MAXPATH, "package/pkglist.d/%s", pkgdirp->d_name) < 0)
  1072. fatal_error("creating path variable failed.");
  1073. if (unlink(path) < 0)
  1074. fatal_error("removing file failed.");
  1075. }
  1076. }
  1077. closedir(pkglistdir);
  1078. return(0);
  1079. }