1998-03-10 05:20:58 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998, Peter Wemm <peter@netplex.com.au>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
1998-10-21 15:13:16 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <objformat.h>
|
1998-03-10 05:20:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1998-10-21 15:13:16 +00:00
|
|
|
#include <unistd.h>
|
1998-03-10 05:20:58 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
1998-10-21 15:13:16 +00:00
|
|
|
char objformat[32];
|
1998-03-10 05:20:58 +00:00
|
|
|
char *path, *chunk;
|
|
|
|
char *cmd, *newcmd = NULL;
|
2001-12-03 21:13:03 +00:00
|
|
|
const char *objformat_path;
|
1998-10-21 15:13:16 +00:00
|
|
|
|
|
|
|
if (getobjformat(objformat, sizeof objformat, &argc, argv) == -1)
|
|
|
|
errx(1, "Invalid object format");
|
1998-03-10 05:20:58 +00:00
|
|
|
|
|
|
|
cmd = strrchr(argv[0], '/');
|
1998-10-21 15:13:16 +00:00
|
|
|
if (cmd != NULL)
|
1998-03-10 05:20:58 +00:00
|
|
|
cmd++;
|
|
|
|
else
|
|
|
|
cmd = argv[0];
|
|
|
|
|
|
|
|
if (strcmp(cmd, "objformat") == 0) {
|
1998-10-24 02:01:30 +00:00
|
|
|
if (argc != 1) {
|
|
|
|
fprintf(stderr, "Usage: objformat\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
1998-10-21 15:13:16 +00:00
|
|
|
printf("%s\n", objformat);
|
1998-03-10 05:20:58 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 'make world' glue */
|
|
|
|
objformat_path = getenv("OBJFORMAT_PATH");
|
|
|
|
if (objformat_path == NULL)
|
1998-05-27 07:59:37 +00:00
|
|
|
objformat_path = "/usr/libexec";
|
1998-03-10 05:20:58 +00:00
|
|
|
path = strdup(objformat_path);
|
|
|
|
|
1998-10-21 15:13:16 +00:00
|
|
|
setenv("OBJFORMAT", objformat, 1);
|
1998-03-10 05:20:58 +00:00
|
|
|
|
|
|
|
while ((chunk = strsep(&path, ":")) != NULL) {
|
|
|
|
if (newcmd != NULL) {
|
|
|
|
free(newcmd);
|
|
|
|
newcmd = NULL;
|
|
|
|
}
|
1998-10-21 15:13:16 +00:00
|
|
|
asprintf(&newcmd, "%s/%s/%s", chunk, objformat, cmd);
|
1998-03-10 05:20:58 +00:00
|
|
|
if (newcmd == NULL)
|
|
|
|
err(1, "cannot allocate memory for new command");
|
|
|
|
|
|
|
|
argv[0] = newcmd;
|
|
|
|
execv(newcmd, argv);
|
|
|
|
}
|
1998-10-21 15:13:16 +00:00
|
|
|
err(1, "could not exec %s/%s in %s", objformat, cmd, objformat_path);
|
1998-03-10 05:20:58 +00:00
|
|
|
}
|