summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-05-04 22:34:56 -0400
committermidipix <writeonce@midipix.org>2016-05-04 22:34:56 -0400
commit5b5408293a750db40d3c4f725405195b2db413b7 (patch)
treebd0371b3a256205bc052cdc8c3df0f6ca2a08648
parent614d85adfdc8a825ff158ac5a739b637e1989ffe (diff)
downloadslibtool-5b5408293a750db40d3c4f725405195b2db413b7.tar.bz2
slibtool-5b5408293a750db40d3c4f725405195b2db413b7.tar.xz
install mode: legabits: install a perfectly compatible wrapper.
-rw-r--r--src/logic/slbt_exec_install.c107
1 files changed, 97 insertions, 10 deletions
diff --git a/src/logic/slbt_exec_install.c b/src/logic/slbt_exec_install.c
index 83cbf4c..f192053 100644
--- a/src/logic/slbt_exec_install.c
+++ b/src/logic/slbt_exec_install.c
@@ -211,6 +211,101 @@ static int slbt_exec_install_import_libraries(
return 0;
}
+static int slbt_exec_install_library_wrapper(
+ const struct slbt_driver_ctx * dctx,
+ struct slbt_exec_ctx * ectx,
+ struct argv_entry * entry,
+ char * dstdir)
+{
+ int ret;
+ FILE * fsrc;
+ FILE * fdst;
+ const char * base;
+ char * cfgline;
+ char * srcline;
+ char * dstline;
+ char clainame[PATH_MAX];
+ char instname[PATH_MAX];
+ char cfgbuf [PATH_MAX*4];
+ struct stat st;
+
+ /* base libfoo.la */
+ if ((base = strrchr(entry->arg,'/')))
+ base++;
+ else
+ base = entry->arg;
+
+ /* /dstdir/libfoo.la */
+ if ((size_t)snprintf(instname,sizeof(instname),"%s/%s",
+ dstdir,base) >= sizeof(instname))
+ return -1;
+
+ /* libfoo.la.slibtool.install */
+ if ((size_t)snprintf(clainame,sizeof(clainame),"%s.slibtool.install",
+ entry->arg) >= sizeof(clainame))
+ return -1;
+
+ /* fdst (libfoo.la.slibtool.install, build directory) */
+ if (!(fdst = fopen(clainame,"w")))
+ return -1;
+
+ /* fsrc (libfoo.la, build directory) */
+ if ((stat(entry->arg,&st))) {
+ fclose(fdst);
+ return -1;
+ }
+
+ if (!(fsrc = fopen(entry->arg,"r"))) {
+ fclose(fdst);
+ return -1;
+ }
+
+ if ((size_t)st.st_size < sizeof(cfgbuf))
+ srcline = cfgbuf;
+ else if (!(srcline = malloc(st.st_size+1))) {
+ fclose(fdst);
+ fclose(fsrc);
+ return -1;
+ }
+
+ /* copy config, install=no --> install=yes */
+ cfgline = fgets(srcline,st.st_size+1,fsrc);
+ ret = 0;
+
+ while (cfgline && (ret == 0)) {
+ dstline = !(strcmp(srcline,"installed=no\n"))
+ ? "installed=yes\n"
+ : srcline;
+
+ if (fprintf(fdst,"%s",dstline) < 0)
+ ret = -1;
+ else
+ cfgline = fgets(srcline,st.st_size+1,fsrc);
+ }
+
+ /* free, flush, verify */
+ if (srcline != cfgbuf)
+ free(srcline);
+
+ if (ret) {
+ fclose(fdst);
+ fclose(fsrc);
+ } else {
+ fflush(fdst);
+ ret = ferror(fdst) ? -1 : 0;
+ fclose(fdst);
+
+ ret = ferror(fsrc) ? -1 : ret;
+ fclose(fsrc);
+ }
+
+ /* cp libfoo.la.slibtool.instal /dstdir/libfoo.la */
+ if (slbt_copy_file(dctx,ectx,clainame,instname))
+ return -1;
+
+ return 0;
+}
+
static int slbt_exec_install_entry(
const struct slbt_driver_ctx * dctx,
struct slbt_exec_ctx * ectx,
@@ -265,17 +360,9 @@ static int slbt_exec_install_entry(
}
/* legabits? */
- if (dctx->cctx->drvflags & SLBT_DRIVER_LEGABITS) {
- *src = (char *)entry->arg;
- *dst = dest ? 0 : (char *)last->arg;
-
- if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
- if (slbt_output_install(dctx,ectx))
- return -1;
-
- if ((slbt_spawn(ectx,true) < 0) || ectx->exitcode)
+ if (dctx->cctx->drvflags & SLBT_DRIVER_LEGABITS)
+ if (slbt_exec_install_library_wrapper(dctx,ectx,entry,dstdir))
return -1;
- }
/* *dst: consider: cp libfoo.la /dest/dir/libfoo.la */
if ((*dst = dest ? 0 : (char *)last->arg))