お茶漬けぶろぐ

M1 MacでRosetta2を使わずにpdftkを使いたい

前まではterminal.appはRosetta2経由で(x86_64で)動かしていたのだけど、Rosetta2を使わずにつかってみたい気持ちになったので、そういうふうに環境を作り直した。
それはまぁ良いのだが、使っていたツールが全部対応しているとも限らない。というわけで、今回はPDFの簡単な処理ならおまかせのやつ、pdftkを使いたかったところ、未対応くさかった。
どうにかして入れてみようと思う。

今回は作業記録なので見出しとかつけにくいので、だらだら書くぞ。

取り敢えずチャレンジ。

❯ brew install pdftk-java
Error: pdftk-java: no bottle available!
You can try to install from source with:
  brew install --build-from-source pdftk-java
Please note building from source is unsupported. You will encounter build
failures with some formulae. If you experience any issues please create pull
requests instead of asking for help on Homebrew's GitHub, Twitter or any other
official channels.

sourceからビルドしろとのこと。やったるで。

❯ brew install --build-from-source pdftk-java
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/manifests/15.0.2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:063189cdbad2c9ef5ab5e7dc34cea
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:063189cdbad2c9
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gradle/manifests/7.0.2_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gradle/blobs/sha256:0d659be86c309f4ac28003a0593d36
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:0d659be86c309f
######################################################################## 100.0%
Error: openjdk@8: no bottle available!
You can try to install from source with:
  brew install --build-from-source openjdk@8
Please note building from source is unsupported. You will encounter build
failures with some formulae. If you experience any issues please create pull
requests instead of asking for help on Homebrew's GitHub, Twitter or any other
official channels.

依存関係のopenjdk@8がインストールできんからこれもsourceからいけと。

❯ brew install --build-from-source openjdk@8 
==> Downloading https://raw.githubusercontent.com/Homebrew/formula-patches/9976a857d574de2927c580f1
######################################################################## 100.0%
==> Downloading https://cdn.azul.com/zulu/bin/zulu7.42.0.13-ca-jdk7.0.282-macosx_x64.tar.gz
######################################################################## 100.0%
==> Downloading https://openjdk-sources.osci.io/openjdk8/openjdk8u282-ga.tar.xz
######################################################################## 100.0%
==> Patching
==> Applying xcode.patch
patching file common/autoconf/basics.m4
patching file common/autoconf/flags.m4
patching file common/autoconf/generated-configure.sh
Hunk #1 succeeded at 1897 (offset 2 lines).
Hunk #2 succeeded at 14009 (offset 1 line).
Hunk #3 succeeded at 26774 (offset 23 lines).
Hunk #4 succeeded at 26837 (offset 23 lines).
Hunk #5 succeeded at 41295 (offset 23 lines).
Hunk #6 succeeded at 41394 (offset 23 lines).
Hunk #7 succeeded at 41420 (offset 23 lines).
Hunk #8 succeeded at 41485 (offset 23 lines).
Hunk #9 succeeded at 42170 (offset 23 lines).
Hunk #10 succeeded at 42259 (offset 23 lines).
Hunk #11 succeeded at 48934 (offset 23 lines).
patching file common/autoconf/libraries.m4
patching file common/autoconf/platform.m4
patching file common/autoconf/toolchain.m4
patching file hotspot/make/bsd/makefiles/gcc.make
patching file hotspot/make/bsd/makefiles/jsig.make
patching file hotspot/src/os/aix/vm/decoder_aix.hpp
patching file hotspot/src/os/bsd/vm/decoder_machO.hpp
patching file hotspot/src/os/windows/vm/decoder_windows.hpp
patching file hotspot/src/share/vm/classfile/classLoader.hpp
patching file hotspot/src/share/vm/prims/jvmtiImpl.hpp
patching file hotspot/src/share/vm/runtime/perfData.hpp
patching file hotspot/src/share/vm/utilities/decoder.hpp
patching file hotspot/src/share/vm/utilities/decoder_elf.hpp
patching file jdk/make/lib/CoreLibraries.gmk
Hunk #1 succeeded at 409 (offset -1 lines).
Hunk #2 succeeded at 443 (offset -1 lines).
Hunk #3 succeeded at 504 (offset -1 lines).
patching file jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m
==> common/autoconf/autogen.sh
==> ./configure --with-boot-jdk-jvmargs=-Duser.home=/Users/tea/Library/Caches/Homebrew/java_cache -
Last 15 lines from /Users/tea/Library/Logs/Homebrew/openjdk@8/02.configure:
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for stdio.h... (cached) yes
checking size of int *... 8
configure: The tested number of bits in the target (64) differs from the number of bits expected to be found in the target (32).
configure: I'll retry after setting the platforms compiler target bits flag to -m32
checking size of int *... 0
configure: error: The tested number of bits in the target (0) differs from the number of bits expected to be found in the target (32)
configure exiting with result code 1

