Linux build:头文件安装

文章目录

  • 1. 前言
  • 2. 安装头文件

1. 前言

限于作者能力水平,本文可能存在谬误,因此而给读者带来的损失,作者不做任何承诺。

2. 安装头文件

Linux通过下面的命令

$makeARCH=arm headers_install

导出头文件给用户空间,通常是给glibc这样的库使用,但用户空间程序也可以直接使用。

先看linux/Makefile

...PHONY+=__headers __headers:$(version_h)scripts_basic uapi-asm-generic archheaders archscripts $(Q)$(MAKE)$(build)=scripts build_unifdef...PHONY+=headers_install headers_install:__headers $(if$(wildcard $(srctree)/arch/$(hdr-arch)/include/uapi/asm/Kbuild),,\ $(error Headers not exportableforthe $(SRCARCH)architecture))$(Q)$(MAKE)$(hdr-inst)=include/uapi dst=include $(Q)$(MAKE)$(hdr-inst)=arch/$(hdr-arch)/include/uapi $(hdr-dst)

具体的安装操作见./scripts/Makefile.headersinst

#SPDX-License-Identifier:GPL-2.0#==========================================================================#Installing headers##All headers under include/uapi,include/generated/uapi,#arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are#exported.#They are preprocessed to remove __KERNEL__ section of the file.# #==========================================================================PHONY:=__headers __headers:include scripts/Kbuild.include srcdir:=$(srctree)/$(obj)#When make is run under a fakechroot environment,the function# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular # files. So, we are using a combination of sort/dir/wildcard which works # with fakechroot. subdirs := $(patsubst $(srcdir)/%/,%,\ $(filter-out $(srcdir)/,\ $(sort $(dir $(wildcard $(srcdir)/*/)))))#Recursion__headers:$(subdirs).PHONY:$(subdirs)$(subdirs):$(Q)$(MAKE)$(hdr-inst)=$(obj)/$@ dst=$(dst)/$@#Skip header install/checkforinclude/uapi and arch/$(hdr-arch)/include/uapi.#We have only sub-directories there.skip-inst:=$(if$(filter%/uapi,$(obj)),1)ifeq($(skip-inst),)#Kbuild file is optionalkbuild-file:=$(srctree)/$(obj)/Kbuild-include $(kbuild-file)installdir:=$(INSTALL_HDR_PATH)/$(dst)gendir:=$(objtree)/$(subst include/,include/generated/,$(obj))header-files:=$(notdir $(wildcard $(srcdir)/*.h)) header-files += $(notdir $(wildcard $(srcdir)/*.agh)) header-files := $(filter-out $(no-export-headers), $(header-files)) genhdr-files := $(notdir $(wildcard $(gendir)/*.h)) genhdr-files := $(filter-out $(header-files), $(genhdr-files)) # files used to track state of install/check install-file := $(installdir)/.install check-file := $(installdir)/.check # all headers files for this dir all-files := $(header-files) $(genhdr-files) output-files := $(addprefix $(installdir)/, $(all-files)) ifneq ($(mandatory-y),) missing := $(filter-out $(all-files),$(mandatory-y)) ifneq ($(missing),) $(error Some mandatory headers ($(missing)) are missing in $(obj)) endif endif # Work out what needs to be removed oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) unwanted := $(filter-out $(all-files),$(oldheaders)) # Prefix unwanted with full paths to $(INSTALL_HDR_PATH) unwanted-file := $(addprefix $(installdir)/, $(unwanted)) printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ file$(if $(word 2, $(all-files)),s)) cmd_install = \ $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ touch $@ quiet_cmd_remove = REMOVE $(unwanted) cmd_remove = rm -f $(unwanted-file) quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) # Headers list can be pretty long, xargs helps to avoid # the "Argument list too long" error. cmd_check = for f in $(all-files); do \ echo "$(installdir)/$${f}"; done \ | xargs \ $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ touch $@ ifndef HDRCHECK # Rules for installing headers __headers: $(install-file) @: targets += $(install-file) $(install-file): scripts/headers_install.sh \ $(addprefix $(srcdir)/,$(header-files)) \ $(addprefix $(gendir)/,$(genhdr-files)) FORCE $(if $(unwanted),$(call cmd,remove),) $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) $(call if_changed,install) else __headers: $(check-file) @: targets += $(check-file) $(check-file): scripts/headers_check.pl $(output-files) FORCE $(call if_changed,check) endif targets := $(wildcard $(sort $(targets))) cmd_files := $(wildcard \ $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) ifneq ($(cmd_files),) include $(cmd_files) endif endif # skip-inst .PHONY: $(PHONY) PHONY += FORCE FORCE: ;

