chGoodchild / TollGateNostrToolKit

0 stars 0 forks source link

generate_npub.c doesn't build yet #4

Closed chGoodchild closed 2 months ago

chGoodchild commented 2 months ago

Reproduce the error with instructions from README on branch 42: https://github.com/chGoodchild/TollGateNostrToolKit/blob/nostr_client_relay/README.md

Followed by individual steps from build_custom_dependencies.sh on branch 42: https://github.com/chGoodchild/TollGateNostrToolKit/blob/31fca7c8bb3acc42088e1087d727616ad38e42ce/build_custom_dependencies.sh#L1-L50

chGoodchild commented 2 months ago
username@ubuntu-32gb-nbg1-1:~/TollGateNostrToolKit$ cat make_logs.md | tail
install -d -m0755 /home/username/openwrt/bin/packages/mips_24kc/custom
/home/username/openwrt/staging_dir/host/bin/fakeroot /home/username/openwrt/staging_dir/host/bin/bash /home/username/openwrt/scripts/ipkg-build -m "" /home/username/openwrt/build_dir/target-mips_24kc_musl/libwally-0.8.1/ipkg-mips_24kc/libwally /home/username/openwrt/bin/packages/mips_24kc/custom
Packaged contents of /home/username/openwrt/build_dir/target-mips_24kc_musl/libwally-0.8.1/ipkg-mips_24kc/libwally into /home/username/openwrt/bin/packages/mips_24kc/custom/libwally_0.8.1-1_mips_24kc.ipk
echo "libwally" >> /home/username/openwrt/staging_dir/target-mips_24kc_musl/pkginfo/libwally.default.install
make[3]: Leaving directory '/home/username/openwrt/feeds/custom/custom/libwally'
time: package/feeds/custom/libwally/compile#54.13#13.80#67.91
make[2]: Leaving directory '/home/username/openwrt'
make[1]: *** [package/Makefile:123: /home/username/openwrt/staging_dir/target-mips_24kc_musl/stamp/.package_compile] Error 2
make[1]: Leaving directory '/home/username/openwrt'
make: *** [/home/username/openwrt/include/toplevel.mk:232: world] Error 2

The above output made it look like there is a problem with libwally, but it turns out that the problem might have been with libtool instead: https://github.com/chGoodchild/TollGateNostrToolKit/issues/8

chGoodchild commented 2 months ago

Missing config.h

https://github.com/chGoodchild/TollGateNostrToolKit/issues/9

./scripts/feeds update -a && ./scripts/feeds install -a && make package/gltollgate/prepare V=s && make package/gltollgate/compile V=s

config.h is only missing in a few places though, so I might be able to generate my own using a bash script...

chGoodchild commented 2 months ago
ln -sf libsecp256k1.so.2.0.0 /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libsecp256k1.so.2
ln -sf libwallycore.so.1.0.0 /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so.1
ln -sf /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so.1 /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so

Used the above linker commands, but didn't add it to the makefile yet

chGoodchild commented 2 months ago
mips-openwrt-linux-musl-gcc -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -fmacro-prefix-map=/home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0=gltollgate-1.0 -mips16 -minterlink-mips16 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -I/home/username/openwrt/staging_dir/target-mips_24kc_musl/usr/include -I/home/username/openwrt/staging_dir/target-mips_24kc_musl/target-mips_24kc_musl/usr/include -c -o sha256.o sha256.c  # Ensure this line begins with a tab
mips-openwrt-linux-musl-gcc -o generate_npub generate_npub.o nostri.o aes.o base64.o sha256.o -L/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/usr/lib -L/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib -znow -zrelro -L/home/username/openwrt/staging_dir/target-mips_24kc_musl/usr/lib -L/home/username/openwrt/staging_dir/target-mips_24kc_musl/target-mips_24kc_musl/usr/lib -L/home/username/openwrt/staging_dir/target-mips_24kc_musl/target-mips_24kc_musl/root-ath79/usr/lib -L/home/username/openwrt/build_dir/target-mips_24kc_musl/libwally-0.8.1/src/.libs -L/home/username/openwrt/build_dir/target-mips_24kc_musl/secp256k1-0.1/.libs -L/home/username/openwrt/staging_dir/target-mips_24kc_musl/target-mips_24kc_musl/root-ath79/usr/lib -lwallycore -lsecp256k1 -lssl -lcrypto  # Ensure this line begins with a tab
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: cannot find -lwallycore: No such file or directory
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:18: generate_npub] Error 1
make[3]: Leaving directory '/home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0'
make[2]: *** [Makefile:61: /home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0/.built] Error 2
make[2]: Leaving directory '/home/username/openwrt/feeds/custom/custom/gltollgate'
time: package/feeds/custom/gltollgate/compile#3.22#1.53#5.75
    ERROR: package/feeds/custom/gltollgate failed to build.
