1 /* $NetBSD: perform.c,v 1.22 2008/09/17 15:21:30 joerg Exp $ */
12 static const char *rcsid
= "from FreeBSD Id: perform.c,v 1.38 1997/10/13 15:03:51 jkh Exp";
14 __RCSID("$NetBSD: perform.c,v 1.22 2008/09/17 15:21:30 joerg Exp $");
19 * FreeBSD install - a package for the installation and maintainance
20 * of non-core utilities.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
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.
34 * This is the main body of the create module.
52 errx(2, "required package comment string is missing (-c comment)");
54 errx(2, "required package description string is missing (-d desc)");
56 errx(2, "required package contents list is missing (-f [-]file)");
60 register_depends(package_t
*plist
, char *deps
, int build_only
)
64 if (Verbose
&& !PlistOnly
) {
66 printf("Registering build depends:");
68 printf("Registering depends:");
71 cp
= strsep(&deps
, " \t\n");
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
)
80 warnx("No matching package installed for %s", cp
);
83 add_plist(plist
, PLIST_PKGDEP
, cp
);
84 if (Verbose
&& !PlistOnly
)
89 if (Verbose
&& !PlistOnly
)
94 * Get a string parameter as a file spec or as a "contents follow -" spec
97 get_dash_string(char **s
)
102 *s
= fileGetContents(*s
);
106 pkg_perform(const char *pkg
)
111 const char *full_pkg
, *suffix
;
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';
125 allocated_pkg
= NULL
;
130 /* Preliminary setup */
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
))
139 pkg_in
= fopen(Contents
, "r");
141 errx(2, "unable to open contents file '%s' for input", Contents
);
143 plist
.head
= plist
.tail
= NULL
;
145 /* If a SrcDir override is set, add it now */
147 if (Verbose
&& !PlistOnly
)
148 printf("Using SrcDir value of %s\n", (realprefix
) ? realprefix
: SrcDir
);
149 add_plist(&plist
, PLIST_SRC
, SrcDir
);
152 /* Stick the dependencies, if any, at the top */
154 register_depends(&plist
, Pkgdeps
, 0);
157 * Put the build dependencies after the dependencies.
158 * This works due to the evaluation order in pkg_add.
161 register_depends(&plist
, BuildPkgdeps
, 1);
163 /* Put the conflicts directly after the dependencies, if any */
165 if (Verbose
&& !PlistOnly
)
166 printf("Registering conflicts:");
168 cp
= strsep(&Pkgcfl
, " \t\n");
170 add_plist(&plist
, PLIST_PKGCFL
, cp
);
171 if (Verbose
&& !PlistOnly
)
175 if (Verbose
&& !PlistOnly
)
179 /* Slurp in the packing list */
180 append_plist(&plist
, pkg_in
);
185 /* Prefix should override the packing list */
187 delete_plist(&plist
, FALSE
, PLIST_CWD
, NULL
);
188 add_plist_top(&plist
, PLIST_CWD
, Prefix
);
191 * Run down the list and see if we've named it, if not stick in a name
194 if (find_plist(&plist
, PLIST_NAME
) == NULL
) {
195 add_plist_top(&plist
, PLIST_NAME
, basename_of(pkg
));
198 /* Make first "real contents" pass over it */
199 check_list(&plist
, basename_of(pkg
));
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.
206 write_plist(&plist
, stdout
, realprefix
);
210 warnx("Package building is not supported in bootstrap mode");
213 retval
= pkg_build(pkg
, full_pkg
, suffix
, &plist
);