How to copy soft link with target name in CMake - linux

I'm using cmake to copy a soft link 'libbssl.so' (which has target libssl.so.3) to a build subdirectory.
COMMAND ${CMAKE_COMMAND} -E copy ${OPENSSL_SSL_LIBRARY} ${CMAKE_CURRENT_BINARY_DIR}/lib
The copy command works as expected and copies the file, however with libssl.so as the filename and not libssl.so.3. How do I get cmake to save the filename as libssl.so.3 keeping in mind that I don't necessarily know this name in advance, i.e., I don't want to hard code it. I'm using find_package(OpenSSL).

I don't know about a convenient way to use the cmake command linke tool for this directly, but starting CMake 3.15, cmake provides the FOLLOW_SYMLINK_CHAIN for file(COPY) for copying the library file including the full symlink chain to the target directory.
You could create a cmake script to execute as command.
copy_symlink_chain.cmake
#[===[
Params:
LIBRARY : the name of the symlink to the lib
DESTINATION : the directory to copy the files to
]===]
file(COPY "${LIBRARY}" DESTINATION "${DESTINATION}" FOLLOW_SYMLINK_CHAIN)
...
COMMAND ${CMAKE_COMMAND} -D "LIBRARY=${OPENSSL_SSL_LIBRARY}" -D "DESTINATION=${CMAKE_CURRENT_BINARY_DIR}/lib" -P ${CMAKE_CURRENT_SOURCE_DIR}/copy_symlink_chain.cmake
...

Related

How do I move files out of a broken directory in linux?

I know the premise of the question may be confusing, but I want to understand what happened.
Recently I have been experimenting with the rockchip OK3399 single-chip computer(see here) and have installed a linux system on it with TF card installation. Using Putty and connecting with serial protocol, I was able to establish a connection with the OK3399 computer and control it through my laptop.
I am trying to self-learn some linux with the OK3399 system. I created a bash code by the name of displayvids.sh inside the directory /usr/bin, which is meant to take a variable number of pictures with a mipi camera and then save in a directory for work.
I finished writing the code, but for some reason I cannot run the .sh file when my working directory is not the /usr/bin directory, despite /usr/bin being in the %PATH% environment variable. So, I executed the following command:
mv /usr/bin/display* /usr/local/bin
... attempting to move the file to /usr/local/bin instead. The command ran successfully, but when I tried to run the command:
cd /usr/local/bin
It tells me that I cannot cd to bin
As seen from the above image, the /usr/local/bin is not even a directory. Why would mv succeed if the target was not a directory? How can I retrieve my bash file?
Why would mv succeed if the target was not a directory?
mv can also rename files:
mv foo.txt bar.txt
You renamed your script to bin and moved it under /usr/local.
You may want to remember to add a trailing slash next time, to have mv barf if the target isn't a directory:
mv /usr/bin/display* /usr/local/bin/
How can I retrieve my bash file?
Rename it back.
mv bin displayvids.sh
For future reference, you can use the file command to (try to) identify the contents of a file, if it's installed:
file bin
would have probably said bin: Bash script or similar.

Copying files using cpio - why do I get an "Invalid cross-device link" error?

For copying large files, I would like to try replacing in my shell scripts cp by cpio, because I hope to be able to fine-tune the performance by specifying explicit buffer sizes. The current development environment is Zsh on Cygwin on Windows 7, but by solution should also run on Linux.
My original copy command is
cp //some.share/some/file local_dir
I replaced it by
cpio -null -pd local_dir <<<//some.share/some/file
and I get the error message
//some.share/some/file: Invalid cross-device link
This surprises me. Why does cpio attempt to create a hard link here? After all, it is supposed to copy the file, not link to it!
I'm aware that I'm misusing cpio somewhat, in that cpio is supposed to copy archives, not individual files, but from my understanding of the -p command line switch, I thought that I could use it also for just copying files.

copy all files of same type using eclipse external tools configuration

I want to create an external tools configuration in eclipse that will copy all .war files in my target directory to my deployments folder on jboss. My attempt looks like this:
but I get:
/bin/cp: cannot stat ‘*.war’: No such file or directory
When I give the actual name of the war file, it works but I don't want to use this approach as the name of the war file will change as the project gets updated. How can I use *.war or equivalent in this configuration?
Expansion of '*' is done by the Shell not the program you run. So to do this you need to run the shell
For the command location specify:
/bin/sh
For the arguments:
-c "cp *.war /home/...."
which runs the shell specifying the command to be run.

Create Google Chrome extension package without specified files

Right now to create an extension with Google Chrome Extensions page we select a directory that contains created extension and it generates .crx file.
The problem is that it contains all files from this directory - for example, all docs, asset drafts, etc.
Is it possible to create some blacklist to ignore specified files like *.psd, *.pdf, docs/* ... ?
The Chromium team decided not to implement a manifest (or similar mechanism) for including only the desired files in a .CRX.
The recommended workflow is to have a build step that outputs only the needed files in a dist directory, and to create the CRX from that directory. This is common practice for JavaScript libraries.
My solution
I have created a .crxignore custom ignore file, like this:
.*
Makefile
*.md
bin
It is made for zip command! It is different than .gitignore. You can't add comments eg! See documentation: https://linux.die.net/man/1/zip , look for --exclude word.
Now you can create a zip without ignred files:
$ zip -qr -9 -X .out/out.zip . -x#.crxignore
# ^^^^^^^^^^^^^ using ignore file
After that I can convert zip to crx file with this go script: https://github.com/mmadfox/go-crx3 You have to build it with go build -o out/crx3 crx3/main.go command (you may get missing mod errors, but there will be the commands what you have to run). --> you can move your out/crx3 to where you want. Eg: [project]/bin/crx3.
I haven't tried, maybe chrome command also can convert zip to crx.
You have to generate a private key:
$ bin/crx3 keygen .out/key.pem
Final Makefile
build:
rm -f .out/out.zip
zip -qr -9 -X .out/out.zip . -x#.crxignore
bin/crx3 pack .out/out.zip -p .out/key.pem -o .out/out.crx
Build process:
$ make build
# --> build the .out/out.crx file
Try the command line program "zip", which could be found in cygwin if you're on windows, or is likely present on OSX, and easy to install if you're using linux.
zip package.zip -r * -x package.sh -x *.git* -x "*.*~" -x "*.pdf" docs/* "*.psd"

What's the best way to move a directory into place in a Makefile install?

I'm currently using the usual technique in my Makefile to install individual files:
install:
install -D executable ${BIN_DIR}
But I just ran across a situation where I need to move a whole directory and all files underneath it into place.
Is cp -r the best way or is there a more linux-y/unix-y way to do this?
Yeah, it's hard to think of a more unix-ish way that cp -r, although the -r is a relatively late addition to cp. I can tell you the way we used to do it, and that works neatly across filesystems and such:
Let src be the source directory you want to move, and /path/to/target be an absolute path to the target. Then you can use:
$ tar cf - src | (cd /path/to/target; tar xf -)
My version of install(1) (Debian) has:
-d, --directory
treat all arguments as directory names; create all components of the specified directories
-t, --target-directory=DIRECTORY
copy all SOURCE arguments into DIRECTORY
So if you wanted to use install(1) consistently throughout your Makefile you could do:
install -d destdir
install srcdir/* -t destdir
-t isn't recursive however - if srcdir contains directories, then they won't get copied.
Linking is another viable alternative. That would allow you to keep multiple directories (representing different versions) accessible.

Resources