Skip to content

Commit

Permalink
build SDK
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Cressey <[email protected]>
  • Loading branch information
bcressey authored and iliana committed Apr 30, 2019
1 parent 90b748b commit 845b1b7
Show file tree
Hide file tree
Showing 16 changed files with 1,216 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build
*.makevar
*.makepkg
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM fedora:latest AS origin
RUN dnf makecache && dnf -y update

FROM origin AS base
RUN dnf -y install rpmdevtools dnf-plugins-core \
&& dnf -y groupinstall "C Development Tools and Libraries" \
&& useradd builder

FROM base AS rpmbuild
ARG PACKAGE
ARG HASH
WORKDIR /home/builder

USER builder
COPY ./packages/${PACKAGE}/* .
COPY ./packages/rpmmacros .rpmmacros
RUN rpmdev-setuptree \
&& mv *.spec rpmbuild/SPECS \
&& find . -maxdepth 1 -not -path '*/\.*' -type f -exec mv {} rpmbuild/SOURCES/ \; \
&& echo ${HASH}

USER root
RUN dnf -y builddep rpmbuild/SPECS/${PACKAGE}.spec

USER builder
RUN rpmbuild -ba rpmbuild/SPECS/${PACKAGE}.spec

FROM scratch AS rpm
COPY --from=rpmbuild /home/builder/rpmbuild/RPMS/*/*.rpm /
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.DEFAULT_GOAL := all

TOPDIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))
SPEC2VAR ?= $(TOPDIR)/bin/spec2var
SPEC2PKG ?= $(TOPDIR)/bin/spec2pkg

SPECS = $(wildcard packages/*/*.spec)
VARS = $(SPECS:.spec=.makevar)
PKGS = $(SPECS:.spec=.makepkg)

OUTPUT ?= $(TOPDIR)/build
OUTVAR := $(shell mkdir -p $(OUTPUT))

BUILDCTL ?= buildctl --addr tcp://127.0.0.1:1234
BUILDCTL_ARGS := --progress=plain
BUILDCTL_ARGS += --frontend=dockerfile.v0
BUILDCTL_ARGS += --local context=.
BUILDCTL_ARGS += --local dockerfile=.

%.makevar : %.spec $(SPEC2VAR)
@$(SPEC2VAR) $< > $@

%.makepkg : %.spec $(SPEC2PKG)
@$(SPEC2PKG) $< > $@

-include $(VARS)
-include $(PKGS)

.PHONY: all
all: $(thar-sdk)
@echo BUILT IT ALL

.PHONY: clean
clean:
@rm -r $(OUTPUT)/*.rpm
31 changes: 31 additions & 0 deletions bin/spec2pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

SPEC="${1:?}"
PKG="${SPEC##*/}"
PKG="${PKG%.*}"

# Collect file-based targets for the outputs of a package build.
RPMS="$(rpmspec --query --queryformat="\$(OUTPUT)/%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm " "${SPEC}")"
RPMS="${RPMS%"${RPMS##*[![:space:]]}"}"

# Collect file-based targets needed as inputs of a package build.
SOURCES="$(rpmspec --parse "${SPEC}"|awk -v pkg="${PKG}" -F '[/ ]' '/^Source/ {printf "packages/"pkg"/"$NF" "}')"
SOURCES="${SOURCES%"${SOURCES##*[![:space:]]}"}"
PATCHES="$(rpmspec --parse "${SPEC}"|awk -v pkg="${PKG}" -F '[/ ]' '/^Patch/ {printf "packages/"pkg"/"$NF" "}')"
PATCHES="${PATCHES%"${PATCHES##*[![:space:]]}"}"

# Collect package-level dependencies needed as inputs of a package build.
BUILDREQUIRES="$(rpmspec --query --buildrequires "${SPEC}" | awk '/thar/ {printf "$(%s) ",$0} END {print ""}')"
BUILDREQUIRES="${BUILDREQUIRES%"${BUILDREQUIRES##*[![:space:]]}"}"

cat <<EOF
${RPMS} : ${SPEC} ${SOURCES} ${PATCHES} ${BUILDREQUIRES}
\$(eval HASH:= \$(shell sha1sum \$^ | sha1sum - | awk '{printf \$\$1}'))
@\$(BUILDCTL) build \\
--frontend-opt target=rpm \\
--frontend-opt build-arg:PACKAGE=${PKG} \\
--frontend-opt build-arg:HASH=\$(HASH) \\
--exporter=local \\
--exporter-opt output=\$(OUTPUT) \\
\$(BUILDCTL_ARGS)
EOF
6 changes: 6 additions & 0 deletions bin/spec2var
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

SPEC="${1:?}"

# Populate variables for the capabilities provided by package names.
rpmspec --query --queryformat="%{NAME} = \$(OUTPUT)/%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm\n" "${SPEC}"
1 change: 1 addition & 0 deletions packages/rpmmacros
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%_binaries_in_noarch_packages_terminate_build 0
14 changes: 14 additions & 0 deletions packages/sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
binutils-2.31.1.tar.xz
bison-3.0.4.tar.xz
buildroot-2018.11.1.tar.gz
gawk-4.2.1.tar.xz
gcc-8.2.0.tar.xz
glibc-glibc-2.28-50-gb8dd0f42780a3133c02f064a2c0c5c4e7ab61aaa.tar.gz
gmp-6.1.2.tar.xz
isl-0.18.tar.xz
linux-4.14.86.tar.xz
lzip-1.20.tar.gz
m4-1.4.18.tar.xz
mpc-1.0.3.tar.gz
mpfr-3.1.6.tar.xz
tar-1.29.cpio.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
From 91f8bfc0fd5eff9066f0371c44fd7c8a5e986d02 Mon Sep 17 00:00:00 2001
From: Ben Cressey <[email protected]>
Date: Sun, 6 Aug 2017 23:15:02 +0000
Subject: [PATCH 1/5] disable shared for host builds of gmp, isl, mpc, mpfr

Building these GCC dependencies as static libraries avoids the need to
provide the shared library paths at runtime, using either rpath entries
at link time or dynamic linker environment variables at runtime.

Signed-off-by: Ben Cressey <[email protected]>
---
package/Makefile.in | 2 +-
package/gmp/gmp.mk | 4 ++++
package/isl/isl.mk | 4 ++++
package/mpc/mpc.mk | 4 ++++
package/mpfr/mpfr.mk | 4 ++++
5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/package/Makefile.in b/package/Makefile.in
index 44761b79c5..f24abdd703 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -217,7 +217,7 @@ HOST_CPPFLAGS = -I$(HOST_DIR)/include
HOST_CFLAGS ?= -O2
HOST_CFLAGS += $(HOST_CPPFLAGS)
HOST_CXXFLAGS += $(HOST_CFLAGS)
-HOST_LDFLAGS += -L$(HOST_DIR)/lib -Wl,-rpath,$(HOST_DIR)/lib
+HOST_LDFLAGS += -L$(HOST_DIR)/lib

# The macros below are taken from linux 4.11 and adapted slightly.
# Copy more when needed.
diff --git a/package/gmp/gmp.mk b/package/gmp/gmp.mk
index 7236e37bb4..4e34b2d001 100644
--- a/package/gmp/gmp.mk
+++ b/package/gmp/gmp.mk
@@ -13,6 +13,10 @@ GMP_LICENSE_FILES = COPYING.LESSERv3 COPYINGv2
GMP_DEPENDENCIES = host-m4
HOST_GMP_DEPENDENCIES = host-m4

+HOST_GMP_CONF_OPTS = \
+ --enable-static \
+ --disable-shared
+
# GMP doesn't support assembly for coldfire or mips r6 ISA yet
# Disable for ARM v7m since it has different asm constraints
ifeq ($(BR2_m68k_cf)$(BR2_MIPS_CPU_MIPS32R6)$(BR2_MIPS_CPU_MIPS64R6)$(BR2_ARM_CPU_ARMV7M),y)
diff --git a/package/isl/isl.mk b/package/isl/isl.mk
index b5f01c4c8d..855de8fb46 100644
--- a/package/isl/isl.mk
+++ b/package/isl/isl.mk
@@ -11,4 +11,8 @@ ISL_LICENSE = MIT
ISL_LICENSE_FILES = LICENSE
HOST_ISL_DEPENDENCIES = host-gmp

+HOST_ISL_CONF_OPTS = \
+ --enable-static \
+ --disable-shared
+
$(eval $(host-autotools-package))
diff --git a/package/mpc/mpc.mk b/package/mpc/mpc.mk
index 89bbfd9c51..ebf01e2069 100644
--- a/package/mpc/mpc.mk
+++ b/package/mpc/mpc.mk
@@ -12,5 +12,9 @@ MPC_INSTALL_STAGING = YES
MPC_DEPENDENCIES = gmp mpfr
HOST_MPC_DEPENDENCIES = host-gmp host-mpfr

+HOST_MPC_CONF_OPTS = \
+ --enable-static \
+ --disable-shared
+
$(eval $(autotools-package))
$(eval $(host-autotools-package))
diff --git a/package/mpfr/mpfr.mk b/package/mpfr/mpfr.mk
index 1b67cf2e45..d65c29b9d1 100644
--- a/package/mpfr/mpfr.mk
+++ b/package/mpfr/mpfr.mk
@@ -14,5 +14,9 @@ MPFR_DEPENDENCIES = gmp
HOST_MPFR_DEPENDENCIES = host-gmp
MPFR_MAKE_OPTS = RANLIB=$(TARGET_RANLIB)

+HOST_MPFR_CONF_OPTS = \
+ --enable-static \
+ --disable-shared
+
$(eval $(autotools-package))
$(eval $(host-autotools-package))
--
2.17.2

31 changes: 31 additions & 0 deletions packages/sdk/0002-allow-unknown-vendor-name-for-toolchain.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 9de3c4af683702c88f92300dc9b3de041a49d4aa Mon Sep 17 00:00:00 2001
From: Ben Cressey <[email protected]>
Date: Sun, 6 Aug 2017 23:22:40 +0000
Subject: [PATCH 2/5] allow unknown vendor name for toolchain

As we do not have a native toolchain for our targets, there is no risk
of confusion, so we can safely use unknown as our vendor name.

Signed-off-by: Ben Cressey <[email protected]>
---
package/Makefile.in | 4 ----
1 file changed, 4 deletions(-)

diff --git a/package/Makefile.in b/package/Makefile.in
index f24abdd703..767a6bea96 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -31,10 +31,6 @@ endif
ifeq ($(TARGET_VENDOR),)
$(error BR2_TOOLCHAIN_BUILDROOT_VENDOR is not allowed to be empty)
endif
-ifeq ($(TARGET_VENDOR),unknown)
-$(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \
- It might be confused with the native toolchain)
-endif

# Compute GNU_TARGET_NAME
GNU_TARGET_NAME = $(ARCH)-$(TARGET_VENDOR)-$(TARGET_OS)-$(LIBC)$(ABI)
--
2.17.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
From 8daab7e68590436321c8c665c6f15cb839c24da4 Mon Sep 17 00:00:00 2001
From: Ben Cressey <[email protected]>
Date: Sun, 6 Aug 2017 23:35:06 +0000
Subject: [PATCH 3/5] add TOOLS_DIR and SYSROOT_DIR to control output

The sysroot directory is essential to our purpose of building a
relocatable toolchain, as GCC will look for it relative to the
path to the compiler.

Because we use a two-stage process to build our compiler, we want
to distinguish between our intermediate sysroot where libraries
and headers from our temporary musl and kernel builds are installed,
and our final sysroot which should be empty of everything except the
libraries and headers from GCC itself.

We also expose an output directory for the final toolchain. In normal
operation, Buildroot treats the toolchain as the means to the end of
an embedded system image, while we only care about the toolchain.

Signed-off-by: Ben Cressey <[email protected]>
---
Makefile | 10 +++++++---
package/Makefile.in | 3 ++-
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index dd8cc7a9ae..2570bf118e 100644
--- a/Makefile
+++ b/Makefile
@@ -228,6 +228,7 @@ TARGET_DIR = $(if $(ROOTFS),$(ROOTFS_$(ROOTFS)_TARGET_DIR),$(BASE_TARGET_DIR))
# .config. HOST_DIR will be overwritten later when .config is included.
HOST_DIR := $(BASE_DIR)/host
GRAPHS_DIR := $(BASE_DIR)/graphs
+TOOLS_DIR := $(BASE_DIR)/toolchain

LEGAL_INFO_DIR = $(BASE_DIR)/legal-info
REDIST_SOURCES_DIR_TARGET = $(LEGAL_INFO_DIR)/sources
@@ -486,7 +487,9 @@ export BR2_CONFIG
export BR2_REPRODUCIBLE
export TARGET_DIR
export STAGING_DIR
+export SYSROOT_DIR
export HOST_DIR
+export TOOLS_DIR
export BINARIES_DIR
export BASE_DIR

@@ -574,7 +577,7 @@ endif

.PHONY: dirs
dirs: $(BUILD_DIR) $(STAGING_DIR) $(BASE_TARGET_DIR) \
- $(HOST_DIR) $(HOST_DIR_SYMLINK) $(BINARIES_DIR)
+ $(HOST_DIR) $(HOST_DIR_SYMLINK) $(BINARIES_DIR) $(TOOLS_DIR)

$(BUILD_DIR)/buildroot-config/auto.conf: $(BR2_CONFIG)
$(MAKE1) $(EXTRAMAKEARGS) HOSTCC="$(HOSTCC_NOCCACHE)" HOSTCXX="$(HOSTCXX_NOCCACHE)" syncconfig
@@ -975,7 +978,7 @@ savedefconfig: $(BUILD_DIR)/buildroot-config/conf prepare-kconfig

# staging and target directories do NOT list these as
# dependencies anywhere else
-$(BUILD_DIR) $(BASE_TARGET_DIR) $(HOST_DIR) $(BINARIES_DIR) $(LEGAL_INFO_DIR) $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST):
+$(BUILD_DIR) $(BASE_TARGET_DIR) $(HOST_DIR) $(BINARIES_DIR) $(LEGAL_INFO_DIR) $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST) $(TOOLS_DIR):
@mkdir -p $@

# outputmakefile generates a Makefile in the output directory, if using a
@@ -1014,7 +1017,8 @@ printvars:
clean:
rm -rf $(BASE_TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) $(HOST_DIR_SYMLINK) \
$(BUILD_DIR) $(BASE_DIR)/staging \
- $(LEGAL_INFO_DIR) $(GRAPHS_DIR)
+ $(LEGAL_INFO_DIR) $(GRAPHS_DIR) \
+ $(TOOLS_DIR)

.PHONY: distclean
distclean: clean
diff --git a/package/Makefile.in b/package/Makefile.in
index 767a6bea96..e984c00c85 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -103,8 +103,9 @@ ifeq ($(BR2_arc)$(BR2_ARC_ATOMIC_EXT),yy)
TARGET_ABI += -matomic
endif

-STAGING_SUBDIR = $(GNU_TARGET_NAME)/sysroot
+STAGING_SUBDIR = $(GNU_TARGET_NAME)/sys-root
STAGING_DIR = $(HOST_DIR)/$(STAGING_SUBDIR)
+SYSROOT_DIR = /$(STAGING_SUBDIR)

ifeq ($(BR2_OPTIMIZE_0),y)
TARGET_OPTIMIZATION = -O0
--
2.17.2

Loading

0 comments on commit 845b1b7

Please sign in to comment.