可以看到,安装下面这4个目录下的头文件:

# 公用 UAPI 头文件include/uapi include/generated/uapi# 编译时生成# 架构 UAPI 头文件arch/$(hdr-arch)/include/uapi# 如 arch/arm/include/uapiarch/<arch>/include/generated/uapi# 编译时生成

./scripts/Makefile.headersinst调用scripts/headers_install.sh进行头文件安装,默认安装在linux/usr目录下,生成一个linux/usr/include文件夹,其中包含所有安装的头文件。

看看4个安装目录下都有哪些头文件:

# 这个有点多,就不用 tree 命令展开了$lsinclude/uapi asm-generic drm linux misc mtd rdma scsi sound video xen $ tree include/generated/uapi/ include/generated/uapi/ └── linux └── version.h1directory,1file$ tree arch/arm/include/uapi arch/arm/include/uapi └── asm ├── auxvec.h ├── byteorder.h ├── fcntl.h ├── hwcap.h ├── ioctls.h ├── Kbuild ├── kvm.h ├── kvm_para.h ├── mman.h ├── perf_regs.h ├── posix_types.h ├── ptrace.h ├── setup.h ├── sigcontext.h ├── signal.h ├── statfs.h ├── stat.h ├── swab.h ├── types.h └── unistd.h1directory,20files asm $ tree arch/arm/include/generated/uapi arch/arm/include/generated/uapi └── asm ├── bitsperlong.h ├── errno.h ├── ioctl.h ├── ipcbuf.h ├── msgbuf.h ├── param.h ├── poll.h ├── resource.h ├── sembuf.h ├── shmbuf.h ├── siginfo.h ├── socket.h ├── sockios.h ├── termbits.h ├── termios.h ├── unistd-common.h ├── unistd-eabi.h └── unistd-oabi.h1directory,18files

看一下安装过程:

$makeARCH=arm headers_installO=output/ make[1]: Entering directory'/home/lxj/Work/qemu-lab/linux-4.14.111'CHK include/generated/uapi/linux/version.h HOSTCC scripts/unifdef INSTALL usr/include/asm-generic/(36files)INSTALL usr/include/drm/(25files)INSTALL usr/include/linux/(485files)INSTALL usr/include/linux/android/(1file)INSTALL usr/include/linux/byteorder/(2files)INSTALL usr/include/linux/caif/(2files)INSTALL usr/include/linux/can/(6files)INSTALL usr/include/linux/cifs/(1file)INSTALL usr/include/linux/dvb/(8files)INSTALL usr/include/linux/genwqe/(1file)INSTALL usr/include/linux/hdlc/(1file)INSTALL usr/include/linux/hsi/(2files)INSTALL usr/include/linux/iio/(2files)INSTALL usr/include/linux/isdn/(1file)INSTALL usr/include/linux/mmc/(1file)INSTALL usr/include/linux/netfilter/(87files)INSTALL usr/include/linux/netfilter/ipset/(4files)INSTALL usr/include/linux/netfilter_arp/(2files)INSTALL usr/include/linux/netfilter_bridge/(17files)INSTALL usr/include/linux/netfilter_ipv4/(9files)INSTALL usr/include/linux/netfilter_ipv6/(12files)INSTALL usr/include/linux/nfsd/(5files)INSTALL usr/include/linux/raid/(2files)INSTALL usr/include/linux/sched/(1file)INSTALL usr/include/linux/spi/(1file)INSTALL usr/include/linux/sunrpc/(1file)INSTALL usr/include/linux/tc_act/(15files)INSTALL usr/include/linux/tc_ematch/(4files)INSTALL usr/include/linux/usb/(12files)INSTALL usr/include/linux/wimax/(1file)INSTALL usr/include/misc/(1file)INSTALL usr/include/mtd/(5files)INSTALL usr/include/rdma/(20files)INSTALL usr/include/rdma/hfi/(2files)INSTALL usr/include/scsi/(4files)INSTALL usr/include/scsi/fc/(4files)INSTALL usr/include/sound/(15files)INSTALL usr/include/video/(3files)INSTALL usr/include/xen/(4files)INSTALL usr/include/asm/(37files)make[1]: Leaving directory'/home/lxj/Work/qemu-lab/linux-4.14.111'

