How to create the sunpinyin package for FreeBSD.
Mon, Mar 18 2024 14:37:21 KSTThe sunpinyin port was removed on June 26, 2021.
https://www.freshports.org/chinese/sunpinyin
However, since Nimf requires sunpinyin, I created the sunpinyin package myself. I disclose how to create the sunpinyin package for FreeBSD®.
The directory structure is as follows:
sunpinyin-pkg/
├── freebsd/
│ ╰── +MANIFEST
├── Makefile
╰── sunpinyin.diff
The +MANIFEST
file to create the package is as follows:
name: zh-sunpinyin
origin: chinese/sunpinyin
version: 3.0.0.r2
comment: Statistical language model based input method engine
maintainer: Hodong Kim <hodong@nimfsoft.art>
www: https://github.com/sunpinyin/sunpinyin
abi: FreeBSD:14:amd64
arch: freebsd:14:x86:64
prefix: /usr/local
licenselogic: or
licenses: [CDDL, LGPL21]
desc: SunPinyin is a statistical language model based Chinese input method.
deps: {
sqlite3: { origin: databases/sqlite3 },
libiconv: { origin: converters/libiconv }
}
Makefile
is as follows:
zh-sunpinyin-3.0.0.r2.pkg:
curl -o sunpinyin-3.0.0-rc2.tar.gz https://codeload.github.com/sunpinyin/sunpinyin/tar.gz/refs/tags/v3.0.0-rc2
tar xf sunpinyin-3.0.0-rc2.tar.gz
patch -i ../sunpinyin.diff -d sunpinyin-3.0.0-rc2
cd sunpinyin-3.0.0-rc2 && scons --install-sandbox=../freebsd
strip sunpinyin-3.0.0-rc2/libsunpinyin.so.3.0
cd sunpinyin-3.0.0-rc2 && \
scons --install-sandbox=../freebsd install
cd sunpinyin-3.0.0-rc2/src && gmake DESTDIR=../../freebsd -f sunpinyin-dictgen
install -m 644 sunpinyin.diff ./freebsd/usr/local/share/doc/sunpinyin/
find ./freebsd/usr/ -type l | sed 's/\.\/freebsd//g' > freebsd/plist
find ./freebsd/usr/ -type f | sed 's/\.\/freebsd//g' >> freebsd/plist
pkg create -m freebsd -r freebsd -p freebsd/plist -o .
clean:
rm -rf \
dict.utf8 \
dict.utf8-20131214.tar.bz2 \
lm_sc.3gm.arpa \
lm_sc.3gm.arpa-20140820.tar.bz2 \
sunpinyin-3.0.0-rc2 \
sunpinyin-3.0.0-rc2.tar.gz \
freebsd/usr \
freebsd/plist \
zh-sunpinyin-3.0.0.r2.pkg
sunpinyin.diff
is as follows:
diff --git a/SConstruct b/SConstruct
index e063c6d..e8b3d90 100644
--- a/SConstruct
+++ b/SConstruct
@@ -197,7 +197,7 @@ opts.Add('DATADIR', default='/usr/local/share')
opts.Add('ENABLE_PLUGINS', default=False)
opts.Add(PathVariable('PYTHON',
'python3 interpreter used to generate header files',
- '/usr/bin/python3',
+ '/usr/local/bin/python3',
PathIsExecutable))
#
@@ -391,7 +391,6 @@ def DoConfigure():
conf.CheckFunc('getopt_long')
conf.CheckFunc('getpagesize')
conf.CheckFunc('get_opt')
- conf.CheckCHeader('iconv.h')
conf.CheckCHeader('inttypes.h')
conf.CheckCHeader('locale.h')
conf.CheckCHeader('libintl.h')
@@ -477,7 +476,7 @@ def DoInstall():
lib_target_bin),
]
- lib_pkgconfig_target = env.Install(os.path.join(libdir, 'pkgconfig'),
+ lib_pkgconfig_target = env.Install(os.path.join(env['PREFIX'], 'libdata/pkgconfig'),
['sunpinyin-2.0.pc'])
bin_target = env.Install(bindir, bins)
man1_target = env.Install(man1dir, man1s)
diff --git a/src/ime-core/imi_options.cpp b/src/ime-core/imi_options.cpp
index 27c4470..67a8825 100644
--- a/src/ime-core/imi_options.cpp
+++ b/src/ime-core/imi_options.cpp
@@ -73,12 +73,15 @@ CSimplifiedChinesePolicy::loadResources()
if (!m_user_data_dir.size()) {
char path[256];
- const char *home = getenv("HOME");
- snprintf(path,
- sizeof(path),
- "%s/%s",
- home,
- SUNPINYIN_USERDATA_DIR_PREFIX);
+ const char *home = getenv("XDG_CONFIG_HOME");
+ if (home == NULL)
+ snprintf(path, sizeof(path),
+ "%s/.config/%s", getenv("HOME"),
+ SUNPINYIN_USERDATA_DIR_PREFIX);
+ else
+ snprintf(path, sizeof(path),
+ "%s/%s", home,
+ SUNPINYIN_USERDATA_DIR_PREFIX);
m_user_data_dir = path;
}
diff --git a/src/ime-core/imi_options.h b/src/ime-core/imi_options.h
index 38a292a..19205c8 100644
--- a/src/ime-core/imi_options.h
+++ b/src/ime-core/imi_options.h
@@ -52,7 +52,7 @@
#include "pinyin/hunpin_seg.h"
#ifndef SUNPINYIN_USERDATA_DIR_PREFIX
-#define SUNPINYIN_USERDATA_DIR_PREFIX ".sunpinyin"
+#define SUNPINYIN_USERDATA_DIR_PREFIX "sunpinyin"
#endif
struct CSimplifiedChinesePolicy : public IConfigurable {
diff --git a/src/ime-core/imi_winHandler.cpp b/src/ime-core/imi_winHandler.cpp
index 3adbfb4..e7d8156 100644
--- a/src/ime-core/imi_winHandler.cpp
+++ b/src/ime-core/imi_winHandler.cpp
@@ -87,6 +87,7 @@ CIMIWinHandler::throwBackKey(unsigned keycode,
void
CIMIWinHandler::updateStatus(int key, int value)
{
+#ifdef DEBUG
switch (key) {
case STATUS_ID_CN:
printf("CN status is "); break;
@@ -101,6 +102,7 @@ CIMIWinHandler::updateStatus(int key, int value)
printf("%d\n", value);
fflush(stdout);
+#endif
}
// -*- indent-tabs-mode: nil -*- vim:et:ts=4
diff --git a/src/sunpinyin-dictgen.mk.in b/src/sunpinyin-dictgen.mk.in
index 8572f1f..9f2ac03 100644
--- a/src/sunpinyin-dictgen.mk.in
+++ b/src/sunpinyin-dictgen.mk.in
@@ -37,21 +37,21 @@ lm_sc.3gm.arpa: ${SLM_AR}
${TAR} xmf $^
lm_sc.3gm: lm_sc.3gm.arpa dict.utf8
- slmpack $^ $@
+ ./slmpack $^ $@
lm_sc.t3g.orig: lm_sc.3gm
- slmthread $^ $@
+ ./slmthread $^ $@
lm_sc.t3g: lm_sc.t3g.orig
- tslmendian -e ${ENDIANNESS} -i $^ -o $@
+ ./tslmendian -e ${ENDIANNESS} -i $^ -o $@
pydict_sc.bin: dict.utf8 lm_sc.t3g
- genpyt -e ${ENDIANNESS} -i dict.utf8 -s lm_sc.t3g \
+ ./genpyt -e ${ENDIANNESS} -i dict.utf8 -s lm_sc.t3g \
-l pydict_sc.log -o $@
install: lm_sc.t3g pydict_sc.bin
- install -d ${DATA_DIR}
- install -m644 $^ ${DATA_DIR}
+ install -d $(DESTDIR)${DATA_DIR}
+ install -m 644 lm_sc.t3g pydict_sc.bin $(DESTDIR)${DATA_DIR}
clean:
rm -rf ${DICT_AR} ${SLM_AR} dict.utf8 lm_sc.3gm.arpa lm_sc.3gm \
After preparing the above directories and files, run make
within the sunpinyin-pkg
directory and zh-sunpinyin-3.0.0.r2.pkg
will be created after completing the task. It will probably take a few minutes.
hodong@:~ $ cd sunpinyin-pkg/
hodong@:~/sunpinyin-pkg $ find .
.
./freebsd
./freebsd/+MANIFEST
./Makefile
./sunpinyin.diff
hodong@:~/sunpinyin-pkg $ make
...
...
...
hodong@:~/sunpinyin-pkg $ ls -F
Makefile sunpinyin-3.0.0-rc2.tar.gz
freebsd/ sunpinyin.diff
sunpinyin-3.0.0-rc2/ zh-sunpinyin-3.0.0.r2.pkg