pkgmaker.c 40 KB

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