Libtool outside autotools: how do I DESTDIR? - makefile

I'm using libtool (version 2.4.6) for creating a simple shared library
under GNU/Linux.
In my specific case, portability is not as important as simplicity: I don't
want to use the whole Autotools suite, nor CMake. I just want a simple
Makefile which can compile a shared library and install it properly.
I've got a couple of variables definitions, which follow the
conventions of GNU Make
prefix ?= /usr/local
exec_prefix ?= $(prefix)
libdir ?= $(exec_prefix)/lib
I want to support an install target, and I believe it should be roughly
like this:
LIBTOOL_LIB := libxyz.la
install: target = $(abspath $(DESTDIR))
install: all
mkdir -p $(target)/$(libdir)
libtool --mode=install install $(LIBTOOL_LIB) $(target)/$(libdir)
libtool --mode=finish $(target)/$(libdir)
If I run make install DESTDIR=./test I get the following message:
mkdir -p /yadayada/src/test//usr/local/lib
libtool --mode=install install libtrullallero.la /yadayada/src/test//usr/local/lib
libtool: install: install .libs/libtrullallero.so.0.0.0 /yadayada/src.so.0.0.0
libtool: install: (cd /yadayada/src.so.0; }; })
libtool: install: (cd /yadayada/src.so; }; })
libtool: install: install .libs/libtrullallero.lai /yadayada/src.la
libtool: install: install .libs/libtrullallero.a /yadayada/src.a
libtool: install: chmod 644 /yadayada/src.a
libtool: install: ranlib /yadayada/src.a
libtool: warning: remember to run 'libtool --finish /usr/local/lib'
libtool --mode=finish /yadayada/src/test//usr/local/lib
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /yadayada/src/test//usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/yadayada/src/test//usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
I guess I deserve this notification, since I'm installing outside the
regular library path. This is by the way the same message I would get in a
Autotools-based project, should I set a --prefix in some arbitrary path at
./configure.
There are however some weird things:
If I run make install as root (within a container, of course), without
defining DESTDIR, I get the same kind of message. This does not feel
correct: this time I did not deserve it.
With or without DESTDIR, a call to ldconfig makes in my opinion no
sense at this point. And when I'm not running it as root, it should be
also ineffective, yet the program succeeds.
Lurking in the libtool documentation, I've found a
reference to the -inst-prefix-dir option,
which should allow me to have a DESTDIR-like behaviour.
Perhaps this is what I do wrong. However it behaves weirdly!
For starters, it seems to work only if specified at the end of the
--mode=install line. In fact, if I do this:
install: target = $(abspath $(DESTDIR))
install: all
mkdir -p $(target)/$(libdir)
libtool --mode=install install -inst-prefix-dir $(target) $(LIBTOOL_LIB) $(target)/$(libdir)
libtool --mode=finish $(target)/$(libdir)
…I clearly get a messy command line:
libtool: install: install -inst-prefix-dir /yadayada/libtrullallero/test/usr/local/lib/-inst-prefix-dir
install: invalid option -- 'i'
If I move -inst-prefix-dir to the end of the line, I just get another
wrong call to install:
mkdir -p /yadayada/src/libtrullallero/test//usr/local/lib
libtool --mode=install install libtrullallero.la /yadayada/src/libtrullallero/test
libtool: install: install .libs/libtrullallero.so.0.0.0 /yadayada/src/libtrullallero/test/libtrullallero.so.0.0.0
libtool: install: (cd /yadayada/src/libtrullallero/test && { ln -s -f libtrullallero.so.0.0.0 libtrullallero.so.0 || { rm -f libtrullallero.so.0 && ln -s libtrullallero.so.0.0.0 libtrullallero.so.0; }; })
libtool: install: (cd /yadayada/src/libtrullallero/test && { ln -s -f libtrullallero.so.0.0.0 libtrullallero.so || { rm -f libtrullallero.so && ln -s libtrullallero.so.0.0.0 libtrullallero.so; }; })
libtool: install: install .libs/libtrullallero.lai /yadayada/src/libtrullallero/test/libtrullallero.la
libtool: install: install /yadayada/src/libtrullallero/test/lib
install: omitting directory '/yadayada/src/libtrullallero/test//usr/local/lib'
Makefile:22: recipe for target 'install' failed
make: *** [install] Error 1
I must be doing something wrong, but I cannot spot it. Any hint?

Related

How to fix ./configure in MSYS2?

