We are shipping some drivers for some linux for our usb products. And in our driver code to make it distribution independent we have to dynamically get the distribution name and find whether there are libraries available in each target distribution at runtime.

To do that, we need to run some commands like ldconfig, pkg-config etc etc. And this question is related to this one. So according to the answer there some distributions may have commands and it's always good to find out whether those commands are available in the distribution before executing them.

So the question is to find out whether these commands are available or not. I'm thinking about checking executable file for it's existance. for a example,

if [ -f /usr/bin/pkg-config ] ; then

Any other better way to do this ?

  • You can check which command to check.. which pkg-config – Piyush Jain Sep 12 '16 at 6:39

I would do it like this:

if type pkg-config >/dev/null 2>/dev/null; then …

But as I commented on your previous question, the pkg-config may not be available even on systems that use pkg-config. Why don't you want to ship your driver packaged according to the distribution-specific standard? Both Debian and RedHat packages have provisions to request specific libraries/versions to be installed.

Compare to the work you did in order to make your device driver the packaging even for several different distributions is nearly nothing.

  • if [ "foo$PKGCONFIG" != "foo" ]; you can also test $? to check whether which inside the command substitution succeeded (except when initializing a local variable). – phg Sep 12 '16 at 7:45
  • The problem is that our sales engineers are not into the linux , so they have little understanding about distributions and packages. When I explain them that there are different linux distributions do exist, so that's why there are more opportunities in the linux side, they are against me and they don't like that idea. They don't like to give up their wisdom "always work" into "we need to make it work". – sandun dhammika Sep 14 '16 at 7:35
  • @sandundhammika, then don't tell them that there are also QNX, VxWorks, etc;) – Serge Sep 14 '16 at 16:47
  • And, again, pkg-config is about development packages, not about binary ones. – Serge Sep 14 '16 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.