Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-2085

[PATCH] Build failure with musl libc

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Done
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.6.7
    • Labels:
      None
    • Platform:
      Linux

      Description

      When building with musl libc on Alpine Linux the following build error happens:
      <pre>
      ncopa-desktop:~/src/cfengine-core$ make
      Making all in libcompat
      CC generic_at.lo
      In file included from ../libutils/platform.h:358:0,
      from generic_at.c:25:
      /usr/include/linux/if.h:71:2: error: expected identifier before numeric constant
      IFF_UP = 1<<0, /* sysfs */
      ^
      In file included from /usr/include/linux/route.h:26:0,
      from ../libutils/platform.h:378,
      from generic_at.c:25:
      /usr/include/linux/if.h:169:8: error: redefinition of 'struct ifmap'
      struct ifmap {
      ^
      ...
      </pre>

      Problem is that linux/*.h headers are used instead of net/route.h, netinet/in.h and netinet/ip.h.

      The criteria for using net/.h and netinet/.h on linux is: @# if defined(_GLIBC) || defined(BIONIC_)@
      None of those are defined with musl libc.

      I propose to use AC_CHECK_HEADERS for each header and do @#if defined HAVE_NET_ROUTE_H@ instead of assume GNU or bionic:
      <pre>
      diff --git a/configure.ac b/configure.ac
      index eb5dc6f..38bd295 100644
      — a/configure.ac
      +++ b/configure.ac
      @@ -596,6 +596,8 @@ AC_CHECK_HEADERS(sys/jail.h, [], [], [AC_INCLUDES_DEFAULT

      1. include <sys/param.h>
        #endif
        ])
        +AC_CHECK_HEADERS(net/route.h netinet/in.h netinet/ip.h)
        +

      AC_HEADER_STDC
      AC_HEADER_TIME
      diff --git a/libutils/platform.h b/libutils/platform.h
      index da2f433..6c3fbcd 100644
      — a/libutils/platform.h
      +++ b/libutils/platform.h
      @@ -370,13 +370,21 @@ union mpinfou
      #endif

      #ifdef _linux_

        1. if defined(_GLIBC) || defined(BIONIC_)
          +# ifdef HAVE_NET_ROUTE_H
      1. include <net/route.h>
        1. include <netinet/in.h>
        2. include <netinet/ip.h>
      2. else
      3. include <linux/route.h>
        +# endif
        +
        +# ifdef HAVE_NETINET_IN_H
        +# include <netinet/in.h>
        +# else
      4. include <linux/in.h>
        +# endif
        +
        +# ifdef HAVE_NETINET_IP_H
        +# include <netinet/ip.h>
        +# else
      5. include <linux/ip.h>
      6. endif
        #endif
        </pre>

      With the above patch it builds with musl libc.

      You might be able to reproduce in debian with CC=musl-gcc

        Attachments

          Activity

            People

            • Assignee:
              a10040 Kristian Amlie
              Reporter:
              ncopa Natanael Copa
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Summary Panel