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
980491
static void slibtool_perform_driver_actions(struct slbt_driver_ctx * dctx)
980491
{
980491
	if (dctx->cctx->drvflags & SLBT_DRIVER_CONFIG)
980491
		dctx->nerrors += (slbt_output_config(dctx) < 0);
980491
980491
	if (dctx->cctx->mode == SLBT_MODE_COMPILE)
980491
		dctx->nerrors += (slbt_exec_compile(dctx,0) < 0);
583c0a
258073
	if (dctx->cctx->mode == SLBT_MODE_INSTALL)
258073
		dctx->nerrors += (slbt_exec_install(dctx,0) < 0);
258073
583c0a
	if (dctx->cctx->mode == SLBT_MODE_LINK)
583c0a
		dctx->nerrors += (slbt_exec_link(dctx,0) < 0);
980491
}
980491
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
980491
	slibtool_perform_driver_actions(dctx);
980491
	ret += dctx->nerrors;
980491
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