| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| int slbt_exec_compile( |
| const struct slbt_driver_ctx * dctx, |
| struct slbt_exec_ctx * ectx) |
| { |
| int ret; |
| int fdlibs; |
| FILE * fout; |
| struct slbt_exec_ctx * actx = 0; |
| |
| |
| if (ectx) |
| slbt_reset_placeholders(ectx); |
| else if ((ret = slbt_get_exec_ctx(dctx,&ectx))) |
| return ret; |
| else |
| actx = ectx; |
| |
| |
| if (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) { |
| if ((fdlibs = open(ectx->ldirname,O_DIRECTORY)) >= 0) |
| close(fdlibs); |
| else if ((errno != ENOENT) || mkdir(ectx->ldirname,0777)) { |
| slbt_free_exec_ctx(actx); |
| return -1; |
| } |
| } |
| |
| |
| ectx->program = ectx->compiler; |
| ectx->argv = ectx->cargv; |
| |
| |
| if (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) { |
| if (!(dctx->cctx->drvflags & SLBT_DRIVER_ANTI_PIC)) { |
| *ectx->dpic = "-DPIC"; |
| *ectx->fpic = "-fPIC"; |
| } |
| |
| *ectx->cass = "-c"; |
| *ectx->lout[0] = "-o"; |
| *ectx->lout[1] = ectx->lobjname; |
| |
| if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT)) { |
| if (slbt_output_compile(dctx,ectx)) { |
| slbt_free_exec_ctx(actx); |
| return -1; |
| } |
| } |
| |
| if (((ret = slbt_spawn(ectx,true)) < 0) || ectx->exitcode) { |
| slbt_free_exec_ctx(actx); |
| return -1; |
| } |
| } |
| |
| |
| if (dctx->cctx->drvflags & SLBT_DRIVER_STATIC) { |
| slbt_reset_placeholders(ectx); |
| |
| if (dctx->cctx->drvflags & SLBT_DRIVER_PRO_PIC) { |
| *ectx->dpic = "-DPIC"; |
| *ectx->fpic = "-fPIC"; |
| } |
| |
| *ectx->cass = "-c"; |
| *ectx->lout[0] = "-o"; |
| *ectx->lout[1] = ectx->aobjname; |
| |
| if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT)) { |
| if (slbt_output_compile(dctx,ectx)) { |
| slbt_free_exec_ctx(actx); |
| return -1; |
| } |
| } |
| |
| if (((ret = slbt_spawn(ectx,true)) < 0) || ectx->exitcode) { |
| slbt_free_exec_ctx(actx); |
| return -1; |
| } |
| } |
| |
| |
| if (!(fout = fopen(ectx->ltobjname,"w"))) { |
| slbt_free_exec_ctx(actx); |
| return -1; |
| } |
| |
| ret = fprintf(fout, |
| "# slibtool (pre-alpha) generated file\n\n" |
| "pic_object='%s'\n" |
| "non_pic_object='%s'\n", |
| (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) |
| ? ectx->lobjname |
| : "none", |
| (dctx->cctx->drvflags & SLBT_DRIVER_STATIC) |
| ? ectx->aobjname |
| : "none"); |
| |
| fclose(fout); |
| slbt_free_exec_ctx(actx); |
| |
| return (ret > 0) ? 0 : -1; |
| } |