diff options
author | Waldemar Brodkorb <wbx@openadk.org> | 2014-03-30 15:55:20 +0200 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2014-03-30 15:55:20 +0200 |
commit | 8aed1fcd443b550c15a21ddbf1b1d3899803120a (patch) | |
tree | ce7c0a22c1d5ed7d437198b4447a3aa2fd578665 /tools/adk | |
parent | 12c9d74bb923174117e28186e4a7698e623803a2 (diff) |
rework hosttools building, add tools into package stuff
Diffstat (limited to 'tools/adk')
-rw-r--r-- | tools/adk/Makefile | 17 | ||||
-rw-r--r-- | tools/adk/depmaker.c | 313 | ||||
-rw-r--r-- | tools/adk/dkgetsz.c | 95 | ||||
-rw-r--r-- | tools/adk/pkgmaker.c | 1194 | ||||
-rw-r--r-- | tools/adk/pkgrebuild.c | 273 | ||||
-rw-r--r-- | tools/adk/sortfile.c | 153 | ||||
-rw-r--r-- | tools/adk/sortfile.h | 1 | ||||
-rw-r--r-- | tools/adk/strmap.c | 510 | ||||
-rw-r--r-- | tools/adk/strmap.h | 350 |
9 files changed, 0 insertions, 2906 deletions
diff --git a/tools/adk/Makefile b/tools/adk/Makefile deleted file mode 100644 index edd559f85..000000000 --- a/tools/adk/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# This file is part of the OpenADK project. OpenADK is copyrighted -# material, please see the LICENCE file in the top-level directory. - -include $(TOPDIR)/rules.mk - -install: ${STAGING_HOST_DIR}/usr/bin/depmaker ${STAGING_HOST_DIR}/usr/bin/pkgrebuild ${STAGING_HOST_DIR}/usr/bin/dkgetsz - -${STAGING_HOST_DIR}/usr/bin/depmaker: depmaker.c - ${CC_FOR_BUILD} ${FLAGS_FOR_BUILD} -o $@ depmaker.c - -${STAGING_HOST_DIR}/usr/bin/pkgrebuild: pkgrebuild.c strmap.c - ${CC_FOR_BUILD} ${FLAGS_FOR_BUILD} -o $@ pkgrebuild.c strmap.c - -${STAGING_HOST_DIR}/usr/bin/dkgetsz: dkgetsz.c - ${CC_FOR_BUILD} ${FLAGS_FOR_BUILD} -o $@ dkgetsz.c - -include $(TOPDIR)/mk/tools.mk diff --git a/tools/adk/depmaker.c b/tools/adk/depmaker.c deleted file mode 100644 index 023e58504..000000000 --- a/tools/adk/depmaker.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * depmaker - create package/Depends.mk for OpenADK buildsystem - * - * Copyright (C) 2010-2014 Waldemar Brodkorb <wbx@openadk.org> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <ctype.h> -#include <dirent.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <sys/types.h> - -#define MAXLINE 1024 -#define MAXPATH 128 - -static int prefix = 0; -static int hprefix = 0; - -static int check_symbol(char *symbol) { - - FILE *config; - char buf[MAXLINE]; - char *sym; - int ret; - - if ((sym = malloc(strlen(symbol) + 2)) != NULL) - memset(sym, 0, strlen(symbol) + 2); - else { - perror("Can not allocate memory."); - exit(EXIT_FAILURE); - } - - strncat(sym, symbol, strlen(symbol)); - strncat(sym, "=", 1); - if ((config = fopen(".config", "r")) == NULL) { - perror("Can not open file \".config\"."); - exit(EXIT_FAILURE); - } - - ret = 1; - while (fgets(buf, MAXLINE, config) != NULL) { - if (strncmp(buf, sym, strlen(sym)) == 0) - ret = 0; - } - - free(sym); - if (fclose(config) != 0) - perror("Closing file stream failed"); - - return(ret); -} - -/*@null@*/ -static char *parse_line(char *package, char *pkgvar, char *string, int checksym, int pprefix, int system, int *prefixp) { - - char *key, *value, *dep, *key_sym, *pkgdeps; - char temp[MAXLINE]; - - string[strlen(string)-1] = '\0'; - if ((key = strtok(string, ":=")) == NULL) { - perror("Can not get key from string."); - exit(EXIT_FAILURE); - } - - if (checksym == 1) { - /* extract symbol */ - if ((key_sym = malloc(MAXLINE)) != NULL) - memset(key_sym, 0, MAXLINE); - else { - perror("Can not allocate memory."); - exit(EXIT_FAILURE); - } - if (system == 0) { - if (pprefix == 0) { - if (snprintf(key_sym, MAXLINE, "ADK_PACKAGE_%s_", pkgvar) < 0) - perror("Can not create string variable."); - } else { - if (snprintf(key_sym, MAXLINE, "ADK_PACKAGE_") < 0) - perror("Can not create string variable."); - } - strncat(key_sym, key+6, strlen(key)-6); - } else { - if (snprintf(key_sym, MAXLINE, "ADK_TARGET_SYSTEM_%s", pkgvar) < 0) - perror("Can not create string variable."); - } - - if (check_symbol(key_sym) != 0) { - free(key_sym); - return(NULL); - } - free(key_sym); - } - - if ((pkgdeps = malloc(MAXLINE)) != NULL) - memset(pkgdeps, 0, MAXLINE); - else { - perror("Can not allocate memory."); - exit(EXIT_FAILURE); - } - - value = strtok(NULL, "=\t"); - dep = strtok(value, " "); - while (dep != NULL) { - if (*prefixp == 0) { - *prefixp = 1; - if (snprintf(temp, MAXLINE, "%s-compile: %s-compile", package, dep) < 0) - perror("Can not create string variable."); - } else { - if (snprintf(temp, MAXLINE, " %s-compile", dep) < 0) - perror("Can not create string variable."); - } - strncat(pkgdeps, temp, strlen(temp)); - dep = strtok(NULL, " "); - } - return(pkgdeps); -} - -int main() { - - DIR *pkgdir; - struct dirent *pkgdirp; - FILE *pkg; - char buf[MAXLINE]; - char path[MAXPATH]; - char *string, *pkgvar, *pkgdeps, *hpkgdeps = NULL, *tmp, *fpkg, *cpkg, *spkg, *key, *check, *dpkg; - char *stringtmp; - int i; - - spkg = NULL; - cpkg = NULL; - fpkg = NULL; - - /* read Makefile's for all packages */ - pkgdir = opendir("package"); - while ((pkgdirp = readdir(pkgdir)) != NULL) { - /* skip dotfiles */ - if (strncmp(pkgdirp->d_name, ".", 1) > 0) { - if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0) - perror("Can not create string variable."); - pkg = fopen(path, "r"); - if (pkg == NULL) - continue; - - /* transform to uppercase variable name */ - pkgvar = strdup(pkgdirp->d_name); - for (i=0; i<(int)strlen(pkgvar); i++) { - if (pkgvar[i] == '+') - pkgvar[i] = 'X'; - if (pkgvar[i] == '-') - pkgvar[i] = '_'; - pkgvar[i] = toupper(pkgvar[i]); - } - - /* exclude manual maintained packages from package/Makefile */ - if ( - !(strncmp(pkgdirp->d_name, "libpthread", 10) == 0 && strlen(pkgdirp->d_name) == 10) && - !(strncmp(pkgdirp->d_name, "uclibc++", 8) == 0) && - !(strncmp(pkgdirp->d_name, "uclibc", 6) == 0) && - !(strncmp(pkgdirp->d_name, "musl", 4) == 0) && - !(strncmp(pkgdirp->d_name, "glibc", 5) == 0)) { - /* print result to stdout */ - printf("package-$(ADK_COMPILE_%s) += %s\n", pkgvar, pkgdirp->d_name); - } - - if ((pkgdeps = malloc(MAXLINE)) != NULL) - memset(pkgdeps, 0, MAXLINE); - else { - perror("Can not allocate memory."); - exit(EXIT_FAILURE); - } - prefix = 0; - hprefix = 0; - - /* generate build dependencies */ - while (fgets(buf, MAXLINE, pkg) != NULL) { - if ((tmp = malloc(MAXLINE)) != NULL) - memset(tmp, 0 , MAXLINE); - else { - perror("Can not allocate memory."); - exit(EXIT_FAILURE); - } - - /* just read variables prefixed with PKG */ - if (strncmp(buf, "PKG", 3) == 0) { - - string = strstr(buf, "PKG_BUILDDEP:="); - if (string != NULL) { - tmp = parse_line(pkgdirp->d_name, pkgvar, string, 0, 0, 0, &prefix); - if (tmp != NULL) { - strncat(pkgdeps, tmp, strlen(tmp)); - } - } - - string = strstr(buf, "PKG_BUILDDEP+="); - if (string != NULL) { - tmp = parse_line(pkgdirp->d_name, pkgvar, string, 0, 0, 0, &prefix); - if (tmp != NULL) - strncat(pkgdeps, tmp, strlen(tmp)); - } - - // We need to find the system name here - string = strstr(buf, "PKG_BUILDDEP_"); - if (string != NULL) { - check = strstr(buf, ":="); - if (check != NULL) { - stringtmp = strdup(string); - string[strlen(string)-1] = '\0'; - key = strtok(string, ":="); - dpkg = strdup(key+13); - tmp = parse_line(pkgdirp->d_name, dpkg, stringtmp, 1, 0, 1, &prefix); - if (tmp != NULL) - strncat(pkgdeps, tmp, strlen(tmp)); - } - } - - // We need to find the subpackage name here - string = strstr(buf, "PKG_FLAVOURS_"); - if (string != NULL) { - check = strstr(buf, ":="); - if (check != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, ":="); - fpkg = strdup(key+13); - } - } - - string = strstr(buf, "PKGFB_"); - if (string != NULL) { - tmp = parse_line(pkgdirp->d_name, fpkg, string, 1, 0, 0, &prefix); - if (tmp != NULL) - strncat(pkgdeps, tmp, strlen(tmp)); - } - - // We need to find the subpackage name here - string = strstr(buf, "PKG_CHOICES_"); - if (string != NULL) { - check = strstr(buf, ":="); - if (check != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, ":="); - cpkg = strdup(key+12); - } - } - string = strstr(buf, "PKGCB_"); - if (string != NULL) { - tmp = parse_line(pkgdirp->d_name, cpkg, string, 1, 0, 0, &prefix); - if (tmp != NULL) - strncat(pkgdeps, tmp, strlen(tmp)); - } - - // We need to find the subpackage name here - string = strstr(buf, "PKG_SUBPKGS_"); - if (string != NULL) { - check = strstr(buf, ":="); - if (check != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, ":="); - spkg = strdup(key+12); - } - } - - string = strstr(buf, "PKGSB_"); - if (string != NULL) { - tmp = parse_line(pkgdirp->d_name, spkg, string, 1, 1, 0, &prefix); - if (tmp != NULL) { - strncat(pkgdeps, tmp, strlen(tmp)); - } - } - } else if (strncmp(buf, "HOST_BUILDDEP", 13) == 0) { - asprintf(&string, "%s-host", pkgdirp->d_name); - // check retval; string for NULL - tmp = parse_line(string, NULL, buf, 0, 0, 0, &hprefix); - if (tmp && *tmp) { - asprintf(&string, "%s%s", - hpkgdeps ? hpkgdeps : "", - tmp); - free(hpkgdeps); - hpkgdeps = string; - } - } - free(tmp); - } - if (strlen(pkgdeps) != 0) - printf("%s\n", pkgdeps); - if (hpkgdeps && *hpkgdeps) - printf("%s\n", hpkgdeps); - free(hpkgdeps); - hpkgdeps = NULL; - free(pkgdeps); - free(pkgvar); - if (fclose(pkg) != 0) - perror("Closing file stream failed"); - } - } - if (closedir(pkgdir) != 0) - perror("Closing directory stream failed"); - - return(0); -} diff --git a/tools/adk/dkgetsz.c b/tools/adk/dkgetsz.c deleted file mode 100644 index b8315be70..000000000 --- a/tools/adk/dkgetsz.c +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * Copyright © 2010 - * Waldemar Brodkorb <wbx@openadk.org> - * Thorsten Glaser <tg@mirbsd.org> - * - * Provided that these terms and disclaimer and all copyright notices - * are retained or reproduced in an accompanying document, permission - * is granted to deal in this work without restriction, including un‐ - * limited rights to use, publicly perform, distribute, sell, modify, - * merge, give away, or sublicence. - * - * This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to - * the utmost extent permitted by applicable law, neither express nor - * implied; without malicious intent or gross negligence. In no event - * may a licensor, author or contributor be held liable for indirect, - * direct, other damage, loss, or other issues arising in any way out - * of dealing in the work, even if advised of the possibility of such - * damage or existence of a defect, except proven that it results out - * of said person’s immediate fault when using the work as intended. - * - * Alternatively, this work may be distributed under the terms of the - * General Public License, any version, as published by the Free Soft- - * ware Foundation. - *- - * Display the size of a block device (e.g. USB stick, CF/SF/MMC card - * or hard disc) in 512-byte sectors. - */ - -#define _FILE_OFFSET_BITS 64 - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/mount.h> - -#if defined(__APPLE__) -#include <sys/disk.h> -#endif - -#if defined(DIOCGDINFO) -#include <sys/disklabel.h> -#endif - -#include <err.h> -#include <fcntl.h> -#include <stdio.h> -#include <unistd.h> - -unsigned long long numsecs(int); - -int -main(int argc, char *argv[]) { - int fd; - - if (argc != 2) - errx(255, "Syntax: dkgetsz /dev/sda"); - - if ((fd = open(argv[1], O_RDONLY)) == -1) - err(1, "open"); - printf("%llu\n", numsecs(fd)); - close(fd); - return (0); -} - -unsigned long long -numsecs(int fd) -{ -#if defined(BLKGETSIZE) || defined(DKIOCGETBLOCKCOUNT) -/* - * note: BLKGETSIZE64 returns bytes, not sectors, but the return - * type is size_t which is 32 bits on an ILP32 platform, so it - * fails interestingly here… thus we use BLKGETSIZE instead. - */ -#if defined(DKIOCGETBLOCKCOUNT) - uint64_t nsecs; -#define THEIOCTL DKIOCGETBLOCKCOUNT -#define STRIOCTL "DKIOCGETBLOCKCOUNT" -#else - unsigned long nsecs; -#define THEIOCTL BLKGETSIZE -#define STRIOCTL "BLKGETSIZE" -#endif - if (ioctl(fd, THEIOCTL, &nsecs) == -1) - err(1, "ioctl %s", STRIOCTL); - return ((unsigned long long)nsecs); -#elif defined(DIOCGDINFO) - struct disklabel dl; - - if (ioctl(fd, DIOCGDINFO, &dl) == -1) - err(1, "ioctl DIOCGDINFO"); - return ((unsigned long long)dl.d_secperunit); -#else -#warning PLEASE DO IMPLEMENT numsecs FOR THIS PLATFORM. -#endif -} diff --git a/tools/adk/pkgmaker.c b/tools/adk/pkgmaker.c deleted file mode 100644 index 51d31aa70..000000000 --- a/tools/adk/pkgmaker.c +++ /dev/null @@ -1,1194 +0,0 @@ -/* - * pkgmaker - create package meta-data for OpenADK buildsystem - * - * Copyright (C) 2010-2014 Waldemar Brodkorb <wbx@openadk.org> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <ctype.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> -#include "sortfile.h" -#include "strmap.h" - -#define MAXLINE 4096 -#define MAXVALUE 168 -#define MAXVAR 64 -#define MAXPATH 320 -#define HASHSZ 96 - -static int nobinpkgs; - -#define fatal_error(...) { \ - fprintf(stderr, "Fatal error. "); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n"); \ - exit(1); \ -} - -static int parse_var_hash(char *buf, const char *varname, StrMap *strmap) { - - char *key, *value, *string; - - string = strstr(buf, varname); - if (string != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, ":="); - value = strtok(NULL, "=\t"); - if (value != NULL) - strmap_put(strmap, key, value); - return(0); - } - return(1); -} - -static int parse_var(char *buf, const char *varname, char *pvalue, char **result) { - - char *pkg_var; - char *key, *value, *string; - char pkg_str[MAXVAR]; - - if ((pkg_var = malloc(MAXLINE)) != NULL) - memset(pkg_var, 0, MAXLINE); - else { - perror("Can not allocate memory"); - exit(EXIT_FAILURE); - } - - if (snprintf(pkg_str, MAXVAR, "%s:=", varname) < 0) - perror("can not create path variable."); - string = strstr(buf, pkg_str); - if (string != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, ":="); - value = strtok(NULL, "=\t"); - if (value != NULL) { - strncat(pkg_var, value, strlen(value)); - *result = strdup(pkg_var); - } else { - nobinpkgs = 1; - *result = NULL; - } - free(pkg_var); - return(0); - } else { - if (snprintf(pkg_str, MAXVAR, "%s+=", varname) < 0) - perror("can not create path variable."); - string = strstr(buf, pkg_str); - if (string != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, "+="); - value = strtok(NULL, "=\t"); - if (pvalue != NULL) - strncat(pkg_var, pvalue, strlen(pvalue)); - strncat(pkg_var, " ", 1); - if (value != NULL) - strncat(pkg_var, value, strlen(value)); - *result = strdup(pkg_var); - free(pkg_var); - return(0); - } - } - free(pkg_var); - return(1); -} - -static int parse_var_with_system(char *buf, const char *varname, char *pvalue, char **result, char **sysname, int varlen) { - - char *pkg_var, *check; - char *key, *value, *string; - - if ((pkg_var = malloc(MAXLINE)) != NULL) - memset(pkg_var, 0, MAXLINE); - else { - perror("Can not allocate memory"); - exit(EXIT_FAILURE); - } - - check = strstr(buf, ":="); - if (check != NULL) { - string = strstr(buf, varname); - if (string != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, ":="); - *sysname = strdup(key+varlen); - value = strtok(NULL, "=\t"); - if (value != NULL) { - strncat(pkg_var, value, strlen(value)); - *result = strdup(pkg_var); - } - free(pkg_var); - return(0); - } - } else { - string = strstr(buf, varname); - if (string != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, "+="); - value = strtok(NULL, "=\t"); - if (pvalue != NULL) - strncat(pkg_var, pvalue, strlen(pvalue)); - strncat(pkg_var, " ", 1); - if (value != NULL) - strncat(pkg_var, value, strlen(value)); - *result = strdup(pkg_var); - free(pkg_var); - return(0); - } - } - free(pkg_var); - return(1); -} - -static int parse_var_with_pkg(char *buf, const char *varname, char *pvalue, char **result, char **pkgname, int varlen) { - - char *pkg_var, *check; - char *key, *value, *string; - - if ((pkg_var = malloc(MAXLINE)) != NULL) - memset(pkg_var, 0, MAXLINE); - else { - perror("Can not allocate memory"); - exit(EXIT_FAILURE); - } - - check = strstr(buf, ":="); - if (check != NULL) { - string = strstr(buf, varname); - if (string != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, ":="); - *pkgname = strdup(key+varlen); - value = strtok(NULL, "=\t"); - if (value != NULL) { - strncat(pkg_var, value, strlen(value)); - *result = strdup(pkg_var); - } - free(pkg_var); - return(0); - } - } else { - string = strstr(buf, varname); - if (string != NULL) { - string[strlen(string)-1] = '\0'; - key = strtok(string, "+="); - value = strtok(NULL, "=\t"); - if (pvalue != NULL) - strncat(pkg_var, pvalue, strlen(pvalue)); - strncat(pkg_var, " ", 1); - if (value != NULL) - strncat(pkg_var, value, strlen(value)); - *result = strdup(pkg_var); - free(pkg_var); - return(0); - } - } - free(pkg_var); - return(1); -} - -#if 0 -static void iter_debug(const char *key, const char *value, const void *obj) { - fprintf(stderr, "HASHMAP key: %s value: %s\n", key, value); -} -#endif - -static int hash_str(char *string) { - - int i; - int hash; - - hash = 0; - for (i=0; i<(int)strlen(string); i++) { - hash += string[i]; - } - return(hash); -} - -static void iter(const char *key, const char *value, const void *obj) { - - FILE *config, *section; - int hash; - char *valuestr, *pkg, *subpkg; - char buf[MAXPATH]; - char infile[MAXPATH]; - char outfile[MAXPATH]; - - valuestr = strdup(value); - config = fopen("package/Config.in.auto", "a"); - if (config == NULL) - fatal_error("Can not open file package/Config.in.auto"); - - hash = hash_str(valuestr); - snprintf(infile, MAXPATH, "package/pkglist.d/sectionlst.%d", hash); - snprintf(outfile, MAXPATH, "package/pkglist.d/sectionlst.%d.sorted", hash); - - if (access(infile, F_OK) == 0) { - valuestr[strlen(valuestr)-1] = '\0'; - fprintf(config, "menu \"%s\"\n", valuestr); - sortfile(infile, outfile); - /* avoid duplicate section entries */ - unlink(infile); - section = fopen(outfile, "r"); - while (fgets(buf, MAXPATH, section) != NULL) { - buf[strlen(buf)-1] = '\0'; - if (buf[strlen(buf)-1] == '@') { - buf[strlen(buf)-1] = '\0'; - fprintf(config, "source \"package/%s/Config.in.manual\"\n", buf); - } else { - subpkg = strtok(buf, "|"); - subpkg[strlen(subpkg)-1] = '\0'; - pkg = strtok(NULL, "|"); - fprintf(config, "source \"package/pkgconfigs.d/%s/Config.in.%s\"\n", pkg, subpkg); - } - } - fprintf(config, "endmenu\n\n"); - fclose(section); - } - fclose(config); -} - -static char *tolowerstr(char *string) { - - int i; - char *str; - - /* transform to lowercase variable name */ - str = strdup(string); - for (i=0; i<(int)strlen(str); i++) { - if (str[i] == '_') - str[i] = '-'; - str[i] = tolower(str[i]); - } - return(str); -} - -static char *toupperstr(char *string) { - - int i; - char *str; - - /* transform to uppercase variable name */ - str = strdup(string); - for (i=0; i<(int)strlen(str); i++) { - if (str[i] == '+') - str[i] = 'X'; - if (str[i] == '-') - str[i] = '_'; - /* remove negation here, useful for package host depends */ - if (str[i] == '!') - str[i] = '_'; - str[i] = toupper(str[i]); - } - return(str); -} - - -int main() { - - DIR *pkgdir, *pkglistdir; - struct dirent *pkgdirp; - FILE *pkg, *cfg, *menuglobal, *section; - char hvalue[MAXVALUE]; - char buf[MAXPATH]; - char tbuf[MAXPATH]; - char path[MAXPATH]; - char spath[MAXPATH]; - char dir[MAXPATH]; - char variable[2*MAXVAR]; - char *key, *value, *token, *cftoken, *sp, *hkey, *val, *pkg_fd; - char *pkg_name, *pkg_depends, *pkg_depends_system, *pkg_section, *pkg_descr, *pkg_url; - char *pkg_cxx, *pkg_subpkgs, *pkg_cfline, *pkg_dflt, *pkg_multi; - char *pkg_need_cxx, *pkg_need_java, *pkgname, *sysname, *pkg_debug; - char *pkg_libc_depends, *pkg_host_depends, *pkg_system_depends, *pkg_arch_depends, *pkg_flavours, *pkg_flavours_string, *pkg_choices, *pseudo_name; - char *packages, *pkg_name_u, *pkgs, *pkg_opts, *pkg_libname; - char *saveptr, *p_ptr, *s_ptr, *pkg_helper; - int result; - StrMap *pkgmap, *sectionmap; - - pkg_name = NULL; - pkg_descr = NULL; - pkg_section = NULL; - pkg_url = NULL; - pkg_depends = NULL; - pkg_depends_system = NULL; - pkg_opts = NULL; - pkg_libname = NULL; - pkg_flavours = NULL; - pkg_flavours_string = NULL; - pkg_choices = NULL; - pkg_subpkgs = NULL; - pkg_arch_depends = NULL; - pkg_system_depends = NULL; - pkg_host_depends = NULL; - pkg_libc_depends = NULL; - pkg_cxx = NULL; - pkg_dflt = NULL; - pkg_cfline = NULL; - pkg_multi = NULL; - pkg_need_cxx = NULL; - pkg_need_java = NULL; - pkgname = NULL; - sysname = NULL; - pkg_helper = NULL; - pkg_debug = NULL; - - p_ptr = NULL; - s_ptr = NULL; - - unlink("package/Config.in.auto"); - /* open global sectionfile */ - menuglobal = fopen("package/Config.in.auto.global", "w"); - if (menuglobal == NULL) - fatal_error("global section file not writable."); - - /* read section list and create a hash table */ - section = fopen("package/section.lst", "r"); - if (section == NULL) - fatal_error("section listfile is missing"); - - sectionmap = strmap_new(HASHSZ); - while (fgets(tbuf, MAXPATH, section) != NULL) { - key = strtok(tbuf, "\t"); - value = strtok(NULL, "\t"); - strmap_put(sectionmap, key, value); - } - fclose(section); - - if (mkdir("package/pkgconfigs.d", S_IRWXU) > 0) - fatal_error("creation of package/pkgconfigs.d failed."); - if (mkdir("package/pkgconfigs.d/gcc", S_IRWXU) > 0) - fatal_error("creation of package/pkgconfigs.d/gcc failed."); - if (mkdir("package/pkglist.d", S_IRWXU) > 0) - fatal_error("creation of package/pkglist.d failed."); - - /* delete Config.in.dev */ - if (snprintf(path, MAXPATH, "package/pkgconfigs.d/gcc/Config.in.dev") < 0) - fatal_error("failed to create path variable."); - unlink(path); - cfg = fopen(path, "w"); - if (cfg == NULL) - fatal_error("Config.in.dev can not be opened"); - fprintf(cfg, "config ADK_PACKAGE_GLIBC_DEV\n"); - fprintf(cfg, "\tprompt \"glibc-dev............ development files for glibc\"\n"); - fprintf(cfg, "\ttristate\n"); - fprintf(cfg, "\tdefault n\n"); - fprintf(cfg, "\tdepends on ADK_TARGET_LIB_GLIBC\n"); - fprintf(cfg, "\thelp\n"); - fprintf(cfg, "\t GNU C library header files.\n\n"); - fprintf(cfg, "config ADK_PACKAGE_UCLIBC_DEV\n"); - fprintf(cfg, "\tprompt \"uclibc-dev........... development files for uclibc\"\n"); - fprintf(cfg, "\ttristate\n"); - fprintf(cfg, "\tdefault n\n"); - fprintf(cfg, "\tdepends on ADK_TARGET_LIB_UCLIBC\n"); - fprintf(cfg, "\thelp\n"); - fprintf(cfg, "\t C library header files.\n\n"); - fprintf(cfg, "config ADK_PACKAGE_MUSL_DEV\n"); - fprintf(cfg, "\tprompt \"musl-dev............. development files for musl\"\n"); - fprintf(cfg, "\ttristate\n"); - fprintf(cfg, "\tdefault n\n"); - fprintf(cfg, "\tdepends on ADK_TARGET_LIB_MUSL\n"); - fprintf(cfg, "\thelp\n"); - fprintf(cfg, "\t C library header files.\n\n"); - fclose(cfg); - - /* read Makefile's for all packages */ - pkgdir = opendir("package"); - while ((pkgdirp = readdir(pkgdir)) != NULL) { - /* skip dotfiles */ - if (strncmp(pkgdirp->d_name, ".", 1) > 0) { - if (snprintf(path, MAXPATH, "package/%s/Makefile", pkgdirp->d_name) < 0) - fatal_error("can not create path variable."); - pkg = fopen(path, "r"); - if (pkg == NULL) - continue; - - /* skip manually maintained packages */ - if (snprintf(path, MAXPATH, "package/%s/Config.in.manual", pkgdirp->d_name) < 0) - fatal_error("can not create path variable."); - if (!access(path, F_OK)) { - while (fgets(buf, MAXPATH, pkg) != NULL) { - if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0) - continue; - } - - memset(hvalue, 0 , MAXVALUE); - result = strmap_get(sectionmap, pkg_section, hvalue, sizeof(hvalue)); - if (result == 1) { - if (snprintf(spath, MAXPATH, "package/pkglist.d/sectionlst.%d", hash_str(hvalue)) < 0) - fatal_error("can not create path variable."); - section = fopen(spath, "a"); - if (section != NULL) { - fprintf(section, "%s@\n", pkgdirp->d_name); - fclose(section); - } - } else - fatal_error("Can not find section description for package %s.", - pkgdirp->d_name); - - fclose(pkg); - continue; - } - - nobinpkgs = 0; - - /* create output directories */ - if (snprintf(dir, MAXPATH, "package/pkgconfigs.d/%s", pkgdirp->d_name) < 0) - fatal_error("can not create dir variable."); - if (mkdir(dir, S_IRWXU) > 0) - fatal_error("can not create directory."); - - - /* allocate memory */ - hkey = malloc(MAXVAR); - memset(hkey, 0, MAXVAR); - memset(variable, 0, 2*MAXVAR); - - pkgmap = strmap_new(HASHSZ); - - /* parse package Makefile */ - while (fgets(buf, MAXPATH, pkg) != NULL) { - /* just read variables prefixed with PKG */ - if (strncmp(buf, "PKG", 3) == 0) { - if ((parse_var(buf, "PKG_NAME", NULL, &pkg_name)) == 0) - continue; - if (pkg_name != NULL) - pkg_name_u = toupperstr(pkg_name); - else - pkg_name_u = toupperstr(pkgdirp->d_name); - - snprintf(variable, MAXVAR, "PKG_CFLINE_%s", pkg_name_u); - if ((parse_var(buf, variable, pkg_cfline, &pkg_cfline)) == 0) - continue; - snprintf(variable, MAXVAR, "PKG_DFLT_%s", pkg_name_u); - if ((parse_var(buf, variable, NULL, &pkg_dflt)) == 0) - continue; - if ((parse_var(buf, "PKG_LIBC_DEPENDS", NULL, &pkg_libc_depends)) == 0) - continue; - if ((parse_var(buf, "PKG_HOST_DEPENDS", NULL, &pkg_host_depends)) == 0) - continue; - if ((parse_var(buf, "PKG_ARCH_DEPENDS", NULL, &pkg_arch_depends)) == 0) - continue; - if ((parse_var(buf, "PKG_SYSTEM_DEPENDS", NULL, &pkg_system_depends)) == 0) - continue; - if ((parse_var(buf, "PKG_DESCR", NULL, &pkg_descr)) == 0) - continue; - if ((parse_var(buf, "PKG_SECTION", NULL, &pkg_section)) == 0) - continue; - if ((parse_var(buf, "PKG_URL", NULL, &pkg_url)) == 0) - continue; - if ((parse_var(buf, "PKG_CXX", NULL, &pkg_cxx)) == 0) - continue; - if ((parse_var(buf, "PKG_NEED_CXX", NULL, &pkg_need_cxx)) == 0) - continue; - if ((parse_var(buf, "PKG_NEED_JAVA", NULL, &pkg_need_java)) == 0) - continue; - if ((parse_var(buf, "PKG_MULTI", NULL, &pkg_multi)) == 0) - continue; - if ((parse_var(buf, "PKG_DEPENDS", pkg_depends, &pkg_depends)) == 0) - continue; - if ((parse_var_with_system(buf, "PKG_DEPENDS_", pkg_depends_system, &pkg_depends_system, &sysname, 12)) == 0) - continue; - if ((parse_var(buf, "PKG_LIBNAME", pkg_libname, &pkg_libname)) == 0) - continue; - if ((parse_var(buf, "PKG_OPTS", pkg_opts, &pkg_opts)) == 0) - continue; - if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_STRING_", pkg_flavours_string, &pkg_flavours_string, &pkgname, 20)) == 0) - continue; - if ((parse_var_with_pkg(buf, "PKG_FLAVOURS_", pkg_flavours, &pkg_flavours, &pkgname, 13)) == 0) - continue; - if ((parse_var_hash(buf, "PKGFD_", pkgmap)) == 0) - continue; - if ((parse_var_hash(buf, "PKGFX_", pkgmap)) == 0) - continue; - if ((parse_var_hash(buf, "PKGFS_", pkgmap)) == 0) - continue; - if ((parse_var_hash(buf, "PKGFC_", pkgmap)) == 0) - continue; - if ((parse_var_with_pkg(buf, "PKG_CHOICES_", pkg_choices, &pkg_choices, &pkgname, 12)) == 0) - continue; - if ((parse_var_hash(buf, "PKGCD_", pkgmap)) == 0) - continue; - if ((parse_var_hash(buf, "PKGCS_", pkgmap)) == 0) - continue; - if ((parse_var(buf, "PKG_SUBPKGS", pkg_subpkgs, &pkg_subpkgs)) == 0) - continue; - if ((parse_var_hash(buf, "PKGSD_", pkgmap)) == 0) - continue; - if ((parse_var_hash(buf, "PKGSS_", pkgmap)) == 0) - continue; - if ((parse_var_hash(buf, "PKGSC_", pkgmap)) == 0) - continue; - } - } - - /* when PKG_LIBNAME exist use this instead of PKG_NAME, but only for !libmix */ - if (pkg_libname != NULL) - if (pkg_opts != NULL) - if (strstr(pkg_opts, "libmix") == NULL) - pkg_name = strdup(pkg_libname); - - /* end of package Makefile parsing */ - if (fclose(pkg) != 0) - perror("Failed to close file stream for Makefile"); - -#if 0 - if (pkg_name != NULL) - fprintf(stderr, "Package name is %s\n", pkg_name); - if (pkg_libname != NULL) - fprintf(stderr, "Package library name is %s\n", pkg_libname); - if (pkg_section != NULL) - fprintf(stderr, "Package section is %s\n", pkg_section); - if (pkg_descr != NULL) - fprintf(stderr, "Package description is %s\n", pkg_descr); - if (pkg_depends != NULL) - fprintf(stderr, "Package dependencies are %s\n", pkg_depends); - if (pkg_depends_system != NULL) - fprintf(stderr, "Package systemspecific dependencies are %s\n", pkg_depends_system); - if (pkg_subpkgs != NULL) - fprintf(stderr, "Package subpackages are %s\n", pkg_subpkgs); - if (pkg_flavours != NULL && pkgname != NULL) - fprintf(stderr, "Package flavours for %s are %s\n", pkgname, pkg_flavours); - if (pkg_flavours_string != NULL && pkgname != NULL) - fprintf(stderr, "Package string flavours for %s are %s\n", pkgname, pkg_flavours_string); - if (pkg_choices != NULL && pkgname != NULL) - fprintf(stderr, "Package choices for %s are %s\n", pkgname, pkg_choices); - if (pkg_url != NULL) - fprintf(stderr, "Package homepage is %s\n", pkg_url); - if (pkg_cfline != NULL) - fprintf(stderr, "Package cfline is %s\n", pkg_cfline); - if (pkg_multi != NULL) - fprintf(stderr, "Package multi is %s\n", pkg_multi); - if (pkg_opts != NULL) - fprintf(stderr, "Package options are %s\n", pkg_opts); - - strmap_enum(pkgmap, iter_debug, NULL); -#endif - - /* generate master source Config.in file */ - if (snprintf(path, MAXPATH, "package/pkgconfigs.d/%s/Config.in", pkgdirp->d_name) < 0) - fatal_error("path variable creation failed."); - fprintf(menuglobal, "source \"%s\"\n", path); - /* recreating file is faster than truncating with w+ */ - unlink(path); - cfg = fopen(path, "w"); - if (cfg == NULL) - continue; - - pkgs = NULL; - if (pkg_subpkgs != NULL) - pkgs = strdup(pkg_subpkgs); - - fprintf(cfg, "config ADK_COMPILE_%s\n", toupperstr(pkgdirp->d_name)); - fprintf(cfg, "\ttristate\n"); - if (nobinpkgs == 0) { - fprintf(cfg, "\tdepends on "); - if (pkgs != NULL) { - if (pkg_multi != NULL) - if (strncmp(pkg_multi, "1", 1) == 0) - fprintf(cfg, "ADK_HAVE_DOT_CONFIG || "); - token = strtok(pkgs, " "); - fprintf(cfg, "ADK_PACKAGE_%s", token); - token = strtok(NULL, " "); - while (token != NULL) { |