PublicNotes on Nostr: # Previous Questions I am building `ipk` files for the `GL-AR300m` and for the ...
# Previous Questions
I am building `ipk` files for the `GL-AR300m` and for the `GL-MT3000` using the same `golang.mk` file below:
```
:~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ cat golang.mk
#
# Copyright (C) 2018 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
ifneq ($(__golang_mk_inc),1)
__golang_mk_inc=1
ifeq ($(DUMP),)
GO_VERSION_MAJOR_MINOR:=$(shell go version | sed -E 's/.*go([0-9]+[.][0-9]+).*/\1/')
endif
GO_ARM:=$(if $(CONFIG_arm),$(if $(CONFIG_HAS_FPU),7,$(if $(CONFIG_GOARM_5),5,$(if $(CONFIG_GOARM_6),6,7))))
GO_MIPS:=$(if $(CONFIG_mips),$(if $(CONFIG_MIPS_FP_32),hardfloat,softfloat),)
GO_MIPS64:=$(if $(CONFIG_mips64),$(if $(CONFIG_MIPS_FP_64),hardfloat,softfloat),)
GO_386:=$(if $(CONFIG_i386),$(if $(CONFIG_CPU_TYPE_PENTIUM4),387,sse2),)
GO_TARGET_ARCH:=$(subst aarch64,arm64,$(subst x86_64,amd64,$(subst i386,386,$(ARCH))))
GO_TARGET_OS:=linux
GO_HOST_ARCH:=$(shell go env GOHOSTARCH)
GO_HOST_OS:=$(shell go env GOHOSTOS)
GO_HOST_TARGET_SAME:=$(if $(and $(findstring $(GO_TARGET_ARCH),$(GO_HOST_ARCH)),$(findstring $(GO_TARGET_OS),$(GO_HOST_OS))),1)
GO_HOST_TARGET_DIFFERENT:=$(if $(GO_HOST_TARGET_SAME),,1)
GO_STRIP_ARGS:=--strip-unneeded --remove-section=.comment --remove-section=.note
GO_PKG_GCFLAGS:=
GO_PKG_LDFLAGS:=-s -w
GO_PKG_BUILD_PKG?=$(GO_PKG)/...
GO_PKG_WORK_DIR_NAME:=.go_work
GO_PKG_WORK_DIR:=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)
GO_PKG_BUILD_DIR:=$(GO_PKG_WORK_DIR)/build
GO_PKG_CACHE_DIR:=$(GO_PKG_WORK_DIR)/cache
GO_PKG_TMP_DIR:=$(GO_PKG_WORK_DIR)/tmp
GO_PKG_BUILD_BIN_DIR:=$(GO_PKG_BUILD_DIR)/bin$(if $(GO_HOST_TARGET_DIFFERENT),/$(GO_TARGET_OS)_$(GO_TARGET_ARCH))
GO_BUILD_DIR_PATH:=$(firstword $(subst :, ,$(GOPATH)))
GO_BUILD_PATH:=$(if $(GO_PKG),$(GO_BUILD_DIR_PATH)/src/$(GO_PKG))
endif # __golang_mk_inc
```
This is the `Makefile` that I used to compile for the `GL-AR300m` and the `GL-MT3000`:
```
:~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ cat Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=tollgate-module-relay-go
PKG_VERSION:=0.1
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/OpenTollGate/tollgate-module-relay-go.git
PKG_SOURCE_VERSION:=HEAD
# You'll need to generate a new hash after first clone
PKG_MIRROR_HASH:=skip
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
# Define IPK path variable
IPK_FILE:=$(BIN_DIR)/packages/$(ARCH_PACKAGES)/custom/$(PKG_NAME)_$(PKG_VERSION)-$(PKG_RELEASE)_$(ARCH_PACKAGES).ipk
# Add this before including golang.mk
$(shell mkdir -p $(TOPDIR)/include)
$(shell cp -f $(CURDIR)/golang.mk $(TOPDIR)/include/golang.mk 2>/dev/null || true)
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/golang.mk
define Package/tollgate-module-relay-go
SECTION:=net
CATEGORY:=Network
TITLE:=TollGate Relay Module
URL:=https://github.com/OpenTollGate/tollgate-module-relay-go
DEPENDS:=+golang
endef
define Package/tollgate-module-relay-go/description
TollGate Relay Module implementation in Go
endef
define Build/Prepare
$(call Build/Prepare/Default)
mkdir -p $(PKG_BUILD_DIR)/src
$(CP) $(PKG_BUILD_DIR)/src/* $(PKG_BUILD_DIR)/
cd $(PKG_BUILD_DIR) && \
rm -f go.mod go.sum && \
go mod init tollgate-module-relay-go && \
go mod edit -replace github.com/OpenTollgate/relay=./ && \
go mod tidy && \
go get github.com/fiatjaf/khatru && \
go get github.com/nbd-wtf/go-nostr
endef
define Build/Configure
endef
define Build/Compile
cd $(PKG_BUILD_DIR) && \
GOOS=$(GO_TARGET_OS) \
GOARCH=$(GO_TARGET_ARCH) \
GOARM=$(GO_ARM) \
GOMIPS=$(GO_MIPS) \
GO386=$(GO_386) \
CGO_ENABLED=1 \
CC=$(TARGET_CC) \
CXX=$(TARGET_CXX) \
GOPATH=$(GOPATH) \
go build -trimpath -ldflags "-s -w" -o $(PKG_BUILD_DIR)/tollgate-relay main.go
endef
define Package/tollgate-module-relay-go/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/tollgate-relay $(1)/usr/bin/
endef
# Add custom target to print IPK path
#define Package/tollgate-module-relay-go/postinst
# echo "Package compiled successfully!"
# echo "IPK file location: $(IPK_FILE)"
#endef
$(eval $(call BuildPackage,tollgate-module-relay-go))
# Print IPK path after successful compilation
PKG_FINISH:=$(shell echo "Successfully built: $(IPK_FILE)" >&2)
```
However, I get the following error when installing the `ipk` files on the `AR300m`.
```
root@GL-AR300M:/tmp# opkg install whoami.ipk
Unknown package 'tollgate-module-whoami-go'.
Collected errors:
* pkg_hash_check_unresolved: cannot find dependency golang for tollgate-module-whoami-go
* pkg_hash_fetch_best_installation_candidate: Packages for tollgate-module-whoami-go found, but incompatible with the architectures configured
* opkg_install_cmd: Cannot install package tollgate-module-whoami-go.
```
How do I need to modify the `golang.mk` file to ensure that it works on both routers?
----------------------------
```
root@GL-AR300M:/tmp# opkg install whoami.ipk
Unknown package 'tollgate-module-whoami-go'.
Collected errors:
* pkg_hash_check_unresolved: cannot find dependency golang for tollgate-module-whoami-go
* pkg_hash_fetch_best_installation_candidate: Packages for tollgate-module-whoami-go found, but incompatible with the architectures configured
* opkg_install_cmd: Cannot install package tollgate-module-whoami-go.
```
Unfortunately, I'm still getting the above error. Go binaries have previously been compiled successfully with the following commands.
```
cd ./src
env GOOS=linux GOARCH=mips GOMIPS=softfloat go build -o relay -trimpath -ldflags="-s -w"
# Hint: copy to connected router
scp -O relay root@192.168.8.1:/tmp/relay
```
Could the above commands help to fix the following `golang.mk` file?
```
6:~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ cat golang.mk
#
# Copyright (C) 2018 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
ifneq ($(__golang_mk_inc),1)
__golang_mk_inc=1
# Explicitly define architectures
GO_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mips64||mipsel||mips64el||powerpc64||x86_64)
ifeq ($(DUMP),)
GO_VERSION_MAJOR_MINOR:=$(shell go version | sed -E 's/.*go([0-9]+[.][0-9]+).*/\1/')
endif
# Architecture-specific settings
GO_ARM:=$(if $(CONFIG_arm),$(if $(CONFIG_HAS_FPU),7,$(if $(CONFIG_GOARM_5),5,$(if $(CONFIG_GOARM_6),6,7))))
GO_MIPS:=$(if $(CONFIG_mips),$(if $(CONFIG_MIPS_FP_32),hardfloat,softfloat),)
GO_MIPS64:=$(if $(CONFIG_mips64),$(if $(CONFIG_MIPS_FP_64),hardfloat,softfloat),)
GO_386:=$(if $(CONFIG_i386),$(if $(CONFIG_CPU_TYPE_PENTIUM4),387,sse2),)
# Target architecture mapping
GO_TARGET_ARCH:=$(subst \
aarch64,arm64,$(subst \
x86_64,amd64,$(subst \
i386,386,$(subst \
mipsel,mipsle,$(subst \
mips64el,mips64le,$(subst \
powerpc64,ppc64,$(ARCH)))))))
GO_TARGET_OS:=linux
# Host settings
GO_HOST_ARCH:=$(shell go env GOHOSTARCH)
GO_HOST_OS:=$(shell go env GOHOSTOS)
GO_HOST_TARGET_SAME:=$(if $(and $(findstring $(GO_TARGET_ARCH),$(GO_HOST_ARCH)),$(findstring $(GO_TARGET_OS),$(GO_HOST_OS))),1)
GO_HOST_TARGET_DIFFERENT:=$(if $(GO_HOST_TARGET_SAME),,1)
# Build flags
GO_STRIP_ARGS:=--strip-unneeded --remove-section=.comment --remove-section=.note
GO_PKG_GCFLAGS:=
GO_PKG_LDFLAGS:=-s -w
# Remove the PIE mode for MIPS architecture
ifeq ($(GO_TARGET_ARCH),mips)
GO_LDFLAGS:=-extldflags "-static -z now"
GO_PKG_GCFLAGS:=-N -l
else
GO_LDFLAGS:=-extldflags "-static"
GO_CUSTOM_FLAGS:=-buildmode pie
endif
# Package build settings
GO_PKG_BUILD_PKG?=$(GO_PKG)/...
GO_PKG_WORK_DIR_NAME:=.go_work
GO_PKG_WORK_DIR:=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)
GO_PKG_BUILD_DIR:=$(GO_PKG_WORK_DIR)/build
GO_PKG_CACHE_DIR:=$(GO_PKG_WORK_DIR)/cache
GO_PKG_TMP_DIR:=$(GO_PKG_WORK_DIR)/tmp
GO_PKG_BUILD_BIN_DIR:=$(GO_PKG_BUILD_DIR)/bin$(if $(GO_HOST_TARGET_DIFFERENT),/$(GO_TARGET_OS)_$(GO_TARGET_ARCH))
# Build paths
GO_BUILD_DIR_PATH:=$(firstword $(subst :, ,$(GOPATH)))
GO_BUILD_PATH:=$(if $(GO_PKG),$(GO_BUILD_DIR_PATH)/src/$(GO_PKG))
# Architecture-specific compile flags
GO_COMPILE_FLAGS:= \
GOOS=$(GO_TARGET_OS) \
GOARCH=$(GO_TARGET_ARCH) \
GO386=$(GO_386) \
GOARM=$(GO_ARM) \
GOMIPS=$(GO_MIPS) \
GOMIPS64=$(GO_MIPS64) \
CGO_ENABLED=1 \
CC=$(TARGET_CC) \
CXX=$(TARGET_CXX) \
GOPATH=$(GOPATH)
endif # __golang_mk_inc
```
---------------------------------
I am getting a `Makefile` related error message now:
```
[ ! -d ./src/ ] || cp -fpR ./src/. /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1
touch /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.prepared_2b86c604625865670896968022b130f6_18f1e190c5d53547fed41a3eaa76e9e9
rm -f /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.configured_*
rm -f /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/target-mips_24kc_musl/stamp/.tollgate-module-relay-go_installed
(cd /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/./; if [ -x ./configure ]; then find /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/ -name config.guess | xargs -r chmod u+w; find /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/ -name config.guess | xargs -r -n1 cp --remove-destination /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/scripts/config.guess; find /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/ -name config.sub | xargs -r chmod u+w; find /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/ -name config.sub | xargs -r -n1 cp --remove-destination /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/scripts/config.sub; AR="mips-openwrt-linux-musl-gcc-ar" AS="mips-openwrt-linux-musl-gcc -c -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -ffile-prefix-map=/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1=tollgate-module-relay-go-0.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=mips-openwrt-linux-musl-ld NM="mips-openwrt-linux-musl-gcc-nm" CC="mips-openwrt-linux-musl-gcc" GCC="mips-openwrt-linux-musl-gcc" CXX="mips-openwrt-linux-musl-g++" RANLIB="mips-openwrt-linux-musl-gcc-ranlib" STRIP=mips-openwrt-linux-musl-strip OBJCOPY=mips-openwrt-linux-musl-objcopy OBJDUMP=mips-openwrt-linux-musl-objdump SIZE=mips-openwrt-linux-musl-size CFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -ffile-prefix-map=/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1=tollgate-module-relay-go-0.1 -mips16 -minterlink-mips16 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CXXFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -ffile-prefix-map=/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1=tollgate-module-relay-go-0.1 -mips16 -minterlink-mips16 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -mips16 -minterlink-mips16 " CPPFLAGS="-I/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/usr/include -I/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/include/fortify -I/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/include " LDFLAGS="-L/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/usr/lib -L/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib -znow -zrelro " ./configure --target=mips-openwrt-linux --host=mips-openwrt-linux --build=x86_64-pc-linux-gnu --disable-dependency-tracking --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 /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.configured_68b329da9893e34099c7d8ad5cb9c940
rm -f /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.built
touch /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.built_check
cd /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1 && GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/tollgate-relay main.go
no required module provides package main.go: go.mod file not found in current directory or any parent directory; see 'go help modules'
make[2]: *** [Makefile:55: /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.built] Error 1
make[2]: Leaving directory '/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/feeds/custom/tollgate-module-relay-go'
time: package/feeds/custom/tollgate-module-relay-go/compile#3.52#0.43#4.76
ERROR: package/feeds/custom/tollgate-module-relay-go failed to build.
make[1]: *** [package/Makefile:129: package/feeds/custom/tollgate-module-relay-go/compile] Error 1
make[1]: Leaving directory '/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64'
make: *** [/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/include/toplevel.mk:225: package/feeds/custom/tollgate-module-relay-go/compile] Error 2
```
Could it be that we broke something in the `Makefile`?
```
~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ cat Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=tollgate-module-relay-go
PKG_VERSION:=0.1
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/OpenTollGate/tollgate-module-relay-go.git
PKG_SOURCE_VERSION:=HEAD
# You'll need to generate a new hash after first clone
PKG_MIRROR_HASH:=skip
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
# Define IPK path variable
IPK_FILE:=$(BIN_DIR)/packages/$(ARCH_PACKAGES)/custom/$(PKG_NAME)_$(PKG_VERSION)-$(PKG_RELEASE)_$(ARCH_PACKAGES).ipk
# Add this before including golang.mk
$(shell mkdir -p $(TOPDIR)/include)
$(shell cp -f $(CURDIR)/golang.mk $(TOPDIR)/include/golang.mk 2>/dev/null || true)
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/golang.mk
define Package/tollgate-module-relay-go
SECTION:=net
CATEGORY:=Network
TITLE:=TollGate Relay Module
URL:=https://github.com/OpenTollGate/tollgate-module-relay-go
DEPENDS:=@(mips||aarch64) $(if $(CONFIG_aarch64),+golang,)
endef
define Build/Compile
cd $(PKG_BUILD_DIR) && \
$(GO_COMPILE_FLAGS) \
go build \
-trimpath \
-ldflags="$(GO_PKG_LDFLAGS)" \
-o $(PKG_BUILD_DIR)/tollgate-relay main.go
endef
define Package/tollgate-module-relay-go/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/tollgate-relay $(1)/usr/bin/
endef
# Add custom target to print IPK path
#define Package/tollgate-module-relay-go/postinst
# echo "Package compiled successfully!"
# echo "IPK file location: $(IPK_FILE)"
#endef
$(eval $(call BuildPackage,tollgate-module-relay-go))
# Print IPK path after successful compilation
PKG_FINISH:=$(shell echo "Successfully built: $(IPK_FILE)" >&2)
```
Here are the changes that we made in the `Makefile`. Some of these changes might be worth keeping because we want to support both the `GLAR300m` and the `GLMT3000`:
```
~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ git diff main Makefile
diff --git a/tollgate-module-relay-go/Makefile b/tollgate-module-relay-go/Makefile
index 82b7ebf..a1dd2ad 100644
--- a/tollgate-module-relay-go/Makefile
+++ b/tollgate-module-relay-go/Makefile
@@ -26,41 +26,16 @@ define Package/tollgate-module-relay-go
CATEGORY:=Network
TITLE:=TollGate Relay Module
URL:=https://github.com/OpenTollGate/tollgate-module-relay-go
- DEPENDS:=+golang
-endef
-
-define Package/tollgate-module-relay-go/description
- TollGate Relay Module implementation in Go
-endef
-
-define Build/Prepare
- $(call Build/Prepare/Default)
- mkdir -p $(PKG_BUILD_DIR)/src
- $(CP) $(PKG_BUILD_DIR)/src/* $(PKG_BUILD_DIR)/
- cd $(PKG_BUILD_DIR) && \
- rm -f go.mod go.sum && \
- go mod init tollgate-module-relay-go && \
- go mod edit -replace github.com/OpenTollgate/relay=./ && \
- go mod tidy && \
- go get github.com/fiatjaf/khatru && \
- go get github.com/nbd-wtf/go-nostr
-endef
-
-define Build/Configure
+ DEPENDS:=@(mips||aarch64) $(if $(CONFIG_aarch64),+golang,)
endef
define Build/Compile
cd $(PKG_BUILD_DIR) && \
- GOOS=$(GO_TARGET_OS) \
- GOARCH=$(GO_TARGET_ARCH) \
- GOARM=$(GO_ARM) \
- GOMIPS=$(GO_MIPS) \
- GO386=$(GO_386) \
- CGO_ENABLED=1 \
- CC=$(TARGET_CC) \
- CXX=$(TARGET_CXX) \
- GOPATH=$(GOPATH) \
- go build -trimpath -ldflags "-s -w" -o $(PKG_BUILD_DIR)/tollgate-relay main.go
+ $(GO_COMPILE_FLAGS) \
+ go build \
+ -trimpath \
+ -ldflags="$(GO_PKG_LDFLAGS)" \
+ -o $(PKG_BUILD_DIR)/tollgate-relay main.go
endef
define Package/tollgate-module-relay-go/install
```
Commit `3197f918d2850799887a91a19e1ee9f240717dad`
As you can see below, it no longer says that whoami has the wrong architecture.
```
root@GL-AR300M:/tmp# wget https://github.com/OpenTollGate/tollgate-sdk/releases/download/t
est_arch/tollgate-module-whoami-go_0.1-1_mips_24kc.ipk
Downloading 'https://github.com/OpenTollGate/tollgate-sdk/releases/download/test_arch/tollgate-module-whoami-go_0.1-1_mips_24kc.ipk';
Connecting to 140.82.121.4:443
Redirected to /github-production-release-asset-2e65be/904311377/669e575a-1522-42e2-b016-3320b12b62f8?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20250127%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250127T180742Z&X-Amz-Expires=300&X-Amz-Signature=2880275209faf79c2b03553e244c090e75b931821dbf1fe31f3ebdfbd4409f91&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dtollgate-module-whoami-go_0.1-1_mips_24kc.ipk&response-content-type=application%2Foctet-stream on objects.githubusercontent.com
Writing to '669e575a-1522-42e2-b016-3320b12b62f8?X-Amz-Algorithm=AWS4-HMAC-SHA256'
669e575a-1522-42e2-b 100% |*******************************| 2048k 0:00:00 ETA
Download completed (2097404 bytes)
root@GL-AR300M:/tmp# mv 669e575a-1522-42e2-b016-3320b12b62f8\?X-Amz-Algorithm=AWS4-HMAC-SH
A256 whoami.ipk
root@GL-AR300M:/tmp# opkg install whoami.ipk
Installing tollgate-module-whoami-go (0.1-1) to root...
Collected errors:
* verify_pkg_installable: Only have 116kb available on filesystem /overlay, pkg tollgate-module-whoami-go needs 2053
* opkg_install_cmd: Cannot install package tollgate-module-whoami-go.
```
I intend to install a fresh OpenWRT image on the router to make space and then see if I can install the `whoami` module..
I am building `ipk` files for the `GL-AR300m` and for the `GL-MT3000` using the same `golang.mk` file below:
```
:~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ cat golang.mk
#
# Copyright (C) 2018 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
ifneq ($(__golang_mk_inc),1)
__golang_mk_inc=1
ifeq ($(DUMP),)
GO_VERSION_MAJOR_MINOR:=$(shell go version | sed -E 's/.*go([0-9]+[.][0-9]+).*/\1/')
endif
GO_ARM:=$(if $(CONFIG_arm),$(if $(CONFIG_HAS_FPU),7,$(if $(CONFIG_GOARM_5),5,$(if $(CONFIG_GOARM_6),6,7))))
GO_MIPS:=$(if $(CONFIG_mips),$(if $(CONFIG_MIPS_FP_32),hardfloat,softfloat),)
GO_MIPS64:=$(if $(CONFIG_mips64),$(if $(CONFIG_MIPS_FP_64),hardfloat,softfloat),)
GO_386:=$(if $(CONFIG_i386),$(if $(CONFIG_CPU_TYPE_PENTIUM4),387,sse2),)
GO_TARGET_ARCH:=$(subst aarch64,arm64,$(subst x86_64,amd64,$(subst i386,386,$(ARCH))))
GO_TARGET_OS:=linux
GO_HOST_ARCH:=$(shell go env GOHOSTARCH)
GO_HOST_OS:=$(shell go env GOHOSTOS)
GO_HOST_TARGET_SAME:=$(if $(and $(findstring $(GO_TARGET_ARCH),$(GO_HOST_ARCH)),$(findstring $(GO_TARGET_OS),$(GO_HOST_OS))),1)
GO_HOST_TARGET_DIFFERENT:=$(if $(GO_HOST_TARGET_SAME),,1)
GO_STRIP_ARGS:=--strip-unneeded --remove-section=.comment --remove-section=.note
GO_PKG_GCFLAGS:=
GO_PKG_LDFLAGS:=-s -w
GO_PKG_BUILD_PKG?=$(GO_PKG)/...
GO_PKG_WORK_DIR_NAME:=.go_work
GO_PKG_WORK_DIR:=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)
GO_PKG_BUILD_DIR:=$(GO_PKG_WORK_DIR)/build
GO_PKG_CACHE_DIR:=$(GO_PKG_WORK_DIR)/cache
GO_PKG_TMP_DIR:=$(GO_PKG_WORK_DIR)/tmp
GO_PKG_BUILD_BIN_DIR:=$(GO_PKG_BUILD_DIR)/bin$(if $(GO_HOST_TARGET_DIFFERENT),/$(GO_TARGET_OS)_$(GO_TARGET_ARCH))
GO_BUILD_DIR_PATH:=$(firstword $(subst :, ,$(GOPATH)))
GO_BUILD_PATH:=$(if $(GO_PKG),$(GO_BUILD_DIR_PATH)/src/$(GO_PKG))
endif # __golang_mk_inc
```
This is the `Makefile` that I used to compile for the `GL-AR300m` and the `GL-MT3000`:
```
:~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ cat Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=tollgate-module-relay-go
PKG_VERSION:=0.1
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/OpenTollGate/tollgate-module-relay-go.git
PKG_SOURCE_VERSION:=HEAD
# You'll need to generate a new hash after first clone
PKG_MIRROR_HASH:=skip
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
# Define IPK path variable
IPK_FILE:=$(BIN_DIR)/packages/$(ARCH_PACKAGES)/custom/$(PKG_NAME)_$(PKG_VERSION)-$(PKG_RELEASE)_$(ARCH_PACKAGES).ipk
# Add this before including golang.mk
$(shell mkdir -p $(TOPDIR)/include)
$(shell cp -f $(CURDIR)/golang.mk $(TOPDIR)/include/golang.mk 2>/dev/null || true)
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/golang.mk
define Package/tollgate-module-relay-go
SECTION:=net
CATEGORY:=Network
TITLE:=TollGate Relay Module
URL:=https://github.com/OpenTollGate/tollgate-module-relay-go
DEPENDS:=+golang
endef
define Package/tollgate-module-relay-go/description
TollGate Relay Module implementation in Go
endef
define Build/Prepare
$(call Build/Prepare/Default)
mkdir -p $(PKG_BUILD_DIR)/src
$(CP) $(PKG_BUILD_DIR)/src/* $(PKG_BUILD_DIR)/
cd $(PKG_BUILD_DIR) && \
rm -f go.mod go.sum && \
go mod init tollgate-module-relay-go && \
go mod edit -replace github.com/OpenTollgate/relay=./ && \
go mod tidy && \
go get github.com/fiatjaf/khatru && \
go get github.com/nbd-wtf/go-nostr
endef
define Build/Configure
endef
define Build/Compile
cd $(PKG_BUILD_DIR) && \
GOOS=$(GO_TARGET_OS) \
GOARCH=$(GO_TARGET_ARCH) \
GOARM=$(GO_ARM) \
GOMIPS=$(GO_MIPS) \
GO386=$(GO_386) \
CGO_ENABLED=1 \
CC=$(TARGET_CC) \
CXX=$(TARGET_CXX) \
GOPATH=$(GOPATH) \
go build -trimpath -ldflags "-s -w" -o $(PKG_BUILD_DIR)/tollgate-relay main.go
endef
define Package/tollgate-module-relay-go/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/tollgate-relay $(1)/usr/bin/
endef
# Add custom target to print IPK path
#define Package/tollgate-module-relay-go/postinst
# echo "Package compiled successfully!"
# echo "IPK file location: $(IPK_FILE)"
#endef
$(eval $(call BuildPackage,tollgate-module-relay-go))
# Print IPK path after successful compilation
PKG_FINISH:=$(shell echo "Successfully built: $(IPK_FILE)" >&2)
```
However, I get the following error when installing the `ipk` files on the `AR300m`.
```
root@GL-AR300M:/tmp# opkg install whoami.ipk
Unknown package 'tollgate-module-whoami-go'.
Collected errors:
* pkg_hash_check_unresolved: cannot find dependency golang for tollgate-module-whoami-go
* pkg_hash_fetch_best_installation_candidate: Packages for tollgate-module-whoami-go found, but incompatible with the architectures configured
* opkg_install_cmd: Cannot install package tollgate-module-whoami-go.
```
How do I need to modify the `golang.mk` file to ensure that it works on both routers?
----------------------------
```
root@GL-AR300M:/tmp# opkg install whoami.ipk
Unknown package 'tollgate-module-whoami-go'.
Collected errors:
* pkg_hash_check_unresolved: cannot find dependency golang for tollgate-module-whoami-go
* pkg_hash_fetch_best_installation_candidate: Packages for tollgate-module-whoami-go found, but incompatible with the architectures configured
* opkg_install_cmd: Cannot install package tollgate-module-whoami-go.
```
Unfortunately, I'm still getting the above error. Go binaries have previously been compiled successfully with the following commands.
```
cd ./src
env GOOS=linux GOARCH=mips GOMIPS=softfloat go build -o relay -trimpath -ldflags="-s -w"
# Hint: copy to connected router
scp -O relay root@192.168.8.1:/tmp/relay
```
Could the above commands help to fix the following `golang.mk` file?
```
6:~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ cat golang.mk
#
# Copyright (C) 2018 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
ifneq ($(__golang_mk_inc),1)
__golang_mk_inc=1
# Explicitly define architectures
GO_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mips64||mipsel||mips64el||powerpc64||x86_64)
ifeq ($(DUMP),)
GO_VERSION_MAJOR_MINOR:=$(shell go version | sed -E 's/.*go([0-9]+[.][0-9]+).*/\1/')
endif
# Architecture-specific settings
GO_ARM:=$(if $(CONFIG_arm),$(if $(CONFIG_HAS_FPU),7,$(if $(CONFIG_GOARM_5),5,$(if $(CONFIG_GOARM_6),6,7))))
GO_MIPS:=$(if $(CONFIG_mips),$(if $(CONFIG_MIPS_FP_32),hardfloat,softfloat),)
GO_MIPS64:=$(if $(CONFIG_mips64),$(if $(CONFIG_MIPS_FP_64),hardfloat,softfloat),)
GO_386:=$(if $(CONFIG_i386),$(if $(CONFIG_CPU_TYPE_PENTIUM4),387,sse2),)
# Target architecture mapping
GO_TARGET_ARCH:=$(subst \
aarch64,arm64,$(subst \
x86_64,amd64,$(subst \
i386,386,$(subst \
mipsel,mipsle,$(subst \
mips64el,mips64le,$(subst \
powerpc64,ppc64,$(ARCH)))))))
GO_TARGET_OS:=linux
# Host settings
GO_HOST_ARCH:=$(shell go env GOHOSTARCH)
GO_HOST_OS:=$(shell go env GOHOSTOS)
GO_HOST_TARGET_SAME:=$(if $(and $(findstring $(GO_TARGET_ARCH),$(GO_HOST_ARCH)),$(findstring $(GO_TARGET_OS),$(GO_HOST_OS))),1)
GO_HOST_TARGET_DIFFERENT:=$(if $(GO_HOST_TARGET_SAME),,1)
# Build flags
GO_STRIP_ARGS:=--strip-unneeded --remove-section=.comment --remove-section=.note
GO_PKG_GCFLAGS:=
GO_PKG_LDFLAGS:=-s -w
# Remove the PIE mode for MIPS architecture
ifeq ($(GO_TARGET_ARCH),mips)
GO_LDFLAGS:=-extldflags "-static -z now"
GO_PKG_GCFLAGS:=-N -l
else
GO_LDFLAGS:=-extldflags "-static"
GO_CUSTOM_FLAGS:=-buildmode pie
endif
# Package build settings
GO_PKG_BUILD_PKG?=$(GO_PKG)/...
GO_PKG_WORK_DIR_NAME:=.go_work
GO_PKG_WORK_DIR:=$(PKG_BUILD_DIR)/$(GO_PKG_WORK_DIR_NAME)
GO_PKG_BUILD_DIR:=$(GO_PKG_WORK_DIR)/build
GO_PKG_CACHE_DIR:=$(GO_PKG_WORK_DIR)/cache
GO_PKG_TMP_DIR:=$(GO_PKG_WORK_DIR)/tmp
GO_PKG_BUILD_BIN_DIR:=$(GO_PKG_BUILD_DIR)/bin$(if $(GO_HOST_TARGET_DIFFERENT),/$(GO_TARGET_OS)_$(GO_TARGET_ARCH))
# Build paths
GO_BUILD_DIR_PATH:=$(firstword $(subst :, ,$(GOPATH)))
GO_BUILD_PATH:=$(if $(GO_PKG),$(GO_BUILD_DIR_PATH)/src/$(GO_PKG))
# Architecture-specific compile flags
GO_COMPILE_FLAGS:= \
GOOS=$(GO_TARGET_OS) \
GOARCH=$(GO_TARGET_ARCH) \
GO386=$(GO_386) \
GOARM=$(GO_ARM) \
GOMIPS=$(GO_MIPS) \
GOMIPS64=$(GO_MIPS64) \
CGO_ENABLED=1 \
CC=$(TARGET_CC) \
CXX=$(TARGET_CXX) \
GOPATH=$(GOPATH)
endif # __golang_mk_inc
```
---------------------------------
I am getting a `Makefile` related error message now:
```
[ ! -d ./src/ ] || cp -fpR ./src/. /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1
touch /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.prepared_2b86c604625865670896968022b130f6_18f1e190c5d53547fed41a3eaa76e9e9
rm -f /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.configured_*
rm -f /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/target-mips_24kc_musl/stamp/.tollgate-module-relay-go_installed
(cd /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/./; if [ -x ./configure ]; then find /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/ -name config.guess | xargs -r chmod u+w; find /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/ -name config.guess | xargs -r -n1 cp --remove-destination /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/scripts/config.guess; find /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/ -name config.sub | xargs -r chmod u+w; find /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/ -name config.sub | xargs -r -n1 cp --remove-destination /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/scripts/config.sub; AR="mips-openwrt-linux-musl-gcc-ar" AS="mips-openwrt-linux-musl-gcc -c -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -ffile-prefix-map=/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1=tollgate-module-relay-go-0.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=mips-openwrt-linux-musl-ld NM="mips-openwrt-linux-musl-gcc-nm" CC="mips-openwrt-linux-musl-gcc" GCC="mips-openwrt-linux-musl-gcc" CXX="mips-openwrt-linux-musl-g++" RANLIB="mips-openwrt-linux-musl-gcc-ranlib" STRIP=mips-openwrt-linux-musl-strip OBJCOPY=mips-openwrt-linux-musl-objcopy OBJDUMP=mips-openwrt-linux-musl-objdump SIZE=mips-openwrt-linux-musl-size CFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -ffile-prefix-map=/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1=tollgate-module-relay-go-0.1 -mips16 -minterlink-mips16 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CXXFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -ffile-prefix-map=/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1=tollgate-module-relay-go-0.1 -mips16 -minterlink-mips16 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -mips16 -minterlink-mips16 " CPPFLAGS="-I/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/usr/include -I/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/include/fortify -I/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/include " LDFLAGS="-L/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/usr/lib -L/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib -znow -zrelro " ./configure --target=mips-openwrt-linux --host=mips-openwrt-linux --build=x86_64-pc-linux-gnu --disable-dependency-tracking --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 /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.configured_68b329da9893e34099c7d8ad5cb9c940
rm -f /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.built
touch /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.built_check
cd /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1 && GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/tollgate-relay main.go
no required module provides package main.go: go.mod file not found in current directory or any parent directory; see 'go help modules'
make[2]: *** [Makefile:55: /tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/build_dir/target-mips_24kc_musl/tollgate-module-relay-go-0.1/.built] Error 1
make[2]: Leaving directory '/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/feeds/custom/tollgate-module-relay-go'
time: package/feeds/custom/tollgate-module-relay-go/compile#3.52#0.43#4.76
ERROR: package/feeds/custom/tollgate-module-relay-go failed to build.
make[1]: *** [package/Makefile:129: package/feeds/custom/tollgate-module-relay-go/compile] Error 1
make[1]: Leaving directory '/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64'
make: *** [/tmp/openwrt-sdk/openwrt-sdk-23.05.3-ath79-generic_gcc-12.3.0_musl.Linux-x86_64/include/toplevel.mk:225: package/feeds/custom/tollgate-module-relay-go/compile] Error 2
```
Could it be that we broke something in the `Makefile`?
```
~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ cat Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=tollgate-module-relay-go
PKG_VERSION:=0.1
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/OpenTollGate/tollgate-module-relay-go.git
PKG_SOURCE_VERSION:=HEAD
# You'll need to generate a new hash after first clone
PKG_MIRROR_HASH:=skip
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
# Define IPK path variable
IPK_FILE:=$(BIN_DIR)/packages/$(ARCH_PACKAGES)/custom/$(PKG_NAME)_$(PKG_VERSION)-$(PKG_RELEASE)_$(ARCH_PACKAGES).ipk
# Add this before including golang.mk
$(shell mkdir -p $(TOPDIR)/include)
$(shell cp -f $(CURDIR)/golang.mk $(TOPDIR)/include/golang.mk 2>/dev/null || true)
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/golang.mk
define Package/tollgate-module-relay-go
SECTION:=net
CATEGORY:=Network
TITLE:=TollGate Relay Module
URL:=https://github.com/OpenTollGate/tollgate-module-relay-go
DEPENDS:=@(mips||aarch64) $(if $(CONFIG_aarch64),+golang,)
endef
define Build/Compile
cd $(PKG_BUILD_DIR) && \
$(GO_COMPILE_FLAGS) \
go build \
-trimpath \
-ldflags="$(GO_PKG_LDFLAGS)" \
-o $(PKG_BUILD_DIR)/tollgate-relay main.go
endef
define Package/tollgate-module-relay-go/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/tollgate-relay $(1)/usr/bin/
endef
# Add custom target to print IPK path
#define Package/tollgate-module-relay-go/postinst
# echo "Package compiled successfully!"
# echo "IPK file location: $(IPK_FILE)"
#endef
$(eval $(call BuildPackage,tollgate-module-relay-go))
# Print IPK path after successful compilation
PKG_FINISH:=$(shell echo "Successfully built: $(IPK_FILE)" >&2)
```
Here are the changes that we made in the `Makefile`. Some of these changes might be worth keeping because we want to support both the `GLAR300m` and the `GLMT3000`:
```
~/TollGate/custom-nostr-feed/tollgate-module-relay-go$ git diff main Makefile
diff --git a/tollgate-module-relay-go/Makefile b/tollgate-module-relay-go/Makefile
index 82b7ebf..a1dd2ad 100644
--- a/tollgate-module-relay-go/Makefile
+++ b/tollgate-module-relay-go/Makefile
@@ -26,41 +26,16 @@ define Package/tollgate-module-relay-go
CATEGORY:=Network
TITLE:=TollGate Relay Module
URL:=https://github.com/OpenTollGate/tollgate-module-relay-go
- DEPENDS:=+golang
-endef
-
-define Package/tollgate-module-relay-go/description
- TollGate Relay Module implementation in Go
-endef
-
-define Build/Prepare
- $(call Build/Prepare/Default)
- mkdir -p $(PKG_BUILD_DIR)/src
- $(CP) $(PKG_BUILD_DIR)/src/* $(PKG_BUILD_DIR)/
- cd $(PKG_BUILD_DIR) && \
- rm -f go.mod go.sum && \
- go mod init tollgate-module-relay-go && \
- go mod edit -replace github.com/OpenTollgate/relay=./ && \
- go mod tidy && \
- go get github.com/fiatjaf/khatru && \
- go get github.com/nbd-wtf/go-nostr
-endef
-
-define Build/Configure
+ DEPENDS:=@(mips||aarch64) $(if $(CONFIG_aarch64),+golang,)
endef
define Build/Compile
cd $(PKG_BUILD_DIR) && \
- GOOS=$(GO_TARGET_OS) \
- GOARCH=$(GO_TARGET_ARCH) \
- GOARM=$(GO_ARM) \
- GOMIPS=$(GO_MIPS) \
- GO386=$(GO_386) \
- CGO_ENABLED=1 \
- CC=$(TARGET_CC) \
- CXX=$(TARGET_CXX) \
- GOPATH=$(GOPATH) \
- go build -trimpath -ldflags "-s -w" -o $(PKG_BUILD_DIR)/tollgate-relay main.go
+ $(GO_COMPILE_FLAGS) \
+ go build \
+ -trimpath \
+ -ldflags="$(GO_PKG_LDFLAGS)" \
+ -o $(PKG_BUILD_DIR)/tollgate-relay main.go
endef
define Package/tollgate-module-relay-go/install
```
Commit `3197f918d2850799887a91a19e1ee9f240717dad`
As you can see below, it no longer says that whoami has the wrong architecture.
```
root@GL-AR300M:/tmp# wget https://github.com/OpenTollGate/tollgate-sdk/releases/download/t
est_arch/tollgate-module-whoami-go_0.1-1_mips_24kc.ipk
Downloading 'https://github.com/OpenTollGate/tollgate-sdk/releases/download/test_arch/tollgate-module-whoami-go_0.1-1_mips_24kc.ipk';
Connecting to 140.82.121.4:443
Redirected to /github-production-release-asset-2e65be/904311377/669e575a-1522-42e2-b016-3320b12b62f8?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20250127%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250127T180742Z&X-Amz-Expires=300&X-Amz-Signature=2880275209faf79c2b03553e244c090e75b931821dbf1fe31f3ebdfbd4409f91&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dtollgate-module-whoami-go_0.1-1_mips_24kc.ipk&response-content-type=application%2Foctet-stream on objects.githubusercontent.com
Writing to '669e575a-1522-42e2-b016-3320b12b62f8?X-Amz-Algorithm=AWS4-HMAC-SHA256'
669e575a-1522-42e2-b 100% |*******************************| 2048k 0:00:00 ETA
Download completed (2097404 bytes)
root@GL-AR300M:/tmp# mv 669e575a-1522-42e2-b016-3320b12b62f8\?X-Amz-Algorithm=AWS4-HMAC-SH
A256 whoami.ipk
root@GL-AR300M:/tmp# opkg install whoami.ipk
Installing tollgate-module-whoami-go (0.1-1) to root...
Collected errors:
* verify_pkg_installable: Only have 116kb available on filesystem /overlay, pkg tollgate-module-whoami-go needs 2053
* opkg_install_cmd: Cannot install package tollgate-module-whoami-go.
```
I intend to install a fresh OpenWRT image on the router to make space and then see if I can install the `whoami` module..