pkgmaker.c 39 KB

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