| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static int slbt_exec_link_create_library_symlink( |
| const struct slbt_driver_ctx * dctx, |
| struct slbt_exec_ctx * ectx, |
| bool fmajor) |
| { |
| char target[PATH_MAX]; |
| char lnkname[PATH_MAX]; |
| |
| if (ectx->relfilename && dctx->cctx->verinfo.verinfo) { |
| strcpy(target,ectx->relfilename); |
| sprintf(lnkname,"%s.dualver",ectx->dsofilename); |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| target,lnkname, |
| SLBT_SYMLINK_DEFAULT)) |
| return SLBT_NESTED_ERROR(dctx); |
| } else if (ectx->relfilename) { |
| strcpy(target,ectx->relfilename); |
| sprintf(lnkname,"%s.release",ectx->dsofilename); |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| target,lnkname, |
| SLBT_SYMLINK_DEFAULT)) |
| return SLBT_NESTED_ERROR(dctx); |
| } else { |
| sprintf(target,"%s%s.%d.%d.%d%s", |
| ectx->dsobasename, |
| dctx->cctx->settings.osdsuffix, |
| dctx->cctx->verinfo.major, |
| dctx->cctx->verinfo.minor, |
| dctx->cctx->verinfo.revision, |
| dctx->cctx->settings.osdfussix); |
| } |
| |
| |
| if (fmajor && ectx->dsorellnkname) { |
| sprintf(lnkname,"%s.%d", |
| ectx->dsorellnkname, |
| dctx->cctx->verinfo.major); |
| |
| } else if (fmajor) { |
| sprintf(lnkname,"%s%s.%d%s", |
| ectx->dsobasename, |
| dctx->cctx->settings.osdsuffix, |
| dctx->cctx->verinfo.major, |
| dctx->cctx->settings.osdfussix); |
| |
| } else { |
| strcpy(lnkname,ectx->dsofilename); |
| } |
| |
| |
| if (fmajor && (dctx->cctx->drvflags & SLBT_DRIVER_IMAGE_PE)) |
| return slbt_copy_file( |
| dctx,ectx, |
| target,lnkname); |
| else |
| return slbt_create_symlink( |
| dctx,ectx, |
| target,lnkname, |
| SLBT_SYMLINK_DEFAULT); |
| } |
| |
| int slbt_exec_link( |
| const struct slbt_driver_ctx * dctx, |
| struct slbt_exec_ctx * ectx) |
| { |
| int ret; |
| const char * output; |
| char * dot; |
| struct slbt_exec_ctx * actx; |
| bool fpic; |
| bool fstaticonly; |
| char soname[PATH_MAX]; |
| char soxyz [PATH_MAX]; |
| char solnk [PATH_MAX]; |
| char arname[PATH_MAX]; |
| char target[PATH_MAX]; |
| char lnkname[PATH_MAX]; |
| |
| |
| if (dctx->cctx->drvflags & SLBT_DRIVER_DRY_RUN) |
| return 0; |
| |
| |
| if (ectx) |
| actx = 0; |
| else if ((ret = slbt_get_exec_ctx(dctx,&ectx))) |
| return SLBT_NESTED_ERROR(dctx); |
| else |
| actx = ectx; |
| |
| |
| if (slbt_snprintf(soxyz,sizeof(soxyz), |
| "%s%s%s%s%s.%d.%d.%d%s", |
| ectx->sonameprefix, |
| dctx->cctx->libname, |
| dctx->cctx->release ? "-" : "", |
| dctx->cctx->release ? dctx->cctx->release : "", |
| dctx->cctx->settings.osdsuffix, |
| dctx->cctx->verinfo.major, |
| dctx->cctx->verinfo.minor, |
| dctx->cctx->verinfo.revision, |
| dctx->cctx->settings.osdfussix) < 0) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_BUFFER_ERROR(dctx); |
| } |
| |
| |
| sprintf(soname,"%s%s%s%s%s.%d%s", |
| ectx->sonameprefix, |
| dctx->cctx->libname, |
| dctx->cctx->release ? "-" : "", |
| dctx->cctx->release ? dctx->cctx->release : "", |
| dctx->cctx->settings.osdsuffix, |
| dctx->cctx->verinfo.major, |
| dctx->cctx->settings.osdfussix); |
| |
| |
| sprintf(solnk,"%s%s%s", |
| ectx->sonameprefix, |
| dctx->cctx->libname, |
| dctx->cctx->settings.dsosuffix); |
| |
| |
| sprintf(arname,"%s%s%s", |
| dctx->cctx->settings.arprefix, |
| dctx->cctx->libname, |
| dctx->cctx->settings.arsuffix); |
| |
| |
| output = dctx->cctx->output; |
| dot = strrchr(output,'.'); |
| |
| |
| if (slbt_mkdir(dctx,ectx->ldirname)) { |
| ret = SLBT_SYSTEM_ERROR(dctx,ectx->ldirname); |
| slbt_free_exec_ctx(actx); |
| return ret; |
| } |
| |
| |
| if (dot && !strcmp(dot,".a")) |
| if (slbt_exec_link_create_archive(dctx,ectx,output,false)) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| |
| if (dctx->cctx->drvflags & SLBT_DRIVER_ALL_STATIC) { |
| fstaticonly = true; |
| fpic = false; |
| } else if (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_SHARED) { |
| fstaticonly = true; |
| fpic = false; |
| } else if (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_STATIC) { |
| fstaticonly = false; |
| fpic = true; |
| } else if (dctx->cctx->drvflags & SLBT_DRIVER_SHARED) { |
| fstaticonly = false; |
| fpic = true; |
| } else { |
| fstaticonly = false; |
| fpic = false; |
| } |
| |
| |
| if (dctx->cctx->libname) { |
| if (slbt_exec_link_create_host_tag( |
| dctx,ectx, |
| ectx->deffilename)) |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| |
| if (dot && !strcmp(dot,".la")) |
| if (slbt_exec_link_create_archive( |
| dctx,ectx, |
| ectx->arfilename, |
| fpic)) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| |
| if (fstaticonly && dot && !strcmp(dot,".la")) { |
| const struct slbt_flavor_settings * dflavor; |
| |
| if (slbt_get_flavor_settings("default",&dflavor) < 0) |
| return SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_LINK_FLOW); |
| |
| if (strcmp(dctx->cctx->settings.dsosuffix,dflavor->dsosuffix)) { |
| strcpy(target,ectx->lafilename); |
| sprintf(lnkname,"%s.shrext%s", |
| ectx->lafilename, |
| dctx->cctx->settings.dsosuffix); |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| target,lnkname, |
| SLBT_SYMLINK_DEFAULT)) |
| return SLBT_NESTED_ERROR(dctx); |
| |
| strcpy(target,lnkname); |
| sprintf(lnkname,"%s.shrext",ectx->lafilename); |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| target,lnkname, |
| SLBT_SYMLINK_DEFAULT)) |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| "/dev/null", |
| ectx->deffilename, |
| SLBT_SYMLINK_LITERAL|SLBT_SYMLINK_DEVNULL)) |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| |
| if (fstaticonly && dctx->cctx->libname) |
| if (slbt_create_symlink( |
| dctx,ectx, |
| "/dev/null", |
| ectx->dsofilename, |
| SLBT_SYMLINK_LITERAL)) |
| return SLBT_NESTED_ERROR(dctx); |
| |
| |
| if (dctx->cctx->rpath && !fstaticonly) { |
| if (dctx->cctx->drvflags & SLBT_DRIVER_MODULE) { |
| if (!dot || strcmp(dot,".la")) { |
| if (slbt_exec_link_create_library( |
| dctx,ectx, |
| ectx->dsobasename, |
| ectx->dsofilename, |
| ectx->relfilename)) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| slbt_free_exec_ctx(actx); |
| return 0; |
| } |
| } |
| } |
| |
| |
| if (dot && !strcmp(dot,".la") && dctx->cctx->rpath && !fstaticonly) { |
| const struct slbt_flavor_settings * dflavor; |
| |
| if (slbt_get_flavor_settings("default",&dflavor) < 0) |
| return SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_LINK_FLOW); |
| |
| |
| if (dctx->cctx->shrext) { |
| strcpy(target,ectx->lafilename); |
| sprintf(lnkname,"%s.shrext%s",ectx->lafilename,dctx->cctx->shrext); |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| target,lnkname, |
| SLBT_SYMLINK_DEFAULT)) |
| return SLBT_NESTED_ERROR(dctx); |
| |
| strcpy(target,lnkname); |
| sprintf(lnkname,"%s.shrext",ectx->lafilename); |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| target,lnkname, |
| SLBT_SYMLINK_DEFAULT)) |
| return SLBT_NESTED_ERROR(dctx); |
| |
| |
| } else if (strcmp(dctx->cctx->settings.dsosuffix,dflavor->dsosuffix)) { |
| strcpy(target,ectx->lafilename); |
| sprintf(lnkname,"%s.shrext%s", |
| ectx->lafilename, |
| dctx->cctx->settings.dsosuffix); |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| target,lnkname, |
| SLBT_SYMLINK_DEFAULT)) |
| return SLBT_NESTED_ERROR(dctx); |
| |
| strcpy(target,lnkname); |
| sprintf(lnkname,"%s.shrext",ectx->lafilename); |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| target,lnkname, |
| SLBT_SYMLINK_DEFAULT)) |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| |
| if (slbt_exec_link_create_library( |
| dctx,ectx, |
| ectx->dsobasename, |
| ectx->dsofilename, |
| ectx->relfilename)) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| if (!(dctx->cctx->drvflags & SLBT_DRIVER_AVOID_VERSION)) { |
| |
| if (slbt_exec_link_create_library_symlink( |
| dctx,ectx, |
| true)) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| |
| if (slbt_exec_link_create_library_symlink( |
| dctx,ectx, |
| false)) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| } else if (ectx->relfilename) { |
| |
| if (slbt_exec_link_create_library_symlink( |
| dctx,ectx, |
| false)) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| } |
| |
| |
| if (dctx->cctx->drvflags & SLBT_DRIVER_IMAGE_PE) { |
| |
| if (slbt_exec_link_create_import_library( |
| dctx,ectx, |
| ectx->pimpfilename, |
| ectx->deffilename, |
| soname)) |
| return SLBT_NESTED_ERROR(dctx); |
| |
| |
| if (slbt_create_symlink( |
| dctx,ectx, |
| ectx->pimpfilename, |
| ectx->dimpfilename, |
| SLBT_SYMLINK_DEFAULT)) |
| return SLBT_NESTED_ERROR(dctx); |
| |
| |
| if (slbt_exec_link_create_import_library( |
| dctx,ectx, |
| ectx->vimpfilename, |
| ectx->deffilename, |
| soxyz)) |
| return SLBT_NESTED_ERROR(dctx); |
| } else { |
| if (slbt_create_symlink( |
| dctx,ectx, |
| "/dev/null", |
| ectx->deffilename, |
| SLBT_SYMLINK_LITERAL|SLBT_SYMLINK_DEVNULL)) |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| } |
| |
| |
| if (!dctx->cctx->libname) { |
| |
| if (slbt_exec_link_create_executable( |
| dctx,ectx, |
| ectx->exefilename)) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| } |
| |
| |
| if (!dot || strcmp(dot,".la")) { |
| slbt_free_exec_ctx(actx); |
| return 0; |
| } |
| |
| |
| if (slbt_create_library_wrapper( |
| dctx,ectx, |
| arname,soname,soxyz,solnk)) { |
| slbt_free_exec_ctx(actx); |
| return SLBT_NESTED_ERROR(dctx); |
| } |
| |
| |
| if ((ret = slbt_create_symlink( |
| dctx,ectx, |
| output, |
| ectx->lafilename, |
| SLBT_SYMLINK_WRAPPER))) |
| SLBT_NESTED_ERROR(dctx); |
| |
| |
| if (ret == 0) |
| if ((ret = slbt_create_symlink( |
| dctx,ectx, |
| output, |
| ectx->laifilename, |
| SLBT_SYMLINK_WRAPPER))) |
| SLBT_NESTED_ERROR(dctx); |
| |
| |
| slbt_free_exec_ctx(actx); |
| |
| return ret; |
| } |