1
0

pkgmaker.c 38 KB

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