默认在linux/usr目录下,创建linux/usr/include目录,然后安装所有UAPI头文件。为什么只安装uapi目录下头文件?因为 linux uapi 下头文件就是导出给用户使用的,其它的头文件不应该导出,是不对用户开放的黑盒子。

另外,可以通过 INSTALL_HDR_PATH 将头文件安装到指定目录:

$makeARCH=armINSTALL_HDR_PATH=<target-path>headers_install

同样会在<target-path>目录下创建<target-path>/include文件夹安装所有头文件。另外,O=参数也是支持的,如:

$makeARCH=armO=output headers_install

则会在output/usr/include目录下安装所有头文件。当然,也可以同时使用 INSTALL_HDR_PATH= 和O=参数:

$makeARCH=armO=outputINSTALL_HDR_PATH=<target-path>headers_install

最后,还可以通过命令:

$makeheaders_install_all

安装所有架构的头文件。

调试可以加上V=1参数。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/1131915.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Soundflower音频路由神器:彻底释放Mac音频系统的无限潜能

Soundflower音频路由神器&#xff1a;彻底释放Mac音频系统的无限潜能 【免费下载链接】Soundflower MacOS system extension that allows applications to pass audio to other applications. 项目地址: https://gitcode.com/gh_mirrors/sou/Soundflower 还在为Mac上的音…

WE Learn智能学习助手终极指南:5步开启高效学习新时代

WE Learn智能学习助手终极指南&#xff1a;5步开启高效学习新时代 【免费下载链接】WELearnHelper 显示WE Learn随行课堂题目答案&#xff1b;支持班级测试&#xff1b;自动答题&#xff1b;刷时长&#xff1b;基于生成式AI(ChatGPT)的答案生成 项目地址: https://gitcode.co…

WE Learn AI学习助手终极指南:5步轻松开启智能学习模式

WE Learn AI学习助手终极指南&#xff1a;5步轻松开启智能学习模式 【免费下载链接】WELearnHelper 显示WE Learn随行课堂题目答案&#xff1b;支持班级测试&#xff1b;自动答题&#xff1b;刷时长&#xff1b;基于生成式AI(ChatGPT)的答案生成 项目地址: https://gitcode.c…

