步骤一 获取htop官方源码

  1. htop官网地址(https://htop.dev/
    在这里插入图片描述

  2. 获取htop源码地址
    在这里插入图片描述

  3. 通过htop官网获取htop源码在Git的仓库地址
    在这里插入图片描述htop源码在Git仓库地址:https://github.com/htop-dev/htop

  4. 在本地新建htop文件夹,将htop源码clone到本地
    mkdir htop
    cd htop/
    git clone https://github.com/htop-dev/htop

oplinux@ubuntu ~/open_project$ mkdir htop
oplinux@ubuntu ~/open_project$ cd htop/
oplinux@ubuntu ~/open_project/htop$
oplinux@ubuntu ~/open_project/htop$
oplinux@ubuntu ~/open_project/htop$
oplinux@ubuntu ~/open_project/htop$
oplinux@ubuntu ~/open_project/htop$ git clone https://github.com/htop-dev/htop
Cloning into 'htop'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 12259 (delta 4), reused 12 (delta 3), pack-reused 12241
Receiving objects: 100% (12259/12259), 3.93 MiB | 11.00 KiB/s, done.
Resolving deltas: 100% (9474/9474), done.
oplinux@ubuntu ~/open_project/htop$

步骤二 正式编译htop前,准备htop依赖的第三方so库libncursesw.so.5.9

  1. 检查Openwrt系统文件中是否有so库libncursesw.so.5.9,方法如下:
    找到Openwrt的本地源码目录,生成的第三方so库一般处于下述路径:
    Openwrt源码目录/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib

我本地Openwrt系统已经安装了libncursesw.so.5.9库:

oplinux@ubuntu ~/hi-wooya/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib [open_dev]$ ls libncursesw*
libncursesw.a  libncursesw.so  libncursesw.so.5  libncursesw.so.5.9
oplinux@ubuntu ~/hi-wooya/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib [open_dev]$

备注:如果安装了libncursesw.so.5.9库,可直接跳到步骤三执行htop编译操作

  1. Openwrt系统添加libncursesw.so.5.9库
    方法:通过Openwrt的make menuconfig执行配置生成libncursesw
  • make menuconfig配置界面选择libncursesw,路径如下: Libraries —> libncursesw
    在这里插入图片描述在这里插入图片描述
  • 配置完成后,在Openwrt源码目录再次执行make V=s即可生成libncursesw相关库,此时可在此查看路径Openwrt源码目录/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib中是否包含了libncursesw.so.5.9

步骤三 编译生成htop可执行程序

  1. 完成上述操作后,现在可以开始编译htop源码了
  2. 执行./autogen.sh生成configure配置程序
oplinux@ubuntu ~/open_project/htop/htop [master]$ ./autogen.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force --warnings=all
autoreconf: configure.ac: tracing
autoreconf: configure.ac: creating directory build-aux
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force --warnings=all
autoreconf: running: /usr/bin/autoheader --force --warnings=all
autoreconf: running: automake --add-missing --copy --force-missing --warnings=all
configure.ac:57: installing 'build-aux/compile'
configure.ac:15: installing 'build-aux/config.guess'
configure.ac:15: installing 'build-aux/config.sub'
configure.ac:16: installing 'build-aux/install-sh'
configure.ac:16: installing 'build-aux/missing'
Makefile.am:298: warning: patsubst -O%,,$(CFLAGS: non-POSIX variable name
Makefile.am:298: (probably a GNU make extension)
Makefile.am: installing './INSTALL'
Makefile.am: installing 'build-aux/depcomp'
autoreconf: Leaving directory `.'
oplinux@ubuntu ~/open_project/htop/htop [master]$

执行完./autogen.sh脚本后,可以发现htop源码目录多出了一个configure配置程序

oplinux@ubuntu ~/open_project/htop/htop [master]$ ls
aclocal.m4               build-aux          configure.ac           docs             htop.png            Makefile.am        OptionItem.c          ScreenManager.h  TraceScreen.h
Action.c                 CategoriesPanel.c  CONTRIBUTING.md        dragonflybsd     htop.svg            Makefile.in        OptionItem.h          scripts          unsupported
Action.h                 CategoriesPanel.h  COPYING                EnvScreen.c      IncSet.c            MemoryMeter.c      Panel.c               Settings.c       UptimeMeter.c
Affinity.c               ChangeLog          CPUMeter.c             EnvScreen.h      IncSet.h            MemoryMeter.h      Panel.h               Settings.h       UptimeMeter.h
Affinity.h               ClockMeter.c       CPUMeter.h             freebsd          InfoScreen.c        Meter.c            Process.c             SignalsPanel.c   UsersTable.c
AffinityPanel.c          ClockMeter.h       CRT.c                  FunctionBar.c    InfoScreen.h        Meter.h            Process.h             SignalsPanel.h   UsersTable.h
AffinityPanel.h          ColorsPanel.c      CRT.h                  FunctionBar.h    INSTALL             MetersPanel.c      ProcessList.c         solaris          Vector.c
AUTHORS                  ColorsPanel.h      darwin                 Hashtable.c      iwyu                MetersPanel.h      ProcessList.h         SwapMeter.c      Vector.h
autogen.sh               ColumnsPanel.c     DateMeter.c            Hashtable.h      linux               NetworkIOMeter.c   ProcessLocksScreen.c  SwapMeter.h      XUtils.c
autom4te.cache           ColumnsPanel.h     DateMeter.h            Header.c         ListItem.c          NetworkIOMeter.h   ProcessLocksScreen.h  SysArchMeter.c   XUtils.h
AvailableColumnsPanel.c  CommandScreen.c    DateTimeMeter.c        Header.h         ListItem.h          NEWS               ProvideCurses.h       SysArchMeter.h   zfs
AvailableColumnsPanel.h  CommandScreen.h    DateTimeMeter.h        HostnameMeter.c  LoadAverageMeter.c  Object.c           README                TasksMeter.c
AvailableMetersPanel.c   Compat.c           DiskIOMeter.c          HostnameMeter.h  LoadAverageMeter.h  Object.h           README.md             TasksMeter.h
AvailableMetersPanel.h   Compat.h           DiskIOMeter.h          htop.1.in        Macros.h            openbsd            RichString.c          TESTPLAN
BatteryMeter.c           config.h.in        DisplayOptionsPanel.c  htop.c           MainPanel.c         OpenFilesScreen.c  RichString.h          test_spec.lua
BatteryMeter.h           configure          DisplayOptionsPanel.h  htop.desktop     MainPanel.h         OpenFilesScreen.h  ScreenManager.c       TraceScreen.c
oplinux@ubuntu ~/open_project/htop/htop [master]$
  1. 配置交叉编译器、指定libncursesw.so.5.9所在的路径以及软件运行平台,主要通过指定下述变量实现:
CC:交叉编译器名称
LDFLAGS:libncursesw.so.5.9所在库目录
CFLAGS:头文件路径
--prefix:指定htop可执行程序的安装目录

大家根据自己的实际情况修改目录路径,下述指令是我的配置情况:
./configure --host=mipsel-openwrt-linux CC=mipsel-openwrt-linux-gcc --prefix=/data1/oplinux/open_project/htop LDFLAGS="-L/data1/oplinux/hi-wooya/openwr t-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib -lncursesw -lncurses" CFLAGS="-I/data1/oplinux/hi-wooya/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/u sr/include"

oplinux@ubuntu ~/open_project/htop/htop [master]$ ./configure --host=mipsel-openwrt-linux CC=mipsel-openwrt-linux-gcc --prefix=/data1/oplinux/open_project/htop LDFLAGS="-L/data1/oplinux/hi-wooya/openwr
t-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib -lncursesw -lncurses" CFLAGS="-I/data1/oplinux/hi-wooya/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/u
sr/include"
checking build system type... x86_64-pc-linux-uclibc
checking host system type... mipsel-openwrt-linux-gnu
checking target system type... mipsel-openwrt-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for mipsel-openwrt-linux-strip... mipsel-openwrt-linux-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for mipsel-openwrt-linux-gcc... mipsel-openwrt-linux-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether mipsel-openwrt-linux-gcc accepts -g... yes
checking for mipsel-openwrt-linux-gcc option to accept ISO C89... none needed
checking whether mipsel-openwrt-linux-gcc understands -c and -o together... yes
checking dependency style of mipsel-openwrt-linux-gcc... gcc3
checking how to run the C preprocessor... mipsel-openwrt-linux-gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for mipsel-openwrt-linux-gcc... (cached) mipsel-openwrt-linux-gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether mipsel-openwrt-linux-gcc accepts -g... (cached) yes
checking for mipsel-openwrt-linux-gcc option to accept ISO C89... (cached) none needed
checking whether mipsel-openwrt-linux-gcc understands -c and -o together... (cached) yes
checking dependency style of mipsel-openwrt-linux-gcc... (cached) gcc3
checking for mipsel-openwrt-linux-gcc option to accept ISO C99... -std=gnu99
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking for ANSI C header files... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking whether sys/types.h defines makedev... yes
checking sys/sysmacros.h usability... yes
checking sys/sysmacros.h presence... yes
checking for sys/sysmacros.h... yes
checking execinfo.h usability... no
checking execinfo.h presence... no
checking for execinfo.h... no
checking for pid_t... yes
checking for uid_t in sys/types.h... yes
checking for uint8_t... yes
checking for uint16_t... yes
checking for uint32_t... yes
checking for uint64_t... yes
checking for ceil in -lm... yes
checking for library containing dlopen... -ldl
checking for library containing clock_gettime... none required
checking for clock_gettime... yes
checking for faccessat... yes
checking for fstatat... yes
checking for host_get_clock_service... no
checking for memfd_create... no
checking for openat... yes
checking for readlinkat... yes
checking for library containing backtrace... no
checking for wadd_wch in -lncursesw... no
checking for wadd_wch in -lncurses... no
checking for addnwstr in -lncursesw6... no
checking for addnwstr in -lncursesw... yes
checking ncursesw/curses.h usability... yes
checking ncursesw/curses.h presence... no
configure: WARNING: ncursesw/curses.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: ncursesw/curses.h: proceeding with the compiler's result
checking for ncursesw/curses.h... yes
checking for library containing keypad... none required
checking for usable sched_setaffinity... yes (assumed while cross compiling)
checking for cap_init in -lcap... no
checking sys/capability.h usability... no
checking sys/capability.h presence... no
checking for sys/capability.h... no
checking for mipsel-openwrt-linux-pkg-config... no
checking for pkg-config... /usr/bin/pkg-config
configure: WARNING: using cross tools not prefixed with host triplet
checking pkg-config is at least version 0.9.0... yes
checking for LIBNL3... no
checking for LIBNL3GENL... no
checking sensors/sensors.h usability... no
checking sensors/sensors.h presence... no
checking for sensors/sensors.h... no
checking whether C compiler accepts -Wnull-dereference... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating htop.1
config.status: creating config.h
config.status: executing depfiles commands

  htop 3.0.6-dev

  platform:                  linux
  (Linux) proc directory:    /proc
  (Linux) openvz:            no
  (Linux) vserver:           no
  (Linux) ancient vserver:   no
  (Linux) affinity:          check
  (Linux) delay accounting:  no
  (Linux) sensors:           no
  (Linux) capabilities:      no
  unicode:                   yes
  hwloc:                     no
  debug:                     no
  static:                    no

oplinux@ubuntu ~/open_project/htop/htop [master]$
  1. 执行make ,即可在htop源码目录生成可在Openwrt平台上运行的htop程序
oplinux@ubuntu ~/open_project/htop/htop [master]$ ls
aclocal.m4               CategoriesPanel.c  config.status          DisplayOptionsPanel.o  htop.desktop        Makefile           OptionItem.c          ScreenManager.o  TraceScreen.o
Action.c                 CategoriesPanel.h  configure              docs                   htop.o              Makefile.am        OptionItem.h          scripts          unsupported
Action.h                 CategoriesPanel.o  configure.ac           dragonflybsd           htop.png            Makefile.in        OptionItem.o          Settings.c       UptimeMeter.c
Action.o                 ChangeLog          CONTRIBUTING.md        EnvScreen.c            htop.svg            MemoryMeter.c      Panel.c               Settings.h       UptimeMeter.h
Affinity.c               ClockMeter.c       COPYING                EnvScreen.h            IncSet.c            MemoryMeter.h      Panel.h               Settings.o       UptimeMeter.o
Affinity.h               ClockMeter.h       CPUMeter.c             EnvScreen.o            IncSet.h            MemoryMeter.o      Panel.o               SignalsPanel.c   UsersTable.c
Affinity.o               ClockMeter.o       CPUMeter.h             freebsd                IncSet.o            Meter.c            Process.c             SignalsPanel.h   UsersTable.h
AffinityPanel.c          ColorsPanel.c      CPUMeter.o             FunctionBar.c          InfoScreen.c        Meter.h            Process.h             SignalsPanel.o   UsersTable.o
AffinityPanel.h          ColorsPanel.h      CRT.c                  FunctionBar.h          InfoScreen.h        Meter.o            ProcessList.c         solaris          Vector.c
AffinityPanel.o          ColorsPanel.o      CRT.h                  FunctionBar.o          InfoScreen.o        MetersPanel.c      ProcessList.h         stamp-h1         Vector.h
AUTHORS                  ColumnsPanel.c     CRT.o                  Hashtable.c            INSTALL             MetersPanel.h      ProcessList.o         SwapMeter.c      Vector.o
autogen.sh               ColumnsPanel.h     darwin                 Hashtable.h            iwyu                MetersPanel.o      ProcessLocksScreen.c  SwapMeter.h      XUtils.c
autom4te.cache           ColumnsPanel.o     DateMeter.c            Hashtable.o            linux               NetworkIOMeter.c   ProcessLocksScreen.h  SwapMeter.o      XUtils.h
AvailableColumnsPanel.c  CommandScreen.c    DateMeter.h            Header.c               ListItem.c          NetworkIOMeter.h   ProcessLocksScreen.o  SysArchMeter.c   XUtils.o
AvailableColumnsPanel.h  CommandScreen.h    DateMeter.o            Header.h               ListItem.h          NetworkIOMeter.o   Process.o             SysArchMeter.h   zfs
AvailableColumnsPanel.o  CommandScreen.o    DateTimeMeter.c        Header.o               ListItem.o          NEWS               ProvideCurses.h       SysArchMeter.o
AvailableMetersPanel.c   Compat.c           DateTimeMeter.h        HostnameMeter.c        LoadAverageMeter.c  Object.c           README                TasksMeter.c
AvailableMetersPanel.h   Compat.h           DateTimeMeter.o        HostnameMeter.h        LoadAverageMeter.h  Object.h           README.md             TasksMeter.h
AvailableMetersPanel.o   Compat.o           DiskIOMeter.c          HostnameMeter.o        LoadAverageMeter.o  Object.o           RichString.c          TasksMeter.o
BatteryMeter.c           config.h           DiskIOMeter.h          htop                   Macros.h            openbsd            RichString.h          TESTPLAN
BatteryMeter.h           config.h.in        DiskIOMeter.o          htop.1                 MainPanel.c         OpenFilesScreen.c  RichString.o          test_spec.lua
BatteryMeter.o           config.h.in~       DisplayOptionsPanel.c  htop.1.in              MainPanel.h         OpenFilesScreen.h  ScreenManager.c       TraceScreen.c
build-aux                config.log         DisplayOptionsPanel.h  htop.c                 MainPanel.o         OpenFilesScreen.o  ScreenManager.h       TraceScreen.h
oplinux@ubuntu ~/open_project/htop/htop [master]$
oplinux@ubuntu ~/open_project/htop/htop [master]$
oplinux@ubuntu ~/open_project/htop/htop [master]$
oplinux@ubuntu ~/open_project/htop/htop [master]$ file htop
htop: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked, interpreter /lib/ld-, not stripped
oplinux@ubuntu ~/open_project/htop/htop [master]$
  1. 最后通过scp或者winscp工具将htoplibncursesw.so.5.9上传至自己的开发板。
  • htop 上传至开发板 /usr/bin目录
  • libncursesw.so.5.9上传至开发板/usr/lib目录
  1. 在开发板创建libncursesw.so.5的软连接,执行指令
root@Hiwooya:/usr/bin# ln -s /usr/lib/libncursesw.so.5.9 /usr/lib/libncursesw.so.5
root@Hiwooya:/usr/bin#
root@Hiwooya:/usr/bin#
  1. 将htop程序添加可执行权限
root@Hiwooya:/usr/bin# chmod 777 htop
root@Hiwooya:/usr/bin#
  1. 在openwrt系统运行htop
    在这里插入图片描述

参考文章

Logo

更多推荐