Annotation of pkgsrc/pkgtools/pkg_install/files/create/perform.c, Revision 1.17
1.17 ! joerg 1: /* $NetBSD: perform.c,v 1.16 2007/08/03 15:44:18 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.17 ! joerg 14: __RCSID("$NetBSD: perform.c,v 1.16 2007/08/03 15:44:18 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) {
! 71: cp = strsep(&Pkgdeps, " \t\n");
! 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.1 schmonz 93: int
1.14 joerg 94: pkg_perform(const char *pkg)
1.1 schmonz 95: {
96: char *cp;
1.15 joerg 97: FILE *pkg_in;
1.1 schmonz 98: package_t plist;
1.15 joerg 99: const char *full_pkg, *suffix;
100: char *allocated_pkg;
101: int retval;
102:
103: /* Break the package name into base and desired suffix (if any) */
104: if ((cp = strrchr(pkg, '.')) != NULL) {
105: if ((allocated_pkg = malloc(cp - pkg + 1)) == NULL)
106: err(2, "malloc failed");
107: memcpy(allocated_pkg, pkg, cp - pkg);
108: allocated_pkg[cp - pkg] = '\0';
109: suffix = cp + 1;
110: full_pkg = pkg;
111: pkg = allocated_pkg;
112: } else {
113: allocated_pkg = NULL;
114: full_pkg = pkg;
115: suffix = "tgz";
116: }
1.1 schmonz 117:
118: /* Preliminary setup */
119: sanity_check();
120: if (Verbose && !PlistOnly)
121: printf("Creating package %s\n", pkg);
122: get_dash_string(&Comment);
123: get_dash_string(&Desc);
124: if (IS_STDIN(Contents))
125: pkg_in = stdin;
126: else {
127: pkg_in = fopen(Contents, "r");
1.15 joerg 128: if (!pkg_in)
1.1 schmonz 129: errx(2, "unable to open contents file '%s' for input", Contents);
130: }
131: plist.head = plist.tail = NULL;
132:
133: /* If a SrcDir override is set, add it now */
134: if (SrcDir) {
135: if (Verbose && !PlistOnly)
136: printf("Using SrcDir value of %s\n", (realprefix) ? realprefix : SrcDir);
137: add_plist(&plist, PLIST_SRC, SrcDir);
138: }
139:
140: /* Stick the dependencies, if any, at the top */
1.17 ! joerg 141: if (Pkgdeps)
! 142: register_depends(&plist, Pkgdeps, 0);
1.1 schmonz 143:
1.11 joerg 144: /*
145: * Put the build dependencies after the dependencies.
146: * This works due to the evaluation order in pkg_add.
147: */
1.17 ! joerg 148: if (BuildPkgdeps)
! 149: register_depends(&plist, BuildPkgdeps, 1);
1.11 joerg 150:
1.1 schmonz 151: /* Put the conflicts directly after the dependencies, if any */
152: if (Pkgcfl) {
153: if (Verbose && !PlistOnly)
154: printf("Registering conflicts:");
155: while (Pkgcfl) {
156: cp = strsep(&Pkgcfl, " \t\n");
157: if (*cp) {
158: add_plist(&plist, PLIST_PKGCFL, cp);
159: if (Verbose && !PlistOnly)
160: printf(" %s", cp);
161: }
162: }
163: if (Verbose && !PlistOnly)
164: printf(".\n");
165: }
166:
167: /* Slurp in the packing list */
168: read_plist(&plist, pkg_in);
169:
170: if (pkg_in != stdin)
171: fclose(pkg_in);
172:
173: /* Prefix should override the packing list */
174: if (Prefix) {
175: delete_plist(&plist, FALSE, PLIST_CWD, NULL);
176: add_plist_top(&plist, PLIST_CWD, Prefix);
177: }
178: /*
179: * Run down the list and see if we've named it, if not stick in a name
180: * at the top.
181: */
182: if (find_plist(&plist, PLIST_NAME) == NULL) {
183: add_plist_top(&plist, PLIST_NAME, basename_of(pkg));
184: }
185:
1.15 joerg 186: /* Make first "real contents" pass over it */
187: check_list(&plist, basename_of(pkg));
188:
1.1 schmonz 189: /*
190: * We're just here for to dump out a revised plist for the FreeBSD ports
191: * hack. It's not a real create in progress.
192: */
193: if (PlistOnly) {
194: write_plist(&plist, stdout, realprefix);
1.15 joerg 195: retval = TRUE;
196: } else {
197: #ifdef BOOTSTRAP
198: warnx("Package building is not supported in bootstrap mode");
199: retval = FALSE;
200: #else
201: retval = pkg_build(pkg, full_pkg, suffix, &plist);
202: #endif
1.1 schmonz 203: }
204:
205: /* Cleanup */
206: free(Comment);
207: free(Desc);
208: free_plist(&plist);
1.15 joerg 209:
210: free(allocated_pkg);
211:
212: return retval;
1.1 schmonz 213: }
CVSweb <webmaster@jp.NetBSD.org>