orbea / cross / slibtool

Forked from cross/slibtool 3 years ago
Clone

Blame src/slibtool.c

9ca8c4
/*******************************************************************/
9ca8c4
/*  slibtool: a skinny libtool implementation, written in C        */
9ca8c4
/*  Copyright (C) 2016  Z. Gilboa                                  */
9ca8c4
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
9ca8c4
/*******************************************************************/
9ca8c4
9ca8c4
#include <stdio.h>
9ca8c4
#include <unistd.h>
9ca8c4
#include <slibtool/slibtool.h>
9ca8c4
#include "slibtool_version.h"
9ca8c4
#include "slibtool_driver_impl.h"
9ca8c4
9ca8c4
#ifndef SLBT_DRIVER_FLAGS
9ca8c4
#define SLBT_DRIVER_FLAGS	SLBT_DRIVER_VERBOSITY_ERRORS \
9ca8c4
				| SLBT_DRIVER_VERBOSITY_USAGE
9ca8c4
#endif
9ca8c4
9ca8c4
static const char vermsg[] = "%s (git://midipix.org/slibtool): commit %s.\n";
9ca8c4
9ca8c4
static ssize_t slibtool_version(struct slbt_driver_ctx * dctx)
9ca8c4
{
9ca8c4
	return fprintf(stdout,vermsg,dctx->program,SLIBTOOL_GIT_VERSION);
9ca8c4
}
9ca8c4
9ca8c4
static void slibtool_perform_unit_actions(struct slbt_unit_ctx * uctx)
9ca8c4
{
9ca8c4
}
9ca8c4
9ca8c4
static int slibtool_exit(struct slbt_driver_ctx * dctx, int nerrors)
9ca8c4
{
9ca8c4
	slbt_free_driver_ctx(dctx);
9ca8c4
	return nerrors ? 2 : 0;
9ca8c4
}
9ca8c4
9ca8c4
int slibtool_main(int argc, char ** argv, char ** envp)
9ca8c4
{
9ca8c4
	int				ret;
9ca8c4
	struct slbt_driver_ctx *	dctx;
9ca8c4
	struct slbt_unit_ctx *		uctx;
9ca8c4
	const char **			unit;
9ca8c4
9ca8c4
	if ((ret = slbt_get_driver_ctx(argv,envp,SLBT_DRIVER_FLAGS,&dctx)))
9ca8c4
		return (ret == SLBT_USAGE) ? !--argc : 2;
9ca8c4
9ca8c4
	if (dctx->cctx->drvflags & SLBT_DRIVER_VERSION)
9ca8c4
		if ((slibtool_version(dctx)) < 0)
9ca8c4
			return slibtool_exit(dctx,2);
9ca8c4
9ca8c4
	for (unit=dctx->units; *unit; unit++) {
9ca8c4
		if (!(slbt_get_unit_ctx(dctx,*unit,&uctx))) {
9ca8c4
			slibtool_perform_unit_actions(uctx);
9ca8c4
			ret += uctx->nerrors;
9ca8c4
			slbt_free_unit_ctx(uctx);
9ca8c4
		}
9ca8c4
	}
9ca8c4
9ca8c4
	return slibtool_exit(dctx,ret);
9ca8c4
}
9ca8c4
9ca8c4
#ifndef SLIBTOOL_IN_A_BOX
9ca8c4
9ca8c4
int main(int argc, char ** argv, char ** envp)
9ca8c4
{
9ca8c4
	return slibtool_main(argc,argv,envp);
9ca8c4
}
9ca8c4
9ca8c4
#endif