基于遗传算法和粒子群算法的潮流计算比较(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

[特殊字符]_内存管理深度解析:如何避免GC导致的性能陷阱[20260108161913]

作为一名经历过无数性能调优案例的工程师&#xff0c;我深知内存管理对Web应用性能的影响有多大。在最近的一个项目中&#xff0c;我们遇到了一个棘手的性能问题&#xff1a;系统在高并发下会出现周期性的延迟飙升&#xff0c;经过深入分析&#xff0c;发现问题根源竟然是垃圾回…

性价比高的海外代理IP:怎么选不踩坑

2026年&#xff0c;海外代理IP在跨境数据采集、区域访问测试、国际化应用开发等领域的需求持续高涨。所以&#xff0c;“性价比高的海外代理IP怎么选”已成为热议焦点。面对市面上鱼龙混杂的服务商&#xff0c;如何选到真正靠谱、成本可控又技术稳定的服务&#xff1f;本文将从…

汽车焊接工艺参数优化的方法和案例

焊接工艺参数的重要性与挑战在现代汽车制造领域&#xff0c;焊接工艺参数的优化是保证产品质量和生产效率的核心环节。焊接参数包括电流、电压、焊接速度、热输入量等多个维度&#xff0c;它们不仅影响焊缝的微观结构&#xff0c;还直接关系到整车的密封性、强度以及耐久性。然…

巴菲特-芒格的神经形态计算投资:类脑计算的未来

巴菲特 - 芒格的神经形态计算投资:类脑计算的未来 关键词:巴菲特、芒格、神经形态计算、类脑计算、投资、未来趋势、人工智能 摘要:本文深入探讨了巴菲特 - 芒格的神经形态计算投资这一热点话题,聚焦类脑计算的未来发展。首先介绍了神经形态计算与类脑计算的背景知识,包括…

【无人机】基于遗传算法混合粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

Docker 基础:怎么配置、怎么拉取运行、怎么构建推送

很多人第一次接触 Docker,是在同事发来一句话: 你别装环境了,直接 docker run 就行。 然后你半信半疑地敲下命令,程序居然真的跑起来了。 Docker 最迷人的地方就在这里:它把“环境”从你的电脑里抽离出来,变成一个可以复制、可以分发、可以回滚的交付物。这篇文章不讲太…

谁说思维链越长越好?Yuan3.0 Flash开源:砍掉70%无效token,重构推理范式

首创「反思抑制」机制&#xff0c;让大模型学会在答对的那一刻果断停下。过去一年&#xff0c;大模型推理能力的进化几乎沿着一条单向路径前进&#xff1a;更复杂的推理过程、更长的思维链、更“像人类”的自我反思。在数学和科学推理等 benchmark 上&#xff0c;这条路径看起来…

欧莱雅集团在CES 2026上发布LED光能面膜

、美通社消息&#xff1a;全球美妆行业巨头欧莱雅集团在2026年国际消费类电子产品展览会(CES 2026)上正式发布两项突破性技术&#xff0c;将光学的力量引入美发与护肤领域&#xff1a;多效光能美发棒(Light Straight Multi-styler)与LED光能面膜(LED Face Mask)&#xff0c;均…

Node.js 用beforeExit优雅关闭应用

&#x1f493; 博客主页&#xff1a;瑕疵的CSDN主页 &#x1f4dd; Gitee主页&#xff1a;瑕疵的gitee主页 ⏩ 文章专栏&#xff1a;《热点资讯》 Node.js应用优雅关闭的艺术&#xff1a;利用beforeExit事件实现资源安全释放目录Node.js应用优雅关闭的艺术&#xff1a;利用bef…

Switch文件传输与RCM注入全攻略:NS-USBLoader深度体验

Switch文件传输与RCM注入全攻略&#xff1a;NS-USBLoader深度体验 【免费下载链接】ns-usbloader Awoo Installer and GoldLeaf uploader of the NSPs (and other files), RCM payload injector, application for split/merge files. 项目地址: https://gitcode.com/gh_mirro…

5分钟快速上手gerbv:电子工程师必备的Gerber文件查看终极指南

5分钟快速上手gerbv&#xff1a;电子工程师必备的Gerber文件查看终极指南 【免费下载链接】gerbv Maintained fork of gerbv, carrying mostly bugfixes 项目地址: https://gitcode.com/gh_mirrors/ge/gerbv 在PCB设计和电子制造领域&#xff0c;Gerber文件作为行业标准…

linux下使用SHC对Shell脚本进行封装和源码隐藏

在很多情况下&#xff0c;需要保护自己所写的shell脚本源码不被别人查看。这时使用shc工具将shell脚本编译成二进制文件是一个有效的方法。 什么是SHC shc是一个由C语言编写的Shell脚本加密程序&#xff0c;它可以将你的脚本编译成二进制可执行文件&#xff0c;从而隐藏源码。…

为什么数据库文件不建议提交:你提交的不是数据,是未来的麻烦

为什么数据库文件不建议提交:你提交的不是数据,是未来的麻烦 你有没有遇到过这种场景:项目刚起步,大家图省事,把本地的 app.db(SQLite)、data.mv.db(H2)、甚至某个 dump.sql 一起丢进 Git。短期看起来很爽——拉下来就能跑、数据也现成。 但过不了多久,你会发现:仓…

当云原生遇见VMware

技术融合背景云原生与VMware的协同价值&#xff0c;传统虚拟化与容器化技术的互补性&#xff0c;企业混合云转型需求。VMware在云原生生态中的角色VMware Tanzu产品套件解析&#xff08;TKG、TAP、TMC&#xff09;&#xff0c;vSphere与Kubernetes集成&#xff08;VCF&#xff…

WE Learn智能助手完整指南:5步掌握高效学习新方法

WE Learn智能助手完整指南&#xff1a;5步掌握高效学习新方法 【免费下载链接】WELearnHelper 显示WE Learn随行课堂题目答案&#xff1b;支持班级测试&#xff1b;自动答题&#xff1b;刷时长&#xff1b;基于生成式AI(ChatGPT)的答案生成 项目地址: https://gitcode.com/gh…

大数据领域数据架构在企业中的应用价值

大数据领域数据架构在企业中的应用价值&#xff1a;从数据碎片到商业洞察的“魔法桥梁”关键词&#xff1a;大数据架构、企业数据治理、数据价值挖掘、业务决策支持、数据驱动增长摘要&#xff1a;在企业数字化转型的浪潮中&#xff0c;数据已成为核心生产要素。但许多企业面临…