pkgmaker.c 34 KB

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