Search code examples
static-librariesautomaked

How to include static library built from D sources in Makefile.am?


I'm writing a utility library libdog-dev for programming with D language, here is the Makefile.am:

sited2dir = /usr/include/d2/site
lib32dir = ${libdir}/i386-linux-gnu
# lib64dir = ${libdir}/x86_64-linux-gnu

lib32_LIBRARIES = \
    i386/libdog.a

# lib64_LIBRARIES = \
#     x86_64/libdog.a

i386/libdog.a:
    mkdir -p i386
    dmd -lib -m32 -of$@ -op -Hdi386/include/ `find src/ -name '*.d'`

x86_64/libdog.a:
    mkdir -p x86_64
    dmd -lib -m64 -of$@ -op -Hdx86_64/include/ `find src/ -name '*.d'`

# Since the header files for i386/x86_64 are the same, let's just pick the i386 one.
install-data-hook: 
    mkdir -p $(DESTDIR)$(sited2dir)
    rsync -av i386-linux-gnu/include/ $(DESTDIR)$(sited2dir)

it's working, however, something I'm still unclear:

  • I need to include AC_PROG_CC and AC_PROG_RANLIB in configure.ac, which should be unnecessary, because there is no c/c++ source in this project. Missing the two statements will result in error.

  • I can only include single libdog.a in the Makefile.am. I had comment out the x86-64 one in the code above, if I included it, automake will show the error:

    cd . && /bin/bash /home/lenik/tasks/1-uni/devel/libdog-dev/missing --run automake-1.11 --gnu Makefile
    Makefile.am: object `libdog.$(OBJEXT)' created by `x86_64/libdog.c' and `i386/libdog.c'
    make: *** [Makefile.in] Error 1
    

    I want to include both versions for i386 and x86-64 in one package, just like the official dmd package for Debian:

    ...                              (install tree of the dmd-2.059-0 package)
    |-- lib/
    |   |-- i386-linux-gnu/
    |   |   `-- libphobos2.a
    |   `-- x86_64-linux-gnu/
    |       `-- libphobos2.a
    
  • I had hard coded the arch name i386-linux-gnu and x86_64-linux-gnu in the Makefile source, however, it should be generated somehow..?


Solution

    1. Automake will try to find C/C++ sources for files listed in _LIBRARIES targets. So, just change them to _DATA targets:

      lib32_DATA = \
          i386/libdog.a
      
      lib64_DATA = \
          x86_64/libdog.a
      
    2. You can generate the name i386-linux-gnu or x86_64-linux-gnu of the host system by running:

      dpkg-architecture -qDEB_HOST_GNU_TYPE
      

      You can also get the library path from /etc/ld.so.conf and /etc/ld.so.conf.d/*.