Do not report this issue to Homebrew/brew or Homebrew/core!

These open issues may also help:
openjdk 16 https://github.com/Homebrew/homebrew-core/pull/72535
openjdk 15.0.3 https://github.com/Homebrew/homebrew-core/pull/76313
OpenJDK is somewhat broken on newer MacOS instances, console is flooded with errors when using JMeter, AdoptOpenJDK has no issues https://github.com/Homebrew/homebrew-core/issues/66953

だめっぽい

別にopenjdk@8のインストールは主目的じゃないので、他のJDKを突っ込んでみようの巻。
あと、gradleでビルドするので、そいつもいれとく。(必要かは知らない…)

❯ brew tap homebrew/cask-versions
❯ brew install adoptopenjdk8 --cask
❯ brew install gradle

ほんで依存関係をいじって(openjdk@8に依存しないように変更して)再度pdftk-javaを突っ込んで見る

❯ brew edit pdftk-java
❯ brew install --build-from-source pdftk-java

エラーなく入ったらしいので実行してみるが、javaが見つからないらしい。

❯ pdftk
/opt/homebrew/bin/pdftk: line 3: /bin/java: No such file or directory
/opt/homebrew/bin/pdftk: line 3: exec: /bin/java: cannot execute: No such file or directory
❯ which java
/usr/bin/java

/bin/javaとしてシンボリックリンクを張ろうと思ったが、怒られた。

sudo ln -s /usr/bin/java /bin/java
Password:
ln: /bin/java: Operation not permitted

Macの「System Integrity Protection」というもののおかげで、/binの下はいじれないようになっているようだ(ほかにも/System, /sbin, /usr, /Applicationsも保護されているらしい)
これをオフにしても良いのだけど、セキュリティ機能なんでしょ?変にいじるのも嫌なので、javaをてきとうに呼び出せるようにしてやれ
さっき入れたadoptopenjdkは/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/javaとして入っているらしく、pdftkjava呼び出し部を見ると、exec "${JAVA_HOME}/bin/java"というように呼び出しているので、/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Homeまでを環境変数JAVA_HOMEに突っ込んでおけば良い。
システムごとJAVA_HOMEを書き換えるのは気まずいので、呼び出し直前になんとかすればええじゃろ。

JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home pdftk

…というわけで、取り敢えず使えるようになった。閲覧パスワードを除去する(pdftk INPUT_PDF input_pw PASSWORD output OUTPUT_PDF)のはうまく動いた。他の機能が動くかどうかは確認してない。ま、駄目だったらその時考えます。

しかし、MacってなんでIMEのモードがシステム共通なんだろうね。アプリケーションごとに状態を保持してほしい…コマンド打ちながら記事書くとかメモ書くとか、そういうのくっそ面倒くさいんだけどな…

おしまい。

< pvr.chinachuをAndroid環境で使いたい

S.M.A.R.T.エラーがちゃんと通知された(?) >