Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avrdude on macOS is built without libreadline #1173

Closed
MCUdude opened this issue Nov 8, 2022 · 112 comments · Fixed by #1207
Closed

Avrdude on macOS is built without libreadline #1173

MCUdude opened this issue Nov 8, 2022 · 112 comments · Fixed by #1207
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@MCUdude
Copy link
Collaborator

MCUdude commented Nov 8, 2022

The issue is caused by #1132.

I'm building using make, and after #1132 was merged, I have to hit enter after every command in order for avrdude> to appear. When I start to type, the text appears on the line below.

Shouldn't this "just work"?

$ ./avrdude -cpickit4_isp -p atmega1284p -t

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9705 (probably m1284p)
avrdude> ?
>>> ? 
Valid commands:
  dump    : dump <memory> [<addr> <len> | <addr> ... | <addr> | ...]
  read    : alias for dump
  write   : write <memory> <addr> <data>[,] {<data>[,]}
          : write <memory> <addr> <len> <data>[,] {<data>[,]} ...
  flush   : synchronise flash & EEPROM writes with the device
  abort   : abort flash & EEPROM writes (reset the r/w cache)
  erase   : perform a chip erase
  pgerase : pgerase <memory> <addr>
  sig     : display device signature bytes
  part    : display the current part information
  send    : send a raw command: send <b1> <b2> <b3> <b4>
  parms   : display adjustable parameters
  sck     : set <SCK period>
  verbose : change verbosity
  quell   : set quell level for progress bars
  help    : show help message
  ?       : same as help
  quit    : quit after writing out cache for flash & EEPROM

Note that not all programmer derivatives support all commands. Flash and
EEPROM type memories are normally read and written using a cache via paged
read and write access; the cache is synchronised on quit or flush commands.
The part command displays valid memory types for use with dump and write.


avrdude> 
read eeprom
avrdude> read eeprom
>>> read eeprom 

Reading | ################################################## | 100% 0.34 s 

0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0020  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0060  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0070  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0090  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|


avrdude> 
sig
avrdude> sig
>>> sig 
Device signature = 0x1e9705


avrdude> 
read flash 0 0x100
avrdude> read flash 0 0x100
>>> read flash 0 0x100 

Reading | ################################################## | 100% 0.09 s 

0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0020  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0060  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0070  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0090  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|


avrdude> 
quit
avrdude> quit
>>> quit 

avrdude done.  Thank you.
@mcuee mcuee added the enhancement New feature or request label Nov 8, 2022
@mcuee
Copy link
Collaborator

mcuee commented Nov 8, 2022

This is because you use the default libedit and not libreadline. I hit this one when I was testing #1132.

I have created PR #1156 to help macOS users. You can use build.sh which takes care of this. You do need to install readline. I'd like to edit Wiki page to mention that but I do not have access to Wiki editing as of now.

MinGW MSYS2 is still having issues if readline is installed due to broken packaging of MSYS2 libreadline/libtermcap. But I have found a work-around to rebuild libtermcap. github action is okay since it does not use readline installed by default.

Click for the issues with MSYS2 mingw
$ ./build.sh
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DON'T HAVE libftdi
-- DO HAVE    libftdi1
-- DISABLED   doc
-- DISABLED   parport
-- DISABLED   linuxgpio
-- DISABLED   linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: C:/work/avr/avrdude_test/avrdude_sr/build_mingw64_nt-10.0-19044
[57/59] Building C object src/CMakeFiles/avrdude.dir/term.c.obj
In function 'tokenize',
    inlined from 'process_line' at C:/work/avr/avrdude_test/avrdude_sr/src/term.c:1212:10,
    inlined from 'term_gotline' at C:/work/avr/avrdude_test/avrdude_sr/src/term.c:1289:10:
C:/work/avr/avrdude_test/avrdude_sr/src/term.c:1118:17: warning: pointer 'buf' may be used after 'realloc' [-Wuse-after-free]
 1118 |       ptrdiff_t k = buf - bufp;
      |                 ^
C:/work/avr/avrdude_test/avrdude_sr/src/term.c:1102:18: note: call to 'realloc' here
 1102 |       buf_tmp  = realloc(buf, bufsize);
      |                  ^~~~~~~~~~~~~~~~~~~~~
[59/59] Linking C executable src\avrdude.exe
FAILED: src/avrdude.exe
cmd.exe /C "cd . && C:\msys64\mingw64\bin\cc.exe -O2 -g -DNDEBUG  src/CMakeFiles/avrdude.dir/main.c.obj src/CMakeFiles/avrdude.dir/term.c.obj src/CMakeFiles/avrdude.dir/avrintel.c.obj src/CMakeFiles/avrdude.dir/developer_opts.c.obj src/CMakeFiles/avrdude.dir/whereami.c.obj src/CMakeFiles/avrdude.dir/windows.rc.obj -o src\avrdude.exe -Wl,--out-implib,src\libavrdude.dll.a -Wl,--major-image-version,0,--minor-image-version,0  src/libavrdude.a  -lm  C:/msys64/mingw64/lib/libelf.a  C:/msys64/mingw64/lib/libusb.a  C:/msys64/mingw64/lib/libusb-1.0.a  C:/msys64/mingw64/lib/libhid.a  C:/msys64/mingw64/lib/libhidapi.a  C:/msys64/mingw64/lib/libftdi1.a  C:/msys64/mingw64/lib/libreadline.a  -lsetupapi  -lws2_32  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(display.o):(.text+0xea0): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(display.o):(.text+0xf08): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(display.o):(.text+0x3683): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(display.o):(.text+0x3812): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(display.o):(.text+0x388e): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(display.o):(.text+0x39cf): more undefined references to `tputs' follow
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0x29c): undefined reference to `tgetnum'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0x2d8): undefined reference to `tgetnum'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0x7f9): undefined reference to `tgetent'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0x837): undefined reference to `tgetstr'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0x896): undefined reference to `tgetflag'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0x8e6): undefined reference to `tgetflag'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0xa80): undefined reference to `tgetflag'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0xceb): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0xdb9): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0xea7): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0xefd): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0xd64): undefined reference to `tputs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/lib/libreadline.a(terminal.o):(.text+0xe23): more undefined references to `tputs' follow
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Build failed.

$ cd build_mingw64_nt-10.0-19044/

$ cmd.exe /C "cd . && C:\msys64\mingw64\bin\cc.exe -O2 -g -DNDEBUG  src/CMakeFiles/avrdude.dir/main.c.obj src/CMakeFiles/avrdude.dir/term.c.obj src/CMakeFiles/avrdude.dir/avrintel.c.obj src/CMakeFiles/avrdude.dir/developer_opts.c.obj src/CMakeFiles/avrdude.dir/whereami.c.obj src/CMakeFiles/avrdude.dir/windows.rc.obj -o src\avrdude.exe -Wl,--out-implib,src\libavrdude.dll.a -Wl,--major-image-version,0,--minor-image-version,0  src/libavrdude.a  -lm  C:/msys64/mingw64/lib/libelf.a  C:/msys64/mingw64/lib/libusb.a  C:/msys64/mingw64/lib/libusb-1.0.a  C:/msys64/mingw64/lib/libhid.a  C:/msys64/mingw64/lib/libhidapi.a  C:/msys64/mingw64/lib/libftdi1.a  C:/msys64/mingw64/lib/libreadline.a C:/msys64/mingw64/lib/libtermcap.a -lsetupapi  -lws2_32  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."

$ ldd src/avrdude.exe
        ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffd66f90000)
        KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffd66380000)
        KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffd647a0000)
        msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7ffd64ff0000)
        SETUPAPI.dll => /c/WINDOWS/System32/SETUPAPI.dll (0x7ffd65190000)
        cfgmgr32.dll => /c/WINDOWS/System32/cfgmgr32.dll (0x7ffd646a0000)
        ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7ffd64ef0000)
        RPCRT4.dll => /c/WINDOWS/System32/RPCRT4.dll (0x7ffd65610000)
        bcrypt.dll => /c/WINDOWS/System32/bcrypt.dll (0x7ffd64ec0000)
        USER32.dll => /c/WINDOWS/System32/USER32.dll (0x7ffd667b0000)
        win32u.dll => /c/WINDOWS/System32/win32u.dll (0x7ffd64a80000)
        GDI32.dll => /c/WINDOWS/System32/GDI32.dll (0x7ffd66b30000)
        gdi32full.dll => /c/WINDOWS/System32/gdi32full.dll (0x7ffd64d10000)
        msvcp_win.dll => /c/WINDOWS/System32/msvcp_win.dll (0x7ffd64e20000)
        WS2_32.dll => /c/WINDOWS/System32/WS2_32.dll (0x7ffd669e0000)
        HID.DLL => /c/WINDOWS/SYSTEM32/HID.DLL (0x7ffd62970000)

I have also created issue #1162 to see if we can adopt arduino-packing project's way of using Containers to cross build static linked avrdude binaries for Linux, macOS and Windows (mingw32).

I am able to use simplified arduino-packing scripts here. I can built git main just fine.
https://github.com/mcuee/avrdude-packing/

@mcuee
Copy link
Collaborator

mcuee commented Nov 9, 2022

If someone can figure out how to make libedit works, then that will be good as well. So I will label this as enhancement. As of now git main will require libreadline for macOS and Linux. We may need to update the Wiki for git main.

@mcuee
Copy link
Collaborator

mcuee commented Nov 9, 2022

@MCUdude
BTW, you may want to use build.sh to simplify the workflow. It will take care of the readline issue.

@MCUdude
Copy link
Collaborator Author

MCUdude commented Nov 9, 2022

The question is why did we have to break terminal mode for macOS? It worked perfectly fine before.
Can't we just use the "legacy way of doing things" if Avrdude was compiled without libreadline?

BTW, you may want to use build.sh to simplify the workflow. It will take care of the readline issue.

Yes, but the classic ./configure + make should also work. At the moment, there is no indication that libreadline is required when building.

The main reason why I'm still using make is that the commands are much shorter and easier to remember. I might adopt Stefan's makefile:

all:
	cmake --build build_linux

install:
	cmake --build build_linux; sudo cmake --build build_linux --target install

new:
	sudo rm -rf build_linux
	cmake -D BUILD_DOC=1 -D CMAKE_BUILD_TYPE=RelWithDebInfo -D HAVE_LINUXGPIO=1 -D HAVE_LINUXSPI=1 -D HAVE_PARPORT=1 -B build_linux
	cmake --build build_linux

@mcuee
Copy link
Collaborator

mcuee commented Nov 9, 2022

The question is why did we have to break terminal mode for macOS? It worked perfectly fine before.
Can't we just use the "legacy way of doing things" if Avrdude was compiled without libreadline?

The problem is that macOS Homebrew reports that it has libreadline without libreadline being installed, since it treats libedit as the replacement as libreadline. Unfortunately libedit behavior is not the same as libreadline. Maybe there is a simple fix but I do not know. I am not so sure if the problem is there for MacPorts or not.

If we need to differentiate libreadline and libedit, probably we need to have some CMake magic from @mariusgreuel; and we need some code change in terminal.c from @stefanrueger.

@MCUdude
Copy link
Collaborator Author

MCUdude commented Nov 9, 2022

The problem is that macOS Homebrew reports that it has libreadline without libreadline being installed, since it treats libedit as the replacement as libreadline. Unfortunately libedit behavior is not the same as libreadline.

OK, fair enough. But is libreadline statically or dynamically linked? Is this something every user has to install before using an Avrdude binary?

It might be possible to report an issue over at the Homebrew repo to fix the issue where Homebrew treats libedit as a replacement.

@mcuee
Copy link
Collaborator

mcuee commented Nov 9, 2022

OK, fair enough. But is libreadline statically or dynamically linked? Is this something every user has to install before using an Avrdude binary?

By default it is dynamically linked. That was why I created issue #1159.

After extensive testing there, finally I came to the conclusion that to me the solution is to adopt arduino-packing way of building the static link binaries using a container and cross-compile. Unfortunately it needs two patches which as is will not be accepted by the avrdude project.

It might be possible to report an issue over at the Homebrew repo to fix the issue where Homebrew treats libedit as a replacement.

We can try but I am not so positive that they will adopt. They may ask use to fix avrdude as many other projects have no issues with libedit, including avrdude prior to the merge of #1132.

@mcuee
Copy link
Collaborator

mcuee commented Nov 9, 2022

There are many hits about libedit not a real replacement for libreadline.

References:
https://superuser.com/questions/1399622/trouble-with-readline-library-on-mac
https://pewpewthespells.com/blog/osx_readline.html

@MCUdude
Copy link
Collaborator Author

MCUdude commented Nov 9, 2022

The problem is this line:

#if defined(HAVE_LIBREADLINE)

If I replace it with #if 0, terminal mode works perfectly fine again. Do you know where LIBREADLINE is defined? maybe there's something else we can look for to detect if it's actually using libedit? This way, we could make it work on macOS with and without libreadline

But how do I install libreadline using homebrew?

When I run brew search libreadline, there's no obvious one to install:

$ brew search readline
==> Formulae
libreadline-java                          readline ✔                                with-readline                             redland

==> Casks
readmoreading

@mcuee
Copy link
Collaborator

mcuee commented Nov 9, 2022

@MCUdude
You can install libreadline by using brew install readline.

As for (HAVE_LIBREADLINE), unfortunately CMake will set it under macOS no matter you install readline or not, because of the presence of libedit in macOS. So we need some CMake magic from @mariusgreuel to differentiate libedit and libreadline. I will also try but I do not know so much about CMake.

@stefanrueger stefanrueger added this to the AVRDUDE 7.1 milestone Nov 10, 2022
@stefanrueger
Copy link
Collaborator

If I replace it with #if 0, terminal mode works perfectly fine again.

You will lose the ability to connect to bootloaders in the terminal (they will time out).

I feel we should solve this by getting CMake to do the right thing for MacOS before the 7.1 release.

@mcuee
Copy link
Collaborator

mcuee commented Nov 10, 2022

If I replace it with #if 0, terminal mode works perfectly fine again.

You will lose the ability to connect to bootloaders in the terminal (they will time out).
I feel we should solve this by getting CMake to do the right thing for MacOS before the 7.1 release.

I think we can detect the presence of Homebrew libreadline by checking the presence of /opt/homebrew/opt/readline/lib/libreadline.dylib or /usr/local/opt/readline/lib/libreadline.dylib. And we can detect the presence of MacPorts libreadline by checking the presence of /usr/local/lib/libreadline.dylib.

If the above is not present, then it will use system libedit. We can set HAVE_LIBREADLINE to be FALSE in that case.

@mariusgreuel
Please jump in as well and I believe you can find a quick solution for this in CMake.

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

If I replace it with #if 0, terminal mode works perfectly fine again.

You will lose the ability to connect to bootloaders in the terminal (they will time out).

I feel we should solve this by getting CMake to do the right thing for MacOS before the 7.1 release.

There are three issues here.

  1. Enhance CMake to differentiate libedit and libreadline. Right now you have to use build.sh which is hardcoded to use libreadline. This may not be a big issue -- we can just to modify the Wiki so that user will install the libreadline dependancy. But it is still good to get CMake to do the job automatically. We can even warn the user certain function may not work without libreadline. I think this is not that difficult.

  2. @MCUdude would like to get the autotools build working with and without libreadline (to differentiate libedit and libreadline). I think this can be done as well.

  3. Staitc linking to libreadline if it is present. This is more difficult since currently it is using dynamic linking by default. I think it is out of scope for this ticket. We can discuss that in the following ticket.

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

Interestingly Homebrew git main build is actually able to use libreadline and not libedit for my system (where I force link by running brew link readline --force).

The formula does not seem to do anything special.
https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/avrdude.rb

mcuee@mcuees-Mac-mini avrdude_main % brew reinstall avrdude
==> Cloning https://github.com/avrdudes/avrdude.git
Updating /Users/mcuee/Library/Caches/Homebrew/avrdude--git
From https://github.com/avrdudes/avrdude
   3e49f07..4c92030  main       -> origin/main
==> Checking out branch main
Already on 'main'
Your branch is behind 'origin/main' by 145 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
HEAD is now at 4c92030 Update NEWS
==> Reinstalling avrdude 
==> cmake -S . -B build/shared -DCMAKE_INSTALL_SYSCONFDIR=/opt/homebrew/etc -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTAL
==> cmake --build build/shared
==> cmake --install build/shared
==> cmake -S . -B build/static -DCMAKE_INSTALL_SYSCONFDIR=/opt/homebrew/etc
==> cmake --build build/static
🍺  /opt/homebrew/Cellar/avrdude/HEAD-4c92030_2: 13 files, 1.9MB, built in 8 seconds
==> Running `brew cleanup avrdude`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
mcuee@mcuees-Mac-mini avrdude_main % otool -L /opt/homebrew/bin/avrdude 
/opt/homebrew/bin/avrdude:
	@rpath/libavrdude.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
	/opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
	/opt/homebrew/opt/libhid/lib/libhid.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
	/opt/homebrew/opt/libftdi0/lib/libftdi.1.dylib (compatibility version 22.0.0, current version 22.0.0)
	/opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)
	/opt/homebrew/opt/readline/lib/libreadline.8.dylib (compatibility version 8.2.0, current version 8.2.0)

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

@MCUdude
I just tried the auto-tool build under macOS, as long as you have readline installed, you should be fine.

There is a warning about the ld: warning: -undefined dynamic_lookup may not work with chained fixups and I am not so sure if the Homebrew patch is relevant or not.
https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/avrdude.rb

mcuee@mcuees-Mac-mini src % ./bootstrap 
+ rm -rf autom4te.cache
+ LIBTOOLIZE=libtoolize
+ glibtoolize --version
+ LIBTOOLIZE=glibtoolize
+ glibtoolize
glibtoolize: putting auxiliary files in '.'.
glibtoolize: linking file './ltmain.sh'
glibtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
glibtoolize: linking file 'm4/libtool.m4'
glibtoolize: linking file 'm4/ltoptions.m4'
glibtoolize: linking file 'm4/ltsugar.m4'
glibtoolize: linking file 'm4/ltversion.m4'
glibtoolize: linking file 'm4/lt~obsolete.m4'
+ aclocal
+ autoheader
+ autoconf
configure.ac:46: warning: AC_PROG_LEX without either yywrap or noyywrap is obsolete
./lib/autoconf/programs.m4:716: _AC_PROG_LEX is expanded from...
./lib/autoconf/programs.m4:709: AC_PROG_LEX is expanded from...
configure.ac:46: the top level
configure.ac:120: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:120: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:120: the top level
configure.ac:227: warning: The macro `AC_HEADER_TIME' is obsolete.
configure.ac:227: You should run autoupdate.
./lib/autoconf/headers.m4:743: AC_HEADER_TIME is expanded from...
configure.ac:227: the top level
configure.ac:249: warning: The macro `AC_TRY_LINK' is obsolete.
configure.ac:249: You should run autoupdate.
./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from...
configure.ac:249: the top level
configure.ac:281: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:281: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:281: the top level
configure.ac:299: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:299: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:299: the top level
configure.ac:311: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:311: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:311: the top level
configure.ac:323: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:323: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:323: the top level
configure.ac:335: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:335: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:335: the top level
configure.ac:440: warning: The macro `AC_TRY_COMPILE' is obsolete.
configure.ac:440: You should run autoupdate.
./lib/autoconf/general.m4:2847: AC_TRY_COMPILE is expanded from...
configure.ac:440: the top level
configure.ac:465: warning: The macro `AC_TRY_COMPILE' is obsolete.
configure.ac:465: You should run autoupdate.
./lib/autoconf/general.m4:2847: AC_TRY_COMPILE is expanded from...
configure.ac:465: the top level
configure.ac:489: warning: The macro `AC_TRY_LINK' is obsolete.
configure.ac:489: You should run autoupdate.
./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from...
configure.ac:489: the top level
+ automake -a -c
configure.ac:37: installing './compile'
configure.ac:28: installing './config.guess'
configure.ac:28: installing './config.sub'
configure.ac:33: installing './install-sh'
configure.ac:33: installing './missing'
Makefile.am: installing './depcomp'
configure.ac: installing './ylwrap'
doc/Makefile.am:33: installing 'doc/mdate-sh'
doc/Makefile.am:33: installing 'doc/texinfo.tex'
mcuee@mcuees-Mac-mini src % CFLAGS="-I/opt/homebrew/include" LDFLAGS="-L/opt/homebrew/lib" ./configure  
checking build system type... aarch64-apple-darwin22.1.0
checking host system type... aarch64-apple-darwin22.1.0
checking target system type... aarch64-apple-darwin22.1.0
checking for a BSD-compatible install... /opt/homebrew/bin/ginstall -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /opt/homebrew/bin/gmkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking how to print strings... printf
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /opt/homebrew/bin/gsed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Library/Developer/CommandLineTools/usr/bin/ld
checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 786432
checking how to convert aarch64-apple-darwin22.1.0 file names to aarch64-apple-darwin22.1.0 format... func_convert_file_noop
checking how to convert aarch64-apple-darwin22.1.0 file names to toolchain format... func_convert_file_noop
checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for sys/time.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin22.1.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether make supports nested variables... (cached) yes
checking for gcc... (cached) gcc
checking whether the compiler supports GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to enable C11 features... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for a sed that does not truncate output... (cached) /opt/homebrew/bin/gsed
checking for bison... bison -y
checking for flex... flex
checking for lex output file root... lex.yy
checking for lex library... none needed
checking for library containing yywrap... -ll
checking whether yytext is a pointer... yes
checking for -ar... ar
checking whether yylex_destroy is generated by flex... version Apple(flex-34) => yes
checking for tputs in -ltermcap... yes
checking for tputs in -lncurses... yes
checking for readline in -lreadline... yes
checking for elf_getshdrstrndx in -lelf... yes
checking for libelf.h... no
checking for libelf/libelf.h... yes
checking for library containing gethostent... none required
checking for library containing setsockopt... none required
checking for usb_get_string_simple in -lusb... yes
checking for usb.h... yes
checking for lusb0_usb.h... no
checking for libusb_init in -lusb-1.0... yes
checking for libusb-1.0/libusb.h... yes
checking for libusb.h... no
checking for libusb_init in -lusb... no
checking for libusb.h... (cached) no
checking for library containing hid_init... -lhidapi
checking for hidapi/hidapi.h... yes
checking for ftdi_new in -lftdi1... yes
checking for ftdi_usb_get_strings in -lftdi... yes
checking for ftdi_tcioflush... yes
checking for pthread.h... yes
checking for pthread_create in -lpthread... yes
checking for limits.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for fcntl.h... yes
checking for sys/ioctl.h... yes
checking for sys/time.h... (cached) yes
checking for termios.h... yes
checking for unistd.h... (cached) yes
checking for ddk/hidsdi.h... no
checking for an ANSI C-conforming const... yes
checking for netinet/in.h... yes
checking for memset... yes
checking for select... yes
checking for strcasecmp... yes
checking for strdup... yes
checking for strerror... yes
checking for strncasecmp... yes
checking for strtol... yes
checking for strtoul... yes
checking for gettimeofday... yes
checking for usleep... yes
checking for getaddrinfo... yes
checking for a Win32 HID library... no
checking for uint_t... no
checking for ulong_t... no
checking for serial device... unknown
checking if gcc accepts -Wno-pointer-sign ... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating doc/Makefile
config.status: creating avrdude.spec
config.status: creating Makefile
config.status: creating avrdude.conf.tmp
config.status: creating ac_cfg.h
config.status: ac_cfg.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands


Configuration summary:
----------------------
DO HAVE    libelf
DO HAVE    libusb
DO HAVE    libusb_1_0
DO HAVE    libftdi1
DO HAVE    libftdi (but prefer to use libftdi1)
DON'T HAVE libhid
DO HAVE    libhidapi
DO HAVE    pthread
DISABLED   doc
DISABLED   parport
DISABLED   linuxgpio
DISABLED   linuxspi
mcuee@mcuees-Mac-mini src % make
/Library/Developer/CommandLineTools/usr/bin/make  all-recursive
Making all in .
  CCLD     avrdude
ld: warning: directory not found for option '-FCoreFoundation'
  CC       libavrdude_la-config_gram.lo
  CC       libavrdude_la-lexer.lo
  CC       libavrdude_la-arduino.lo
  CC       libavrdude_la-avr.lo
  CC       libavrdude_la-avr910.lo
  CC       libavrdude_la-avrcache.lo
  CC       libavrdude_la-avrftdi.lo
  CC       libavrdude_la-avrftdi_tpi.lo
  CC       libavrdude_la-avrpart.lo
  CC       libavrdude_la-bitbang.lo
  CC       libavrdude_la-buspirate.lo
  CC       libavrdude_la-butterfly.lo
  CC       libavrdude_la-config.lo
  CC       libavrdude_la-confwin.lo
  CC       libavrdude_la-crc16.lo
  CC       libavrdude_la-dfu.lo
  CC       libavrdude_la-fileio.lo
  CC       libavrdude_la-flip1.lo
  CC       libavrdude_la-flip2.lo
  CC       libavrdude_la-ft245r.lo
  CC       libavrdude_la-jtagmkI.lo
  CC       libavrdude_la-jtagmkII.lo
  CC       libavrdude_la-jtag3.lo
  CC       libavrdude_la-linuxgpio.lo
  CC       libavrdude_la-linuxspi.lo
  CC       libavrdude_la-lists.lo
  CC       libavrdude_la-micronucleus.lo
  CC       libavrdude_la-par.lo
  CC       libavrdude_la-pgm.lo
  CC       libavrdude_la-pgm_type.lo
  CC       libavrdude_la-pickit2.lo
  CC       libavrdude_la-pindefs.lo
  CC       libavrdude_la-ppi.lo
  CC       libavrdude_la-ppiwin.lo
  CC       libavrdude_la-serbb_posix.lo
  CC       libavrdude_la-serbb_win32.lo
  CC       libavrdude_la-ser_avrdoper.lo
  CC       libavrdude_la-ser_posix.lo
  CC       libavrdude_la-ser_win32.lo
  CC       libavrdude_la-stk500.lo
  CC       libavrdude_la-stk500v2.lo
  CC       libavrdude_la-stk500generic.lo
  CC       libavrdude_la-teensy.lo
  CC       libavrdude_la-usbasp.lo
  CC       libavrdude_la-serialupdi.lo
  CC       libavrdude_la-updi_link.lo
  CC       libavrdude_la-updi_state.lo
  CC       libavrdude_la-updi_readwrite.lo
  CC       libavrdude_la-updi_nvm.lo
  CC       libavrdude_la-usb_hidapi.lo
  CC       libavrdude_la-usb_libusb.lo
  CC       libavrdude_la-usbtiny.lo
  CC       libavrdude_la-update.lo
  CC       libavrdude_la-wiring.lo
  CC       libavrdude_la-xbee.lo
  CCLD     libavrdude.la
ld: warning: -undefined dynamic_lookup may not work with chained fixups
mcuee@mcuees-Mac-mini src % otool -L ./avrdude
./avrdude:
	/opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
	/opt/homebrew/opt/readline/lib/libreadline.8.dylib (compatibility version 8.2.0, current version 8.2.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

@MCUdude
Please install libreadline and test using both CMake and auto-tools. You will need to force link readline as well by running brew link --force readline. If both are fine, we have a very simple work-around, ask the user to install libreadline and force link it. Without the force link step, avrdude will use libedit and the issue will be present.

mcuee@mcuees-Mac-mini avrdude_bin % brew link readline  
Warning: readline is keg-only and must be linked with `--force`.
mcuee@mcuees-Mac-mini avrdude_bin % brew link readline --force
Linking /opt/homebrew/Cellar/readline/8.2.1... 18 symlinks created.
mcuee@mcuees-Mac-mini avrdude_bin % pkg-config --libs readline
-L/opt/homebrew/Cellar/readline/8.2.1/lib -lreadline
mcuee@mcuees-Mac-mini avrdude_bin % pkg-config --cflags readline
-I/opt/homebrew/Cellar/readline/8.2.1/include

Without the force link step, avrdude will use libedit and the issue will be present.

mcuee@mcuees-Mac-mini src % otool -L avrdude
avrdude:
	/opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
	/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)

But yes it will still be good to be able to automatically detect the lack of libreadline (only libedit is present) and then warn the user to install libreadline before proceeding.

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

@MCUdude
You do not need to force link readline either, just follow the instruction from brew info readline and you will be fine.

mcuee@mcuees-Mac-mini src % brew info readline
==> readline: stable 8.2.1 (bottled) [keg-only]
Library for command-line editing
https://tiswww.case.edu/php/chet/readline/rltop.html
/opt/homebrew/Cellar/readline/8.2.1 (50 files, 1.7MB)
  Poured from bottle on 2022-10-20 at 19:12:26
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/readline.rb
License: GPL-3.0-or-later
==> Caveats
readline is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides BSD libedit.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/readline/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig"

==> Analytics
install: 968,971 (30 days), 1,939,945 (90 days), 7,279,339 (365 days)
install-on-request: 33,853 (30 days), 72,830 (90 days), 245,882 (365 days)
build-error: 11 (30 days)

mcuee@mcuees-Mac-mini src % CFLAGS="-I/opt/homebrew/include -I/opt/homebrew/opt/readline/include" LDFLAGS="-L/opt/homebrew/lib -L/opt/homebrew/opt/readline/lib" ./configure
...
mcuee@mcuees-Mac-mini src % make
...
mcuee@mcuees-Mac-mini src % otool -L avrdude  
avrdude:
	/opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
	/opt/homebrew/opt/readline/lib/libreadline.8.dylib (compatibility version 8.2.0, current version 8.2.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

There is a discussion here for reference -- to me it is good to mandate the use of readline.

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

@mariusgreuel

Would you please look at the script here for a more comprehensive way of finding readline so that libedit will not be detected as readline? Thanks.
https://github.com/monero-project/monero/blob/master/cmake/FindReadline.cmake

The project has similar more complex scripts for libusb and hidapi, but I think those are not necessary.
https://github.com/monero-project/monero/blob/master/cmake/FindLibUSB.cmake
https://github.com/monero-project/monero/blob/master/cmake/FindHIDAPI.cmake

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

For auto-tools build configure.ac needs to be changed to detect libedit, right now the following lines will not do the job.
https://github.com/avrdudes/avrdude/blob/main/src/configure.ac#L80-L83

# Checks for libraries.
AC_CHECK_LIB([termcap], [tputs])
AC_CHECK_LIB([ncurses], [tputs])
AC_CHECK_LIB([readline], [readline])

Something for reference from Postgres.
https://github.com/postgres/postgres/blob/master/configure.ac#L1503-L1521

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

@MCUdude and @stefanrueger

If I replace it with #if 0, terminal mode works perfectly fine again.

You will lose the ability to connect to bootloaders in the terminal (they will time out).

I feel we should solve this by getting CMake to do the right thing for MacOS before the 7.1 release.

Yet the other quick solution is to follow @MCUdude's suggestion to sort out the immediate issue and then forego the benefits of the terminal time out as of now. In this case, everything will work out of the box under macOS except the terminal mode timeout improvement (no more quick flashing LEDs if you want some visual hints).

mcuee@mcuees-Mac-mini avrdude_sr % git diff
diff --git a/src/term.c b/src/term.c
index c3f643f..7cbaf8f 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1230,7 +1230,7 @@ static int process_line(char *cmdbuf, PROGRAMMER *pgm, struct avrpart *p) {
 
 
 
-#if defined(HAVE_LIBREADLINE)
+#if defined(HAVE_LIBREADLINE) && !defined(__APPLE__)
 
 static PROGRAMMER *term_pgm;
 static struct avrpart *term_p;

Take note libedit (or libreadline) is still needed for other parts of term.c. For example, if I disable HAVE_LIBREADLINE totoally it will fail to build.

mcuee@mcuees-Mac-mini avrdude_main % cmake -D CMAKE_C_FLAGS=-I/opt/homebrew/include
 -D CMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/Cellar -D HAVE_LIBREADLINE='' 
-D CMAKE_BUILD_TYPE=RelWithDebInfo -B build_macos
...
mcuee@mcuees-Mac-mini avrdude_main % cmake --build build_macos -v
...
[100%] Linking C executable avrdude
cd /Users/mcuee/build/avr/avrdude_test/avrdude_main/build_macos/src && /opt/homebrew/Cellar/cmake/3.24.2/bin/cmake -E cmake_link_script CMakeFiles/avrdude.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/cc -I/opt/homebrew/include -O2 -g -DNDEBUG -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.0.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/opt/homebrew/Cellar CMakeFiles/avrdude.dir/main.c.o CMakeFiles/avrdude.dir/term.c.o CMakeFiles/avrdude.dir/avrintel.c.o CMakeFiles/avrdude.dir/developer_opts.c.o CMakeFiles/avrdude.dir/whereami.c.o -o avrdude  libavrdude.a -lm /opt/homebrew/lib/libelf.a /opt/homebrew/lib/libusb.dylib /opt/homebrew/lib/libusb-1.0.dylib /opt/homebrew/lib/libhid.dylib /opt/homebrew/lib/libhidapi.dylib /opt/homebrew/lib/libftdi.dylib /opt/homebrew/lib/libftdi1.dylib 
Undefined symbols for architecture arm64:
  "_add_history", referenced from:
      _term_gotline in term.c.o
  "_rl_callback_handler_install", referenced from:
      _terminal_mode in term.c.o
  "_rl_callback_handler_remove", referenced from:
      _terminal_mode in term.c.o
  "_rl_callback_read_char", referenced from:
      _terminal_mode in term.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/avrdude] Error 1
make[1]: *** [src/CMakeFiles/avrdude.dir/all] Error 2

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

BTW, it is not a big problem to require readline under macOS. You can see common software like Python, sqlite and gtk+ depend on readline. Most likely it is because libedit is not able to do the job.

I got smaller x86_64 homebrew installation but you can see readline is still essential.

mcuee@mcuees-Mac-mini ~ % brew uninstall readline
Error: Refusing to uninstall /usr/local/Cellar/readline/8.2.1
because it is required by amtk, atk, cairo, enchant, glib-networking, gnutls, gobject-introspection, gtk+, 
gtk+3, gtk-mac-integration, gtksourceview4, gts, guile, itstool, liblqr, libpeas, libsoup, libxml2, neofetch, 
py3cairo, pygobject3, python-tk@3.10, python-tk@3.9, python@3.10, python@3.9, ranger, ruby, 
shared-mime-info and sqlite, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies readline

For my ARM64 homebrew installation, it is even more obvious.

mcuee@mcuees-Mac-mini ~ % brew uninstall readline
Error: Refusing to uninstall /opt/homebrew/Cellar/readline/8.2.1
because it is required by ansible, ansible-lint, atk, avrdude, byobu, cairo, ceres-solver, cgdb, clisp, 
cmus, cython, dosbox-staging, enchant, ffmpeg, ffmpeg@4, fluid-synth, gawk, glib-networking, 
gnutls, gobject-introspection, gpsim, gtk+, gtk+3, gtk-chtheme, gtk-mac-integration, gtk-vnc, 
gts, guile, hunspell, iproute2mac, jsonschema, libass, liblqr, libpeas, libproxy, libslirp, libsoup, 
libxml2, llvm, meson, ncmpcpp, neofetch, newt, nnn, opencv, pipenv, platformio, proselint, 
pygobject3, pyqt@5, pyside, python-tabulate, python-tk@3.10, python-tk@3.9, python@3.10, 
python@3.11, python@3.9, qt, ranger, rlwrap, ruby, scipy, sdcc, shared-mime-info, sqlite, texlive, 
tiger-vnc, vim, virtualenv, vtk, yamllint, youtube-dl and zile, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies readline

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

So the following is my recommendation for macOS Homebrew users. For macports users, just require readline will do, no need the extra stuff mentioned below. No code changes, just Wiki documentation updates.

  1. Require readline under macOS but no force link

  2. Ask the user to use build.sh or use extra CMake option which hard code readline location
    -D HAVE_LIBREADLINE:FILEPATH=/opt/homebrew/opt/readline/lib/libreadline.dylib" for ARM64 and -D HAVE_LIBREADLINE:FILEPATH=/usr/local/opt/readline/lib/libreadline.dylib" for x86_64.

  3. For auto-tool users who use Homebrew, ask them to use the follow the configure option recommendation from readline keg. As far as I know, auto-tools are not official supported now, so the following is only for reference.

CFLAGS="-I/opt/homebrew/include -I/opt/homebrew/opt/readline/include" LDFLAGS="-L/opt/homebrew/lib -L/opt/homebrew/opt/readline/lib" ./configure

for ARM64 or

CFLAGS="-I/usr/local/include -I/usr/local/opt/readline/include" LDFLAGS="-L/usr/local/lib -L/usr/local/opt/readline/lib" ./configure

for x86_64.

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

But if @MCUdude prefers not to require readline, I am also okay with the following one line change. (Line number is for PR #1171 as I expect it to be merged soon).

mcuee@mcuees-Mac-mini avrdude_sr % git diff
diff --git a/src/term.c b/src/term.c
index c3f643f..7cbaf8f 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1230,7 +1230,7 @@ static int process_line(char *cmdbuf, PROGRAMMER *pgm, struct avrpart *p) {
 
 
 
-#if defined(HAVE_LIBREADLINE)
+#if defined(HAVE_LIBREADLINE) && !defined(__APPLE__)
 
 static PROGRAMMER *term_pgm;
 static struct avrpart *term_p;

@mcuee
Copy link
Collaborator

mcuee commented Nov 12, 2022

Future improvement when @mariusgreuel or other CMake experts are available -- to differentiate libedit vs libreadline and set that line accordingly. I am not so sure if @dl8dtl or @mariusgreuel want to fix the configure.ac file.

Reference:

Please use CMake instead. The automake files are no longer maintained for all targets.

@MCUdude
Copy link
Collaborator Author

MCUdude commented Nov 16, 2022

Please install libreadline and test using both CMake and auto-tools. You will need to force link readline as well by running brew link --force readline. If both are fine, we have a very simple work-around, ask the user to install libreadline and force link it. Without the force link step, avrdude will use libedit and the issue will be present.

mcuee@mcuees-Mac-mini avrdude_bin % brew link readline  
Warning: readline is keg-only and must be linked with `--force`.
mcuee@mcuees-Mac-mini avrdude_bin % brew link readline --force
Linking /opt/homebrew/Cellar/readline/8.2.1... 18 symlinks created.
mcuee@mcuees-Mac-mini avrdude_bin % pkg-config --libs readline
-L/opt/homebrew/Cellar/readline/8.2.1/lib -lreadline
mcuee@mcuees-Mac-mini avrdude_bin % pkg-config --cflags readline
-I/opt/homebrew/Cellar/readline/8.2.1/include

I'm really having a hard time getting the Avrdude build system to pick the correct readline library.
libreadline are for some reason installed under /usr/local/opt/readline/lib/libreadline.dylib

$ brew install readline

Warning: readline 8.2.1 is already installed and up-to-date.
To reinstall 8.2.1, run:
  brew reinstall readline

$ brew link readline --force
Warning: Refusing to link macOS provided/shadowed software: readline
For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

$ brew info readline
==> readline: stable 8.2.1 [keg-only]
Library for command-line editing
https://tiswww.case.edu/php/chet/readline/rltop.html
/usr/local/Cellar/readline/8.2.1 (50 files, 1.6MB)
  Built from source on 2022-11-09 at 20:44:06
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/readline.rb
License: GPL-3.0-or-later
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BSD libedit.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

==> Analytics
install: 923,419 (30 days), 1,977,417 (90 days), 7,285,861 (365 days)
install-on-request: 31,810 (30 days), 74,058 (90 days), 246,585 (365 days)
build-error: 10 (30 days)

When I build using

$ cmake -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/Cellar -D CMAKE_BUILD_TYPE=RelWithDebInfo -B build_macos

$ cmake --build build_macos

Terminal mode is still broken, just like when I build with make

I've also tried

$ cmake -D CMAKE_C_FLAGS="-I/usr/local/include -I/usr/local/opt/readline/include" -D CMAKE_EXE_LINKER_FLAGS="-L/usr/local/Cellar -L/usr/local/opt/readline/lib" -D CMAKE_BUILD_TYPE=RelWithDebInfo -B build_macos

but I'm getting the exact same result

EDIT:
I tried replacing
CMAKE_C_FLAGS="-I/usr/local/include -I/usr/local/opt/readline/include"
with
CMAKE_C_FLAGS="-I/usr/local/include -I/usr/local/Cellar/readline/8.2.1/include/"
but I'm still seeing the same result...

@mcuee
Copy link
Collaborator

mcuee commented Nov 17, 2022

@MCUdude
I have already added the necessary change to build.sh in PR #1156 which has been merged.
https://github.com/avrdudes/avrdude/blob/main/build.sh

You can just use build.sh or you need to use something like this.

cmake -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/Cellar \
-D HAVE_LIBREADLINE:FILEPATH=/usr/local/opt/readline/lib/libreadline.dylib" \
-D CMAKE_BUILD_TYPE=RelWithDebInfo -B build_macos

@MCUdude
Copy link
Collaborator Author

MCUdude commented Nov 17, 2022

Thanks @mcuee! Using build.sh did work. I'm totally OK with Avrdude requiring libreadline in order to work, but I think that the precense/absense of libreadline should be detected and printed on the screen when building with build.sh, cmake, or make.

Currently, there's no mention of libreadline anywhere:

 ./build.sh 
-- The C compiler identification is AppleClang 10.0.1.10010046
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Git: /usr/local/bin/git (found version "2.30.0") 
-- Found FLEX: /usr/bin/flex (found version "2.5.35") 
-- Found BISON: /usr/bin/bison (found version "2.3")
-- Looking for libelf.h
-- Looking for libelf.h - not found
-- Looking for libelf/libelf.h
-- Looking for libelf/libelf.h - found
-- Looking for usb.h
-- Looking for usb.h - found
-- Looking for lusb0_usb.h
-- Looking for lusb0_usb.h - not found
-- Looking for libusb.h
-- Looking for libusb.h - not found
-- Looking for libusb-1.0/libusb.h
-- Looking for libusb-1.0/libusb.h - found
-- Looking for hidapi/hidapi.h
-- Looking for hidapi/hidapi.h - found
-- Looking for ftdi_tcioflush
-- Looking for ftdi_tcioflush - found
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DO HAVE    libftdi (but prefer to use libftdi1)
-- DO HAVE    libftdi1
-- DISABLED   doc
-- DISABLED   parport
-- DISABLED   linuxgpio
-- DISABLED   linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/hans/Downloads/avrdude-terminal/build_darwin

To me, it's important that building Avrdude "just works", on any system, as long as the user follows the build instructions. The instructions are yet to be updated (for macOS at least).

@MCUdude
Copy link
Collaborator Author

MCUdude commented Nov 24, 2022

What about if you go as far back as
https://github.com/avrdudes/avrdude/tree/b864d7e73afbaf2a94a4398913e2972a2984bb73/
This uses readline() (presumably from libedit) and would give you line editing. Does that allow you to pipe into avrdude?

Yes, when going as far back as this, I'm able to pipe into Avrdude

@mcuee
Copy link
Collaborator

mcuee commented Nov 25, 2022

Maybe there's a workaround for this as well? If not, libreadline should be used instead. However, the old make build system should be updated to get the correct libreadline library, from either brew or Macports.

@MCUdude and @stefanrueger
If there is a workaround for libedit, that will be good.

If there is no easy workaround, I will agree to use GNU Readline under macOS. I think we should be able to change configure.ac to use GNU Readline as well. Let me give it a try over this weekend.

@mcuee
Copy link
Collaborator

mcuee commented Nov 25, 2022

I think we need to decide what we want:

  1. Native experience of line editing (fgets in Windows, libedit in MacOS, GNU readline in Linux, FreeBSD etc): Only the latter group can do avrdude -t for bootloaders, but all can pipe
  2. Same avrdude experience for users: all can pipe and all can keep bootloaders parts open in the terminal, but they won't have native line editing (only Windows has a noticeably different line editing, eg, F7 for whatdoiknow etc) : must compile all with libreadline
  3. We keep it as it is, but pipes don't work for MacOS

I can help with 1 (I know how to build back for MacOS so it has readline() from libedit, but not readline callbacks). I cannot help with 2. We already have 3.

Opinions?

I think Option 3 is no go as it is a regression. What I suggest is a mix of Option 1 and Option 2.

For macOS, I hope we can get libedit to work with either avrdude -t for bootloaders and pipe. But if that is not possible with libedit, we should use GNU Readline under macOS. Basically I'd like to have macOS behave similar to Linux to have the full functionality. I believe that is the same opinion as @MCUdude.

As for Windows, it is a different story.

  1. As of now, GNU Readline build does not work out of box for both MSYS2 and MSVC.
  2. Therefore we should go with Option 1 for Windows as of now by default.
  3. And it is not really that bad for -c urclock -t since we can use pipe as the workaround. That tip given by @MCUdude is actually valid for -c arduino -t as well. Test results are here.
  1. But we should not prevent Windows from building using Readline with some hacks. I can provide the Windows binaries with Readline as well using MSYS2. This just means we need to be careful about ifdefs.

@mcuee
Copy link
Collaborator

mcuee commented Nov 25, 2022

Another thing, I can provide Linux/macOS/Windows avrdude binaries with GNU Readline here, using the nice infrastructure provided by Arduino project.
https://github.com/mcuee/avrdude-packing/releases

@mcuee
Copy link
Collaborator

mcuee commented Nov 25, 2022

What about if you go as far back as
https://github.com/avrdudes/avrdude/tree/b864d7e73afbaf2a94a4398913e2972a2984bb73/
This uses readline() (presumably from libedit) and would give you line editing. Does that allow you to pipe into avrdude?

Yes, when going as far back as this, I'm able to pipe into Avrdude

So basically this commit (PR #1132) will not work with libedit in two aspects under macOS.

  1. Terminal mode input problem, fixed by @dl8dtl in PR Add a workaround for issue #1173 #1185 using a work-around for libedit bug
  2. Terminal mode pipe does not work -- need to see if there is a simple workaround or not.

@mcuee
Copy link
Collaborator

mcuee commented Nov 25, 2022

BTW, the following is the build command Homebrew is using (macOS Apple Silicon). So it is linked to libedit by default.

mcuee@mcuees-Mac-mini avrdude_main % brew reinstall avrdude
==> Cloning https://github.com/avrdudes/avrdude.git
Updating /Users/mcuee/Library/Caches/Homebrew/avrdude--git
==> Checking out branch main
Already on 'main'
Your branch is up to date with 'origin/main'.
HEAD is now at afa57ac Merge pull request #1196 from mcuee/disable_readline_msvc
==> Reinstalling avrdude 
==> cmake -S . -B build/shared -DCMAKE_INSTALL_SYSCONFDIR=/opt/homebrew/etc -DBUILD_SHARED_LIBS=ON 
-DCMAKE_INSTALL_RPATH=@loader_path/../lib 
-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-undefined,dynamic_lookup
==> cmake --build build/shared
==> cmake --install build/shared
==> cmake -S . -B build/static -DCMAKE_INSTALL_SYSCONFDIR=/opt/homebrew/etc
==> cmake --build build/static
🍺  /opt/homebrew/Cellar/avrdude/HEAD-afa57ac_2: 13 files, 2MB, built in 7 seconds
==> Running `brew cleanup avrdude`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

mcuee@mcuees-Mac-mini avrdude_main % otool -L /opt/homebrew/bin/avrdude 
/opt/homebrew/bin/avrdude:
	@rpath/libavrdude.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
	/opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
	/opt/homebrew/opt/libhid/lib/libhid.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
	/opt/homebrew/opt/libftdi0/lib/libftdi.1.dylib (compatibility version 22.0.0, current version 22.0.0)
	/opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)
	/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)```

@mcuee
Copy link
Collaborator

mcuee commented Nov 25, 2022

Here is the default auto-tools build.

Even though it does not claim to find GNU Readline in this case (some modifications will be be needed to make the display that correct), it is actually linked to libedit.

Terminal mode call back will work thanks to the workaround by @dl8dtl. But unfortunately pipes will not work.

mcuee@mcuees-Mac-mini src % ./bootstrap 
+ rm -rf autom4te.cache
+ LIBTOOLIZE=libtoolize
+ glibtoolize --version
+ LIBTOOLIZE=glibtoolize
+ glibtoolize
glibtoolize: putting auxiliary files in '.'.
glibtoolize: linking file './ltmain.sh'
glibtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
glibtoolize: linking file 'm4/libtool.m4'
glibtoolize: linking file 'm4/ltoptions.m4'
glibtoolize: linking file 'm4/ltsugar.m4'
glibtoolize: linking file 'm4/ltversion.m4'
glibtoolize: linking file 'm4/lt~obsolete.m4'
+ aclocal
+ autoheader
+ autoconf
configure.ac:46: warning: AC_PROG_LEX without either yywrap or noyywrap is obsolete
./lib/autoconf/programs.m4:716: _AC_PROG_LEX is expanded from...
./lib/autoconf/programs.m4:709: AC_PROG_LEX is expanded from...
configure.ac:46: the top level
configure.ac:120: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:120: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:120: the top level
configure.ac:227: warning: The macro `AC_HEADER_TIME' is obsolete.
configure.ac:227: You should run autoupdate.
./lib/autoconf/headers.m4:743: AC_HEADER_TIME is expanded from...
configure.ac:227: the top level
configure.ac:249: warning: The macro `AC_TRY_LINK' is obsolete.
configure.ac:249: You should run autoupdate.
./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from...
configure.ac:249: the top level
configure.ac:281: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:281: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:281: the top level
configure.ac:299: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:299: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:299: the top level
configure.ac:311: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:311: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:311: the top level
configure.ac:323: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:323: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:323: the top level
configure.ac:335: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:335: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:335: the top level
configure.ac:440: warning: The macro `AC_TRY_COMPILE' is obsolete.
configure.ac:440: You should run autoupdate.
./lib/autoconf/general.m4:2847: AC_TRY_COMPILE is expanded from...
configure.ac:440: the top level
configure.ac:465: warning: The macro `AC_TRY_COMPILE' is obsolete.
configure.ac:465: You should run autoupdate.
./lib/autoconf/general.m4:2847: AC_TRY_COMPILE is expanded from...
configure.ac:465: the top level
configure.ac:489: warning: The macro `AC_TRY_LINK' is obsolete.
configure.ac:489: You should run autoupdate.
./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from...
configure.ac:489: the top level
+ automake -a -c
configure.ac:37: installing './compile'
configure.ac:28: installing './config.guess'
configure.ac:28: installing './config.sub'
configure.ac:33: installing './install-sh'
configure.ac:33: installing './missing'
Makefile.am: installing './depcomp'
configure.ac: installing './ylwrap'
doc/Makefile.am:33: installing 'doc/mdate-sh'
doc/Makefile.am:33: installing 'doc/texinfo.tex'

mcuee@mcuees-Mac-mini src % CPPFLAGS=-I/opt/homebrew/include LDFLAGS="-L/opt/homebrew/lib -Wl,-undefined,dynamic_lookup" ./configure
checking build system type... aarch64-apple-darwin22.1.0
checking host system type... aarch64-apple-darwin22.1.0
checking target system type... aarch64-apple-darwin22.1.0
checking for a BSD-compatible install... /opt/homebrew/bin/ginstall -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /opt/homebrew/bin/gmkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking how to print strings... printf
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /opt/homebrew/bin/gsed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Library/Developer/CommandLineTools/usr/bin/ld
checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 786432
checking how to convert aarch64-apple-darwin22.1.0 file names to aarch64-apple-darwin22.1.0 format... func_convert_file_noop
checking how to convert aarch64-apple-darwin22.1.0 file names to toolchain format... func_convert_file_noop
checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for sys/time.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin22.1.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether make supports nested variables... (cached) yes
checking for gcc... (cached) gcc
checking whether the compiler supports GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to enable C11 features... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for a sed that does not truncate output... (cached) /opt/homebrew/bin/gsed
checking for bison... bison -y
checking for flex... flex
checking for lex output file root... lex.yy
checking for lex library... none needed
checking for library containing yywrap... none required
checking whether yytext is a pointer... yes
checking for -ar... ar
checking whether yylex_destroy is generated by flex... version Apple(flex-34) => yes
checking for tputs in -ltermcap... yes
checking for tputs in -lncurses... yes
checking for readline in -lreadline... yes
checking for elf_getshdrstrndx in -lelf... yes
checking for libelf.h... no
checking for libelf/libelf.h... yes
checking for library containing gethostent... none required
checking for library containing setsockopt... none required
checking for usb_get_string_simple in -lusb... yes
checking for usb.h... yes
checking for lusb0_usb.h... no
checking for libusb_init in -lusb-1.0... yes
checking for libusb-1.0/libusb.h... yes
checking for libusb.h... no
checking for libusb_init in -lusb... yes
checking for libusb.h... (cached) no
checking for library containing hid_init... none required
checking for hidapi/hidapi.h... yes
checking for ftdi_new in -lftdi1... yes
checking for ftdi_usb_get_strings in -lftdi... yes
checking for ftdi_tcioflush... yes
checking for pthread.h... yes
checking for pthread_create in -lpthread... yes
checking for limits.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for fcntl.h... yes
checking for sys/ioctl.h... yes
checking for sys/time.h... (cached) yes
checking for termios.h... yes
checking for unistd.h... (cached) yes
checking for ddk/hidsdi.h... no
checking for an ANSI C-conforming const... yes
checking for netinet/in.h... yes
checking for memset... yes
checking for select... yes
checking for strcasecmp... yes
checking for strdup... yes
checking for strerror... yes
checking for strncasecmp... yes
checking for strtol... yes
checking for strtoul... yes
checking for gettimeofday... yes
checking for usleep... yes
checking for getaddrinfo... yes
checking for a Win32 HID library... no
checking for uint_t... no
checking for ulong_t... no
checking for serial device... unknown
checking if gcc accepts -Wno-pointer-sign ... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating doc/Makefile
config.status: creating avrdude.spec
config.status: creating Makefile
config.status: creating avrdude.conf.tmp
config.status: creating ac_cfg.h
config.status: executing depfiles commands
config.status: executing libtool commands


Configuration summary:
----------------------
DO HAVE    libelf
DO HAVE    libusb
DO HAVE    libusb_1_0
DO HAVE    libftdi1
DO HAVE    libftdi (but prefer to use libftdi1)
DON'T HAVE libhid
DO HAVE    libhidapi
DON'T HAVE libreadline
DO HAVE    pthread
DISABLED   doc
DISABLED   parport
DISABLED   linuxgpio
DISABLED   linuxspi
mcuee@mcuees-Mac-mini src % make
  YACC     config_gram.c
updating config_gram.h
  LEX      lexer.c
/Library/Developer/CommandLineTools/usr/bin/make  all-recursive
Making all in .
...
mcuee@mcuees-Mac-mini src % otool -L avrdude
avrdude:
	/opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
	/opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)

mcuee@mcuees-Mac-mini src % echo "dump eeprom 0 0x10" | ./avrdude -c urclock -P /dev/tty.usbmodem2213701 -p m328p -t  

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e950f (probably m328p)


avrdude done.  Thank you.

mcuee@mcuees-Mac-mini src % ./avrdude -c urclock -P /dev/tty.usbmodem2213701 -p m328p -t 

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e950f (probably m328p)
avrdude> dump eeprom 0 0x10
>>> dump eeprom 0 0x10 

Reading | ################################################## | 100% 0.02 s 

0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> quit
>>> quit 
avrdude> 
avrdude done.  Thank you.

mcuee@mcuees-Mac-mini src % 

@mcuee
Copy link
Collaborator

mcuee commented Nov 25, 2022

@MCUdude
But it is very easy to build with GNU Readline using the auto-tools by following the info provided by brew info readline. You can try the following command. It is not necessary to change configure.ac for the build to be success.

CPPFLAGS="-I/usr/local/include -I/usr/local/opt/readline/include"  
LDFLAGS="-Wl,-undefined,dynamic_lookup -L/usr/local/lib -L/usr/local/opt/readline/lib" 
./configure

Again, even though it does not claim to find GNU Readline in this case, it is actually linked to libreadline. Some modifications to configure.ac will be needed to make the display correct. My simple patch in PR #1184 does not make it in this case.

mcuee@mcuees-Mac-mini src % brew info readline
==> readline: stable 8.2.1 (bottled) [keg-only]
Library for command-line editing
https://tiswww.case.edu/php/chet/readline/rltop.html
/opt/homebrew/Cellar/readline/8.2.1 (50 files, 1.7MB)
  Poured from bottle on 2022-10-20 at 19:12:26
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/readline.rb
License: GPL-3.0-or-later
==> Caveats
readline is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides BSD libedit.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/readline/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig"

==> Analytics
install: 810,541 (30 days), 2,072,790 (90 days), 7,290,570 (365 days)
install-on-request: 27,222 (30 days), 76,824 (90 days), 247,549 (365 days)
build-error: 5 (30 days)

mcuee@mcuees-Mac-mini src % CPPFLAGS="-I/opt/homebrew/include -I/opt/homebrew/opt/readline/include"  LDFLAGS="-Wl,-undefined,dynamic_lookup -L/opt/homebrew/lib -L/opt/homebrew/opt/readline/lib" ./configure
checking build system type... aarch64-apple-darwin22.1.0
checking host system type... aarch64-apple-darwin22.1.0
checking target system type... aarch64-apple-darwin22.1.0
checking for a BSD-compatible install... /opt/homebrew/bin/ginstall -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /opt/homebrew/bin/gmkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking how to print strings... printf
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /opt/homebrew/bin/gsed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Library/Developer/CommandLineTools/usr/bin/ld
checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 786432
checking how to convert aarch64-apple-darwin22.1.0 file names to aarch64-apple-darwin22.1.0 format... func_convert_file_noop
checking how to convert aarch64-apple-darwin22.1.0 file names to toolchain format... func_convert_file_noop
checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for sys/time.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin22.1.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether make supports nested variables... (cached) yes
checking for gcc... (cached) gcc
checking whether the compiler supports GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to enable C11 features... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for a sed that does not truncate output... (cached) /opt/homebrew/bin/gsed
checking for bison... bison -y
checking for flex... flex
checking for lex output file root... lex.yy
checking for lex library... none needed
checking for library containing yywrap... none required
checking whether yytext is a pointer... yes
checking for -ar... ar
checking whether yylex_destroy is generated by flex... version Apple(flex-34) => yes
checking for tputs in -ltermcap... yes
checking for tputs in -lncurses... yes
checking for readline in -lreadline... yes
checking for elf_getshdrstrndx in -lelf... yes
checking for libelf.h... no
checking for libelf/libelf.h... yes
checking for library containing gethostent... none required
checking for library containing setsockopt... none required
checking for usb_get_string_simple in -lusb... yes
checking for usb.h... yes
checking for lusb0_usb.h... no
checking for libusb_init in -lusb-1.0... yes
checking for libusb-1.0/libusb.h... yes
checking for libusb.h... no
checking for libusb_init in -lusb... yes
checking for libusb.h... (cached) no
checking for library containing hid_init... none required
checking for hidapi/hidapi.h... yes
checking for ftdi_new in -lftdi1... yes
checking for ftdi_usb_get_strings in -lftdi... yes
checking for ftdi_tcioflush... yes
checking for pthread.h... yes
checking for pthread_create in -lpthread... yes
checking for limits.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for fcntl.h... yes
checking for sys/ioctl.h... yes
checking for sys/time.h... (cached) yes
checking for termios.h... yes
checking for unistd.h... (cached) yes
checking for ddk/hidsdi.h... no
checking for an ANSI C-conforming const... yes
checking for netinet/in.h... yes
checking for memset... yes
checking for select... yes
checking for strcasecmp... yes
checking for strdup... yes
checking for strerror... yes
checking for strncasecmp... yes
checking for strtol... yes
checking for strtoul... yes
checking for gettimeofday... yes
checking for usleep... yes
checking for getaddrinfo... yes
checking for a Win32 HID library... no
checking for uint_t... no
checking for ulong_t... no
checking for serial device... unknown
checking if gcc accepts -Wno-pointer-sign ... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating doc/Makefile
config.status: creating avrdude.spec
config.status: creating Makefile
config.status: creating avrdude.conf.tmp
config.status: creating ac_cfg.h
config.status: executing depfiles commands
config.status: executing libtool commands


Configuration summary:
----------------------
DO HAVE    libelf
DO HAVE    libusb
DO HAVE    libusb_1_0
DO HAVE    libftdi1
DO HAVE    libftdi (but prefer to use libftdi1)
DON'T HAVE libhid
DO HAVE    libhidapi
DON'T HAVE libreadline
DO HAVE    pthread
DISABLED   doc
DISABLED   parport
DISABLED   linuxgpio
DISABLED   linuxspi
mcuee@mcuees-Mac-mini src % make
  YACC     config_gram.c
updating config_gram.h
  LEX      lexer.c
/Library/Developer/CommandLineTools/usr/bin/make  all-recursive
Making all in .
...

mcuee@mcuees-Mac-mini src % otool -L ./avrdude
./avrdude:
	/opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
	/opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/opt/homebrew/opt/readline/lib/libreadline.8.dylib (compatibility version 8.2.0, current version 8.2.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)

mcuee@mcuees-Mac-mini src % ./avrdude -c urclock -P /dev/tty.usbmodem2213701 -p m328p -qqt 
avrdude> dump eeprom 0 0x10
>>> dump eeprom 0 0x10 
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> quit
>>> quit 
mcuee@mcuees-Mac-mini src % echo "dump eeprom 0 0x10" | ./avrdude -c urclock -P /dev/tty.usbmodem2213701 -p m328p -qqt                                
avrdude> dump eeprom 0 0x10
>>> dump eeprom 0 0x10 
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> 
avrdude> % 

@stefanrueger
Copy link
Collaborator

@MCUdude and @stefanrueger
If there is a workaround for libedit, that will be good.

Well, @MCUdude identified that by using libedit's callback functions pipelines cease to work. Pipes work with the regular readline() version from libedit without callback. I for my part have no idea how a workaround could look like.

BTW, I think this all has been caused by Stallman overreaching himself. He insisted GNU readline to be GNU copyleft in the hope that everyone who used the library would be forced to open source. Well, Apple and Microsoft certainly did not like the idea and rolled their own line editors for their command lines, which brought us here.

@mcuee
Copy link
Collaborator

mcuee commented Nov 26, 2022

BTW, I think this all has been caused by Stallman overreaching himself. He insisted GNU readline to be GNU copyleft in the hope that everyone who used the library would be forced to open source. Well, Apple and Microsoft certainly did not like the idea and rolled their own line editors for their command lines, which brought us here.

Indeed this is what happened.

@mcuee
Copy link
Collaborator

mcuee commented Nov 26, 2022

@MCUdude and @stefanrueger
If there is a workaround for libedit, that will be good.

Well, @MCUdude identified that by using libedit's callback functions pipelines cease to work. Pipes work with the regular readline() version from libedit without callback. I for my part have no idea how a workaround could look like.

Indeed there may be no easy workaround. Let's wait for a while to see if @dl8dtl or others who can come out with a potential solution.

In any case, there are no real issues as of now to build with GNU Readline with git main. I have updated the macOS build instructions here and I include recommendations to build with GNU Readline to have better user experiences with terminal mode.
https://github.com/avrdudes/avrdude/wiki/Building-AVRDUDE-for-macOS

If there is no easy workaround and we can reinstate PR #1156 later and I can update the Wiki again.

@mcuee
Copy link
Collaborator

mcuee commented Nov 26, 2022

@dl8dtl and @MCUdude

Just wondering what is your preference?

  1. Require GNU Readline for 7.1 release for macOS, reinstate PR Readline macos #1156
  2. Keep the current status, build with libedit by default, shell pipes would not work. Users can choose to build with GNU Readline to get shell pipes working.
  3. Work on the work-around so that libedit will work with shell pipes. This may not be easy.
  4. Use ifdef APPLE to get shell pipes working again on macOS but give up on -c urclock -t because callback will not work. Users who choose to build with GNU Readline has to change the source code term.c. to remove the ifdef APPLE thingy.

My preference is either Option 1 or Option 3 if someone wants to work on Option 3.

I think we can always go with Option 1 for 7.1 Release and later go with Option 3 if there are work-around.

BTW, please also review the wiki here.
https://github.com/avrdudes/avrdude/wiki/Building-AVRDUDE-for-macOS

@stefanrueger
Copy link
Collaborator

For what my tuppence are worth, if it was me I'd go for 1, 4 in that order. 2 is no good as pipes are more important than keeping bootloaders alive. I predict 3 to be too much work.

@MCUdude
Copy link
Collaborator Author

MCUdude commented Nov 27, 2022

I'd prefer 3, 1, in this order.

If piping is impossible with libedit, then option 1 is the second best. If I'm going to incorporate Urboot into my Arduino cores someday, I'd like all features to work on MacOS, Windows and Linux favours. However, ./configure + make should be updated to automatically detect if libreadline is present on macOS (brew or macports), and use this instead of libedit.

@mcuee
Copy link
Collaborator

mcuee commented Nov 27, 2022

@MCUdude @dl8dtl and @stefanrueger

I guess @dl8dtl would prefer Option 3 over Option 1 as well.

Looks like nobody would like to go with Option 2. Option 1 is the common denominator now.

On the other hand, I think we should not prevent 7.1 release because of this, rather we should go with Option 1 for 7.1 release unless Option 3 somehow gets implemented miracally with two to three weeks, We can always keep Option 3 as future enhancement for macOS.

Is this an okay compromise?

@dl8dtl
Copy link
Contributor

dl8dtl commented Nov 27, 2022

Yes, I'll see how to find a workaround.
Should't be too hard. Basically, it means to have both implementations of the terminal function, and use one or the other, depending on whether we are actually operating on a terminal or not. That implies that also for GNU libreadline, commands passed through a pipe wouldn't be recorded in the history, but that's IMHO a good thing anyway. The purpose of the history is to record interactive commands.

@mcuee
Copy link
Collaborator

mcuee commented Nov 27, 2022

I'd prefer 3, 1, in this order.

If piping is impossible with libedit, then option 1 is the second best. If I'm going to incorporate Urboot into my Arduino cores someday, I'd like all features to work on MacOS, Windows and Linux favours. However, ./configure + make should be updated to automatically detect if libreadline is present on macOS (brew or macports), and use this instead of libedit.

@MCUdude

I am not exactly sure what you mean by automatically with ./configure + make. You have to specify some options anyway with Homebrew, no matter it is CMake or ./configure + make, especially if we are following the recomendation of brew info readline.

Please refer to the comments earlier. There is a error that it does not detect GNU Readline but the result binary is correct.

@mcuee
Copy link
Collaborator

mcuee commented Nov 27, 2022

Yes, I'll see how to find a workaround. Should't be too hard. Basically, it means to have both implementations of the terminal function, and use one or the other, depending on whether we are actually operating on a terminal or not. That implies that also for GNU libreadline, commands passed through a pipe wouldn't be recorded in the history, but that's IMHO a good thing anyway. The purpose of the history is to record interactive commands.

@dl8dtl

If Option 3 can be implemented before Release 7.1, that will be great. I think your idea sounds good.

@MCUdude
Copy link
Collaborator Author

MCUdude commented Nov 27, 2022

If Option 3 can be implemented before Release 7.1, that will be great. I think your idea sounds good.

When is the 7.1 release planned? I was hoping to get TPI support for JTAG3 compatible programmers in before the release. It's in the works and almost ready.

@mcuee
Copy link
Collaborator

mcuee commented Nov 27, 2022

When is the 7.1 release planned? I was hoping to get TPI support for JTAG3 compatible programmers in before the release. It's in the works and almost ready.

Not officially planned but the hope is before Christmas.

@dl8dtl agrees that Christmas is a good target date for 7.1 release.

@stefanrueger
Copy link
Collaborator

stefanrueger commented Nov 27, 2022

to have both implementations of the terminal function, and use one or the other, depending on whether we are actually operating on a terminal or not

@dl8dtl That's a very clever idea - and should work! Gets around having to fix libedit (which I predict to be non-trivial). Why didn't I think of that? (Don't answer that question, though, I don't want to hear the answer ;)

If I'm going to incorporate Urboot into my Arduino cores someday, I'd like all features to work on MacOS, Windows and Linux favours.

@MCUdude AVRDUDE's ability to keep any bootloader alive does not depend on urboot. It currently also works with optiboot. The trick is

  1. For the terminal to be able to send NOP commands to the programmer (which is the bootloader here) whilst idling
  2. To have a function prg->term_keep_alive() in the -c programmer code that sends a NOP command

Currently -c urclock is the only programmer that provides term_keep_alive(), but something like that could be put into -c arduino, -c xbee and other bootloader programmers (a stk500v2 programmer will need a different "NOP").

@MCUdude
Copy link
Collaborator Author

MCUdude commented Nov 27, 2022

If I'm going to incorporate Urboot into my Arduino cores someday, I'd like all features to work on MacOS, Windows and Linux favours.

@MCUdude AVRDUDE's ability to keep any bootloader alive does not depend on urboot. It currently also works with optiboot.

It would be vvv neat to have this functionality present when using -c arduino as well! If it isn't too much hassle to implement.

@dl8dtl
Copy link
Contributor

dl8dtl commented Dec 1, 2022

Yes, I'll see how to find a workaround. Should't be too hard.

See PR #1207

@mcuee
Copy link
Collaborator

mcuee commented Dec 8, 2022

#1207 (comment)

I actully figured out a rather hacky way to use CMake to differentiate libedit vs GNU Readline, as macOS detects the symbolic link libreadline.tbd as GNU readline. But then I need to add another one to detect libedit and we need to change term.c as well.

So I think @dl8dtl's idea to detect at runtime is much better.

mcuee@mcuees-Mac-mini avrdude_jw % git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1269650..57521b6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -132,7 +132,7 @@ else()
     set(PREFERRED_LIBHIDAPI hidapi hidapi-libusb hidapi-hidraw)
     set(PREFERRED_LIBFTDI ftdi)
     set(PREFERRED_LIBFTDI1 ftdi1)
-    set(PREFERRED_LIBREADLINE readline)
+    set(PREFERRED_LIBREADLINE libreadline.so libreadline.dylib libreadline.dll.a readline.lib)
 endif()

@mcuee
Copy link
Collaborator

mcuee commented Jan 5, 2023

Latest git with auto-tools.

mcuee@mcuees-Mac-mini src % ./bootstrap 
+ rm -rf autom4te.cache
+ LIBTOOLIZE=libtoolize
+ glibtoolize --version
+ LIBTOOLIZE=glibtoolize
+ glibtoolize
+ aclocal
+ autoheader
+ autoconf
configure.ac:46: warning: AC_PROG_LEX without either yywrap or noyywrap is obsolete
./lib/autoconf/programs.m4:716: _AC_PROG_LEX is expanded from...
./lib/autoconf/programs.m4:709: AC_PROG_LEX is expanded from...
configure.ac:46: the top level
configure.ac:120: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:120: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:120: the top level
configure.ac:227: warning: The macro `AC_HEADER_TIME' is obsolete.
configure.ac:227: You should run autoupdate.
./lib/autoconf/headers.m4:743: AC_HEADER_TIME is expanded from...
configure.ac:227: the top level
configure.ac:249: warning: The macro `AC_TRY_LINK' is obsolete.
configure.ac:249: You should run autoupdate.
./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from...
configure.ac:249: the top level
configure.ac:281: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:281: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:281: the top level
configure.ac:299: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:299: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:299: the top level
configure.ac:311: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:311: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:311: the top level
configure.ac:323: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:323: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:323: the top level
configure.ac:335: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:335: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:335: the top level
configure.ac:440: warning: The macro `AC_TRY_COMPILE' is obsolete.
configure.ac:440: You should run autoupdate.
./lib/autoconf/general.m4:2847: AC_TRY_COMPILE is expanded from...
configure.ac:440: the top level
configure.ac:465: warning: The macro `AC_TRY_COMPILE' is obsolete.
configure.ac:465: You should run autoupdate.
./lib/autoconf/general.m4:2847: AC_TRY_COMPILE is expanded from...
configure.ac:465: the top level
configure.ac:489: warning: The macro `AC_TRY_LINK' is obsolete.
configure.ac:489: You should run autoupdate.
./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from...
configure.ac:489: the top level
+ automake -a -c

mcuee@mcuees-Mac-mini src % CFLAGS="-I/opt/homebrew/include" LDFLAGS="-L/opt/homebrew/lib" ./configure
checking build system type... aarch64-apple-darwin22.2.0
checking host system type... aarch64-apple-darwin22.2.0
checking target system type... aarch64-apple-darwin22.2.0
checking for a BSD-compatible install... /opt/homebrew/bin/ginstall -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /opt/homebrew/bin/gmkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking how to print strings... printf
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /opt/homebrew/bin/gsed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Library/Developer/CommandLineTools/usr/bin/ld
checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 786432
checking how to convert aarch64-apple-darwin22.2.0 file names to aarch64-apple-darwin22.2.0 format... func_convert_file_noop
checking how to convert aarch64-apple-darwin22.2.0 file names to toolchain format... func_convert_file_noop
checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for sys/time.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin22.2.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether make supports nested variables... (cached) yes
checking for gcc... (cached) gcc
checking whether the compiler supports GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to enable C11 features... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for a sed that does not truncate output... (cached) /opt/homebrew/bin/gsed
checking for bison... bison -y
checking for flex... flex
checking for lex output file root... lex.yy
checking for lex library... none needed
checking for library containing yywrap... -ll
checking whether yytext is a pointer... yes
checking for -ar... ar
checking whether yylex_destroy is generated by flex... version Apple(flex-34) => yes
checking for tputs in -ltermcap... yes
checking for tputs in -lncurses... yes
checking for readline in -lreadline... yes
checking for elf_getshdrstrndx in -lelf... yes
checking for libelf.h... no
checking for libelf/libelf.h... yes
checking for library containing gethostent... none required
checking for library containing setsockopt... none required
checking for usb_get_string_simple in -lusb... yes
checking for usb.h... yes
checking for lusb0_usb.h... no
checking for libusb_init in -lusb-1.0... yes
checking for libusb-1.0/libusb.h... yes
checking for libusb.h... no
checking for libusb_init in -lusb... no
checking for libusb.h... (cached) no
checking for library containing hid_init... -lhidapi
checking for hidapi/hidapi.h... yes
checking for ftdi_new in -lftdi1... yes
checking for ftdi_usb_get_strings in -lftdi... yes
checking for ftdi_tcioflush... yes
checking for pthread.h... yes
checking for pthread_create in -lpthread... yes
checking for limits.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for fcntl.h... yes
checking for sys/ioctl.h... yes
checking for sys/time.h... (cached) yes
checking for termios.h... yes
checking for unistd.h... (cached) yes
checking for ddk/hidsdi.h... no
checking for an ANSI C-conforming const... yes
checking for netinet/in.h... yes
checking for memset... yes
checking for select... yes
checking for strcasecmp... yes
checking for strdup... yes
checking for strerror... yes
checking for strncasecmp... yes
checking for strtol... yes
checking for strtoul... yes
checking for gettimeofday... yes
checking for usleep... yes
checking for getaddrinfo... yes
checking for a Win32 HID library... no
checking for uint_t... no
checking for ulong_t... no
checking for serial device... unknown
checking if gcc accepts -Wno-pointer-sign ... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating doc/Makefile
config.status: creating avrdude.spec
config.status: creating Makefile
config.status: creating avrdude.conf.tmp
config.status: creating ac_cfg.h
config.status: executing depfiles commands
config.status: executing libtool commands


Configuration summary:
----------------------
DO HAVE    libelf
DO HAVE    libusb
DO HAVE    libusb_1_0
DO HAVE    libftdi1
DO HAVE    libftdi (but prefer to use libftdi1)
DON'T HAVE libhid
DO HAVE    libhidapi
DON'T HAVE libreadline
DO HAVE    pthread
DISABLED   doc
DISABLED   parport
DISABLED   linuxgpio
DISABLED   linuxspi
mcuee@mcuees-Mac-mini src % make
  YACC     config_gram.c
updating config_gram.h
  LEX      lexer.c
/Library/Developer/CommandLineTools/usr/bin/make  all-recursive
Making all in .
  CC       avrdude-main.o
  CC       avrdude-whereami.o
  CC       avrdude-avrintel.o
  CC       avrdude-developer_opts.o
  CC       avrdude-term.o
  CC       libavrdude_a-config_gram.o
  CC       libavrdude_a-lexer.o
  CC       libavrdude_a-arduino.o
  CC       libavrdude_a-avr.o
  CC       libavrdude_a-avr910.o
  CC       libavrdude_a-avrcache.o
  CC       libavrdude_a-avrftdi.o
  CC       libavrdude_a-avrftdi_tpi.o
  CC       libavrdude_a-avrpart.o
  CC       libavrdude_a-bitbang.o
  CC       libavrdude_a-buspirate.o
  CC       libavrdude_a-butterfly.o
  CC       libavrdude_a-config.o
  CC       libavrdude_a-confwin.o
  CC       libavrdude_a-crc16.o
  CC       libavrdude_a-dfu.o
  CC       libavrdude_a-fileio.o
  CC       libavrdude_a-flip1.o
  CC       libavrdude_a-flip2.o
  CC       libavrdude_a-ft245r.o
  CC       libavrdude_a-jtagmkI.o
  CC       libavrdude_a-jtagmkII.o
  CC       libavrdude_a-jtag3.o
  CC       libavrdude_a-linuxgpio.o
  CC       libavrdude_a-linuxspi.o
  CC       libavrdude_a-lists.o
  CC       libavrdude_a-micronucleus.o
  CC       libavrdude_a-par.o
  CC       libavrdude_a-pgm.o
  CC       libavrdude_a-pgm_type.o
  CC       libavrdude_a-pickit2.o
  CC       libavrdude_a-pindefs.o
  CC       libavrdude_a-ppi.o
  CC       libavrdude_a-ppiwin.o
  CC       libavrdude_a-serbb_posix.o
  CC       libavrdude_a-serbb_win32.o
  CC       libavrdude_a-ser_avrdoper.o
  CC       libavrdude_a-ser_posix.o
  CC       libavrdude_a-ser_win32.o
  CC       libavrdude_a-stk500.o
  CC       libavrdude_a-stk500v2.o
  CC       libavrdude_a-stk500generic.o
  CC       libavrdude_a-teensy.o
  CC       libavrdude_a-usbasp.o
  CC       libavrdude_a-serialupdi.o
  CC       libavrdude_a-updi_link.o
  CC       libavrdude_a-updi_state.o
  CC       libavrdude_a-updi_readwrite.o
  CC       libavrdude_a-updi_nvm.o
  CC       libavrdude_a-urclock.o
  CC       libavrdude_a-usb_hidapi.o
  CC       libavrdude_a-usb_libusb.o
  CC       libavrdude_a-usbtiny.o
  CC       libavrdude_a-update.o
  CC       libavrdude_a-wiring.o
  CC       libavrdude_a-xbee.o
  AR       libavrdude.a
  CCLD     avrdude
ld: warning: directory not found for option '-FCoreFoundation'
  CC       libavrdude_la-config_gram.lo
  CC       libavrdude_la-lexer.lo
  CC       libavrdude_la-arduino.lo
  CC       libavrdude_la-avr.lo
  CC       libavrdude_la-avr910.lo
  CC       libavrdude_la-avrcache.lo
  CC       libavrdude_la-avrftdi.lo
  CC       libavrdude_la-avrftdi_tpi.lo
  CC       libavrdude_la-avrpart.lo
  CC       libavrdude_la-bitbang.lo
  CC       libavrdude_la-buspirate.lo
  CC       libavrdude_la-butterfly.lo
  CC       libavrdude_la-config.lo
  CC       libavrdude_la-confwin.lo
  CC       libavrdude_la-crc16.lo
  CC       libavrdude_la-dfu.lo
  CC       libavrdude_la-fileio.lo
  CC       libavrdude_la-flip1.lo
  CC       libavrdude_la-flip2.lo
  CC       libavrdude_la-ft245r.lo
  CC       libavrdude_la-jtagmkI.lo
  CC       libavrdude_la-jtagmkII.lo
  CC       libavrdude_la-jtag3.lo
  CC       libavrdude_la-linuxgpio.lo
  CC       libavrdude_la-linuxspi.lo
  CC       libavrdude_la-lists.lo
  CC       libavrdude_la-micronucleus.lo
  CC       libavrdude_la-par.lo
  CC       libavrdude_la-pgm.lo
  CC       libavrdude_la-pgm_type.lo
  CC       libavrdude_la-pickit2.lo
  CC       libavrdude_la-pindefs.lo
  CC       libavrdude_la-ppi.lo
  CC       libavrdude_la-ppiwin.lo
  CC       libavrdude_la-serbb_posix.lo
  CC       libavrdude_la-serbb_win32.lo
  CC       libavrdude_la-ser_avrdoper.lo
  CC       libavrdude_la-ser_posix.lo
  CC       libavrdude_la-ser_win32.lo
  CC       libavrdude_la-stk500.lo
  CC       libavrdude_la-stk500v2.lo
  CC       libavrdude_la-stk500generic.lo
  CC       libavrdude_la-teensy.lo
  CC       libavrdude_la-usbasp.lo
  CC       libavrdude_la-serialupdi.lo
  CC       libavrdude_la-updi_link.lo
  CC       libavrdude_la-updi_state.lo
  CC       libavrdude_la-updi_readwrite.lo
  CC       libavrdude_la-updi_nvm.lo
  CC       libavrdude_la-urclock.lo
  CC       libavrdude_la-usb_hidapi.lo
  CC       libavrdude_la-usb_libusb.lo
  CC       libavrdude_la-usbtiny.lo
  CC       libavrdude_la-update.lo
  CC       libavrdude_la-wiring.lo
  CC       libavrdude_la-xbee.lo
  CCLD     libavrdude.la
ld: warning: -undefined dynamic_lookup may not work with chained fixups
mcuee@mcuees-Mac-mini src % otool -L ./avrdude
./avrdude:
	/opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/opt/homebrew/opt/libusb-compat/lib/libusb-0.1.4.dylib (compatibility version 9.0.0, current version 9.4.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.255.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/opt/homebrew/opt/hidapi/lib/libhidapi.0.dylib (compatibility version 0.0.0, current version 0.12.0)
	/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/opt/homebrew/opt/libftdi/lib/libftdi1.2.dylib (compatibility version 2.0.0, current version 2.5.0)

@mcuee
Copy link
Collaborator

mcuee commented Jan 5, 2023

auto-tools generated tar-ball under macOS Homebrew.
avrdude-7.1-20230106.tar.gz

@mcuee
Copy link
Collaborator

mcuee commented Jan 5, 2023

The above tarball seems to kind of working for MSYS2 as well with proper configure options, except the last linking step (missing Winsock2 library).

$ CFLAGS="-I/mingw64/include -I/mingw64/include/libusb-1.0 -I/mingw64/include/libelf -I/mingw64/include/libftdi1 -I/mingw64/include/libusb-compat" LDFLAGS="-L/mingw64/lib" ./configure
...

$ make V=1
make  all-recursive
make[1]: Entering directory '/c/work/avr/avrdude_test/avrdude-7.1-20230106'
Making all in .
make[2]: Entering directory '/c/work/avr/avrdude_test/avrdude-7.1-20230106'
/bin/sh ./libtool  --tag=CC   --mode=link gcc -Wall -Wno-pointer-sign -I/mingw64/include -I/mingw64/include/libusb-1.0 -I/mingw64/include/libelf -I/mingw64/include/libftdi1 -I/mingw64/include/libusb-compat -DWIN32NATIVE  -L/mingw64/lib -static -o avrdude.exe avrdude-main.o avrdude-whereami.o avrdude-avrintel.o avrdude-developer_opts.o avrdude-term.o ./libavrdude.a -lusb-1.0  -lusb -lftdi1  -lhid -lsetupapi -lelf -lpthread -lm -lhidapi -lreadline -lncurses -ltermcap  -lftdi1
libtool: link: gcc -Wall -Wno-pointer-sign -I/mingw64/include -I/mingw64/include/libusb-1.0 -I/mingw64/include/libelf -I/mingw64/include/libftdi1 -I/mingw64/include/libusb-compat -DWIN32NATIVE -o avrdude.exe avrdude-main.o avrdude-whereami.o avrdude-avrintel.o avrdude-developer_opts.o avrdude-term.o  -L/mingw64/lib ./libavrdude.a -lusb-1.0 -lusb -lhid -lsetupapi -lelf -lpthread -lhidapi -lreadline -lncurses -ltermcap -lftdi1
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x23a): undefined reference to `__imp_WSAStartup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x47a): undefined reference to `__imp_gethostbyname'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x51d): undefined reference to `__imp_socket'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x539): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x60a): undefined reference to `__imp_htons'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x63f): undefined reference to `__imp_connect'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x650): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0xb01): undefined reference to `__imp_closesocket'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0xb0a): undefined reference to `__imp_WSACleanup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0xe4d): undefined reference to `__imp_send'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0xe63): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x144c): undefined reference to `__imp_select'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x14ce): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x14de): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x1538): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x1624): undefined reference to `__imp_recv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x1640): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x1e51): undefined reference to `__imp_select'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x1ecd): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x1edd): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x1f37): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x2007): undefined reference to `__imp_recv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libavrdude.a(libavrdude_a-ser_win32.o):ser_win32.c:(.text+0x2023): undefined reference to `__imp_WSAGetLastError'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [Makefile:988: avrdude.exe] Error 1
make[2]: Leaving directory '/c/work/avr/avrdude_test/avrdude-7.1-20230106'
make[1]: *** [Makefile:2494: all-recursive] Error 1
make[1]: Leaving directory '/c/work/avr/avrdude_test/avrdude-7.1-20230106'
make: *** [Makefile:831: all] Error 2

$ /bin/sh ./libtool  --tag=CC   --mode=link gcc -Wall -Wno-pointer-sign -I/mingw64/include -I/mingw64/include/libusb-1.0 -I/mingw64/include/libelf -I/mingw64/include/libftdi1 -I/mingw64/include/libusb-compat -DWIN32NATIVE  -L/mingw64/lib -static -o avrdude.exe avrdude-main.o avrdude-whereami.o avrdude-avrintel.o avrdude-developer_opts.o avrdude-term.o ./libavrdude.a -lusb-1.0  -lusb -lftdi1  -lhid -lsetupapi -lelf -lpthread -lm -lhidapi -lreadline -lncurses -ltermcap  -lftdi1 -lws2_32
libtool: link: gcc -Wall -Wno-pointer-sign -I/mingw64/include -I/mingw64/include/libusb-1.0 -I/mingw64/include/libelf -I/mingw64/include/libftdi1 -I/mingw64/include/libusb-compat -DWIN32NATIVE -o avrdude.exe avrdude-main.o avrdude-whereami.o avrdude-avrintel.o avrdude-developer_opts.o avrdude-term.o  -L/mingw64/lib ./libavrdude.a -lusb-1.0 -lusb -lhid -lsetupapi -lelf -lpthread -lhidapi -lreadline -lncurses -ltermcap -lftdi1 -lws2_32

$ ldd ./avrdude
        ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7fff8ba60000)
        KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7fff89e40000)
        KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7fff89110000)
        msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7fff898e0000)
        SETUPAPI.dll => /c/WINDOWS/System32/SETUPAPI.dll (0x7fff89f00000)
        HID.DLL => /c/WINDOWS/SYSTEM32/HID.DLL (0x7fff878a0000)
        WS2_32.dll => /c/WINDOWS/System32/WS2_32.dll (0x7fff89d70000)
        RPCRT4.dll => /c/WINDOWS/System32/RPCRT4.dll (0x7fff8b810000)
        libhidapi-0.dll => /mingw64/bin/libhidapi-0.dll (0x7fff83090000)
        libftdi1.dll => /mingw64/bin/libftdi1.dll (0x7fff82510000)
        libusb-1.0.dll => /mingw64/bin/libusb-1.0.dll (0x7fff81dd0000)
        libusb-1.0.dll => /mingw64/bin/libusb-1.0.dll (0x1adcca00000)
        libreadline8.dll => /mingw64/bin/libreadline8.dll (0x7fff81870000)
        USER32.dll => /c/WINDOWS/System32/USER32.dll (0x7fff8a7c0000)
        win32u.dll => /c/WINDOWS/System32/win32u.dll (0x7fff896d0000)
        GDI32.dll => /c/WINDOWS/System32/GDI32.dll (0x7fff8b7e0000)
        gdi32full.dll => /c/WINDOWS/System32/gdi32full.dll (0x7fff89700000)
        msvcp_win.dll => /c/WINDOWS/System32/msvcp_win.dll (0x7fff89630000)
        ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7fff89510000)
        libusb-0-1-4.dll => /mingw64/bin/libusb-0-1-4.dll (0x7fff79590000)
        libtermcap-0.dll => /mingw64/bin/libtermcap-0.dll (0x6ac40000)

$ ./avrdude
Usage: avrdude [options]
Options:
  -p <partno>                Specify AVR device
  -p <wildcard>/<flags>      Run developer options for matched AVR devices
  -b <baudrate>              Override RS-232 baud rate
  -B <bitclock>              Specify bit clock period (us)
  -C <config-file>           Specify location of configuration file
  -c <programmer>            Specify programmer type
  -c <wildcard>/<flags>      Run developer options for matched programmers
  -A                         Disable trailing-0xff removal from file and AVR read
  -D                         Disable auto erase for flash memory; implies -A
  -i <delay>                 ISP Clock Delay [in microseconds]
  -P <port>                  Specify connection port
  -F                         Override invalid signature or initialisation check
  -e                         Perform a chip erase
  -O                         Perform RC oscillator calibration (see AVR053)
  -U <memtype>:r|w|v:<filename>[:format]
                             Memory operation specification
                             Multiple -U options are allowed, each request
                             is performed in the order specified
  -n                         Do not write anything to the device
  -V                         Do not verify
  -t                         Enter terminal mode
  -E <exitspec>[,<exitspec>] List programmer exit specifications
  -x <extended_param>        Pass <extended_param> to programmer
  -v                         Verbose output; -v -v for more
  -q                         Quell progress output; -q -q for less
  -l logfile                 Use logfile rather than stderr for diagnostics
  -?                         Display this usage

avrdude version 7.1-20230106, URL: <https://github.com/avrdudes/avrdude>

$ ./avrdude -c urclock -P COM3 -p m168p -qqt
avrdude> dump lfuse
avrdude error: bootloader cannot read from lfuse
avrdude error: (dump) error reading lfuse address 0x00000 of part ATmega168P
               read operation not supported on memory type lfuse
avrdude> dump flash 0 0x30
0000  0c 94 61 00 0c 94 73 00  0c 94 73 00 0c 94 73 00  | .a. .s. .s. .s.|
0010  0c 94 73 00 0c 94 73 00  0c 94 73 00 0c 94 73 00  | .s. .s. .s. .s.|
0020  0c 94 73 00 0c 94 73 00  0c 94 73 00 0c 94 73 00  | .s. .s. .s. .s.|

avrdude> q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants