diff options
Diffstat (limited to 'dists/amiga/Ext_Inst_so.rexx')
-rw-r--r-- | dists/amiga/Ext_Inst_so.rexx | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/dists/amiga/Ext_Inst_so.rexx b/dists/amiga/Ext_Inst_so.rexx new file mode 100644 index 0000000000..845acc687b --- /dev/null +++ b/dists/amiga/Ext_Inst_so.rexx @@ -0,0 +1,107 @@ +/* +$VER: Ext_Inst_so.rexx 0.3 (21.10.2019) Extract and install compiled-in shared libraries from a given ELF binary. +*/ + +PARSE ARG executable install_path + +/* +Check if arguments are available, otherwise quit. +*/ +IF ~ARG() THEN DO + SAY 'No Arguments given!' + SAY 'Usage: Ext_Inst_so.rexx EXECUTABLE INSTALL_PATH' + EXIT No Arguments given! +END + +/* +If the given filename/path has spaces in it, AmigaDOS/CLI +will add extra quotation marks to secure a sane working path. +Get rid of them to make AREXX find the file and remove leading +and trailing spaces. +*/ +IF ~EXISTS(executable) THEN DO + SAY executable' not available!' + EXIT EXECUTABLE not available! +END +ELSE DO + executable=STRIP(executable) + executable=COMPRESS(executable,'"') +END +IF installpath='' THEN DO + SAY 'No installation destination given!' + EXIT No installation destination given! +END +ELSE DO + install_path=STRIP(install_path) + install_path=COMPRESS(install_path,'"') + /* + Check for destination path and create it, if needed. + */ + IF ~EXISTS(install_path'/sobjs/') THEN + ADDRESS COMMAND 'makedir 'install_path'/sobjs' +END + +/* +Create shared objects dump. +*/ +ADDRESS COMMAND 'readelf -d 'executable' >so_dump' + +/* +Error check, if I/O went wrong. +*/ +IF ~OPEN(SO_read,'so_dump','R') THEN DO + SAY 'File so_dump opening failed!' + EXIT File so_dump opening failed! +END + +/* +We know that the dumped shared library entries always start +at line 4. Skip unneeded lines to speed up processing. +*/ +working_line=CALL READLN(SO_read) +working_line=CALL READLN(SO_read) +working_line=CALL READLN(SO_read) + +i=1 + +DO WHILE i>0 + working_line=READLN(SO_read) + IF POS('Shared library:', working_line)>0 THEN DO + i=1 + /* + We know that the shared library names always start at position 59. + */ + lib.so=SUBSTR(working_line,59,LASTPOS(']', working_line)-59) + /* + Check whether the installed shared libraries are placed in the SDK + (most of them) or AmigaOS SOBJS: drawer (few of them) and copy them accordingly. + */ + IF EXISTS('SDK:local/newlib/lib/'lib.so) THEN + ADDRESS COMMAND 'copy clone SDK:local/newlib/lib/'lib.so install_path'/sobjs/' + ELSE + IF EXISTS('SYS:SOBJS/'lib.so) THEN + ADDRESS COMMAND 'copy clone SYS:SOBJS/'lib.so install_path'/sobjs/' + ELSE DO + /* + If a shared library is not found, abort. + */ + SAY lib.so' not found! Aborting!' + EXIT Shared Library not found! Aborting! + END + END + ELSE + i=0 +END + +/* +AREXX is doing its own cleaning up of open files. +Close the file manually anyway. +*/ +IF ~CLOSE(SO_Read) THEN DO + SAY 'File so_dump closing failed!' + EXIT File so_dump opening failed! +END + +ADDRESS COMMAND 'delete so_dump' + +EXIT 0 |