Coreutils の install (Ubuntu 20.04.3)

lsやsortなどの標準コマンド(GNU core utilities)を,ソースからインストールする方法を説明します.

環境

Ubuntu 20.04.3 LTS

インストール

wget https://ftp.jaist.ac.jp/pub/GNU/coreutils/coreutils-8.32.tar.xz
tar xfJ coreutils-8.32.tar.xz
cd coreutils-8.32/
./configure --prefix=/opt/coreutils-8.32
make
sudo mkdir /opt/coreutils-8.32
sudo make install

使ってみる

$ /opt/coreutils-8.32/bin/sort --version
sort (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and Paul Eggert.

改造してみる 1

vi src/sort.c
521行目
*** WARNING ***\n\

*** WARNING (^o^) ***\n\

make
sudo make install

/opt/coreutils-8.32/bin/sort --help
Usage: /opt/coreutils-8.32/bin/sort [OPTION]... [FILE]...
or: /opt/coreutils-8.32/bin/sort [OPTION]... --files0-from=F
(略)
*** WARNING (^o^) ***

改造してみる 2

vi src/sort.c
下記の様に4757行目, 4768行目, 4770行目, 4771行目を追加

4756 {
4757 struct timespec ts0, ts1;
4758 if (!nthreads)
4759 {
4760 unsigned long int np = num_processors (NPROC_CURRENT_OVERRIDABLE);
4761 nthreads = MIN (np, DEFAULT_MAX_THREADS);
4762 }
4763
4764 /* Avoid integer overflow later. */
4765 size_t nthreads_max = SIZE_MAX / (2 * sizeof (struct merge_node));
4766 nthreads = MIN (nthreads, nthreads_max);
4767
4768 clock_gettime(CLOCK_REALTIME, &ts0);
4769 sort (files, nfiles, outfile, nthreads);
4770 clock_gettime(CLOCK_REALTIME, &ts1);
4771 fprintf(stderr,"%ld.%09ld %ld.%09ld\n", ts0.tv_sec, ts0.tv_nsec, ts1.tv_sec, ts1.tv_n sec);
4772 }

make
sudo make install
/opt/coreutils-8.32/bin/sort src/sort.c > /dev/null
1648689893.859449263 1648689893.884153365

ソート前の時刻とソート後の時刻が表示される.
引き算結果がソート処理の時間.
データ読み込み時間を含まない

この記事が気に入ったらサポートをしてみませんか?