make[1]: *** [package/Makefile:129: package/feeds/custom/gltollgate/compile] Error 1
make[1]: Leaving directory '/home/username/openwrt'
make: *** [/home/username/openwrt/include/toplevel.mk:232: package/gltollgate/compile] Error 2
username@ubuntu-32gb-nbg1-1:~/openwrt$ ls -l /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwally*
lrwxrwxrwx 1 username username      93 Aug 15 14:55 /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so -> /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so.1
lrwxrwxrwx 1 username username      97 Aug 15 15:12 /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so.1 -> /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so.1.3.0
-rwxr-xr-x 1 username username 2962780 Aug 15 12:04 /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so.1.3.0
username@ubuntu-32gb-nbg1-1:~/openwrt$ find /home/username/openwrt/ -name libwally*
/home/username/openwrt/staging_dir/target-mips_24kc_musl/pkginfo/libwally.provides
/home/username/openwrt/staging_dir/target-mips_24kc_musl/pkginfo/libwally.default.install
/home/username/openwrt/staging_dir/target-mips_24kc_musl/pkginfo/libwally.default.install.flags
/home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so
/home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so.1
/home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/lib/libwallycore.so.1.3.0
/home/username/openwrt/package/feeds/custom/libwally
/home/username/openwrt/feeds/custom/custom/libwally
/home/username/openwrt/build_dir/target-mips_24kc_musl/libwally-0.8.1
/home/username/openwrt/build_dir/target-mips_24kc_musl/libwally-0.8.1/contrib/gitian-descriptors/libwally-core-linux.yml
/home/username/openwrt/build_dir/target-mips_24kc_musl/libwally-0.8.1/contrib/gitian-descriptors/libwally-core-android.yml
/home/username/openwrt/dl/libwally-0.8.1.tar.xz
username@ubuntu-32gb-nbg1-1:~/openwrt$ cat feeds/custom/custom/gltollgate/Makefile 
include $(TOPDIR)/rules.mk

PKG_NAME:=gltollgate
PKG_VERSION:=1.0
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/chGoodchild/GLTollGate.git
PKG_SOURCE_VERSION:=42-generate-nsec-on-the-router
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/gltollgate
    SECTION:=utils
    CATEGORY:=Utilities
    TITLE:=GLTollGate Utilities
    DEPENDS:=+libopenssl +libsecp256k1 +libwallycore
endef

define Package/gltollgate/description
    GLTollGate Utilities including generate_npub tool.
endef

