Gentoo Archives: gentoo-dev

From: Nekun <nekokun@××××××××.cc>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] TEXTRELs in assembly program
Date: Thu, 22 Apr 2021 21:32:21
Message-Id: 640aa18e2d2e88f8bec1bc5b103910c1@firemail.cc
In Reply to: [gentoo-dev] TEXTRELs in assembly program by Nekun
1 Ah, looks like attachment isn't attached, post my ebuild in plain text.
2
3 EAPI=7
4
5 inherit multilib toolchain-funcs
6
7 DESCRIPTION="Open source assembly language compiler"
8 HOMEPAGE="https://flatassembler.net"
9 SRC_URI="https://flatassembler.net/${P}.tgz"
10
11 LICENSE="MIT"
12 SLOT="0"
13 KEYWORDS="amd64 x86"
14
15 IUSE="-tools -libc"
16
17 DEPEND=""
18 RDEPEND=""
19
20 S="${WORKDIR}/${PN}"
21 PATCHES=( "${FILESDIR}/1-fix-gnu-stack.patch" )
22
23 TOOLS=(listing prepsrc symbols)
24
25 pkg_setup() {
26 if use tools || use libc; then
27 if [[ ${ARCH} = "amd64" && ! $(get_all_abis) =~ "x86" ]]; then
28 die "Multilib profile must be selected to build 32-bit tools or
29 libc-linked FASM for amd64 target"
30 fi
31 fi
32 CC=$(tc-getCC)
33 }
34
35 src_compile() {
36 # fasm is written on itself; so, if fasm already installed,
37 # assemble it with system fasm, otherwise assemble it
38 # with binary provided in tarball
39 if has_version -b "${CATEGORY}/${PN}"; then
40 FASM="${PN}"
41 is_bootstrap=1
42 elif [[ ${ARCH} = "x86" ]]; then
43 einfo "Bootstrapping fasm from binary"
44 FASM="./${PN}"
45 else # amd64
46 einfo "Bootstrapping fasm from binary"
47 FASM="./${PN}.x64"
48 fi
49
50 if ! use libc; then
51 if [[ ${ARCH} = "x86" ]]; then
52 ${FASM} "source/Linux/${PN}.asm" "${T}/${PN}" || die
53 else # amd64
54 ${FASM} "source/Linux/x64/${PN}.asm" "${T}/${PN}" || die
55 fi
56 else
57 ${FASM} "source/libc/fasm.asm" || die
58 ${CC} -m32 ${LDFLAGS} -o "${T}/${PN}" "source/libc/fasm.o" || die
59 fi
60
61 if use tools; then
62 # bootstrapping is done at this point, we can use
63 # our homebrewed binary for building tools
64 [[ -v is_bootstrap ]] && FASM="${T}/${PN}"
65
66 for tool in "${TOOLS[@]}"; do
67 ${FASM} "tools/libc/${tool}.asm" || die
68 ${CC} -m32 ${LDFLAGS} -o "${T}/${tool}" "tools/libc/${tool}.o" || die
69 done
70 fi
71 }
72
73 src_install() {
74 exeinto /usr/bin
75 doexe "${T}/${PN}"
76 dodoc "${PN}.txt"
77 if use tools; then
78 for tool in "${TOOLS[@]}"; do
79 doexe "${T}/${tool}"
80 done
81 dodoc "tools/fas.txt"
82 fi
83 }