I'm trying to build libxc-4.3.4 in an MSYS2 shell on Windows 10. I've installed the latest version of MSYS2 (msys2-x86_64-20220319.exe) and followed the installation instructions. I've installed build tools using
pacman -S --needed base-devel mingw-w64-x86_64-toolchain autoconf
I've installed libxc dozens of time on Linux machines. The first step is
./configure --prefix /somewhere
But in MSYS2 I get
$ ./configure --prefix $PWD/../libxc
bash: ./configure: No such file or directory
How can I make this work?
MSYS2 prerequisites
First of all make sure MSYS2 has all programs that are needed.
In the MSYS2 shell first update the package manager information:
pacman -Syu --noconfirm
Then install the packages you need. I would recommend at least these:
pacman -S --noconfirm autoconf autoconf-archive automake make libtool pkg-config
Project sources
Next you should make sure the folder you are in actually has a configure script:
ls -l configure
A lot of projects these days are switching to more efficient build systems like CMake or Meson.
I usually use the following command in the projects source folder to check for several build systems:
ls -ld configure* m4 CMakeLists.txt cmake Makefile GNUmakefile setup.py scons SConscript SConstruct meson.build meson_options.txt *.pro *.proj *.sln BUILD.gn .gn 2> /dev/null
building libxc
For the libxc project I see there is a CMakeLists.txt file and also a configure.ac file.
So either you should look into using CMake or generate the configure file with:
touch README ChangeLog
autoreconf -f -i -I m4
I have just tried to build libxc in MSYS2 with CMake and Ninja and this worked:
# set the line below to the desired install location
INSTALLPREFIX=D:\Prog\changeme
# build static library
cmake -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DENABLE_PYTHON:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_static &&
ninja -Cbuild_static install/strip &&
echo SUCCESS
# build shared library
cmake -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DENABLE_PYTHON:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_shared &&
ninja -Cbuild_shared install/strip &&
echo SUCCESS

how to solve Kernel configuration is invalid issues

I'm trying to build module.
But here's some issues.
ERROR: Kernel configuration is invalid.
include/generated/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.`
And here's my makefile
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY: modules modules_install clean
else
# called from kernel build system: just declare what our modules are
obj-m := hello.o hellop.o seq.o jit.o jiq.o sleepy.o complete.o \
silly.o faulty.o kdatasize.o kdataalign.o
endif
I tried building like this:
export KERNELDIR=/path/to/extern/linux/source
make
How can I solve this problem?
Okay, so I would try to re-install the Linux-headers.
prerequisites
terminal access(bash presumably)
root privileges
(or a user who can do 'sudo')
First, we try to re install (using APT) the linux-headers package but adding your specific version. Which is determined by the following command: $(uname -r)
and to do it all in one line:
sudo apt install --reinstall linux-headers-$(uname -r)
Then, as we talk about the kernel, and making changes to it (quite major too, a reinstall of a kernel that is) we want to reboot as soon as the APT command is done:
sudo reboot
If you get it couldn't find any package, (or similar) (from apt)
try apt update and re-try the above.
Logs
Do check /var/log/kern.log for any messages that is,
cat /var/log/kern.log
I solved this problem with the following commands:
From your built sources take the most recent .config file with kernel configuration. Copy it to kernel-source directory (e.g.: build/tmp/work-shared/lmm-corei7/kernel-source).
Run make prepare.
I spent hours on the same problem, having the same error message : ERROR: Kernel configuration is invalid...
The solution was so simple...
I was running sudo make and this created the errors.
After having done what is suggested by William Martens (reinstall the headers and reboot), I logged as root, and the module built perfectly.
To be sure, I did a second test with an admin account and sudo make, and it failed again. So I am sure this is the reason. I noticed also that after a fail, I have to reinstall the headers otherwise, even in root, it fails.
This happened on a Debian 11 with kernel 5.10.0-16-amd64.

can’t install perl module Glib on OS X (El Capitan)

I want to install perl Gtk2, and for this I need first to have Glib installed. I tried sudo cpanm Glib, but I get an error when compiling (I also tried downloading the .tar.gz source etc., with the same effect). I also tried with an older version of Glib. I’m on OS X 10.11 (El Capitan). Here’s the error :
error: '_GStaticAssertCompileTimeAssertion_0' declared as an array with a negative size
I don’t know how to fix it… Thanks a lot if anyone can do something for me !
(BTW, brew install glib works fine, but it seems the app that I’m trying to build and run — auto-multiple-choice, for instance — is looking for a Gtk2.pm somewhere. So, the ‘glib’ installed by Homebrew is of no help.)
Benjamin
p.-s. : below is the complete log, if it helps :
cpanm (App::cpanminus) 1.7042 on perl 5.018002 built for darwin-thread-multi-2level
Work directory is /Users/benjamin/.cpanm/work/1474765262.7331
You have make /usr/bin/make
You have LWP 6.05
You have /usr/bin/tar: bsdtar 2.8.3 - libarchive 2.8.3
You have /usr/bin/unzip
Searching Glib () on cpanmetadb ...
--> Working on Glib
Fetching http://www.cpan.org/authors/id/X/XA/XAOC/Glib-1.322.tar.gz
-> OK
Unpacking Glib-1.322.tar.gz
Entering Glib-1.322
Checking configure dependencies from META.json
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (6.66)
Checking if you have ExtUtils::PkgConfig 1.000 ... Yes (1.15)
Checking if you have ExtUtils::Depends 0.300 ... Yes (0.306)
Configuring Glib-1.322
Running Makefile.PL
Including generated API documentation...
Checking if your kit is complete...
Looks good
Writing Makefile for Glib
Writing MYMETA.yml and MYMETA.json
-> OK
Checking dependencies from MYMETA.json ...
Checking if you have ExtUtils::Depends 0.300 ... Yes (0.306)
Checking if you have ExtUtils::PkgConfig 1.000 ... Yes (1.15)
Checking if you have ExtUtils::MakeMaker 0 ... Yes (6.66)
Building and testing Glib-1.322
cp lib/Glib/CodeGen.pm blib/lib/Glib/CodeGen.pm
cp /Users/benjamin/.cpanm/work/1474765262.7331/Glib-1.322/typemap blib/arch/Glib/Install/typemap
cp lib/Glib/ParseXSDoc.pm blib/lib/Glib/ParseXSDoc.pm
cp doctypes blib/arch/Glib/Install/doctypes
cp devel.pod blib/lib/Glib/devel.pod
cp gperl_marshal.h blib/arch/Glib/Install/gperl_marshal.h
cp lib/Glib/MakeHelper.pm blib/lib/Glib/MakeHelper.pm
cp gperl.h blib/arch/Glib/Install/gperl.h
cp lib/Glib.pm blib/lib/Glib.pm
cp lib/Glib/Object/Subclass.pm blib/lib/Glib/Object/Subclass.pm
cp build/IFiles.pm blib/arch/Glib/Install/Files.pm
cp lib/Glib/GenPod.pm blib/lib/Glib/GenPod.pm
[ XS Glib.xs ]
[ CC Glib.c ]
In file included from Glib.xs:22:
In file included from ./gperl.h:37:
In file included from /usr/local/Cellar/glib/2.48.2/include/glib-2.0/glib-object.h:23:
In file included from /usr/local/Cellar/glib/2.48.2/include/glib-2.0/gobject/gbinding.h:28:
In file included from /usr/local/Cellar/glib/2.48.2/include/glib-2.0/glib.h:30:
In file included from /usr/local/Cellar/glib/2.48.2/include/glib-2.0/glib/galloca.h:32:
/usr/local/Cellar/glib/2.48.2/include/glib-2.0/glib/gtypes.h:422:3: error: '_GStaticAssertCompileTimeAssertion_0' declared as an array with a negative size
G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/glib/2.48.2/include/glib-2.0/glib/gmacros.h:232:103: note: expanded from macro 'G_STATIC_ASSERT'
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
^~~~~~~~~~~~~~~
1 error generated.
make: *** [Glib.o] Error 1
-> FAIL Installing Glib failed. See
/Users/benjamin/.cpanm/work/1474765262.7331/build.log for details. Retry with --force to force install it.
This was posted to a GitHub issue.
I tracked down the problem by running:
cpanm --verbose --build-args=NOECHO=' ' Glib
so that I could see the specific compilation command that failed:
cc -c -I. -I/usr/local/Cellar/glib/2.50.0/include/glib-2.0 -I/usr/local/Cellar/glib/2.50.0/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.39/include -D_REENTRANT -arch x86_64 -arch i386 -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector -Os -DVERSION=\"1.323\" -DXS_VERSION=\"1.323\" -o Glib.o "-I/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE" Glib.c
Since the problem was something to do with mismatching sizeof's, I figured that the problem was that the architecture that Perl was building with does not the architecture that Homebrew's libglib-2.0 was built against.
The fix is to specify that you only want to build for x86_64 by setting the ARCHFLAGS environment variable:
ARCHFLAGS="-arch x86_64" cpanm --verbose Glib
This is all using the system Perl. If you want the install to work in the long run across system upgrades, you will want to install your own user Perl using either perlbrew or plenv.
I ran into the same issue.
Installing gtk+ as a prerequisite fixed it.

Library Installation order in automake

When I am running make distcheck, one library (lib2 in this example) is not being installed because it requires lib1.
Is there any way to mandate the order of library installation?
Makefile.am:
lib_LTLIBRARIES = libTwo.la libOne.la
libOne_la_SOURCES = lib/one/example.cpp \
lib/one/example.h
libTwo_la_SOURCES = lib/two/Example2.cpp \
lib/two/Example2.h
libTwo_la_CPPFLAGS = -I$(srcdir)/lib/one
libTwo_la_LIBADD = libOne.la
I am using:
RedHatEnterpriseServer 5.5
automake (GNU automake) 1.9.6
*Edit: * Here is what I am seeing on the make distcheck output.
/usr/bin/ld: cannot find -lOne
collect2: ld returned 1 exit status
libtool: install: error: relink `libTwo.la' with the above command before installing it
/bin/sh ./libtool --mode=install /usr/bin/install -c 'libOne.la' '/tmp/xx-x-yy-21346 /home/foo/commonlib-1.0/_inst/lib/libOne.la'
Try exchanging:
lib_LTLIBRARIES = libTwo.la libOne.la
for:
lib_LTLIBRARIES = libOne.la libTwo.la
IIRC, the order in lib_LTLIBRARIES matters at install time.

A clean Homebrew won't install anything

I was trying to install rabbitmq on OS X 10.6.8 with homebrew, and it failed.. so I tried wiping out my Homebrew installation and reinstalling. Howevever, now I get the same failure message for anything I try to install. I don't see any way to debug this either. Has anyone seen this before? I have XCode 3.2.6 installed as well. Here, I try to install git with
brew install git -v
Output
make -C templates DESTDIR='' install
: no custom templates yet
install -d -m 755 '/usr/local/Cellar/git/1.7.7.1/share/git-core/templates'
readlink: illegal option -- f
usage: readlink [-n] [file ...]
usage: dirname path
ls: /install_*: No such file or directory
(cd blt && tar cf - .) | \
(cd '/usr/local/Cellar/git/1.7.7.1/share/git-core/templates' && umask 022 && tar xof -)
/bin/sh: line 0: cd: /usr/local/Cellar/git/1.7.7.1/share/git-core/templates: No such file or directory
make[1]: *** [install] Error 1
make: *** [install] Error 2
==> Exit Status: 2
http://github.com/mxcl/homebrew/blob/master/Library/Formula/git.rb#L40
==> Environment
HOMEBREW_VERSION: 0.8
HEAD: 9a6bd3473936175163a642e28f6ce0b8a659cf6d
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_REPOSITORY: /usr/local
HOMEBREW_LIBRARY_PATH: /usr/local/Library/Homebrew
Hardware: 8-core 64-bit sandybridge
OS X: 10.6.8
Kernel Architecture: x86_64
Ruby: 1.8.7-249
/usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
Xcode: 3.2.6
GCC-4.0: build 5494
GCC-4.2: build 5666
LLVM: build 2335
MacPorts or Fink? false
X11 installed? true
==> Build Flags
CC: /usr/bin/gcc-4.2
CXX: /usr/bin/g++-4.2
LD: /usr/bin/gcc-4.2
CFLAGS: -O3 -march=core2 -w -pipe
CXXFLAGS: -O3 -march=core2 -w -pipe
MAKEFLAGS: -j8
Error: Failed executing: make prefix=/usr/local/Cellar/git/1.7.7.1 install
These existing issues may help you:
https://github.com/mxcl/homebrew/issues/6257
https://github.com/mxcl/homebrew/issues/6820
https://github.com/mxcl/homebrew/issues/6971
https://github.com/mxcl/homebrew/issues/7462
https://github.com/mxcl/homebrew/issues/8030
https://github.com/mxcl/homebrew/issues/8230
https://github.com/mxcl/homebrew/issues/8244
Otherwise, please report the bug:
https://github.com/mxcl/homebrew/wiki/checklist-before-filing-a-new-issue
:~ $
Assuming homebrew pulled down the files to /usr/local/Cellar/git/1.7.7.1 it looks like you might have an issue with the make command. A few things to try:
Check to see which 'make' is being used : which make by default should be at /usr/bin/make.
If #1 is pointing where you would expect you might try to build a simple hello world project with a make file just to check that it's working properly.

Resources