pkgmaker.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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, *scriptdir;
  271. struct dirent *pkgdirp;
  272. struct dirent *scriptdirp;
  273. size_t len;
  274. FILE *pkg, *cfg, *menuglobal, *section, *initscript, *icfg;
  275. char hvalue[MAXVALUE];
  276. char buf[MAXPATH];
  277. char ibuf[MAXPATH];
  278. char tbuf[MAXPATH];
  279. char path[MAXPATH];
  280. char script[MAXPATH];
  281. char script2[MAXPATH];
  282. char spath[MAXPATH];
  283. char dir[MAXPATH];
  284. char variable[2*MAXVAR];
  285. char *key, *value, *token, *cftoken, *sp, *hkey, *val, *pkg_fd;
  286. char *pkg_name, *pkg_depends, *pkg_depends_system, *pkg_section, *pkg_descr, *pkg_url;
  287. char *pkg_cxx, *pkg_subpkgs, *pkg_cfline, *pkg_dflt;
  288. char *pkgname, *sysname, *pkg_debug;
  289. char *pkg_libc_depends, *pkg_host_depends, *pkg_system_depends, *pkg_arch_depends, *pkg_flavours, *pkg_flavours_string, *pkg_choices, *pseudo_name;
  290. char *packages, *pkg_name_u, *pkgs, *pkg_opts, *pkg_libname;
  291. char *saveptr, *p_ptr, *s_ptr, *pkg_helper, *sname, *sname2;
  292. int result;
  293. StrMap *pkgmap, *sectionmap;
  294. const char runtime[] = "target/config/Config.in.scripts";
  295. pkg_name = NULL;
  296. pkg_descr = NULL;
  297. pkg_section = NULL;
  298. pkg_url = NULL;
  299. pkg_depends = NULL;
  300. pkg_depends_system = NULL;
  301. pkg_opts = NULL;
  302. pkg_libname = NULL;
  303. pkg_flavours = NULL;
  304. pkg_flavours_string = NULL;
  305. pkg_choices = NULL;
  306. pkg_subpkgs = NULL;
  307. pkg_arch_depends = NULL;
  308. pkg_system_depends = NULL;
  309. pkg_host_depends = NULL;
  310. pkg_libc_depends = NULL;
  311. pkg_cxx = NULL;
  312. pkg_dflt = NULL;
  313. pkg_cfline = NULL;
  314. pkgname = NULL;
  315. sysname = NULL;
  316. pkg_helper = NULL;
  317. pkg_debug = NULL;
  318. p_ptr = NULL;
  319. s_ptr = NULL;
  320. unlink("package/Config.in.auto");
  321. unlink(runtime);
  322. /* open global sectionfile */
  323. menuglobal = fopen("package/Config.in.auto.global", "w");
  324. if (menuglobal == NULL)
  325. fatal_error("global section file not writable.");
  326. /* read section list and create a hash table */
  327. section = fopen("package/section.lst", "r");
  328. if (section == NULL)
  329. fatal_error("section listfile is missing");
  330. sectionmap = strmap_new(HASHSZ);
  331. while (fgets(tbuf, MAXPATH, section) != NULL) {
  332. key = strtok(tbuf, "\t");
  333. value = strtok(NULL, "\t");
  334. strmap_put(sectionmap, key, value);
  335. }
  336. fclose(section);
  337. if (mkdir("package/pkgconfigs.d", S_IRWXU) > 0)
  338. fatal_error("creation of package/pkgconfigs.d failed.");
  339. if (mkdir("package/pkgconfigs.d/gcc", S_IRWXU) > 0)
  340. fatal_error("creation of package/pkgconfigs.d/gcc failed.");
  341. if (mkdir("package/pkglist.d", S_IRWXU) > 0)
  342. fatal_error("creation of package/pkglist.d failed.");
  343. /* delete Config.in.dev */
  344. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
  345. fatal_error("failed to create path variable.");
  346. unlink(path);
  347. cfg = fopen(path, "w");
  348. if (cfg == NULL)
  349. fatal_error("Config.in.dev can not be opened");
  350. fprintf(cfg, "config ADK_PACKAGE_GLIBC_DEV\n");
  351. fprintf(cfg, "\tprompt \"glibc-dev............ development files for glibc\"\n");
  352. fprintf(cfg, "\tboolean\n");
  353. fprintf(cfg, "\tdefault n\n");
  354. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_GLIBC\n");
  355. fprintf(cfg, "\thelp\n");
  356. fprintf(cfg, "\t GNU C library header files.\n\n");
  357. fprintf(cfg, "config ADK_PACKAGE_UCLIBC_DEV\n");
  358. fprintf(cfg, "\tprompt \"uclibc-dev........... development files for uclibc\"\n");
  359. fprintf(cfg, "\tboolean\n");
  360. fprintf(cfg, "\tdefault n\n");
  361. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_UCLIBC\n");
  362. fprintf(cfg, "\thelp\n");
  363. fprintf(cfg, "\t C library header files.\n\n");
  364. fprintf(cfg, "config ADK_PACKAGE_MUSL_DEV\n");
  365. fprintf(cfg, "\tprompt \"musl-dev............. development files for musl\"\n");
  366. fprintf(cfg, "\tboolean\n");
  367. fprintf(cfg, "\tdefault n\n");
  368. fprintf(cfg, "\tdepends on ADK_TARGET_LIB_MUSL\n");
  369. fprintf(cfg, "\thelp\n");
  370. fprintf(cfg, "\t C library header files.\n\n");
  371. fclose(cfg);
  372. /* read Makefile's for all packages */
  373. pkgdir = opendir("package");
  374. while ((pkgdirp = readdir(pkgdir)) != NULL) {
  375. /* skip dotfiles */
  376. if (strncmp(pkgdirp->d_name, ".", 1) > 0) {
  377. if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0)
  378. fatal_error("can not create path variable.");
  379. pkg = fopen(path, "r");
  380. if (pkg == NULL)
  381. continue;
  382. /* runtime configuration */
  383. if (snprintf(script, MAXPATH, "package/%s/files", pkgdirp->d_name) < 0)
  384. fatal_error("script variable creation failed.");
  385. scriptdir = opendir(script);
  386. if (scriptdir != NULL) {
  387. while ((scriptdirp = readdir(scriptdir)) != NULL) {
  388. /* skip dotfiles */
  389. if (strncmp(scriptdirp->d_name, ".", 1) > 0) {
  390. len = strlen(scriptdirp->d_name);
  391. if (strlen(".init") > len)
  392. continue;
  393. if (strncmp(scriptdirp->d_name + len - strlen(".init"), ".init", strlen(".init")) == 0) {
  394. if (snprintf(script, MAXPATH, "package/%s/files/%s", pkgdirp->d_name, scriptdirp->d_name) < 0)
  395. fatal_error("script variable creation failed.");
  396. initscript = fopen(script, "r");
  397. if (initscript == NULL)
  398. continue;
  399. while (fgets(ibuf, MAXPATH, initscript) != NULL) {
  400. if (strncmp("#PKG", ibuf, 4) == 0) {
  401. sname = strdup(ibuf+5);
  402. sname[strlen(sname)-1] = '\0';
  403. sname2 = strdup(scriptdirp->d_name);
  404. sname2[strlen(sname2)-5] = '\0';
  405. icfg = fopen(runtime, "a");
  406. if (icfg == NULL)
  407. continue;
  408. if (strncmp("busybox", sname, 7) == 0)
  409. fprintf(icfg, "config ADK_RUNTIME_START_%s_%s\n", toupperstr(sname), toupperstr(sname2));
  410. else
  411. fprintf(icfg, "config ADK_RUNTIME_START_%s\n", toupperstr(sname));
  412. fprintf(icfg, "\tprompt \"Start %s on boot\"\n", sname2);
  413. fprintf(icfg, "\tboolean\n");
  414. if (strncmp("busybox", sname, 7) == 0)
  415. fprintf(icfg, "\tdepends on BUSYBOX_%s\n", toupperstr(sname2));
  416. else
  417. fprintf(icfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(sname));
  418. fprintf(icfg, "\tdepends on ADK_RUNTIME_START_SERVICES\n");
  419. fprintf(icfg, "\tdefault n\n\n");
  420. fclose(icfg);
  421. }
  422. continue;
  423. free(sname);
  424. free(sname2);
  425. }
  426. }
  427. }
  428. }
  429. closedir(scriptdir);
  430. }
  431. /* skip manually maintained packages */
  432. if (snprintf(path, MAXPATH, "package/%s/Config.in.manual", pkgdirp->d_name) < 0)
  433. fatal_error("can not create path variable.");
  434. if (!access(path, F_OK)) {
  435. while (fgets(buf, MAXPATH, pkg) != NULL) {
  436. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  437. continue;
  438. }
  439. memset(hvalue, 0 , MAXVALUE);
  440. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  441. if (result == 1) {
  442. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  443. fatal_error("can not create path variable.");
  444. section = fopen(spath, "a");
  445. if (section != NULL) {
  446. fprintf(section, "%s@\n", pkgdirp->d_name);
  447. fclose(section);
  448. }
  449. } else
  450. fatal_error("Can not find section description for package %s.",
  451. pkgdirp->d_name);
  452. fclose(pkg);
  453. continue;
  454. }
  455. nobinpkgs = 0;
  456. /* create output directories */
  457. if (snprintf(dir, MAXPATH, "package/pkgconfigs.d/%s", pkgdirp->d_name) < 0)
  458. fatal_error("can not create dir variable.");
  459. if (mkdir(dir, S_IRWXU) > 0)
  460. fatal_error("can not create directory.");
  461. /* allocate memory */
  462. hkey = malloc(MAXVAR);
  463. memset(hkey, 0, MAXVAR);
  464. memset(variable, 0, 2*MAXVAR);
  465. pkgmap = strmap_new(HASHSZ);
  466. /* parse package Makefile */
  467. while (fgets(buf, MAXPATH, pkg) != NULL) {
  468. /* just read variables prefixed with PKG */
  469. if (strncmp(buf, "PKG", 3) == 0) {
  470. if ((parse_var(buf, "PKG_NAME", NULL, &pkg_name)) == 0)
  471. continue;
  472. if (pkg_name != NULL)
  473. pkg_name_u = toupperstr(pkg_name);
  474. else
  475. pkg_name_u = toupperstr(pkgdirp->d_name);
  476. snprintf(variable, MAXVAR, "PKG_CFLINE_%s", pkg_name_u);
  477. if ((parse_var(buf, variable, pkg_cfline, &pkg_cfline)) == 0)
  478. continue;
  479. snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u);
  480. if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0)
  481. continue;
  482. if ((parse_var(buf, "PKG_LIBC_DEPENDS", NULL, &pkg_libc_depends)) == 0)
  483. continue;
  484. if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0)
  485. continue;
  486. if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0)
  487. continue;
  488. if ((parse_var(buf, "PKG_SYSTEM_DEPENDS", NULL, &pkg_system_depends)) == 0)
  489. continue;
  490. if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0)
  491. continue;
  492. if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0)
  493. continue;
  494. if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0)
  495. continue;
  496. if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0)
  497. continue;
  498. if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0)
  499. continue;
  500. if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_system, &pkg_depends_system, &sysname, 12)) == 0)
  501. continue;
  502. if ((parse_var(buf, "PKG_LIBNAME", pkg_libname, &pkg_libname)) == 0)
  503. continue;
  504. if ((parse_var(buf, "PKG_OPTS", pkg_opts, &pkg_opts)) == 0)
  505. continue;
  506. if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_STRING_", pkg_flavours_string, &pkg_flavours_string, &pkgname, 20)) == 0)
  507. continue;
  508. if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_", pkg_flavours, &pkg_flavours, &pkgname, 13)) == 0)
  509. continue;
  510. if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0)
  511. continue;
  512. if ((parse_var_hash(buf, "PKGFX_", pkgmap)) == 0)
  513. continue;
  514. if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0)
  515. continue;
  516. if ((parse_var_hash(buf, "PKGFC_", pkgmap)) == 0)
  517. continue;
  518. if ((parse_var_with_pkg(buf, "PKG_CHOICES_", pkg_choices, &pkg_choices, &pkgname, 12)) == 0)
  519. continue;
  520. if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0)
  521. continue;
  522. if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0)
  523. continue;
  524. if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0)
  525. continue;
  526. if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0)
  527. continue;
  528. if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0)
  529. continue;
  530. if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0)
  531. continue;
  532. if ((parse_var_hash(buf, "PKGSN_", pkgmap)) == 0)
  533. continue;
  534. }
  535. }
  536. /* when PKG_LIBNAME exist use this instead of PKG_NAME, but only for !libmix */
  537. if (pkg_libname != NULL)
  538. if (pkg_opts != NULL)
  539. if (strstr(pkg_opts, "libmix") == NULL)
  540. pkg_name = strdup(pkg_libname);
  541. /* end of package Makefile parsing */
  542. if (fclose(pkg) != 0)
  543. perror("Failed to close file stream for Makefile");
  544. #if 0
  545. if (pkg_name != NULL)
  546. fprintf(stderr, "Package name is %s\n", pkg_name);
  547. if (pkg_libname != NULL)
  548. fprintf(stderr, "Package library name is %s\n", pkg_libname);
  549. if (pkg_section != NULL)
  550. fprintf(stderr, "Package section is %s\n", pkg_section);
  551. if (pkg_descr != NULL)
  552. fprintf(stderr, "Package description is %s\n", pkg_descr);
  553. if (pkg_depends != NULL)
  554. fprintf(stderr, "Package dependencies are %s\n", pkg_depends);
  555. if (pkg_depends_system != NULL)
  556. fprintf(stderr, "Package systemspecific dependencies are %s\n", pkg_depends_system);
  557. if (pkg_subpkgs != NULL)
  558. fprintf(stderr, "Package subpackages are %s\n", pkg_subpkgs);
  559. if (pkg_flavours != NULL && pkgname != NULL)
  560. fprintf(stderr, "Package flavours for %s are %s\n", pkgname, pkg_flavours);
  561. if (pkg_flavours_string != NULL && pkgname != NULL)
  562. fprintf(stderr, "Package string flavours for %s are %s\n", pkgname, pkg_flavours_string);
  563. if (pkg_choices != NULL && pkgname != NULL)
  564. fprintf(stderr, "Package choices for %s are %s\n", pkgname, pkg_choices);
  565. if (pkg_url != NULL)
  566. fprintf(stderr, "Package homepage is %s\n", pkg_url);
  567. if (pkg_cfline != NULL)
  568. fprintf(stderr, "Package cfline is %s\n", pkg_cfline);
  569. if (pkg_opts != NULL)
  570. fprintf(stderr, "Package options are %s\n", pkg_opts);
  571. strmap_enum(pkgmap, iter_debug, NULL);
  572. #endif
  573. /* generate master source Config.in file */
  574. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in", pkgdirp->d_name) < 0)
  575. fatal_error("path variable creation failed.");
  576. fprintf(menuglobal, "source \"%s\"\n", path);
  577. /* recreating file is faster than truncating with w+ */
  578. unlink(path);
  579. cfg = fopen(path, "w");
  580. if (cfg == NULL)
  581. continue;
  582. pkgs = NULL;
  583. if (pkg_subpkgs != NULL)
  584. pkgs = strdup(pkg_subpkgs);
  585. fprintf(cfg, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  586. fprintf(cfg, "\tboolean\n");
  587. if (nobinpkgs == 0) {
  588. fprintf(cfg, "\tdepends on ");
  589. if (pkgs != NULL) {
  590. token = strtok(pkgs, " ");
  591. fprintf(cfg, "ADK_PACKAGE_%s", token);
  592. token = strtok(NULL, " ");
  593. while (token != NULL) {
  594. fprintf(cfg, " || ADK_PACKAGE_%s", token);
  595. token = strtok(NULL, " ");
  596. }
  597. fprintf(cfg, "\n");
  598. } else {
  599. fprintf(cfg, "ADK_PACKAGE_%s\n", toupperstr(pkg_name));
  600. }
  601. }
  602. fprintf(cfg, "\tdefault n\n");
  603. fclose(cfg);
  604. free(pkgs);
  605. /* skip packages without binary package output */
  606. if (nobinpkgs == 1)
  607. continue;
  608. /* generate binary package specific Config.in files */
  609. if (pkg_subpkgs != NULL)
  610. packages = tolowerstr(pkg_subpkgs);
  611. else
  612. packages = strdup(pkg_name);
  613. token = strtok_r(packages, " ", &p_ptr);
  614. while (token != NULL) {
  615. strncat(hkey, "PKGSC_", 6);
  616. strncat(hkey, toupperstr(token), strlen(token));
  617. memset(hvalue, 0 , MAXVALUE);
  618. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  619. memset(hkey, 0 , MAXVAR);
  620. if (result == 1)
  621. pkg_section = strdup(hvalue);
  622. strncat(hkey, "PKGSD_", 6);
  623. strncat(hkey, toupperstr(token), strlen(token));
  624. memset(hvalue, 0 , MAXVALUE);
  625. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  626. memset(hkey, 0 , MAXVAR);
  627. if (result == 1)
  628. pkg_descr = strdup(hvalue);
  629. pseudo_name = malloc(MAXLINE);
  630. memset(pseudo_name, 0, MAXLINE);
  631. strncat(pseudo_name, token, strlen(token));
  632. while (strlen(pseudo_name) < 20)
  633. strncat(pseudo_name, ".", 1);
  634. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in.%s", pkgdirp->d_name, token) < 0)
  635. fatal_error("failed to create path variable.");
  636. /* create temporary section files */
  637. memset(hvalue, 0 , MAXVALUE);
  638. result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue));
  639. if (result == 1) {
  640. if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0)
  641. fatal_error("failed to create path variable.");
  642. section = fopen(spath, "a");
  643. if (section != NULL) {
  644. fprintf(section, "%s |%s\n", token, pkgdirp->d_name);
  645. fclose(section);
  646. }
  647. } else
  648. fatal_error("Can not find section description for package %s.", pkgdirp->d_name);
  649. unlink(path);
  650. cfg = fopen(path, "w");
  651. if (cfg == NULL)
  652. perror("Can not open Config.in file");
  653. /* save token in pkg_debug */
  654. pkg_debug = strdup(token);
  655. fprintf(cfg, "config ADK_PACKAGE_%s\n", toupperstr(token));
  656. /* no prompt for devonly packages */
  657. if (pkg_opts != NULL) {
  658. if (strstr(pkg_opts, "devonly") != NULL) {
  659. fprintf(cfg, "\t#prompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  660. } else {
  661. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  662. }
  663. } else {
  664. fprintf(cfg, "\tprompt \"%s. %s\"\n", pseudo_name, pkg_descr);
  665. }
  666. fprintf(cfg, "\tboolean\n");
  667. free(pseudo_name);
  668. /* print custom cf line */
  669. if (pkg_cfline != NULL) {
  670. cftoken = strtok_r(pkg_cfline, "@", &saveptr);
  671. while (cftoken != NULL) {
  672. fprintf(cfg, "\t%s\n", cftoken);
  673. cftoken = strtok_r(NULL, "@", &saveptr);
  674. }
  675. free(pkg_cfline);
  676. pkg_cfline = NULL;
  677. }
  678. /* add sub package dependencies */
  679. strncat(hkey, "PKGSN_", 6);
  680. strncat(hkey, toupperstr(token), strlen(token));
  681. memset(hvalue, 0, MAXVALUE);
  682. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  683. if (result == 1) {
  684. val = strtok_r(hvalue, " ", &saveptr);
  685. while (val != NULL) {
  686. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(val));
  687. val = strtok_r(NULL, " ", &saveptr);
  688. }
  689. }
  690. memset(hkey, 0, MAXVAR);
  691. /* add sub package auto selections */
  692. strncat(hkey, "PKGSS_", 6);
  693. strncat(hkey, toupperstr(token), strlen(token));
  694. memset(hvalue, 0, MAXVALUE);
  695. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  696. if (result == 1) {
  697. val = strtok_r(hvalue, " ", &saveptr);
  698. while (val != NULL) {
  699. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  700. val = strtok_r(NULL, " ", &saveptr);
  701. }
  702. }
  703. memset(hkey, 0, MAXVAR);
  704. /* create package target system dependency information */
  705. if (pkg_system_depends != NULL) {
  706. pkg_helper = strdup(pkg_system_depends);
  707. token = strtok(pkg_helper, " ");
  708. fprintf(cfg, "\tdepends on ");
  709. sp = "";
  710. while (token != NULL) {
  711. if(strncmp(token, "!", 1) == 0) {
  712. fprintf(cfg, "%s!ADK_TARGET_SYSTEM%s", sp, toupperstr(token));
  713. sp = " && ";
  714. } else {
  715. fprintf(cfg, "%sADK_TARGET_SYSTEM_%s", sp, toupperstr(token));
  716. sp = " || ";
  717. }
  718. token = strtok(NULL, " ");
  719. }
  720. fprintf(cfg, "\n");
  721. free(pkg_helper);
  722. pkg_helper = NULL;
  723. }
  724. /* create package host dependency information */
  725. if (pkg_host_depends != NULL) {
  726. pkg_helper = strdup(pkg_host_depends);
  727. token = strtok(pkg_helper, " ");
  728. fprintf(cfg, "\tdepends on ");
  729. sp = "";
  730. while (token != NULL) {
  731. if(strncmp(token, "!", 1) == 0) {
  732. fprintf(cfg, "%s!ADK_HOST%s", sp, toupperstr(token));
  733. sp = " && ";
  734. } else {
  735. fprintf(cfg, "%sADK_HOST_%s", sp, toupperstr(token));
  736. sp = " || ";
  737. }
  738. token = strtok(NULL, " ");
  739. }
  740. fprintf(cfg, "\n");
  741. free(pkg_helper);
  742. pkg_helper = NULL;
  743. }
  744. /* create package libc dependency information */
  745. if (pkg_libc_depends != NULL) {
  746. pkg_helper = strdup(pkg_libc_depends);
  747. token = strtok(pkg_helper, " ");
  748. fprintf(cfg, "\tdepends on ");
  749. sp = "";
  750. while (token != NULL) {
  751. if(strncmp(token, "!", 1) == 0) {
  752. fprintf(cfg, "%s!ADK_TARGET_LIB_%s", sp, toupperstr(token));
  753. sp = " && ";
  754. } else {
  755. fprintf(cfg, "%sADK_TARGET_LIB_%s", sp, toupperstr(token));
  756. sp = " || ";
  757. }
  758. token = strtok(NULL, " ");
  759. }
  760. fprintf(cfg, "\n");
  761. free(pkg_helper);
  762. pkg_helper = NULL;
  763. }
  764. /* create package target architecture dependency information */
  765. if (pkg_arch_depends != NULL) {
  766. pkg_helper = strdup(pkg_arch_depends);
  767. token = strtok(pkg_helper, " ");
  768. fprintf(cfg, "\tdepends on ");
  769. sp = "";
  770. while (token != NULL) {
  771. if(strncmp(token, "!", 1) == 0) {
  772. fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
  773. sp = " && ";
  774. } else {
  775. fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
  776. sp = " || ";
  777. }
  778. token = strtok(NULL, " ");
  779. }
  780. fprintf(cfg, "\n");
  781. free(pkg_helper);
  782. pkg_helper = NULL;
  783. }
  784. /* create package dependency information */
  785. if (pkg_depends != NULL) {
  786. token = strtok(pkg_depends, " ");
  787. while (token != NULL) {
  788. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(token));
  789. token = strtok(NULL, " ");
  790. }
  791. free(pkg_depends);
  792. pkg_depends = NULL;
  793. }
  794. /* create system specific package dependency information */
  795. if (pkg_depends_system != NULL) {
  796. token = strtok(pkg_depends_system, " ");
  797. while (token != NULL) {
  798. fprintf(cfg, "\tselect ADK_PACKAGE_%s if ADK_TARGET_SYSTEM_%s\n", toupperstr(token), sysname);
  799. token = strtok(NULL, " ");
  800. }
  801. free(pkg_depends_system);
  802. pkg_depends_system = NULL;
  803. }
  804. fprintf(cfg, "\tselect ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name));
  805. if (pkg_dflt != NULL) {
  806. fprintf(cfg, "\tdefault %s\n", pkg_dflt);
  807. pkg_dflt = NULL;
  808. } else {
  809. fprintf(cfg, "\tdefault n\n");
  810. }
  811. fprintf(cfg, "\thelp\n");
  812. fprintf(cfg, "\t %s\n\n", pkg_descr);
  813. if (pkg_url != NULL)
  814. fprintf(cfg, "\t WWW: %s\n", pkg_url);
  815. /* handle special C++ packages */
  816. if (pkg_cxx != NULL) {
  817. fprintf(cfg, "\nchoice\n");
  818. fprintf(cfg, "prompt \"C++ library to use\"\n");
  819. fprintf(cfg, "depends on ADK_COMPILE_%s\n\n", toupperstr(pkgdirp->d_name));
  820. fprintf(cfg, "default ADK_COMPILE_%s_WITH_STDCXX if ADK_TARGET_LIB_GLIBC\n", pkg_cxx);
  821. fprintf(cfg, "default ADK_COMPILE_%s_WITH_UCLIBCXX if ADK_TARGET_LIB_UCLIBC\n\n", pkg_cxx);
  822. fprintf(cfg, "config ADK_COMPILE_%s_WITH_STDCXX\n", pkg_cxx);
  823. fprintf(cfg, "\tbool \"GNU C++ library\"\n");
  824. fprintf(cfg, "\tselect ADK_PACKAGE_LIBSTDCXX\n\n");
  825. fprintf(cfg, "config ADK_COMPILE_%s_WITH_UCLIBCXX\n", pkg_cxx);
  826. fprintf(cfg, "\tbool \"uClibc++ library\"\n");
  827. fprintf(cfg, "\tselect ADK_PACKAGE_UCLIBCXX\n\n");
  828. fprintf(cfg, "endchoice\n");
  829. free(pkg_cxx);
  830. pkg_cxx = NULL;
  831. }
  832. /* handle debug subpackages */
  833. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_DBG\n", toupperstr(pkg_debug));
  834. fprintf(cfg, "\tprompt \"add debug symbols package\"\n");
  835. fprintf(cfg, "\tboolean\n");
  836. fprintf(cfg, "\tdepends on ADK_PACKAGE_GDB\n");
  837. fprintf(cfg, "\tdepends on !ADK_DEBUG\n");
  838. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", toupperstr(pkg_debug));
  839. fprintf(cfg, "\tdefault n\n");
  840. fprintf(cfg, "\thelp\n\n");
  841. /* package flavours */
  842. if (pkg_flavours != NULL) {
  843. token = strtok(pkg_flavours, " ");
  844. while (token != NULL) {
  845. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  846. // process default value
  847. strncat(hkey, "PKGFX_", 6);
  848. strncat(hkey, token, strlen(token));
  849. memset(hvalue, 0 , MAXVALUE);
  850. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  851. memset(hkey, 0 , MAXVAR);
  852. pkg_fd = strdup(hvalue);
  853. if (strlen(pkg_fd) > 0)
  854. fprintf(cfg, "\tdefault %s\n", pkg_fd);
  855. else
  856. fprintf(cfg, "\tdefault n\n");
  857. // process flavour cfline
  858. strncat(hkey, "PKGFC_", 6);
  859. strncat(hkey, token, strlen(token));
  860. memset(hvalue, 0 , MAXVALUE);
  861. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  862. memset(hkey, 0 , MAXVAR);
  863. pkg_fd = strdup(hvalue);
  864. if (strlen(pkg_fd) > 0)
  865. fprintf(cfg, "\t%s\n", pkg_fd);
  866. fprintf(cfg, "\tboolean ");
  867. strncat(hkey, "PKGFD_", 6);
  868. strncat(hkey, token, strlen(token));
  869. memset(hvalue, 0 , MAXVALUE);
  870. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  871. memset(hkey, 0 , MAXVAR);
  872. pkg_fd = strdup(hvalue);
  873. fprintf(cfg, "\"%s\"\n", pkg_fd);
  874. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
  875. strncat(hkey, "PKGFS_", 6);
  876. strncat(hkey, token, strlen(token));
  877. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  878. if (result == 1) {
  879. val = strtok_r(hvalue, " ", &saveptr);
  880. while (val != NULL) {
  881. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  882. val = strtok_r(NULL, " ", &saveptr);
  883. }
  884. }
  885. memset(hkey, 0, MAXVAR);
  886. fprintf(cfg, "\thelp\n");
  887. fprintf(cfg, "\t %s\n", pkg_fd);
  888. token = strtok(NULL, " ");
  889. }
  890. free(pkg_flavours);
  891. pkg_flavours = NULL;
  892. }
  893. /* package flavours string */
  894. if (pkg_flavours_string != NULL) {
  895. token = strtok(pkg_flavours_string, " ");
  896. while (token != NULL) {
  897. fprintf(cfg, "\nconfig ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  898. // process default value
  899. strncat(hkey, "PKGFX_", 6);
  900. strncat(hkey, token, strlen(token));
  901. memset(hvalue, 0 , MAXVALUE);
  902. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  903. memset(hkey, 0 , MAXVAR);
  904. pkg_fd = strdup(hvalue);
  905. if (strlen(pkg_fd) > 0)
  906. fprintf(cfg, "\tdefault \"%s\"\n", pkg_fd);
  907. // process flavour cfline
  908. strncat(hkey, "PKGFC_", 6);
  909. strncat(hkey, token, strlen(token));
  910. memset(hvalue, 0 , MAXVALUE);
  911. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  912. memset(hkey, 0 , MAXVAR);
  913. pkg_fd = strdup(hvalue);
  914. if (strlen(pkg_fd) > 0)
  915. fprintf(cfg, "\t%s\n", pkg_fd);
  916. fprintf(cfg, "\tstring ");
  917. strncat(hkey, "PKGFD_", 6);
  918. strncat(hkey, token, strlen(token));
  919. memset(hvalue, 0 , MAXVALUE);
  920. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  921. memset(hkey, 0 , MAXVAR);
  922. pkg_fd = strdup(hvalue);
  923. fprintf(cfg, "\"%s\"\n", pkg_fd);
  924. fprintf(cfg, "\tdepends on ADK_PACKAGE_%s\n", pkgname);
  925. strncat(hkey, "PKGFS_", 6);
  926. strncat(hkey, token, strlen(token));
  927. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  928. if (result == 1) {
  929. val = strtok_r(hvalue, " ", &saveptr);
  930. while (val != NULL) {
  931. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  932. val = strtok_r(NULL, " ", &saveptr);
  933. }
  934. }
  935. memset(hkey, 0, MAXVAR);
  936. fprintf(cfg, "\thelp\n");
  937. fprintf(cfg, "\t %s\n", pkg_fd);
  938. token = strtok(NULL, " ");
  939. }
  940. free(pkg_flavours_string);
  941. pkg_flavours_string = NULL;
  942. }
  943. /* package choices */
  944. if (pkg_choices != NULL) {
  945. fprintf(cfg, "\nchoice\n");
  946. fprintf(cfg, "prompt \"Package flavour choice\"\n");
  947. fprintf(cfg, "depends on ADK_PACKAGE_%s\n\n", pkgname);
  948. token = strtok(pkg_choices, " ");
  949. while (token != NULL) {
  950. fprintf(cfg, "config ADK_PACKAGE_%s_%s\n", pkgname, toupperstr(token));
  951. fprintf(cfg, "\tbool ");
  952. strncat(hkey, "PKGCD_", 6);
  953. strncat(hkey, token, strlen(token));
  954. memset(hvalue, 0 , MAXVALUE);
  955. strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  956. memset(hkey, 0 , MAXVAR);
  957. fprintf(cfg, "\"%s\"\n", hvalue);
  958. strncat(hkey, "PKGCS_", 6);
  959. strncat(hkey, token, strlen(token));
  960. memset(hvalue, 0, MAXVALUE);
  961. result = strmap_get(pkgmap, hkey, hvalue, sizeof(hvalue));
  962. if (result == 1) {
  963. val = strtok_r(hvalue, " ", &saveptr);
  964. while (val != NULL) {
  965. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(val));
  966. val = strtok_r(NULL, " ", &saveptr);
  967. }
  968. }
  969. memset(hkey, 0, MAXVAR);
  970. token = strtok(NULL, " ");
  971. }
  972. fprintf(cfg, "\nendchoice\n");
  973. free(pkg_choices);
  974. pkg_choices = NULL;
  975. }
  976. /* close file descriptor for Config.in file */
  977. fclose(cfg);
  978. /* create Config.in files for development packages */
  979. if (pkg_opts != NULL) {
  980. if (strstr(pkg_opts, "dev") != NULL) {
  981. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0)
  982. fatal_error("failed to create path variable.");
  983. cfg = fopen(path, "a");
  984. if (cfg == NULL)
  985. perror("Can not open Config.in.dev file");
  986. if (pkg_libname == NULL)
  987. pkg_libname = strdup(pkg_name);
  988. fprintf(cfg, "\n");
  989. fprintf(cfg, "config ADK_PACKAGE_%s_DEV\n", toupperstr(pkg_libname));
  990. pseudo_name = malloc(MAXLINE);
  991. memset(pseudo_name, 0, MAXLINE);
  992. strncat(pseudo_name, pkg_libname, strlen(pkg_libname));
  993. strncat(pseudo_name, "-dev", 4);
  994. while (strlen(pseudo_name) < 20)
  995. strncat(pseudo_name, ".", 1);
  996. fprintf(cfg, "\tprompt \"%s. development files for %s\"\n", pseudo_name, pkg_libname);
  997. fprintf(cfg, "\tboolean\n");
  998. /* create package target architecture dependency information */
  999. if (pkg_arch_depends != NULL) {
  1000. pkg_helper = strdup(pkg_arch_depends);
  1001. token = strtok(pkg_helper, " ");
  1002. fprintf(cfg, "\tdepends on ");
  1003. sp = "";
  1004. while (token != NULL) {
  1005. if(strncmp(token, "!", 1) == 0) {
  1006. fprintf(cfg, "%s!ADK_LINUX%s", sp, toupperstr(token));
  1007. sp = " && ";
  1008. } else {
  1009. fprintf(cfg, "%sADK_LINUX_%s", sp, toupperstr(token));
  1010. sp = " || ";
  1011. }
  1012. token = strtok(NULL, " ");
  1013. }
  1014. fprintf(cfg, "\n");
  1015. free(pkg_helper);
  1016. pkg_helper = NULL;
  1017. }
  1018. fprintf(cfg, "\tdepends on ADK_PACKAGE_GCC\n");
  1019. fprintf(cfg, "\tselect ADK_PACKAGE_%s\n", toupperstr(pkg_libname));
  1020. fprintf(cfg, "\tdefault n\n");
  1021. fclose(cfg);
  1022. free(pseudo_name);
  1023. free(pkg_libname);
  1024. pkg_libname = NULL;
  1025. }
  1026. pkg_opts = NULL;
  1027. }
  1028. /* parse next package */
  1029. token = strtok_r(NULL, " ", &p_ptr);
  1030. }
  1031. /* end of package output generation */
  1032. free(packages);
  1033. packages = NULL;
  1034. /* reset flags, free memory */
  1035. free(pkg_name);
  1036. free(pkg_libname);
  1037. free(pkg_descr);
  1038. free(pkg_section);
  1039. free(pkg_url);
  1040. free(pkg_depends);
  1041. free(pkg_flavours);
  1042. free(pkg_flavours_string);
  1043. free(pkg_choices);
  1044. free(pkg_subpkgs);
  1045. free(pkg_arch_depends);
  1046. free(pkg_system_depends);
  1047. free(pkg_host_depends);
  1048. free(pkg_libc_depends);
  1049. free(pkg_cxx);
  1050. free(pkg_dflt);
  1051. free(pkg_cfline);
  1052. pkg_name = NULL;
  1053. pkg_libname = NULL;
  1054. pkg_descr = NULL;
  1055. pkg_section = NULL;
  1056. pkg_url = NULL;
  1057. pkg_depends = NULL;
  1058. pkg_flavours = NULL;
  1059. pkg_flavours_string = NULL;
  1060. pkg_choices = NULL;
  1061. pkg_subpkgs = NULL;
  1062. pkg_arch_depends = NULL;
  1063. pkg_system_depends = NULL;
  1064. pkg_host_depends = NULL;
  1065. pkg_libc_depends = NULL;
  1066. pkg_cxx = NULL;
  1067. pkg_dflt = NULL;
  1068. pkg_cfline = NULL;
  1069. strmap_delete(pkgmap);
  1070. nobinpkgs = 0;
  1071. free(hkey);
  1072. }
  1073. }
  1074. /* add menu to gcc package */
  1075. if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.gcc") < 0)
  1076. fatal_error("failed to create path variable.");
  1077. cfg = fopen(path, "a");
  1078. if (cfg == NULL)
  1079. perror("Can not open Config.in.gcc file");
  1080. fprintf(cfg, "menu \"Development packages\"\n");
  1081. fprintf(cfg, "depends on ADK_PACKAGE_GCC\n");
  1082. fprintf(cfg, "source \"package/pkgconfigs.d/gcc/Config.in.dev\"\n");
  1083. fprintf(cfg, "endmenu\n");
  1084. fclose(cfg);
  1085. /* create Config.in.auto */
  1086. strmap_enum(sectionmap, iter, NULL);
  1087. strmap_delete(sectionmap);
  1088. fclose(menuglobal);
  1089. closedir(pkgdir);
  1090. /* remove temporary section files */
  1091. pkglistdir = opendir("package/pkglist.d");
  1092. while ((pkgdirp = readdir(pkglistdir)) != NULL) {
  1093. if (strncmp(pkgdirp->d_name, "sectionlst.", 11) == 0) {
  1094. if (snprintf(path, MAXPATH, "package/pkglist.d/%s", pkgdirp->d_name) < 0)
  1095. fatal_error("creating path variable failed.");
  1096. if (unlink(path) < 0)
  1097. fatal_error("removing file failed.");
  1098. }
  1099. }
  1100. closedir(pkglistdir);
  1101. return(0);
  1102. }