summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-05-21 00:35:59 -0400
committermidipix <writeonce@midipix.org>2016-05-21 00:52:17 -0400
commita9cfe4a0639462e3834adee3d6136c3d41c5dce3 (patch)
treeb3b0954f1cc3df10b8f8dc91d5a3d0e76498018e
parente49ee9a45bed57d972f2e6d6107fc6ee49a0e4a3 (diff)
downloadslibtool-a9cfe4a0639462e3834adee3d6136c3d41c5dce3.tar.bz2
slibtool-a9cfe4a0639462e3834adee3d6136c3d41c5dce3.tar.xz
link mode: slbt_create_library_wrapper(): initial implementation.
-rw-r--r--project/common.mk1
-rw-r--r--src/internal/slibtool_libmeta_impl.c147
-rw-r--r--src/internal/slibtool_metafile_impl.h8
-rw-r--r--src/logic/slbt_exec_link.c115
4 files changed, 166 insertions, 105 deletions
diff --git a/project/common.mk b/project/common.mk
index b00f745..27d8d9f 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -1,4 +1,5 @@
COMMON_SRCS = \
+ src/internal/slibtool_libmeta_impl.c \
src/internal/slibtool_objmeta_impl.c \
src/internal/slibtool_symlink_impl.c \
src/driver/slbt_driver_ctx.c \
diff --git a/src/internal/slibtool_libmeta_impl.c b/src/internal/slibtool_libmeta_impl.c
new file mode 100644
index 0000000..f08aa94
--- /dev/null
+++ b/src/internal/slibtool_libmeta_impl.c
@@ -0,0 +1,147 @@
+/*******************************************************************/
+/* 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 <stdbool.h>
+#include <slibtool/slibtool.h>
+#include "slibtool_metafile_impl.h"
+
+static int slbt_create_default_library_wrapper(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ char * arname,
+ char * soname,
+ char * soxyz,
+ char * solnk)
+{
+ int ret;
+ FILE * fout;
+ const char * header;
+ const char * base;
+ bool fnover;
+ bool fvernum;
+ int current;
+ int revision;
+ int age;
+ const struct slbt_source_version * verinfo;
+
+ (void)ectx;
+
+ /* create */
+ if (!(fout = fopen(dctx->cctx->output,"w")))
+ return -1;
+
+ /* version info */
+ current = 0;
+ age = 0;
+ revision = 0;
+
+ if (dctx->cctx->verinfo.verinfo)
+ sscanf(dctx->cctx->verinfo.verinfo,"%d:%d:%d",
+ &current,&revision,&age);
+
+ fnover = !!(dctx->cctx->drvflags & SLBT_DRIVER_AVOID_VERSION);
+ fvernum = !!(dctx->cctx->verinfo.vernumber);
+ verinfo = slbt_source_version();
+
+ /* wrapper header */
+ header = "libtool compatible library wrapper\n";
+ base = "";
+
+ /* wrapper content */
+ ret = fprintf(fout,
+ "# %s%s"
+ "# Generated by %s (slibtool %d.%d.%d)\n"
+ "# [commit reference: %s]\n\n"
+
+ "dlname='%s'\n"
+ "library_names='%s %s %s'\n"
+ "old_library='%s'\n\n"
+
+ "inherited_linker_flags='%s'\n"
+ "dependency_libs='%s'\n"
+ "weak_library_names='%s'\n\n"
+
+ "current=%d\n"
+ "age=%d\n"
+ "revision=%d\n\n"
+
+ "installed=%s\n"
+ "shouldnotlink=%s\n\n"
+
+ "dlopen='%s'\n"
+ "dlpreopen='%s'\n\n"
+
+ "libdir='%s'\n",
+
+ /* wrapper header */
+ base,header,
+
+ /* nickname, verinfo */
+ dctx->program,
+ verinfo->major,verinfo->minor,verinfo->revision,
+ verinfo->commit,
+
+ /* dlname */
+ fnover ? solnk : soxyz,
+
+ /* library_names */
+ fnover ? solnk : soxyz,
+ fnover ? solnk : soname,
+ solnk,
+
+ /* old_library */
+ arname,
+
+ /* inherited_linker_flags, dependency_libs, weak_library_names */
+ "","","",
+
+ /* current, age, revision */
+ fvernum ? dctx->cctx->verinfo.major : current,
+ fvernum ? dctx->cctx->verinfo.minor : age,
+ fvernum ? dctx->cctx->verinfo.major : revision,
+
+ /* installed, shouldnotlink */
+ "no","no",
+
+ /* dlopen, dlpreopen */
+ "","",
+
+ /* libdir */
+ dctx->cctx->rpath ? dctx->cctx->rpath : "");
+
+ return (ret <= 0) || fclose(fout)
+ ? -1 : 0;
+}
+
+static int slbt_create_compatible_library_wrapper(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ char * arname,
+ char * soname,
+ char * soxyz,
+ char * solnk)
+{
+ /* awaiting submission */
+ return slbt_create_default_library_wrapper(
+ dctx,ectx,arname,soxyz,soname,solnk);
+}
+
+int slbt_create_library_wrapper(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ char * arname,
+ char * soname,
+ char * soxyz,
+ char * solnk)
+{
+ if (dctx->cctx->drvflags & SLBT_DRIVER_LEGABITS)
+ return slbt_create_compatible_library_wrapper(
+ dctx,ectx,arname,soxyz,soname,solnk);
+ else
+ return slbt_create_default_library_wrapper(
+ dctx,ectx,arname,soxyz,soname,solnk);
+}
diff --git a/src/internal/slibtool_metafile_impl.h b/src/internal/slibtool_metafile_impl.h
index 9a56db2..8b24d8f 100644
--- a/src/internal/slibtool_metafile_impl.h
+++ b/src/internal/slibtool_metafile_impl.h
@@ -9,3 +9,11 @@
int slbt_create_object_wrapper(
const struct slbt_driver_ctx * dctx,
struct slbt_exec_ctx * ectx);
+
+int slbt_create_library_wrapper(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ char * arname,
+ char * soname,
+ char * soxyz,
+ char * solnk);
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index 9e88420..4c78757 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -15,6 +15,7 @@
#include <slibtool/slibtool.h>
#include "slibtool_spawn_impl.h"
#include "slibtool_mkdir_impl.h"
+#include "slibtool_metafile_impl.h"
#include "slibtool_readlink_impl.h"
#include "slibtool_symlink_impl.h"
@@ -1054,23 +1055,14 @@ int slbt_exec_link(
{
int ret;
const char * output;
- const char * header;
- const char * base;
char * dot;
- FILE * fout;
struct slbt_exec_ctx * actx;
bool fpic;
bool fstaticonly;
- bool fnover;
- bool fvernum;
- int current;
- int revision;
- int age;
char soname[PATH_MAX];
char soxyz [PATH_MAX];
char solnk [PATH_MAX];
char arname[PATH_MAX];
- const struct slbt_source_version * verinfo;
/* dry run */
if (dctx->cctx->drvflags & SLBT_DRIVER_DRY_RUN)
@@ -1251,106 +1243,20 @@ int slbt_exec_link(
return 0;
}
- /* hey, yo, let's rap it up */
- if (!(fout = fopen(output,"w"))) {
+ /* library wrapper */
+ if (slbt_create_library_wrapper(
+ dctx,ectx,
+ arname,soname,soxyz,solnk)) {
slbt_free_exec_ctx(actx);
return -1;
}
- /* compatible library wrapper */
- current = 0;
- age = 0;
- revision = 0;
-
- if (dctx->cctx->verinfo.verinfo)
- sscanf(dctx->cctx->verinfo.verinfo,"%d:%d:%d",
- &current,&revision,&age);
-
- fnover = !!(dctx->cctx->drvflags & SLBT_DRIVER_AVOID_VERSION);
- fvernum = !!(dctx->cctx->verinfo.vernumber);
- verinfo = slbt_source_version();
-
- /* wrapper header */
- if (dctx->cctx->drvflags & SLBT_DRIVER_LEGABITS) {
- header = " - a libtool library file\n";
-
- if ((base = strrchr(output,'/')))
- base++;
- else
- base = output;
- } else {
- header = "libtool compatible library wrapper\n";
- base = "";
- }
-
- ret = fprintf(fout,
- "# %s%s"
- "# Generated by %s (slibtool %d.%d.%d)\n"
- "# [commit reference: %s]\n\n"
-
- "dlname='%s'\n"
- "library_names='%s %s %s'\n"
- "old_library='%s'\n\n"
-
- "inherited_linker_flags='%s'\n"
- "dependency_libs='%s'\n"
- "weak_library_names='%s'\n\n"
-
- "current=%d\n"
- "age=%d\n"
- "revision=%d\n\n"
-
- "installed=%s\n"
- "shouldnotlink=%s\n\n"
-
- "dlopen='%s'\n"
- "dlpreopen='%s'\n\n"
-
- "libdir='%s'\n",
-
- /* wrapper header */
- base,header,
-
- /* nickname, verinfo */
- dctx->program,
- verinfo->major,verinfo->minor,verinfo->revision,
- verinfo->commit,
-
- /* dlname */
- fnover ? solnk : soxyz,
-
- /* library_names */
- fnover ? solnk : soxyz,
- fnover ? solnk : soname,
- solnk,
-
- /* old_library */
- arname,
-
- /* inherited_linker_flags, dependency_libs, weak_library_names */
- "","","",
-
- /* current, age, revision */
- fvernum ? dctx->cctx->verinfo.major : current,
- fvernum ? dctx->cctx->verinfo.minor : age,
- fvernum ? dctx->cctx->verinfo.major : revision,
-
- /* installed, shouldnotlink */
- "no","no",
-
- /* dlopen, dlpreopen */
- "","",
-
- /* libdir */
- dctx->cctx->rpath ? dctx->cctx->rpath : "");
-
/* wrapper symlink */
- if (ret > 0)
- ret = (slbt_create_symlink(
- dctx,ectx,
- output,
- ectx->lafilename,
- true));
+ ret = (slbt_create_symlink(
+ dctx,ectx,
+ output,
+ ectx->lafilename,
+ true));
/* .lai wrapper symlink */
if (ret == 0)
@@ -1361,7 +1267,6 @@ int slbt_exec_link(
true));
/* all done */
- fclose(fout);
slbt_free_exec_ctx(actx);
return ret;