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

To make this repo compatible with MSYS2 mingw and other OS (Linux, macOS, BSDs) #1

Open
mcuee opened this issue Feb 28, 2024 · 6 comments

Comments

@mcuee
Copy link
Collaborator

mcuee commented Feb 28, 2024

One way to fix avrdudes/avrdude#1653 is to use this repo for avrdude, not only for MSVC build, but also for other OS.

@mcuee
Copy link
Collaborator Author

mcuee commented Feb 28, 2024

It actually build under MSYS2 mingw.

MINGW64 /c/work/avr/avrdude_test/avrdude_depend/libelf
$ cmake -B build
-- Building for: Ninja
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (4.1s)
-- Generating done (0.0s)
-- Build files have been written to: C:/work/avr/avrdude_test/avrdude_depend/libelf/build

xiaof@LAPTOP-913SIMUD MINGW64 /c/work/avr/avrdude_test/avrdude_depend/libelf
$ cmake --build build
[4/56] Building C object CMakeFiles/libelf.dir/src/32.newphdr.c.obj
C:/work/avr/avrdude_test/avrdude_depend/libelf/src/32.newphdr.c: In function 'gelf_newphdr':
C:/work/avr/avrdude_test/avrdude_depend/libelf/src/32.newphdr.c:115:12: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  115 |     return (unsigned long)_elf_newphdr(elf, phnum, elf->e_class);
      |            ^
[6/56] Building C object CMakeFiles/libelf.dir/src/32.newehdr.c.obj
C:/work/avr/avrdude_test/avrdude_depend/libelf/src/32.newehdr.c: In function 'gelf_newehdr':
C:/work/avr/avrdude_test/avrdude_depend/libelf/src/32.newehdr.c:77:12: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   77 |     return (unsigned long)_elf_newehdr(elf, cls);
      |            ^
[56/56] Linking C static library liblibelf.a

@mcuee
Copy link
Collaborator Author

mcuee commented Mar 2, 2024

It also works under macOS. Tested under macOS 14.3.1, Mac Mini M1 2020.

But take note currently it only build static link library.

mcuee@mcuees-Mac-mini libelf % cmake -B build
-- The C compiler identification is AppleClang 15.0.0.15000100
-- The CXX compiler identification is AppleClang 15.0.0.15000100
-- 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
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.8s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/mcuee/build/avr/libelf/build

mcuee@mcuees-Mac-mini libelf % cmake --build build 
[  1%] Building C object CMakeFiles/libelf.dir/src/32.fsize.c.o
[  3%] Building C object CMakeFiles/libelf.dir/src/32.getehdr.c.o
[  5%] Building C object CMakeFiles/libelf.dir/src/32.getphdr.c.o
[  7%] Building C object CMakeFiles/libelf.dir/src/32.getshdr.c.o
[  8%] Building C object CMakeFiles/libelf.dir/src/32.newehdr.c.o
[ 10%] Building C object CMakeFiles/libelf.dir/src/32.newphdr.c.o
[ 12%] Building C object CMakeFiles/libelf.dir/src/32.xlatetof.c.o
[ 14%] Building C object CMakeFiles/libelf.dir/src/64.xlatetof.c.o
[ 16%] Building C object CMakeFiles/libelf.dir/src/assert.c.o
[ 17%] Building C object CMakeFiles/libelf.dir/src/begin.c.o
/Users/mcuee/build/avr/libelf/src/begin.c:271:26: warning: passing arguments to 'lseek' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    else if ((off = lseek(fd, (off_t)0, SEEK_END)) == (off_t)-1
                         ^
1 warning generated.
[ 19%] Building C object CMakeFiles/libelf.dir/src/checksum.c.o
[ 21%] Building C object CMakeFiles/libelf.dir/src/cntl.c.o
[ 23%] Building C object CMakeFiles/libelf.dir/src/cook.c.o
[ 25%] Building C object CMakeFiles/libelf.dir/src/data.c.o
[ 26%] Building C object CMakeFiles/libelf.dir/src/end.c.o
[ 28%] Building C object CMakeFiles/libelf.dir/src/errmsg.c.o
[ 30%] Building C object CMakeFiles/libelf.dir/src/errno.c.o
[ 32%] Building C object CMakeFiles/libelf.dir/src/fill.c.o
[ 33%] Building C object CMakeFiles/libelf.dir/src/flag.c.o
[ 35%] Building C object CMakeFiles/libelf.dir/src/gelfehdr.c.o
[ 37%] Building C object CMakeFiles/libelf.dir/src/gelfphdr.c.o
[ 39%] Building C object CMakeFiles/libelf.dir/src/gelfshdr.c.o
[ 41%] Building C object CMakeFiles/libelf.dir/src/gelftrans.c.o
[ 42%] Building C object CMakeFiles/libelf.dir/src/getarhdr.c.o
[ 44%] Building C object CMakeFiles/libelf.dir/src/getaroff.c.o
[ 46%] Building C object CMakeFiles/libelf.dir/src/getarsym.c.o
[ 48%] Building C object CMakeFiles/libelf.dir/src/getbase.c.o
[ 50%] Building C object CMakeFiles/libelf.dir/src/getdata.c.o
[ 51%] Building C object CMakeFiles/libelf.dir/src/getident.c.o
[ 53%] Building C object CMakeFiles/libelf.dir/src/getscn.c.o
[ 55%] Building C object CMakeFiles/libelf.dir/src/hash.c.o
[ 57%] Building C object CMakeFiles/libelf.dir/src/input.c.o
/Users/mcuee/build/avr/libelf/src/input.c:38:10: warning: passing arguments to 'read' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
        n = read(fd, buffer + done, len - done);
                ^
/Users/mcuee/build/avr/libelf/src/input.c:67:11: warning: passing arguments to 'lseek' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
        if (lseek(elf->e_fd, (off_t)off, SEEK_SET) != (off_t)off) {
                 ^
2 warnings generated.
[ 58%] Building C object CMakeFiles/libelf.dir/src/kind.c.o
[ 60%] Building C object CMakeFiles/libelf.dir/src/memset.c.o
[ 62%] Building C object CMakeFiles/libelf.dir/src/ndxscn.c.o
[ 64%] Building C object CMakeFiles/libelf.dir/src/newdata.c.o
[ 66%] Building C object CMakeFiles/libelf.dir/src/newscn.c.o
[ 67%] Building C object CMakeFiles/libelf.dir/src/next.c.o
[ 69%] Building C object CMakeFiles/libelf.dir/src/nextscn.c.o
[ 71%] Building C object CMakeFiles/libelf.dir/src/nlist.c.o
/Users/mcuee/build/avr/libelf/src/nlist.c:237:16: warning: passing arguments to 'open' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
        if ((fd = open(filename, FILE_OPEN_MODE)) != -1) {
                      ^
/Users/mcuee/build/avr/libelf/src/nlist.c:242:11: warning: passing arguments to 'close' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
            close(fd);
                 ^
2 warnings generated.
[ 73%] Building C object CMakeFiles/libelf.dir/src/opt.delscn.c.o
[ 75%] Building C object CMakeFiles/libelf.dir/src/rand.c.o
[ 76%] Building C object CMakeFiles/libelf.dir/src/rawdata.c.o
[ 78%] Building C object CMakeFiles/libelf.dir/src/rawfile.c.o
[ 80%] Building C object CMakeFiles/libelf.dir/src/strptr.c.o
[ 82%] Building C object CMakeFiles/libelf.dir/src/swap64.c.o
[ 83%] Building C object CMakeFiles/libelf.dir/src/update.c.o
/Users/mcuee/build/avr/libelf/src/update.c:893:11: warning: passing arguments to 'write' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
        n = write(fd, buffer + done, len - done);
                 ^
/Users/mcuee/build/avr/libelf/src/update.c:955:11: warning: passing arguments to 'lseek' without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
        if (lseek(fd, (off_t)0, SEEK_SET)) {
                 ^
2 warnings generated.
[ 85%] Building C object CMakeFiles/libelf.dir/src/verdef_32_tof.c.o
[ 87%] Building C object CMakeFiles/libelf.dir/src/verdef_32_tom.c.o
[ 89%] Building C object CMakeFiles/libelf.dir/src/verdef_64_tof.c.o
[ 91%] Building C object CMakeFiles/libelf.dir/src/verdef_64_tom.c.o
[ 92%] Building C object CMakeFiles/libelf.dir/src/version.c.o
[ 94%] Building C object CMakeFiles/libelf.dir/src/x.elfext.c.o
[ 96%] Building C object CMakeFiles/libelf.dir/src/x.movscn.c.o
[ 98%] Building C object CMakeFiles/libelf.dir/src/x.remscn.c.o
[100%] Linking C static library liblibelf.a
[100%] Built target libelf

@mcuee
Copy link
Collaborator Author

mcuee commented Mar 2, 2024

Linux (Ubuntu 20.04) build

mcuee@UbuntuSwift3 ~/build/avr/avrdude_libelf (windows)$ cmake -B build
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/mcuee/build/avr/avrdude_libelf/build

mcuee@UbuntuSwift3 ~/build/avr/avrdude_libelf (windows)$ cmake --build build
[  1%] Building C object CMakeFiles/libelf.dir/src/32.fsize.c.o
[  3%] Building C object CMakeFiles/libelf.dir/src/32.getehdr.c.o
[  5%] Building C object CMakeFiles/libelf.dir/src/32.getphdr.c.o
[  7%] Building C object CMakeFiles/libelf.dir/src/32.getshdr.c.o
[  8%] Building C object CMakeFiles/libelf.dir/src/32.newehdr.c.o
[ 10%] Building C object CMakeFiles/libelf.dir/src/32.newphdr.c.o
[ 12%] Building C object CMakeFiles/libelf.dir/src/32.xlatetof.c.o
[ 14%] Building C object CMakeFiles/libelf.dir/src/64.xlatetof.c.o
[ 16%] Building C object CMakeFiles/libelf.dir/src/assert.c.o
[ 17%] Building C object CMakeFiles/libelf.dir/src/begin.c.o
[ 19%] Building C object CMakeFiles/libelf.dir/src/checksum.c.o
[ 21%] Building C object CMakeFiles/libelf.dir/src/cntl.c.o
[ 23%] Building C object CMakeFiles/libelf.dir/src/cook.c.o
[ 25%] Building C object CMakeFiles/libelf.dir/src/data.c.o
[ 26%] Building C object CMakeFiles/libelf.dir/src/end.c.o
[ 28%] Building C object CMakeFiles/libelf.dir/src/errmsg.c.o
[ 30%] Building C object CMakeFiles/libelf.dir/src/errno.c.o
[ 32%] Building C object CMakeFiles/libelf.dir/src/fill.c.o
[ 33%] Building C object CMakeFiles/libelf.dir/src/flag.c.o
[ 35%] Building C object CMakeFiles/libelf.dir/src/gelfehdr.c.o
[ 37%] Building C object CMakeFiles/libelf.dir/src/gelfphdr.c.o
[ 39%] Building C object CMakeFiles/libelf.dir/src/gelfshdr.c.o
[ 41%] Building C object CMakeFiles/libelf.dir/src/gelftrans.c.o
[ 42%] Building C object CMakeFiles/libelf.dir/src/getarhdr.c.o
[ 44%] Building C object CMakeFiles/libelf.dir/src/getaroff.c.o
[ 46%] Building C object CMakeFiles/libelf.dir/src/getarsym.c.o
[ 48%] Building C object CMakeFiles/libelf.dir/src/getbase.c.o
[ 50%] Building C object CMakeFiles/libelf.dir/src/getdata.c.o
[ 51%] Building C object CMakeFiles/libelf.dir/src/getident.c.o
[ 53%] Building C object CMakeFiles/libelf.dir/src/getscn.c.o
[ 55%] Building C object CMakeFiles/libelf.dir/src/hash.c.o
[ 57%] Building C object CMakeFiles/libelf.dir/src/input.c.o
[ 58%] Building C object CMakeFiles/libelf.dir/src/kind.c.o
[ 60%] Building C object CMakeFiles/libelf.dir/src/memset.c.o
[ 62%] Building C object CMakeFiles/libelf.dir/src/ndxscn.c.o
[ 64%] Building C object CMakeFiles/libelf.dir/src/newdata.c.o
[ 66%] Building C object CMakeFiles/libelf.dir/src/newscn.c.o
[ 67%] Building C object CMakeFiles/libelf.dir/src/next.c.o
[ 69%] Building C object CMakeFiles/libelf.dir/src/nextscn.c.o
[ 71%] Building C object CMakeFiles/libelf.dir/src/nlist.c.o
[ 73%] Building C object CMakeFiles/libelf.dir/src/opt.delscn.c.o
[ 75%] Building C object CMakeFiles/libelf.dir/src/rand.c.o
[ 76%] Building C object CMakeFiles/libelf.dir/src/rawdata.c.o
[ 78%] Building C object CMakeFiles/libelf.dir/src/rawfile.c.o
[ 80%] Building C object CMakeFiles/libelf.dir/src/strptr.c.o
[ 82%] Building C object CMakeFiles/libelf.dir/src/swap64.c.o
[ 83%] Building C object CMakeFiles/libelf.dir/src/update.c.o
[ 85%] Building C object CMakeFiles/libelf.dir/src/verdef_32_tof.c.o
[ 87%] Building C object CMakeFiles/libelf.dir/src/verdef_32_tom.c.o
[ 89%] Building C object CMakeFiles/libelf.dir/src/verdef_64_tof.c.o
[ 91%] Building C object CMakeFiles/libelf.dir/src/verdef_64_tom.c.o
[ 92%] Building C object CMakeFiles/libelf.dir/src/version.c.o
[ 94%] Building C object CMakeFiles/libelf.dir/src/x.elfext.c.o
[ 96%] Building C object CMakeFiles/libelf.dir/src/x.movscn.c.o
[ 98%] Building C object CMakeFiles/libelf.dir/src/x.remscn.c.o
[100%] Linking C static library liblibelf.a
[100%] Built target libelf

mcuee@UbuntuSwift3 ~/build/avr/avrdude_libelf (windows)$ sudo cmake --build build --target install
make: *** No rule to make target 'install'.  Stop

@hp77-creator
Copy link

Hey @mcuee, if static libelf is compiled from this, can we use it in place of libelf provided by brew ?

@mcuee
Copy link
Collaborator Author

mcuee commented Jun 30, 2024

Hey @mcuee, if static libelf is compiled from this, can we use it in place of libelf provided by brew ?

This is supposed to be the case. But please test against your application.

@hp77-creator
Copy link

I am trying to compile libbpf on my system(macOS m2), brew and macports aren't working. Stumbled upon an issue that was raised by Homebrew maintainer in your repo. And now I am looking for alternatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants