Package Makefile: Architecture Variable

Hi,

I'm trying to write an package for the metric collector telegraf. So far my PKG_SOURCE code is downloaded correctly. Because it is written in GO, I need to set an environment variable GO_ARCH to compile the source code correctly.

I'm doing it by overwriting the Build/Compile function:

define Build/Compile
    GOARCH=$(KERNEL_ARCH) $(MAKE) -C $(PKG_BUILD_DIR) $(TARGET_CONFIGURE_OPTS)
endef

The problem I am now faced, is that the openwrt arch is eg. aarch64 instead of arm64. I found the following wireguard patch where such a translation is done:

+ifeq ($(ARCH),aarch64)
160 +QEMU_ARCH := aarch64
161 +KERNEL_ARCH := arm64

But I am unable to set any variable in the Build/Compile function. I tried many variation. But the variable is not set.
I also do not why code inside this function is now called as bash -c and not in Makefile syntax anymore..

define Build/Compile
        KERNEL_ARCH=ERROR
	@echo "ARCH: $(KERNEL_ARCH)"
	if [ "$(ARCH)" == "aarch64" ]; then \
		KERNEL_ARCH="arm64"; \
	elif [ "$(ARCH)" == "aarch64_be" ]; then \
		KERNEL_ARCH=arm64; \
	elif [ "$(ARCH)" == "arm" ]; then \
		KERNEL_ARCH=arm; \
	elif [ "$(ARCH)" == "armeb" ]; then \
		KERNEL_ARCH=arm; \
	elif [ "$(ARCH)" == "x86_64" ]; then \
		KERNEL_ARCH=x86_64; \
	elif [ "$(ARCH)" == "i686" ]; then \
		KERNEL_ARCH=x86; \
	elif [ "$(ARCH)" == "mips64" ]; then \
		KERNEL_ARCH=mips; \
	elif [ "$(ARCH)" == "mips64el" ]; then \
		KERNEL_ARCH=mips; \
	elif [ "$(ARCH)" == "mips" ]; then \
		KERNEL_ARCH=mips; \
	elif [ "$(ARCH)" == "mipsel" ]; then \
		KERNEL_ARCH=mips; \
	elif [ "$(ARCH)" == "powerpc64le" ]; then \
		KERNEL_ARCH=powerpc; \
	elif [ "$(ARCH)" == "powerpc" ]; then \
		KERNEL_ARCH=powerpc; \
	elif [ "$(ARCH)" == "m68k" ]; then \
		KERNEL_ARCH=m68k; \
	fi
	@echo "ARCH: $(KERNEL_ARCH)"

	GOARCH=$(KERNEL_ARCH) $(MAKE) -C $(PKG_BUILD_DIR) $(TARGET_CONFIGURE_OPTS)
endef

Can you help me ? What am I doing wrong ? Or this there already an variable with "correct" archicture name ?

Thanks in advance! :slight_smile:

Edit: My current way is to define it outside a function like this. It is working but not really pretty.

KERNEL_ARCH= `\
	if [ "$(ARCH)" == "aarch64" ]; then \
		echo arm64; \
	elif [ "$(ARCH)" == "aarch64_be" ]; then \
		echo arm64; \
	elif [ "$(ARCH)" == "arm" ]; then \
		echo arm; \
	elif [ "$(ARCH)" == "armeb" ]; then \
		echo arm; \
	elif [ "$(ARCH)" == "x86_64" ]; then \
		echo x86_64; \
	elif [ "$(ARCH)" == "i686" ]; then \
		echo x86; \
	elif [ "$(ARCH)" == "mips64" ]; then \
		echo mips; \
	elif [ "$(ARCH)" == "mips64el" ]; then \
		echo mips; \
	elif [ "$(ARCH)" == "mips" ]; then \
		echo mips; \
	elif [ "$(ARCH)" == "mipsel" ]; then \
		echo mips; \
	elif [ "$(ARCH)" == "powerpc64le" ]; then \
		echo powerpc; \
	elif [ "$(ARCH)" == "powerpc" ]; then \
		echo powerpc; \
	elif [ "$(ARCH)" == "m68k" ]; then \
		echo m68k; \
	fi`
1 Like

@grommish would probably be well suited to assist

Why not just use

