1

I'm having a problem running ar command on Linux with ASTERISK *.o in command of custom_target. When running this command:

  target_build_cmd = [
    'ar', '-qcs', '/home/bassem/meson/lib.a', meson.project_build_root() + '/tmp/*.o',
  ]
target_dma_lib = custom_target (
  'target_lib', 
  output: lib.a,  
  build_by_default: true,
  command: target_build_cmd,
)

I get error:

/usr/bin/ar -qcs /home/bassem/meson/lib.a '/home/bassem/meson/crono_dma_driver/tools/meson/bf5/tmp/*.o'                                                                                                                                        /usr/bin/ar: /home/bassem/meson/tmp/*.o: No such file or directory 

It appends single quote for an unknown reason. While, when I run the command manually without the single quote it works:

ar -qcs /home/bassem/meson/lib.a /home/bassem/meson/crono_dma_driver/tools/meson/bf5/tmp/*.o                                                                                                   

Also, when I write one of the files instead of ASTRISK it works, e.g.

  target_build_cmd = [
    'ar', '-qcs', '/home/bassem/meson/lib.a', meson.project_build_root() + '/tmp/sysfs.o',
  ]

I tried to use unicode escape /tmp/\N{ASTERISK}.o, got the same error.

How to pass *.o in the command?

meson version: 0.60.3

Linux: 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Bassem Ramzy
  • 326
  • 3
  • 10

1 Answers1

2

First of all, it's a bit strange that you build library with custom_target - for such standard operation there is static_libary function, have you checked if it doesn't suffice to your needs?

Now, the question itself: meson doesn't support wildcard syntax and the reason for that is in reference FAQ:

Meson does not support this syntax and the reason for this is simple. This can not be made both reliable and fast. By reliable we mean that if the user adds a new source file to the subdirectory, Meson should detect that and make it part of the build automatically. ... The main backend of Meson is Ninja, which does not support wildcard matches either, and for the same reasons.

So, by the book, you should build array of object files and pass them as input parameter, not inside the command. (By the way, it's better not repeat and specify explicitly output, there are placeholders: @INPUT@, @OUTPUT@ - check in the reference).

However, as the next FAQ chapter explains, there is an workaround: wrapping all into own script and execute it as command (then meson looses control over what's going on at the cost of performance, duplication, hiding paths etc which doesn't look justified in this case).

pmod
  • 10,450
  • 1
  • 37
  • 50
  • Thanks for the prompt support. You are right, it's strange, but I had to do that since I don't have the source code, I extracted the .o files from a 3rd party .a static library to merge them with my static library. I got an answer from meson github group very much similar, issue https://github.com/mesonbuild/meson/issues/9790 – Bassem Ramzy Jan 09 '22 at 08:06