[BACK]Return to perform.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / pkgtools / pkg_install / files / create

Annotation of pkgsrc/pkgtools/pkg_install/files/create/perform.c, Revision 1.21

1.20      joerg       1: /*     $NetBSD: perform.c,v 1.19 2008/04/18 17:16:44 joerg Exp $       */
1.1       schmonz     2:
1.4       jlam        3: #if HAVE_CONFIG_H
                      4: #include "config.h"
                      5: #endif
1.5       jlam        6: #include <nbcompat.h>
1.4       jlam        7: #if HAVE_SYS_CDEFS_H
1.1       schmonz     8: #include <sys/cdefs.h>
1.4       jlam        9: #endif
1.1       schmonz    10: #ifndef lint
                     11: #if 0
                     12: static const char *rcsid = "from FreeBSD Id: perform.c,v 1.38 1997/10/13 15:03:51 jkh Exp";
                     13: #else
1.20      joerg      14: __RCSID("$NetBSD: perform.c,v 1.19 2008/04/18 17:16:44 joerg Exp $");
1.1       schmonz    15: #endif
                     16: #endif
                     17:
                     18: /*
                     19:  * FreeBSD install - a package for the installation and maintainance
                     20:  * of non-core utilities.
                     21:  *
                     22:  * Redistribution and use in source and binary forms, with or without
                     23:  * modification, are permitted provided that the following conditions
                     24:  * are met:
                     25:  * 1. Redistributions of source code must retain the above copyright
                     26:  *    notice, this list of conditions and the following disclaimer.
                     27:  * 2. Redistributions in binary form must reproduce the above copyright
                     28:  *    notice, this list of conditions and the following disclaimer in the
                     29:  *    documentation and/or other materials provided with the distribution.
                     30:  *
                     31:  * Jordan K. Hubbard
                     32:  * 18 July 1993
                     33:  *
                     34:  * This is the main body of the create module.
                     35:  *
                     36:  */
                     37:
                     38: #include "lib.h"
                     39: #include "create.h"
                     40:
1.4       jlam       41: #if HAVE_ERR_H
1.1       schmonz    42: #include <err.h>
                     43: #endif
1.4       jlam       44: #if HAVE_UNISTD_H
1.1       schmonz    45: #include <unistd.h>
1.4       jlam       46: #endif
1.1       schmonz    47:
                     48: static void
                     49: sanity_check(void)
                     50: {
1.15      joerg      51:        if (!Comment)
1.1       schmonz    52:                errx(2, "required package comment string is missing (-c comment)");
1.15      joerg      53:        if (!Desc)
1.1       schmonz    54:                errx(2, "required package description string is missing (-d desc)");
1.15      joerg      55:        if (!Contents)
1.1       schmonz    56:                errx(2, "required package contents list is missing (-f [-]file)");
                     57: }
                     58:
1.17      joerg      59: static void
                     60: register_depends(package_t *plist, char *deps, int build_only)
                     61: {
                     62:        char *cp;
                     63:
                     64:        if (Verbose && !PlistOnly) {
                     65:                if (build_only)
                     66:                        printf("Registering build depends:");
                     67:                else
                     68:                        printf("Registering depends:");
                     69:        }
                     70:        while (deps) {
1.18      joerg      71:                cp = strsep(&deps, " \t\n");
1.17      joerg      72:                if (*cp) {
                     73:                        char *best_installed;
                     74:                        best_installed = find_best_matching_installed_pkg(cp);
                     75:                        if (best_installed != NULL) {
                     76:                                add_plist(plist, PLIST_BLDDEP, best_installed);
                     77:                                if (Verbose && !PlistOnly && build_only)
                     78:                                        printf(" %s", cp);
                     79:                        } else
                     80:                                warnx("No matching package installed for %s", cp);
                     81:                        free(best_installed);
                     82:                        if (!build_only) {
                     83:                                add_plist(plist, PLIST_PKGDEP, cp);
                     84:                                if (Verbose && !PlistOnly)
                     85:                                        printf(" %s", cp);
                     86:                        }
                     87:                }
                     88:        }
                     89:        if (Verbose && !PlistOnly)
                     90:                printf(".\n");
                     91: }
                     92:
1.19      joerg      93: /*
                     94:  * Get a string parameter as a file spec or as a "contents follow -" spec
                     95:  */
                     96: static void
                     97: get_dash_string(char **s)
                     98: {
                     99:        if (**s == '-')
                    100:                *s = strdup(*s + 1);
                    101:        else
                    102:                *s = fileGetContents(*s);
                    103: }
                    104:
