diff --git a/backend/Dockerfile.postgres b/backend/Dockerfile.postgres index 5a5a8bf..a101363 100644 --- a/backend/Dockerfile.postgres +++ b/backend/Dockerfile.postgres @@ -4,43 +4,56 @@ FROM postgres:16-bookworm # Debian / PGDG 仓库里都没有 postgresql-16-zhparser / libscws-dev / scws 包, # 必须从 GitHub 拉源码自己 make。 # +# 关键点:scws 仓库年代久远,自带的 autotools 脚本跟新 automake (>=1.16) 不兼容 +# (Makefile.am:24: error: '#' comment at start of rule is unportable) +# 所以绕过 autotools,直接 gcc 编译 libscws/*.c 然后 ld 拼 .so +# # 步骤: # 1) 装编译工具链 + PG dev headers -# 2) 编译 scws(autotools 项目,先 ./acprep 生成 configure) +# 2) 手编 libscws(绕过 autotools)+ 装到 /usr/local # 3) 编译 zhparser(PGXS 扩展,直接 make) # # build 时间:~3-5 分钟 -# 产物:/usr/lib/postgresql/16/lib/zhparser.so + /usr/lib/libscws.so +# 产物: +# /usr/local/lib/libscws.so* +# /usr/local/include/scws/*.h +# /usr/lib/postgresql/16/lib/zhparser.so RUN set -eux; \ - # 1) 编译工具 + PG dev headers apt-get update; \ apt-get install -y --no-install-recommends \ build-essential \ git \ ca-certificates \ - # autotools(scws 依赖) - autoconf \ - automake \ - libtool \ # pg_config / pgxs(编译 PG 扩展用) postgresql-server-dev-16; \ rm -rf /var/lib/apt/lists/* -# 2) 编译装 scws(autotools:先 ./acprep 生成 configure,再 ./configure && make) +# 2) 手编 libscws(绕过 autotools — Makefile.am 不兼容新 automake) RUN set -eux; \ cd /tmp; \ git clone --depth 1 https://github.com/hightman/scws.git; \ - cd scws; \ - ./acprep; \ - ./configure --prefix=/usr; \ - make -j$(nproc); \ - make install; \ + cd scws/libscws; \ + # scws 的 autotools 会生成 version.h,手编自己造 + printf '#define SCWS_VERSION "1.2.3"\n#define SCWS_BUILT __DATE__ " " __TIME__\n' > version.h; \ + # 编译所有 .c + gcc -c -O2 -fPIC -Wall \ + charset.c crc32.c pool.c scws.c xdict.c darray.c rule.c lock.c xdb.c xtree.c; \ + # 装头文件 + mkdir -p /usr/local/include/scws; \ + cp charset.h crc32.h pool.h scws.h xdict.h darray.h rule.h xdb.h xtree.h version.h /usr/local/include/scws/; \ + # 拼 .so + gcc -shared -Wl,-soname,libscws.so.1 -o libscws.so.1.0.0 *.o -lc; \ + cp libscws.so.1.0.0 /usr/local/lib/; \ + ln -sf libscws.so.1.0.0 /usr/local/lib/libscws.so.1; \ + ln -sf libscws.so.1.0.0 /usr/local/lib/libscws.so; \ ldconfig; \ cd /; \ rm -rf /tmp/scws -# 3) 编译装 zhparser(PGXS 扩展,直接 make) +# 3) 编译 zhparser(PGXS — 直接 make) +# 注意:zhparser 内部用 #include ,需要 /usr/local/include 在 CPATH 上 +ENV CPATH=/usr/local/include RUN set -eux; \ cd /tmp; \ git clone --depth 1 https://github.com/zhparser/zhparser.git; \ @@ -50,5 +63,5 @@ RUN set -eux; \ cd /; \ rm -rf /tmp/zhparser -# 验证:扩展文件 + scws .so 都已就位 -RUN ls -la /usr/lib/postgresql/16/lib/zhparser.so /usr/lib/libscws.so* 2>&1 | head -5 +# 验证 +RUN ls -la /usr/lib/postgresql/16/lib/zhparser.so /usr/local/lib/libscws.so* 2>&1 | head -5