makefile - NXP - busybox环境下makefile中调用系统命令的方法
文章目录
- makefile - NXP - busybox环境下makefile中调用系统命令的方法
- 概述
- 笔记
- 环境准备
- 用一个makefile来实验
- END
makefile - NXP - busybox环境下makefile中调用系统命令的方法
概述
前面实验(debug - MCUXpresso - 从NXP工程做一个makefile工程出来), 在makefile中居然不能调用clear命令,好惊讶。
刚才搞明白了,在busybox环境下,clear命令都是busybox的内建命令,并不是一个外部命令(没法找到clear.exe)。必须用busybox来调用clear命令。
笔记
环境准备
用的是MCUXpresso的命令行编译环境
@echo off
rem @file mcu_expresso_cmd_env.bat
rem @breif MCUXpresso IDE v25.6.136 的命令行环境
set path=C:\nxp\MCUXpressoIDE_25.6.136\ide\plugins\com.nxp.mcuxpresso.tools.win32_25.6.0.202501151204\buildtools\bin;%path%
set path=C:\nxp\MCUXpressoIDE_25.6.136\ide\plugins\com.nxp.mcuxpresso.tools.win32_25.6.0.202501151204\tools\bin;%path%
cmd /k "sh"
运行mcu_expresso_cmd_env.bat, 看一下sh的版本
D:/my_dev/my_test/nxp-build-test/v0.1 $ where sh
C:\nxp\MCUXpressoIDE_25.6.136\ide\plugins\com.nxp.mcuxpresso.tools.win32_25.6.0.202501151204\buildtools\bin\sh.exe
D:/my_dev/my_test/nxp-build-test/v0.1 $ sh --help
BusyBox v1.37.0.git (2023-11-14 08:47:30 UTC)Usage: sh [-il] [-|+Cabefmnuvx] [-|+o OPT]... [-c 'SCRIPT' [ARG0 ARGS] | FILE ARGS | -s ARGS]Unix shell interpreter
可知,nxp中用的sh, 是busybox的一个程序。
在sh环境中,用clear命令来清屏,是可以的。
找clear在哪来?找不到,说明clear命令是一个busybox内部命令。也有可能是win10 cmd的一个内建命令。
D:/my_dev/my_test/nxp-build-test/v0.1 $ where clear
信息: 用提供的模式无法找到文件。
D:/my_dev/my_test/nxp-build-test/v0.1 $ where where
C:\Windows\System32\where.exe
但是在makefile中调用clear, 会失败的。
这说明,在makefile中调用的命令,都是外部命令才行。
因为sh就是一个busybox环境下的程序,那么看看busybox有哪些内部命令
D:/my_dev/my_test/nxp-build-test/v0.1 $ where sh
C:\nxp\MCUXpressoIDE_25.6.136\ide\plugins\com.nxp.mcuxpresso.tools.win32_25.6.0.202501151204\buildtools\bin\sh.exe
D:/my_dev/my_test/nxp-build-test/v0.1 $ ls C:\nxp\MCUXpressoIDE_25.6.136\ide\plugins\com.nxp.mcuxpresso.tools.win32_25.6.0.202501151204\buildtools\bin
ls: C:nxpMCUXpressoIDE_25.6.136idepluginscom.nxp.mcuxpresso.tools.win32_25.6.0.202501151204buildtoolsbin: No such file or directory
D:/my_dev/my_test/nxp-build-test/v0.1 $ busybox --help
BusyBox v1.37.0.git (2023-11-14 08:47:30 UTC)
(glob)
D:/my_dev/my_test/nxp-build-test/v0.1 $ busybox --help
BusyBox v1.37.0.git (2023-11-14 08:47:30 UTC)
(glob)BusyBox is copyrighted by many authors between 1998-2023.
Licensed under GPLv2. See source distribution for detailed
copyright notices.Usage: busybox [function [arguments]...]or: busybox --list[-full]or: busybox --install [-s] [-u|DIR]or: busybox --uninstall [-n] fileor: function [arguments]...BusyBox is a multi-call binary that combines many common Unixutilities into a single executable. The shell in this buildis configured to run built-in utilities without $PATH search.You don't need to install a link to busybox for each utility.To run external program, use full path (/sbin/ip instead of ip).Currently defined functions:[, [[, ar, arch, ascii, ash, awk, base32, base64, basename, bash, bc, bunzip2, busybox, bzcat, bzip2, cal, cat,cdrop, chattr, chmod, cksum, clear, cmp, comm, cp, cpio, crc32, cut, date, dc, dd, df, diff, dirname, dos2unix,dpkg, dpkg-deb, drop, du, echo, ed, egrep, env, expand, expr, factor, false, fgrep, find, fold, free, fsync,ftpget, ftpput, getopt, grep, groups, gunzip, gzip, hd, head, hexdump, httpd, iconv, id, inotifyd, install,ipcalc, jn, kill, killall, less, link, ln, logname, ls, lsattr, lzcat, lzma, lzop, lzopcat, man, md5sum, mkdir,mktemp, mv, nc, nl, nproc, od, paste, patch, pdrop, pgrep, pidof, pipe_progress, pkill, printenv, printf, ps,pwd, readlink, realpath, reset, rev, rm, rmdir, rpm, rpm2cpio, sed, seq, sh, sha1sum, sha256sum, sha3sum,sha512sum, shred, shuf, sleep, sort, split, ssl_client, stat, strings, su, sum, sync, tac, tail, tar, tee,test, time, timeout, touch, tr, true, truncate, ts, tsort, ttysize, uname, uncompress, unexpand, uniq,unix2dos, unlink, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vi, watch, wc, wget, which,whoami, whois, xargs, xxd, xz, xzcat, yes, zcat
D:/my_dev/my_test/nxp-build-test/v0.1 $
可以看到busybox有内建的clear命令
那就可以在makefile中调用 busybox clear, 而不是直接调用clear. 其他busybox内建命令同理。
用一个makefile来实验
# @file makefile
# @brief 从build.bat进化出来的makefile
# v0.1 最简单的makefile, 从.bat直接改过来# makefile_obj : depend(可选)
# action
# makefile_obj从行首开始
# action必须从TAB键开始
# 命令之前加@, 就关掉了echo回显all:@busybox clear
# clear@echo ----------@echo END@echo ----------
在busyboxy的环境中,执行这个makefile
到此,就可以调用系统命令了。但是这些命令不能按照普通的写法,必须用busybox来调用.
等于是这些系统命令,都是busybox实现的内建命令。
在makefile中能执行的命令,都必须是外部命令才行。