CONFIGURE_VARS += \
   GOARCH=$(ARCH)

Which will set the ARCH (or maybe TARGET_ARCH would be better?) to whatever it's supposed to be as called by the target, and define your GOARCH environmental at the same time.

Or is there a reason this wouldn't work? I've not been dabbling in the OpenWrt stuff for a few months now, it's all about Discord Python at the moment.. Yay! :wink:

Edit: Added benefit of doing it this way is being able to completely remove your Build/Compile section

2 Likes

Thanks for your reply!

As I mentioned $(ARCH) does not work because it has a diffrent naming (aarch64 instead of arm64) and the go compiler does not recognize it.
That is the reason why I "translated" it like that (I found it as mentioned in a wireguard patch).

$(TARGET_ARCH) is empty when i use it... How do I set it ?

And yes I would love to get rid of Build/Compile

Edit: If I use CONFIGURE_VARS like you wrote the environment variable is not set. I also tried to run make package/telegraf/configure before running for compile.

1 Like

You can also try $(REAL_GNU_TARGET_NAME) and see what it gets you.

You could also override the ARCH just before the CONFIGURE_VARS

ifeq($(ARCH), $(filter $(ARCH),aarch64 aarch64_be))
ARCH="arm64"
endif

ONFIGURE_VARS += \
   GOARCH=$(ARCH)

This will allow other, correctly labelled archs to also use the package

Yes but that is basically what I was doing there. I only stored it in a different Variable.

Do you know the setting CONFIGURE_VARS does not work for me ? The environment variable is not set. I delted the Build/Compile function and added

CONFIGURE_VARS += \
   GOARCH=arm64

for testing.
I also tried to run configure before I run compile

Can you post your entire Makefile?

include $(TOPDIR)/rules.mk

PKG_NAME:=telegraf
PKG_VERSION:=1.19.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/influxdata/telegraf/tar.gz/v$(PKG_VERSION)?
PKG_HASH:=cec43bb0acfff8b4c963ffec6e3eab44ffb52c8f34e6a697207977cfd05882aa

PKG_BUILD_DEPENDS:=golang/host
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

PKG_MAINTAINER:=Jonathan Pagel <j.pagel@riotcat.org>
PKG_LICENSE:=MIT

include $(INCLUDE_DIR)/package.mk

define Package/telegraf
	SECTION:=utils
	CATEGORY:=Utilities
	TITLE:=Telegraf
	PKGARCH:=all
endef

define Package/telegraf/description
	Telegraf is a plugin-driven agent for collecting and sending metrics and events.
	It supports various inputs (including prometheus endpoints) and is able to send data into InfluxDB.
endef

KERNEL_ARCH= `\
	if [ "$(ARCH)" == "aarch64" ]; then \
		echo arm64; \
	elif [ "$(ARCH)" == "aarch64_be" ]; then \
		echo arm64; \
	elif [ "$(ARCH)" == "arm" ]; then \
		echo arm; \
	elif [ "$(ARCH)" == "armeb" ]; then \
		echo arm; \
	elif [ "$(ARCH)" == "x86_64" ]; then \
		echo x86_64; \
	elif [ "$(ARCH)" == "i686" ]; then \
		echo x86; \
	elif [ "$(ARCH)" == "mips64" ]; then \
		echo mips; \
	elif [ "$(ARCH)" == "mips64el" ]; then \
		echo mips; \
	elif [ "$(ARCH)" == "mips" ]; then \
		echo mips; \
	elif [ "$(ARCH)" == "mipsel" ]; then \
		echo mips; \
	elif [ "$(ARCH)" == "powerpc64le" ]; then \
		echo powerpc; \
	elif [ "$(ARCH)" == "powerpc" ]; then \
		echo powerpc; \
	elif [ "$(ARCH)" == "m68k" ]; then \
		echo m68k; \
	fi`

CONFIGURE_VARS += \
	GOARCH=$(KERNEL_ARCH)