define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    rm -rf $(PKG_BUILD_DIR)
    mkdir -p $(PKG_BUILD_DIR)
    git clone $(PKG_SOURCE_URL) $(PKG_BUILD_DIR) --branch $(PKG_SOURCE_VERSION) --single-branch
    (cd $(PKG_BUILD_DIR); git submodule update --init --recursive)
    [ -d "$(PKG_BUILD_DIR)/nostr/c" ] && $(CP) $(PKG_BUILD_DIR)/nostr/c/* $(PKG_BUILD_DIR)/ || (echo "The expected subdirectory does not exist." && exit 1)
    # Execute the script to generate config.h
    (cd $(PKG_BUILD_DIR); ./generate_config_h.sh)
endef

define Build/Compile
    $(MAKE) -C $(PKG_BUILD_DIR) \
        CC=$(TARGET_CC) \
        CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/target-mips_24kc_musl/usr/include" \
        LDFLAGS="$(TARGET_LDFLAGS) \
        -L$(STAGING_DIR)/usr/lib \
        -L$(STAGING_DIR)/target-mips_24kc_musl/usr/lib \
        -L$(STAGING_DIR)/target-mips_24kc_musl/root-ath79/usr/lib \
        -L$(BUILD_DIR)/libwally-0.8.1/src/.libs \
        -L$(BUILD_DIR)/secp256k1-0.1/.libs \
        -L$(STAGING_DIR)/target-mips_24kc_musl/root-ath79/usr/lib \
        -lwallycore -lsecp256k1 -lssl -lcrypto" \
        $(TARGET_CONFIGURE_OPTS)
endef

define Package/gltollgate/install
    $(INSTALL_DIR) $(1)/usr/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/generate_npub $(1)/usr/bin/
endef

$(eval $(call BuildPackage,gltollgate))
thefux commented 2 months ago

-lwallycore -lsecp256k1 -lssl -lcrypto

would remove these and see what happens

thefux commented 2 months ago

file: config.h

#include <endian.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
    #define HAVE_LITTLE_ENDIAN 1
    #define HAVE_BIG_ENDIAN 0
#elif __BYTE_ORDER == __BIG_ENDIAN
    #define HAVE_LITTLE_ENDIAN 0
    #define HAVE_BIG_ENDIAN 1
#else
    #error "Unknown endianness"
#endif
chGoodchild commented 2 months ago

Missing secp256k1

mips-openwrt-linux-musl-gcc -o generate_npub generate_npub.o nostri.o aes.o base64.o sha256.o -L/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/usr/lib -L/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib -znow -zrelro -L/home/username/openwrt/staging_dir/target-mips_24kc_musl/usr/lib -L/home/username/openwrt/staging_dir/target-mips_24kc_musl/target-mips_24kc_musl/usr/lib -L/home/username/openwrt/staging_dir/target-mips_24kc_musl/target-mips_24kc_musl/root-ath79/usr/lib -L/home/username/openwrt/build_dir/target-mips_24kc_musl/libwally-0.8.1/src/.libs -L/home/username/openwrt/build_dir/target-mips_24kc_musl/secp256k1-0.1/.libs -L/home/username/openwrt/staging_dir/target-mips_24kc_musl/target-mips_24kc_musl/root-ath79/usr/lib  # Ensure this line begins with a tab
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: generate_npub.o: in function `generate_ecdsa_keypair':
generate_npub.c:(.text+0xbe): undefined reference to `secp256k1_context_destroy'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: generate_npub.c:(.text+0xee): undefined reference to `secp256k1_context_destroy'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: nostri.o: in function `create_key':
nostri.c:(.text+0x176): undefined reference to `secp256k1_keypair_create'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: nostri.c:(.text+0x194): undefined reference to `secp256k1_keypair_xonly_pub'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: nostri.c:(.text+0x1a2): undefined reference to `secp256k1_xonly_pubkey_serialize'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: nostri.o: in function `init_secp_context':
nostri.c:(.text+0x61c): undefined reference to `secp256k1_context_create'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: nostri.c:(.text+0x630): undefined reference to `secp256k1_context_randomize'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: nostri.o: in function `sign_event':
nostri.c:(.text+0x6b0): undefined reference to `secp256k1_schnorrsig_sign32'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: nostri.o: in function `make_encrypted_dm':
nostri.c:(.text+0x90e): undefined reference to `secp256k1_ec_seckey_verify'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: nostri.c:(.text+0x93e): undefined reference to `secp256k1_ec_pubkey_parse'
/home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/bin/ld: nostri.c:(.text+0x95a): undefined reference to `secp256k1_ecdh'
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:18: generate_npub] Error 1
make[3]: Leaving directory '/home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0'
make[2]: *** [Makefile:60: /home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0/.built] Error 2
make[2]: Leaving directory '/home/username/openwrt/feeds/custom/custom/gltollgate'
time: package/feeds/custom/gltollgate/compile#1.50#1.15#4.29
    ERROR: package/feeds/custom/gltollgate failed to build.
make[1]: *** [package/Makefile:129: package/feeds/custom/gltollgate/compile] Error 1
make[1]: Leaving directory '/home/username/openwrt'
make: *** [/home/username/openwrt/include/toplevel.mk:232: package/gltollgate/compile] Error 2
username@ubuntu-32gb-nbg1-1:~/openwrt$ ls build_dir/target-mips_24kc_musl/gltollgate-1.0/
aes.c     build_libbtc.sh              config.h              generate_config_h.sh    install_openssl_v3.3.1.sh  nostri.o          secp256k1_ellswift.h      setup_online.sh
aes.h     build_libwally.sh            configurator.c        generate_npub.c         Makefile                   proof.h           secp256k1_extrakeys.h     sha256.c
aes.o     build_nostr_client_relay.sh  cursor.h              generate_npub.o         nostr                      random.h          secp256k1.h               sha256.h
base64.c  build_secp256k1.sh           endian.h              generate_npub_setup.sh  nostri.c                   README.md         secp256k1_preallocated.h  sha256.o
base64.h  clock_gettime.h              etc                   hex.h                   nostri.h                   RelayLink.c       secp256k1_recovery.h      useful_commands.md
base64.o  compiler.h                   failed_to_get_bech32  images                  nostril.c                  secp256k1_ecdh.h  secp256k1_schnorrsig.h    www
username@ubuntu-32gb-nbg1-1:~/openwrt$ cd build_dir/target-mips_24kc_musl/gltollgate-1.0/
username@ubuntu-32gb-nbg1-1:~/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0$ cat nostri.c | grep "secp256k1_ecdh"
  if (!secp256k1_ecdh(ctx, shared_secret, &pubkey, key->secret, copyx, NULL))
    fprintf(stderr, "make_encrypted_dm: secp256k1_ecdh failed\n");
username@ubuntu-32gb-nbg1-1:~/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0$ grep -r "secp256k1_ecdh"
grep: .git/index: binary file matches
nostri.c:  if (!secp256k1_ecdh(ctx, shared_secret, &pubkey, key->secret, copyx, NULL))
nostri.c:    fprintf(stderr, "make_encrypted_dm: secp256k1_ecdh failed\n");
nostr/c/nostri.c:  if (!secp256k1_ecdh(ctx, shared_secret, &pubkey, key->secret, copyx, NULL))
nostr/c/nostri.c:    fprintf(stderr, "make_encrypted_dm: secp256k1_ecdh failed\n");
nostr/c/nostri.h:#include "secp256k1_ecdh.h"
nostr/c/secp256k1_ecdh.h: *           0 will cause secp256k1_ecdh to fail and return 0.
nostr/c/secp256k1_ecdh.h: *           secp256k1_ecdh is undefined for other return values.
nostr/c/secp256k1_ecdh.h:typedef int (*secp256k1_ecdh_hash_function)(
nostr/c/secp256k1_ecdh.h:SECP256K1_API const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_sha256;
nostr/c/secp256k1_ecdh.h:/** A default ECDH hash function (currently equal to secp256k1_ecdh_hash_function_sha256).
nostr/c/secp256k1_ecdh.h:SECP256K1_API const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_default;
nostr/c/secp256k1_ecdh.h: *                       secp256k1_ecdh_hash_function_sha256 is used
nostr/c/secp256k1_ecdh.h: *                       (can be NULL for secp256k1_ecdh_hash_function_sha256).
nostr/c/secp256k1_ecdh.h:SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(
nostr/c/secp256k1_ecdh.h:  secp256k1_ecdh_hash_function hashfp,
grep: nostr/c/generate_npub: binary file matches
nostri.h:#include "secp256k1_ecdh.h"
grep: nostri.o: binary file matches
secp256k1_ecdh.h: *           0 will cause secp256k1_ecdh to fail and return 0.
secp256k1_ecdh.h: *           secp256k1_ecdh is undefined for other return values.
secp256k1_ecdh.h:typedef int (*secp256k1_ecdh_hash_function)(
secp256k1_ecdh.h:SECP256K1_API const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_sha256;
secp256k1_ecdh.h:/** A default ECDH hash function (currently equal to secp256k1_ecdh_hash_function_sha256).
secp256k1_ecdh.h:SECP256K1_API const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_default;
secp256k1_ecdh.h: *                       secp256k1_ecdh_hash_function_sha256 is used
secp256k1_ecdh.h: *                       (can be NULL for secp256k1_ecdh_hash_function_sha256).
secp256k1_ecdh.h:SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(
secp256k1_ecdh.h:  secp256k1_ecdh_hash_function hashfp,
username@ubuntu-32gb-nbg1-1:~/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0$ cat /home/username/openwrt/feeds/custom/custom/gltollgate/Makefile
include $(TOPDIR)/rules.mk

PKG_NAME:=gltollgate
PKG_VERSION:=1.0
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/chGoodchild/GLTollGate.git
PKG_SOURCE_VERSION:=42-generate-nsec-on-the-router
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/gltollgate
    SECTION:=utils
    CATEGORY:=Utilities
    TITLE:=GLTollGate Utilities
    DEPENDS:=+libopenssl +libsecp256k1 +libwallycore
endef

define Package/gltollgate/description
    GLTollGate Utilities including generate_npub tool.
endef

define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    rm -rf $(PKG_BUILD_DIR)
    mkdir -p $(PKG_BUILD_DIR)
    git clone $(PKG_SOURCE_URL) $(PKG_BUILD_DIR) --branch $(PKG_SOURCE_VERSION) --single-branch
    (cd $(PKG_BUILD_DIR); git submodule update --init --recursive)
    [ -d "$(PKG_BUILD_DIR)/nostr/c" ] && $(CP) $(PKG_BUILD_DIR)/nostr/c/* $(PKG_BUILD_DIR)/ || (echo "The expected subdirectory does not exist." && exit 1)
    # Execute the script to generate config.h
    (cd $(PKG_BUILD_DIR); ./generate_config_h.sh)
endef

define Build/Compile
    $(MAKE) -C $(PKG_BUILD_DIR) \
        CC=$(TARGET_CC) \
        CFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/target-mips_24kc_musl/usr/include" \
        LDFLAGS="$(TARGET_LDFLAGS) \
        -L$(STAGING_DIR)/usr/lib \
        -L$(STAGING_DIR)/target-mips_24kc_musl/usr/lib \
        -L$(STAGING_DIR)/target-mips_24kc_musl/root-ath79/usr/lib \
        -L$(BUILD_DIR)/libwally-0.8.1/src/.libs \
        -L$(BUILD_DIR)/secp256k1-0.1/.libs \
        -L$(STAGING_DIR)/target-mips_24kc_musl/root-ath79/usr/lib" \
        $(TARGET_CONFIGURE_OPTS)
endef

define Package/gltollgate/install
    $(INSTALL_DIR) $(1)/usr/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/generate_npub $(1)/usr/bin/
endef

$(eval $(call BuildPackage,gltollgate))
chGoodchild commented 2 months ago

Binary available with and without debug information:

username@ubuntu-32gb-nbg1-1:~/openwrt$ ls -la /home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0/ipkg-mips_24kc/gltollgate/usr/bin/generate_npub
-rwxr-xr-x 1 username username 1311108 Aug 16 08:21 /home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0/ipkg-mips_24kc/gltollgate/usr/bin/generate_npub
username@ubuntu-32gb-nbg1-1:~/openwrt$ ls -la /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/bin/generate_npub
-rwxr-xr-x 1 username username 1638460 Aug 16 08:21 /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/bin/generate_npub
username@ubuntu-32gb-nbg1-1:~/openwrt$ file /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/bin/generate_npub
/home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/bin/generate_npub: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), statically linked, with debug_info, not stripped
username@ubuntu-32gb-nbg1-1:~/openwrt$ ldd /home/username/openwrt/staging_dir/target-mips_24kc_musl/root-ath79/usr/bin/generate_npub
    not a dynamic executable
username@ubuntu-32gb-nbg1-1:~/openwrt$ file /home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0/ipkg-mips_24kc/gltollgate/usr/bin/generate_npub
/home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0/ipkg-mips_24kc/gltollgate/usr/bin/generate_npub: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), statically linked, no section header
username@ubuntu-32gb-nbg1-1:~/openwrt$ ldd /home/username/openwrt/build_dir/target-mips_24kc_musl/gltollgate-1.0/ipkg-mips_24kc/gltollgate/usr/bin/generate_npub
    not a dynamic executable
chGoodchild commented 2 months ago

It works:

root@GL-AR300M:/tmp# ./generate_npub_optimized 
{
  "npub_hex": "0e498e21f00af0eb4353b3d89b0911e3a9a669e6e3824a42e12f939452d2a248",
  "nsec_hex": "3fe31d61416215eedd43aeee1f51c0ec6ac93c74f297dfdd4a45139c90bf1cd4"
}
root@GL-AR300M:/tmp# ./generate_npub_optimized 
{
  "npub_hex": "974ba84d466023b5b687a5f6315a7e928e0d0148105669a74c5a1115e4046d1a",
  "nsec_hex": "2be74bfc16be875957170ad28379fab3341d0bcc31785aaa3116bfdac82b504f"
}
root@GL-AR300M:/tmp# ./generate_npub_optimized 
{
  "npub_hex": "2e6ed640512e21ce1a34fe65c56c18d91fea4e955d17f9525f99a3f1f53c5ec6",
  "nsec_hex": "37a8686441619f929f902ddbe2540e79a6732cc19211f24dc920022d681cab11"
}

Now I just need to clean up and I can close the issue + branch...

chGoodchild commented 2 months ago
root@GL-AR300M:/tmp# ./generate_npub
./generate_npub: line 1: syntax error: unexpected word (expecting ")")

The build that worked wasn't reproducible, this binary seems to be for x86...

chGoodchild commented 2 months ago

Fixed the library names in feed: https://github.com/chGoodchild/secp256k1_openwrt_feed/commit/1b7596f23901f8d8f67240dffb88b36b33d788b9

For consistency with makefile of gltollgate

chGoodchild commented 2 months ago

Builds are reproducible in commit 5365bc174167afebf5f85c722adb1cb52d0e660e

chGoodchild commented 2 months ago

Expecting path related problems in relay_link and sign_event: 3ee7a88b2f755e4e5202aa30ec81db7f19ab748d

chGoodchild commented 2 months ago
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.3.0 (OpenWrt GCC 12.3.0 r23809-234f1a2efa) 
COLLECT_GCC_OPTIONS='-v' '-I' '/home/username/openwrt/staging_dir/target-mips_24kc_musl/usr/include' '-c' '-o' '/home/username/TollGateNostrToolKit/RelayLink.o' '-msoft-float' '-mllsc' '-mplt' '-mno-shared' '-EB' '-mabi=32' '-dumpdir' '/home/username/TollGateNostrToolKit/'
 /home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/libexec/gcc/mips-openwrt-linux-musl/12.3.0/cc1 -quiet -v -I /home/username/openwrt/staging_dir/target-mips_24kc_musl/usr/include -idirafter /home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/usr/include /home/username/TollGateNostrToolKit/RelayLink.c -meb -quiet -dumpdir /home/username/TollGateNostrToolKit/ -dumpbase RelayLink.c -dumpbase-ext .c -msoft-float -mllsc -mplt -mno-shared -mabi=32 -version -o /tmp/cc9p85MK.s
GNU C17 (OpenWrt GCC 12.3.0 r23809-234f1a2efa) version 12.3.0 (mips-openwrt-linux-musl)
    compiled by GNU C version 13.2.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
#include "..." search starts here:
#include <...> search starts here:
 /home/username/openwrt/staging_dir/target-mips_24kc_musl/usr/include
 /home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/sys-include
 /home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/../../../../mips-openwrt-linux-musl/include
 /home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/lib/gcc/mips-openwrt-linux-musl/12.3.0/include
 /home/username/openwrt/staging_dir/toolchain-mips_24kc_gcc-12.3.0_musl/usr/include
End of search list.
GNU C17 (OpenWrt GCC 12.3.0 r23809-234f1a2efa) version 12.3.0 (mips-openwrt-linux-musl)
    compiled by GNU C version 13.2.0, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 05ba3032e4ec00a09febe7b057b768d4
/home/username/TollGateNostrToolKit/RelayLink.c:4:10: fatal error: libwebsockets.h: No such file or directory
    4 | #include <libwebsockets.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.

It wasn't set in .config. The RelayLink and SignEvent build procedures need to be refactored to work like that of gltollgate. Perhaps they can even be included in gltollgate...

chGoodchild commented 2 months ago

82b7cf36e28bfafdff7b5769698d1f300c5df045

Everything builds. Checking for reproducibility.

Reproducibility confirmed: ebe6ae0b02fdaeb95b81df1a267800893d47bf69

chGoodchild commented 2 months ago

Refactoring required, but thats not part of this issue: https://github.com/chGoodchild/TollGateNostrToolKit/issues/10