do not edit — generated by btf.
git.druid.rocksindexdruid520mpsrc/mpx.c

src/mpx.c


#define _POSIX_C_SOURCE 200809L
#define _NETBSD_SOURCE 1
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include "mpx.h"
 
static void printusage(const char* prog, FILE* out);
static void usage(const char* prog);
 
static void
printusage(const char* prog, FILE* out)
{
	fprintf(out, "usage: %s <cmd> ...\n", prog);
	fprintf(out, "  stage <portdir> <dest>       recursively copy portdir into dest.\n");
	fprintf(out, "  unstage <dest>               recursively remove dest.\n");
	fprintf(out, "  runsh <dir> <script> [NAME=VAL ...]  run dir/script via SHELL -e regardless of the script's own shebang or set -e, SHELL from /etc/mpx.conf or /bin/sh. trailing NAME=VAL args are exported to the script's environment.\n");
	fprintf(out, "                                runsh also exports MP_TARGET, and when TARGET_* keys are set in /etc/mpx.conf: CC/AR/RANLIB/STRIP, MP_HOST, MP_SYSROOT, appends --sysroot to CFLAGS/LDFLAGS, and exports QEMU_LD_PREFIX=TARGET_SYSROOT for qemu-user.\n");
	fprintf(out, "                                runsh also exports MP_JOBS (JOBS from /etc/mpx.conf, or the online cpu count if unset) and sets/appends -jMP_JOBS to MAKEFLAGS.\n");
	fprintf(out, "                                runsh also exports MP_ARCH/MP_MICROARCH when ARCH/MICROARCH are set in /etc/mpx.conf, and appends -march=MICROARCH to CFLAGS.\n");
	fprintf(out, "                                runsh also appends -I<prefix>/include to CFLAGS and -L<prefix>/lib -Wl,-rpath,<prefix>/lib to LDFLAGS, <prefix> from an MP_PREFIX_BASE or MP_PREFIX NAME=VAL arg, else the inherited MP_PREFIX env.\n");
	fprintf(out, "                                runsh also appends -I/-L/-Wl,-rpath to CFLAGS/LDFLAGS and prepends to PKG_CONFIG_PATH for each ':'-separated prefix in an MP_DEP_PREFIXES NAME=VAL arg (one per slotted dependency).\n");
#ifdef __linux__
	fprintf(out, "                                runsh also sandboxes the script (fresh network+mount namespace, root read-only except <dir> and the prefix) unless SANDBOX=\"no\" in /etc/mpx.conf or an MP_SANDBOX=no NAME=VAL arg.\n");
#endif
	fprintf(out, "  snapshot <prefix> <outfile>  list every file under prefix as \"path\\tsec.nsec\\n\" lines.\n");
	fprintf(out, "  merge <src> <dst> <manifest>  copy every path <manifest> lists from src onto dst, atomically per file, overwriting -- never deletes anything.\n");
	fprintf(out, "  version                      print the cc/target/cflags this mpx was actually built with.\n");
	fprintf(out, "  help                         print this usage text to stdout and exit 0.\n");
	fprintf(out, "all commands exit 0 on success, 1 on failure, with an err: message on stderr.\n");
}
 
static void
usage(const char* prog)
{
	printusage(prog, stderr);
	exit(1);
}
 
void
badusage(const char* prog, const char* syntax)
{
	fprintf(stderr, "err: bad usage.\n");
	fprintf(stderr, "usage: %s %s\n", prog, syntax);
	exit(1);
}
 
int
main(int argc, char** argv)
{
	if(argc < 2)
	{
		usage(argv[0]);
	}
	if(strcmp(argv[1], "stage") == 0)
	{
		cmd_stage(argc, argv);
		return 0;
	}
	if(strcmp(argv[1], "unstage") == 0)
	{
		cmd_unstage(argc, argv);
		return 0;
	}
	if(strcmp(argv[1], "runsh") == 0)
	{
		cmd_runsh(argc, argv);
		return 0;
	}
	if(strcmp(argv[1], "snapshot") == 0)
	{
		cmd_snapshot(argc, argv);
		return 0;
	}
	if(strcmp(argv[1], "merge") == 0)
	{
		cmd_merge(argc, argv);
		return 0;
	}
	if(strcmp(argv[1], "version") == 0)
	{
		cmd_version(argc, argv);
		return 0;
	}
	if(strcmp(argv[1], "help") == 0)
	{
		printusage(argv[0], stdout);
		return 0;
	}
	usage(argv[0]);
	return 1;
}
powered by btf.