1.1       schmonz   105: int
1.14      joerg     106: pkg_perform(const char *pkg)
1.1       schmonz   107: {
                    108:        char   *cp;
1.15      joerg     109:        FILE   *pkg_in;
1.1       schmonz   110:        package_t plist;
1.15      joerg     111:        const char *full_pkg, *suffix;
                    112:        char *allocated_pkg;
                    113:        int retval;
                    114:
                    115:        /* Break the package name into base and desired suffix (if any) */
                    116:        if ((cp = strrchr(pkg, '.')) != NULL) {
                    117:                if ((allocated_pkg = malloc(cp - pkg + 1)) == NULL)
                    118:                        err(2, "malloc failed");
                    119:                memcpy(allocated_pkg, pkg, cp - pkg);
                    120:                allocated_pkg[cp - pkg] = '\0';
                    121:                suffix = cp + 1;
                    122:                full_pkg = pkg;
                    123:                pkg = allocated_pkg;
                    124:        } else {
                    125:                allocated_pkg = NULL;
                    126:                full_pkg = pkg;
                    127:                suffix = "tgz";
                    128:        }
1.1       schmonz   129:
                    130:        /* Preliminary setup */
                    131:        sanity_check();
                    132:        if (Verbose && !PlistOnly)
                    133:                printf("Creating package %s\n", pkg);
                    134:        get_dash_string(&Comment);
                    135:        get_dash_string(&Desc);
                    136:        if (IS_STDIN(Contents))
                    137:                pkg_in = stdin;
                    138:        else {
                    139:                pkg_in = fopen(Contents, "r");
1.15      joerg     140:                if (!pkg_in)
1.1       schmonz   141:                        errx(2, "unable to open contents file '%s' for input", Contents);
                    142:        }
                    143:        plist.head = plist.tail = NULL;
                    144:
                    145:        /* If a SrcDir override is set, add it now */
                    146:        if (SrcDir) {
                    147:                if (Verbose && !PlistOnly)
                    148:                        printf("Using SrcDir value of %s\n", (realprefix) ? realprefix : SrcDir);
                    149:                add_plist(&plist, PLIST_SRC, SrcDir);
                    150:        }
                    151:
                    152:        /* Stick the dependencies, if any, at the top */
1.17      joerg     153:        if (Pkgdeps)
                    154:                register_depends(&plist, Pkgdeps, 0);
1.1       schmonz   155:
1.11      joerg     156:        /*
                    157:         * Put the build dependencies after the dependencies.
                    158:         * This works due to the evaluation order in pkg_add.
                    159:         */
1.17      joerg     160:        if (BuildPkgdeps)
                    161:                register_depends(&plist, BuildPkgdeps, 1);
1.11      joerg     162:
1.1       schmonz   163:        /* Put the conflicts directly after the dependencies, if any */
                    164:        if (Pkgcfl) {
                    165:                if (Verbose && !PlistOnly)
                    166:                        printf("Registering conflicts:");
                    167:                while (Pkgcfl) {
                    168:                        cp = strsep(&Pkgcfl, " \t\n");
                    169:                        if (*cp) {
                    170:                                add_plist(&plist, PLIST_PKGCFL, cp);
                    171:                                if (Verbose && !PlistOnly)
                    172:                                        printf(" %s", cp);
                    173:                        }
                    174:                }
                    175:                if (Verbose && !PlistOnly)
                    176:                        printf(".\n");
                    177:        }
                    178:
                    179:        /* Slurp in the packing list */
                    180:        read_plist(&plist, pkg_in);
                    181:
                    182:        if (pkg_in != stdin)
                    183:                fclose(pkg_in);
                    184:
                    185:        /* Prefix should override the packing list */
                    186:        if (Prefix) {
                    187:                delete_plist(&plist, FALSE, PLIST_CWD, NULL);
                    188:                add_plist_top(&plist, PLIST_CWD, Prefix);
                    189:        }
                    190:        /*
                    191:          * Run down the list and see if we've named it, if not stick in a name
                    192:          * at the top.
                    193:          */
                    194:        if (find_plist(&plist, PLIST_NAME) == NULL) {
                    195:                add_plist_top(&plist, PLIST_NAME, basename_of(pkg));
                    196:        }
                    197:
1.15      joerg     198:        /* Make first "real contents" pass over it */
                    199:        check_list(&plist, basename_of(pkg));
                    200:
1.1       schmonz   201:        /*
                    202:          * We're just here for to dump out a revised plist for the FreeBSD ports
                    203:          * hack.  It's not a real create in progress.
                    204:          */
                    205:        if (PlistOnly) {
                    206:                write_plist(&plist, stdout, realprefix);
1.15      joerg     207:                retval = TRUE;
                    208:        } else {
                    209: #ifdef BOOTSTRAP
                    210:                warnx("Package building is not supported in bootstrap mode");
                    211:                retval = FALSE;
                    212: #else
                    213:                retval = pkg_build(pkg, full_pkg, suffix, &plist);
                    214: #endif
1.1       schmonz   215:        }
                    216:
                    217:        /* Cleanup */
                    218:        free(Comment);
                    219:        free(Desc);
                    220:        free_plist(&plist);
1.15      joerg     221:
                    222:        free(allocated_pkg);
                    223:
                    224:        return retval;
1.1       schmonz   225: }

CVSweb <webmaster@jp.NetBSD.org>