define Package/telegraf/install
	$(INSTALL_DIR) $(1)/usr/bin/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/telegraf $(1)/usr/bin/telegraf
	$(CP) ./files/* $(1)/
	$(CP) $(PKG_BUILD_DIR)/etc/telegraf.conf $(1)/etc/config/telegraf
endef

$(eval $(call BuildPackage,telegraf))

btw it is empty for me as well.

I'm building the package out now, but not for an aarch64 device. Which device should I build for to test if it builds?

What device do you have around ?

I'm currently working on RPI 3 B. A problem for router with smaller flash will be that the binary is around 120MB. (But I think tiny version are possible, if other plugins are excluded, but thats work for the future :D)

The Makefile will not compile and wrongly with the posted script, because the environment variable GOARCHis not set und then the go compiler uses the host arch.

Right.. I'm working on that :slight_smile: But I'm going to test on a known good build arch before I start exploring with others (plus, it means I don't have to build a toolchain right away).

My device is a mips64, but again, I've got a toolchain for that already for gnu and I'm building one for golang it seems. If I build out for a rpi3b and it builds, then it'll have verified at least the Makefile issue regarding aarch64.. after that, you can figure out the rest

2 Likes

Try this:

include $(TOPDIR)/rules.mk

PKG_NAME:=telegraf
PKG_VERSION:=1.19.1
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/influxdata/telegraf/tar.gz/v$(PKG_VERSION)?
PKG_HASH:=cec43bb0acfff8b4c963ffec6e3eab44ffb52c8f34e6a697207977cfd05882aa

PKG_BUILD_DEPENDS:=golang/host
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

PKG_MAINTAINER:=Jonathan Pagel <j.pagel@riotcat.org>
PKG_LICENSE:=MIT

include $(INCLUDE_DIR)/package.mk

ifeq ($(ARCH),$(filter $(ARCH),"aarch64" "aarch64_be"))
ARCH = "arm64"
endif

CONFIGURE_VARS += \
        GO_ARCH=$(ARCH)

define Package/telegraf
        SECTION:=utils
        CATEGORY:=Utilities
        TITLE:=Telegraf
        PKGARCH:=all
endef

define Package/telegraf/description
        Telegraf is a plugin-driven agent for collecting and sending metrics and events.
        It supports various inputs (including prometheus endpoints) and is able to send data into InfluxDB.
endef

define Package/telegraf/install
        $(INSTALL_DIR) $(1)/usr/bin/
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/telegraf $(1)/usr/bin/telegraf
        $(CP) ./files/* $(1)/
        $(CP) $(PKG_BUILD_DIR)/etc/telegraf.conf $(1)/etc/config/telegraf
endef

$(eval $(call BuildPackage,telegraf))

I'm doing this based on the assumption you've done homework on this. I know golang-values.mk has provisions for aarch64 archs

It also might help to call it GO_ARCH and not GOARCH

go_arch=$(subst \
  aarch64,arm64,$(subst \
  i386,386,$(subst \
  mipsel,mipsle,$(subst \
  mips64el,mips64le,$(subst \
  powerpc64,ppc64,$(subst \
  x86_64,amd64,$(1)))))))

GO_OS:=linux
GO_ARCH:=$(call go_arch,$(ARCH))
(cd /home/grommish/openwrt/build_dir/target-mips64_octeonplus_64_musl/telegraf-1.19.1/./; if [ -x ./configure ]; then find /home/grommish/openwrt/build_dir/target-mips64_octeonplus_64_musl/telegraf-1.19.1/ -name config.guess | xargs -r chmod u+w; find /home/grommish/openwrt/build_dir/target-mips64_octeonplus_64_musl/telegraf-1.19.1/ -name config.guess | xargs -r -n1 cp --remove-destination /home/grommish/openwrt/scripts/config.guess; find /home/grommish/openwrt/build_dir/target-mips64_octeonplus_64_musl/telegraf-1.19.1/ -name config.sub | xargs -r chmod u+w; find /home/grommish/openwrt/build_dir/target-mips64_octeonplus_64_musl/telegraf-1.19.1/ -name config.sub | xargs -r -n1 cp --remove-destination /home/grommish/openwrt/scripts/config.sub; AR="mips64-openwrt-linux-musl-gcc-ar" AS="mips64-openwrt-linux-musl-gcc -c -Os -pipe -mno-branch-likely -march=octeon+ -mabi=64 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -fmacro-prefix-map=/home/grommish/openwrt/build_dir/target-mips64_octeonplus_64_musl/telegraf-1.19.1=telegraf-1.19.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=mips64-openwrt-linux-musl-ld.gold NM="mips64-openwrt-linux-musl-gcc-nm" CC="mips64-openwrt-linux-musl-gcc" GCC="mips64-openwrt-linux-musl-gcc" CXX="mips64-openwrt-linux-musl-g++" RANLIB="mips64-openwrt-linux-musl-gcc-ranlib" STRIP=mips64-openwrt-linux-musl-strip OBJCOPY=mips64-openwrt-linux-musl-objcopy OBJDUMP=mips64-openwrt-linux-musl-objdump SIZE=mips64-openwrt-linux-musl-size CFLAGS="-Os -pipe -mno-branch-likely -march=octeon+ -mabi=64 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -fmacro-prefix-map=/home/grommish/openwrt/build_dir/target-mips64_octeonplus_64_musl/telegraf-1.19.1=telegraf-1.19.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CXXFLAGS="-Os -pipe -mno-branch-likely -march=octeon+ -mabi=64 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -fmacro-prefix-map=/home/grommish/openwrt/build_dir/target-mips64_octeonplus_64_musl/telegraf-1.19.1=telegraf-1.19.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CPPFLAGS="-I/home/grommish/openwrt/staging_dir/toolchain-mips64_octeonplus_64_gcc-10.3.0_musl/usr/include -I/home/grommish/openwrt/staging_dir/toolchain-mips64_octeonplus_64_gcc-10.3.0_musl/include/fortify -I/home/grommish/openwrt/staging_dir/toolchain-mips64_octeonplus_64_gcc-10.3.0_musl/include " LDFLAGS="-L/home/grommish/openwrt/staging_dir/toolchain-mips64_octeonplus_64_gcc-10.3.0_musl/usr/lib -L/home/grommish/openwrt/staging_dir/toolchain-mips64_octeonplus_64_gcc-10.3.0_musl/lib -znow -zrelro "  GO_ARCH=mips64  ./configure --target=mips64-openwrt-linux --host=mips64-openwrt-linux --build=x86_64-pc-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls  ; fi; )

That's the make package/feeds/packages/telegraf/{configure} output.. You'll notice GO_ARCH= is there

No it needs to be GOARCH as stated in the documentation: https://golang.org/doc/install/source#environment

The problem for me is, that the env variable is present when calling configure but not when calling compile

jonny@padlizsan:~/openwrt$ make package/telegraf/{configure,compile} -j1 V=s
Collecting package info: done
make[1]: Entering directory '/home/jonny/openwrt'
make[2]: Entering directory '/home/jonny/openwrt/feeds/packages/utils/telegraf'
mkdir -p /home/jonny/openwrt/dl
SHELL= flock /home/jonny/openwrt/tmp/.telegraf-1.19.1.tar.gz.flock -c '  	/home/jonny/openwrt/scripts/download.pl "/home/jonny/openwrt/dl" "telegraf-1.19.1.tar.gz" "cec43bb0acfff8b4c963ffec6e3eab44ffb52c8f34e6a697207977cfd05882aa" "" "https://codeload.github.com/influxdata/telegraf/tar.gz/v1.19.1?"    '
touch /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/.prepared_03ae364ace3f6a1020c325aec9d8cfa3_6664517399ebbbc92a37c5bb081b5c53_check
. /home/jonny/openwrt/include/shell.sh; gzip -dc /home/jonny/openwrt/dl/telegraf-1.19.1.tar.gz | tar -C /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/.. -xf -
[ ! -d ./src/ ] || cp -fpR ./src/. /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1
touch /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/.prepared_03ae364ace3f6a1020c325aec9d8cfa3_6664517399ebbbc92a37c5bb081b5c53
rm -f /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/.configured_*
rm -f /home/jonny/openwrt/staging_dir/target-aarch64_cortex-a53_musl/stamp/.telegraf_installed
(cd /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/./; if [ -x ./configure ]; then find /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/ -name config.guess | xargs -r chmod u+w; find /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/ -name config.guess | xargs -r -n1 cp --remove-destination /home/jonny/openwrt/scripts/config.guess; find /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/ -name config.sub | xargs -r chmod u+w; find /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/ -name config.sub | xargs -r -n1 cp --remove-destination /home/jonny/openwrt/scripts/config.sub; AR="aarch64-openwrt-linux-musl-gcc-ar" AS="aarch64-openwrt-linux-musl-gcc -c -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1=telegraf-1.19.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=aarch64-openwrt-linux-musl-ld NM="aarch64-openwrt-linux-musl-gcc-nm" CC="aarch64-openwrt-linux-musl-gcc" GCC="aarch64-openwrt-linux-musl-gcc" CXX="aarch64-openwrt-linux-musl-g++" RANLIB="aarch64-openwrt-linux-musl-gcc-ranlib" STRIP=aarch64-openwrt-linux-musl-strip OBJCOPY=aarch64-openwrt-linux-musl-objcopy OBJDUMP=aarch64-openwrt-linux-musl-objdump SIZE=aarch64-openwrt-linux-musl-size CFLAGS="-Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1=telegraf-1.19.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CXXFLAGS="-Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1=telegraf-1.19.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CPPFLAGS="-I/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/include -I/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include/fortify -I/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include " LDFLAGS="-L/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/lib -L/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/lib -znow -zrelro "  GOARCH=aarch64  ./configure --target=aarch64-openwrt-linux --host=aarch64-openwrt-linux --build=x86_64-pc-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls  ; fi; )
touch /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/.configured_68b329da9893e34099c7d8ad5cb9c940
make[2]: Leaving directory '/home/jonny/openwrt/feeds/packages/utils/telegraf'
time: package/feeds/packages/telegraf/configure#0.28#0.11#0.32
make[1]: Leaving directory '/home/jonny/openwrt'
make[1]: Entering directory '/home/jonny/openwrt'
make[2]: Entering directory '/home/jonny/openwrt/feeds/packages/lang/golang/golang'
mkdir -p /home/jonny/openwrt/dl
SHELL= flock /home/jonny/openwrt/tmp/.go1.4-bootstrap-20171003.tar.gz.flock -c '  	/home/jonny/openwrt/scripts/download.pl "/home/jonny/openwrt/dl" "go1.4-bootstrap-20171003.tar.gz" "f4ff5b5eb3a3cae1c993723f3eab519c5bae18866b5e5f96fe1102f0cb5c3e52" "" "https://dl.google.com/go/" "https://mirrors.ustc.edu.cn/golang/" "https://mirrors.nju.edu.cn/golang/"    '
mkdir -p /home/jonny/openwrt/dl
SHELL= flock /home/jonny/openwrt/tmp/.go1.16.6.src.tar.gz.flock -c '  	/home/jonny/openwrt/scripts/download.pl "/home/jonny/openwrt/dl" "go1.16.6.src.tar.gz" "a3a5d4bc401b51db065e4f93b523347a4d343ae0c0b08a65c3423b05a138037d" "" "https://dl.google.com/go/" "https://mirrors.ustc.edu.cn/golang/" "https://mirrors.nju.edu.cn/golang/"    '
make[2]: Leaving directory '/home/jonny/openwrt/feeds/packages/lang/golang/golang'
time: package/feeds/packages/golang/host-compile#0.43#0.16#0.48
make[2]: Entering directory '/home/jonny/openwrt/package/libs/toolchain'
echo "libc" >> /home/jonny/openwrt/staging_dir/target-aarch64_cortex-a53_musl/pkginfo/toolchain.default.install
echo "libgcc" >> /home/jonny/openwrt/staging_dir/target-aarch64_cortex-a53_musl/pkginfo/toolchain.default.install
echo "libpthread" >> /home/jonny/openwrt/staging_dir/target-aarch64_cortex-a53_musl/pkginfo/toolchain.default.install
echo "librt" >> /home/jonny/openwrt/staging_dir/target-aarch64_cortex-a53_musl/pkginfo/toolchain.default.install
make[2]: Leaving directory '/home/jonny/openwrt/package/libs/toolchain'
time: package/libs/toolchain/compile#0.16#0.05#0.20
make[2]: Entering directory '/home/jonny/openwrt/feeds/packages/utils/telegraf'
mkdir -p /home/jonny/openwrt/dl
SHELL= flock /home/jonny/openwrt/tmp/.telegraf-1.19.1.tar.gz.flock -c '  	/home/jonny/openwrt/scripts/download.pl "/home/jonny/openwrt/dl" "telegraf-1.19.1.tar.gz" "cec43bb0acfff8b4c963ffec6e3eab44ffb52c8f34e6a697207977cfd05882aa" "" "https://codeload.github.com/influxdata/telegraf/tar.gz/v1.19.1?"    '
rm -f /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/.built
touch /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/.built_check
CFLAGS="-Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1=telegraf-1.19.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro  -I/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/include -I/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include/fortify -I/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include " CXXFLAGS="-Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1=telegraf-1.19.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro  -I/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/include -I/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include/fortify -I/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include " LDFLAGS="-L/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/lib -L/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/lib -znow -zrelro " make -j1 -C /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/. AR="aarch64-openwrt-linux-musl-gcc-ar" AS="aarch64-openwrt-linux-musl-gcc -c -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1=telegraf-1.19.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=aarch64-openwrt-linux-musl-ld NM="aarch64-openwrt-linux-musl-gcc-nm" CC="aarch64-openwrt-linux-musl-gcc" GCC="aarch64-openwrt-linux-musl-gcc" CXX="aarch64-openwrt-linux-musl-g++" RANLIB="aarch64-openwrt-linux-musl-gcc-ranlib" STRIP=aarch64-openwrt-linux-musl-strip OBJCOPY=aarch64-openwrt-linux-musl-objcopy OBJDUMP=aarch64-openwrt-linux-musl-objdump SIZE=aarch64-openwrt-linux-musl-size CROSS="aarch64-openwrt-linux-musl-" ARCH="aarch64" ;
make[3]: Entering directory '/home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1'
go mod download -x
go build -ldflags "-L/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/lib -L/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/lib -znow -zrelro  -X main.commit=39f81b0b -X main.branch=master -X main.goos=linux -X main.goarch=amd64 -X main.commit=39f81b0b -X main.branch=master -X main.goos=linux -X main.goarch=amd64" ./cmd/telegraf
# runtime/cgo
aarch64-openwrt-linux-musl-gcc: error: unrecognized command line option '-m64'
make[4]: *** [Makefile:93: telegraf] Error 2
make[3]: *** [Makefile:67: all] Error 2
make[3]: Leaving directory '/home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1'
make[2]: *** [Makefile:47: /home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1/.built] Error 2
make[2]: Leaving directory '/home/jonny/openwrt/feeds/packages/utils/telegraf'
time: package/feeds/packages/telegraf/compile#4.06#0.72#1.66
    ERROR: package/feeds/packages/telegraf failed to build.
make[1]: *** [package/Makefile:116: package/feeds/packages/telegraf/compile] Error 1
make[1]: Leaving directory '/home/jonny/openwrt'
make: *** [/home/jonny/openwrt/include/toplevel.mk:230: package/telegraf/compile] Error 2

I did miss that and managed to get the right arch name now with

include $(TOPDIR)/feeds/packages/lang/golang/golang-values.mk
[...]
CONFIGURE_VARS += \
	GOARCH=$(GO_ARCH)

BUT unfortunately the environment variable is only present in configure and not in compile.

Do you have any idea why ?
Is the environment variable present for you in compile ?

I found it!

It is call MAKE_VARS. Why isn't it descriped in the wiki ? :smiley:

include $(TOPDIR)/feeds/packages/lang/golang/golang-values.mk
[...]
MAKE_VARS += \
	GOARCH="$(GO_ARCH)"

But now I run into problem while linking... Any idea ?


make[3]: Entering directory '/home/jonny/openwrt/build_dir/target-aarch64_cortex-a53_musl/telegraf-1.19.1'
go mod download -x
go build -ldflags "-L/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/lib -L/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/lib -znow -zrelro  -X main.commit=39f81b0b -X main.branch=master -X main.goos=linux -X main.goarch=arm64 -X main.commit=39f81b0b -X main.branch=master -X main.goos=linux -X main.goarch=arm64" ./cmd/telegraf
# github.com/influxdata/telegraf/cmd/telegraf
flag provided but not defined: -L/home/jonny/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/lib
usage: link [options] main.o
  -B note
    	add an ELF NT_GNU_BUILD_ID note when using ELF
  -E entry
    	set entry symbol name
  -H type
    	set header type
  -I linker
    	use linker as ELF dynamic linker
  -L directory
    	add specified directory to library path
  -R quantum
    	set address rounding quantum (default -1)
  -T address
    	set text segment address (default -1)
  -V	print version and exit
  -X definition
    	add string value definition of the form importpath.name=value
  -a	no-op (deprecated)
  -aslr
    	enable ASLR for buildmode=c-shared on windows (default true)
  -benchmark string
    	set to 'mem' or 'cpu' to enable phase benchmarking
  -benchmarkprofile base
    	emit phase profiles to base_phase.{cpu,mem}prof
  -buildid id
    	record id as Go toolchain build id
  -buildmode mode
    	set build mode
  -c	dump call graph
  -compressdwarf
    	compress DWARF if possible (default true)
  -cpuprofile file
    	write cpu profile to file
  -d	disable dynamic executable
  -debugppc64textsize int
    	debug PPC64 text section max
  -debugtramp int
    	debug trampolines
  -dumpdep
    	dump symbol dependency graph
  -extar string
    	archive program for buildmode=c-archive
  -extld linker
    	use linker when linking in external mode
  -extldflags flags
    	pass flags to external linker
  -f	ignore version mismatch
  -g	disable go package data checks
  -h	halt on error
  -importcfg file
    	read import configuration from file
  -installsuffix suffix
    	set package directory suffix
  -k symbol
    	set field tracking symbol
  -libgcc string
    	compiler support lib for internal linking; use "none" to disable
  -linkmode mode
    	set link mode
  -linkshared
    	link against installed Go shared libraries
  -memprofile file
    	write memory profile to file
  -memprofilerate rate
    	set runtime.MemProfileRate to rate
  -msan
    	enable MSan interface
  -n	dump symbol table
  -o file
    	write output to file
  -pluginpath string
    	full path name for plugin
  -r path
    	set the ELF dynamic linker search path to dir1:dir2:...
  -race
    	enable race detector
  -s	disable symbol table
  -strictdups int
    	sanity check duplicate symbol contents during object file reading (1=warn 2=err).
  -tmpdir directory
    	use directory for temporary files
  -v	print link trace
  -w	disable DWARF generation
make[4]: *** [Makefile:93: telegraf] Error 2
make[3]: *** [Makefile:67: all] Error 2

Okay found it. Sorry for spamming here.

The solution was:

1.) Include the golang-values.mk
2.) Use MAKE_VARS and replace them with GOARCH

In total:

include $(TOPDIR)/rules.mk

PKG_NAME:=telegraf

PKG_VERSION:=1.19.1

PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz

PKG_SOURCE_URL:=https://codeload.github.com/influxdata/telegraf/tar.gz/v$(PKG_VERSION)?

PKG_HASH:=cec43bb0acfff8b4c963ffec6e3eab44ffb52c8f34e6a697207977cfd05882aa

PKG_BUILD_DEPENDS:=golang/host

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

PKG_MAINTAINER:=Jonathan Pagel <jonny_tischbein@systemli.org>

PKG_LICENSE:=MIT

include $(INCLUDE_DIR)/package.mk

include $(TOPDIR)/feeds/packages/lang/golang/golang-values.mk

MAKE_VARS = \

GOARCH=$(GO_ARCH)

define Package/telegraf

SECTION:=utils

CATEGORY:=Utilities

TITLE:=Telegraf

PKGARCH:=all

endef

define Package/telegraf/description

Telegraf is a plugin-driven agent for collecting and sending metrics and events.

It supports various inputs (including prometheus endpoints) and is able to send data into InfluxDB.

endef

define Package/telegraf/install

$(INSTALL_DIR) $(1)/usr/bin/

$(INSTALL_BIN) $(PKG_BUILD_DIR)/telegraf $(1)/usr/bin/telegraf

$(CP) ./files/* $(1)/

$(CP) $(PKG_BUILD_DIR)/etc/telegraf.conf $(1)/etc/config/telegraf

endef

$(eval $(call BuildPackage,telegraf))

I would highly recommend to add MAKE_VARS to the documentation!

Thanks for your help @Grommish !

You can find my PR Draft here.

3 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.