1 /* $NetBSD: perform.c,v 1.1.1.5 2009/11/05 18:39:02 joerg Exp $ */
10 __RCSID("$NetBSD: perform.c,v 1.1.1.5 2009/11/05 18:39:02 joerg Exp $");
13 * FreeBSD install - a package for the installation and maintainance
14 * of non-core utilities.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
28 * This is the main body of the create module.
49 errx(2, "required package comment string is missing (-c comment)");
51 errx(2, "required package description string is missing (-d desc)");
53 errx(2, "required package contents list is missing (-f [-]file)");
57 register_depends(package_t
*plist
, char *deps
, int build_only
)
61 if (Verbose
&& !PlistOnly
) {
63 printf("Registering build depends:");
65 printf("Registering depends:");
68 cp
= strsep(&deps
, " \t\n");
71 best_installed
= find_best_matching_installed_pkg(cp
);
72 if (best_installed
!= NULL
) {
73 add_plist(plist
, PLIST_BLDDEP
, best_installed
);
74 if (Verbose
&& !PlistOnly
&& build_only
)
77 warnx("No matching package installed for %s", cp
);
80 add_plist(plist
, PLIST_PKGDEP
, cp
);
81 if (Verbose
&& !PlistOnly
)
86 if (Verbose
&& !PlistOnly
)
91 * Expect "fname" to point at a file, and read it into
92 * the buffer returned.
95 fileGetContents(char *fname
)
101 if (stat(fname
, &sb
) == FAIL
) {
102 errx(2, "can't stat '%s'", fname
);
105 contents
= xmalloc((size_t) (sb
.st_size
) + 1);
106 fd
= open(fname
, O_RDONLY
, 0);
108 errx(2, "unable to open '%s' for reading", fname
);
110 if (read(fd
, contents
, (size_t) sb
.st_size
) != (ssize_t
) sb
.st_size
) {
111 errx(2, "short read on '%s' - did not get %lld bytes",
112 fname
, (long long) sb
.st_size
);
115 contents
[(size_t) sb
.st_size
] = '\0';
120 * Get a string parameter as a file spec or as a "contents follow -" spec
123 get_dash_string(char **s
)
126 *s
= xstrdup(*s
+ 1);
128 *s
= fileGetContents(*s
);
132 pkg_perform(const char *pkg
)
137 const char *full_pkg
, *suffix
;
141 /* Break the package name into base and desired suffix (if any) */
142 if ((cp
= strrchr(pkg
, '.')) != NULL
) {
143 allocated_pkg
= xmalloc(cp
- pkg
+ 1);
144 memcpy(allocated_pkg
, pkg
, cp
- pkg
);
145 allocated_pkg
[cp
- pkg
] = '\0';
150 allocated_pkg
= NULL
;
155 /* Preliminary setup */
157 if (Verbose
&& !PlistOnly
)
158 printf("Creating package %s\n", pkg
);
159 get_dash_string(&Comment
);
160 get_dash_string(&Desc
);
161 if (IS_STDIN(Contents
))
164 pkg_in
= fopen(Contents
, "r");
166 errx(2, "unable to open contents file '%s' for input", Contents
);
169 plist
.head
= plist
.tail
= NULL
;
171 /* Stick the dependencies, if any, at the top */
173 register_depends(&plist
, Pkgdeps
, 0);
176 * Put the build dependencies after the dependencies.
177 * This works due to the evaluation order in pkg_add.
180 register_depends(&plist
, BuildPkgdeps
, 1);
182 /* Put the conflicts directly after the dependencies, if any */
184 if (Verbose
&& !PlistOnly
)
185 printf("Registering conflicts:");
187 cp
= strsep(&Pkgcfl
, " \t\n");
189 add_plist(&plist
, PLIST_PKGCFL
, cp
);
190 if (Verbose
&& !PlistOnly
)
194 if (Verbose
&& !PlistOnly
)
198 /* Slurp in the packing list */
199 append_plist(&plist
, pkg_in
);
204 /* Prefix should override the packing list */
206 delete_plist(&plist
, FALSE
, PLIST_CWD
, NULL
);
207 add_plist_top(&plist
, PLIST_CWD
, Prefix
);
210 * Run down the list and see if we've named it, if not stick in a name
213 if (find_plist(&plist
, PLIST_NAME
) == NULL
) {
214 add_plist_top(&plist
, PLIST_NAME
, basename_of(pkg
));
217 /* Make first "real contents" pass over it */
218 check_list(&plist
, basename_of(pkg
));
221 * We're just here for to dump out a revised plist for the FreeBSD ports
222 * hack. It's not a real create in progress.
225 write_plist(&plist
, stdout
, realprefix
);
229 warnx("Package building is not supported in bootstrap mode");
232 retval
= pkg_build(pkg
, full_pkg
, suffix
, &plist
);