首页 > 解决方案 > 如何在 yocto 中将源文件添加到 PN-src 包中

问题描述

我为 Simple C 应用程序编写了一个基本配方

DESCRIPTION = "Simple helloworld C application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://userprog.c \
       file://function.c \
       file://ReadMe.txt"

S = "${WORKDIR}"

do_compile() {
    ${CC} userprog.c function.c ${LDFLAGS} -o userprog
}

do_install() {
    install -d ${D}${bindir}
    install -m 0755 userprog ${D}${bindir}
    install -d ${D}${docdir}
    install -m 0644 ReadMe.txt ${D}${docdir}
}

包拆分文件夹上的树命令

tree packages-split/
packages-split/
├── myhello
│   └── usr
│       └── bin
│           └── userprog
├── myhello-dbg
│   └── usr
│       └── bin
├── myhello-dev
├── myhello-doc
│   └── usr
│       └── share
│           └── doc
│               └── ReadMe.txt
├── myhello-locale
├── myhello.shlibdeps
├── myhello-src
└── myhello-staticdev

因此,ReadMe.txt 会自动复制到“myhello-doc”包中。我应该对源文件进行哪些更改才能将其复制到“myhello-src”包中

当我将配方更改为使用 Makefile 时,它​​会自动添加到 src 包中

DESCRIPTION = "Simple helloworld C application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://userprog.c \
        file://Makefile"

S = "${WORKDIR}"

EXTRA_OEMAKE = "'DESTDIR=${D}/usr/bin' V=1"

do_install() {
    oe_runmake install
}

生成文件:

# compiler flags:
#  -g    adds debugging information to the executable file
#  -Wall turns on most, but not all, compiler warnings
CFLAGS  = -g -Wall -DUSE_SYSCALL

# the name to use for both the target source file, and the output file:
TARGET = userprog

all: $(TARGET)

$(TARGET): $(TARGET).c
    ${CC} $(CFLAGS) -o $(TARGET)  $(TARGET).c $(LDFLAGS)

install:
    install -d $(DESTDIR)
    install -m 0755 $(TARGET) $(DESTDIR)

clean:
    rm  -f $(TARGET)

uninstall:
    rm $(DESTDIR)$(TARGET)

包拆分:

packages-split/
├── myhello4
│   └── usr
│       └── bin
│           └── userprog
├── myhello4-dbg
│   └── usr
│       └── bin
├── myhello4-dev
├── myhello4-doc
├── myhello4-locale
├── myhello4.shlibdeps
├── myhello4-src
│   └── usr
│       └── src
│           └── debug
│               └── myhello4
│                   └── 0.1-r0
│                       └── userprog.c
└── myhello4-staticdev

第一种方法和第二种方法有什么区别,以及如何将 userprog.c 文件添加到第二种方法中

标签: yoctobitbake

解决方案


    DESCRIPTION = "Simple helloworld C application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://userprog.c \
       file://function.c \
       file://ReadMe.txt"

S = "${WORKDIR}"

do_compile() {
    ${CC} userprog.c function.c ${LDFLAGS} -o userprog
}

do_install() {
    install -d ${D}${bindir}
    install -m 0755 userprog ${D}${bindir}
    install -d ${D}${docdir}
    install -m 0644 ReadMe.txt ${D}${docdir}
    install -d ${D}/src
    cp -rf ${S}/*.c ${D}/src/
}

PACKAGES = "${PN} ${PN}-src ${PN}-doc"
FILES_${PN} = "
 ${bindir}/*
"
FILES_${PN}-src = "
 /src/*
"
FILES_${PN}-doc = "
${docdir}/*
"

推荐阅读