Ninja: only pass -Wl,--no-as-needed to shared object target

On d7159f95, (Ninja: Fix LINK_WHAT_YOU_USE link flag placement,
2021-06-24), we fixed usage of -Wl,--no-as-needed to override
-Wl,--as-needed from LDFLAGS. However, that change also passes
-Wl,--no-as-needed to `ar`, which is incorrect flag for `ar`.

Let's check the target type before passing down the flags.

Fix: #22487
34 jobs for !6418 with ninja-lwyu-ar in 6 minutes and 51 seconds (queued for 2 seconds)
detached
Status Job ID Name Coverage
  Build
manual build:centos6-x86_64 #6022875
linux docker build cmake manual
manual build:fedora34-ninja #6022876
linux-3.17 linux docker build cmake manual
manual build:macos-x86_64-makefiles #6022878
nonconcurrent xcode-12.5 shell macos cmake manual
manual build:macos-x86_64-ninja #6022877
nonconcurrent xcode-12.5 shell macos cmake manual
manual build:windows-vs2019-x64-ninja #6022879
nonconcurrent msvc-19.29-16.10 vs2019 shell windows cmake manual
passed lint:codespell #6022871
linux docker build cmake

00:00:26

passed lint:debian10-iwyu #6022872
linux docker build cmake

00:01:43

passed lint:fedora34-sphinx #6022874
linux-3.17 linux docker build cmake

00:04:53

passed lint:fedora34-tidy #6022873
linux-3.17 linux docker build cmake

00:06:51

 
  Test
created test:fedora34-ninja #6022880
x11 linux-3.17 linux docker cmake
created test:macos-x86_64-makefiles #6022882
nonconcurrent xcode-12.5 shell macos cmake
created test:macos-x86_64-ninja #6022881
nonconcurrent xcode-12.5 shell macos cmake
created test:windows-vs2019-x64-ninja #6022883
nonconcurrent msvc-19.29-16.10 vs2019 shell windows cmake
 
  Test Ext
created test:cuda10.2-nvidia #6022886
linux docker cuda-rt cmake
created test:debian10-ninja #6022884
linux-3.17 linux docker build cmake
created test:fedora34-makefiles #6022885
linux-3.17 linux docker build cmake
created test:fedora34-ninja-multi #6022887
linux-3.17 linux docker build cmake
created test:macos-x86_64-xcode #6022888
concurrent xcode-12.5 shell macos cmake
created test:windows-vs2019-x64 #6022889
concurrent msvc-19.29-16.10 vs2019 shell windows cmake
 
  External
passed cdash

passed ghostflow-check-master

passed ghostflow-check-release

passed cdash

passed cdash

passed cdash

passed cdash

passed cdash

passed cdash

passed cdash

passed cdash

passed cdash

passed cdash

passed cdash

passed ghostflow-check-master