pkgmaker.c 38 KB

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