summaryrefslogtreecommitdiffhomepage
path: root/src/slibtool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/slibtool.c')
-rw-r--r--src/slibtool.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/slibtool.c b/src/slibtool.c
new file mode 100644
index 0000000..6fb3422
--- /dev/null
+++ b/src/slibtool.c
@@ -0,0 +1,67 @@
+/*******************************************************************/
+/* slibtool: a skinny libtool implementation, written in C */
+/* Copyright (C) 2016 Z. Gilboa */
+/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
+/*******************************************************************/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <slibtool/slibtool.h>
+#include "slibtool_version.h"
+#include "slibtool_driver_impl.h"
+
+#ifndef SLBT_DRIVER_FLAGS
+#define SLBT_DRIVER_FLAGS SLBT_DRIVER_VERBOSITY_ERRORS \
+ | SLBT_DRIVER_VERBOSITY_USAGE
+#endif
+
+static const char vermsg[] = "%s (git://midipix.org/slibtool): commit %s.\n";
+
+static ssize_t slibtool_version(struct slbt_driver_ctx * dctx)
+{
+ return fprintf(stdout,vermsg,dctx->program,SLIBTOOL_GIT_VERSION);
+}
+
+static void slibtool_perform_unit_actions(struct slbt_unit_ctx * uctx)
+{
+}
+
+static int slibtool_exit(struct slbt_driver_ctx * dctx, int nerrors)
+{
+ slbt_free_driver_ctx(dctx);
+ return nerrors ? 2 : 0;
+}
+
+int slibtool_main(int argc, char ** argv, char ** envp)
+{
+ int ret;
+ struct slbt_driver_ctx * dctx;
+ struct slbt_unit_ctx * uctx;
+ const char ** unit;
+
+ if ((ret = slbt_get_driver_ctx(argv,envp,SLBT_DRIVER_FLAGS,&dctx)))
+ return (ret == SLBT_USAGE) ? !--argc : 2;
+
+ if (dctx->cctx->drvflags & SLBT_DRIVER_VERSION)
+ if ((slibtool_version(dctx)) < 0)
+ return slibtool_exit(dctx,2);
+
+ for (unit=dctx->units; *unit; unit++) {
+ if (!(slbt_get_unit_ctx(dctx,*unit,&uctx))) {
+ slibtool_perform_unit_actions(uctx);
+ ret += uctx->nerrors;
+ slbt_free_unit_ctx(uctx);
+ }
+ }
+
+ return slibtool_exit(dctx,ret);
+}
+
+#ifndef SLIBTOOL_IN_A_BOX
+
+int main(int argc, char ** argv, char ** envp)
+{
+ return slibtool_main(argc,argv,envp);
+}
+
+#endif