2
votes

I've made a program in C++, but now I must install this program with autoconf and automake.

So, when I run command "./configure && make && make install", it must do the following:

  • compile program
  • create folder my_program inside /opt (example: /opt/my_program/) and in this folder I must also have all static libraries and source files
  • There must be symbolic link in /usr/local/bin for my_program
  • Libraries must be in /usr/local/lib (DONE - Thanks to @Galik )
  • Header files of my_program must be in /usr/local/include (DONE)

I've wrote this configure.ac script:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([my_program], [0.1], [my_mail])
AC_CONFIG_SRCDIR([AbsAlgorithm.hpp])
AM_INIT_AUTOMAKE

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC

# Checks for libraries.

# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h sys/time.h unistd.h wchar.h wctype.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_MKTIME
AC_CHECK_FUNCS([gettimeofday memset mkdir])

LIBS="-ldl"

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

and this Makefile.am script:

AUTOMAKE_OPTIONS = foreign

AM_CXXFLAGS=-Wall -std=gnu++11 -DVERSION=\"$(VERSION)\" -DPROG="\"$(PACKAGE)\""

bin_PROGRAMS = algatorc
noinst_LIBRARIES = libalgatorc.a
libalgatorc_a_SOURCES = Timer.cpp
include_HEADERS = Timer.hpp TestSetIterator.hpp TestCase.hpp ETestSet.hpp EParameter.hpp Entity.hpp ParameterSet.hpp AbsAlgorithm.hpp Log.hpp JSON.hpp
algatorc_SOURCES = ParameterSet.cpp TestCase.cpp EParameter.cpp ETestSet.cpp TestSetIterator.cpp Entity.cpp Timer.cpp  main.cpp JSON.cpp JSONValue.cpp

Now, when I run "./configure && make && make install" I don't get new folder called my_program in /opt. But, I now, I do have header files in /usr/local/include. I don't have lib files in /usr/local/lib. There is just one folder for python. I would like to have folder called my_program and inside that folder I would like to have static libs.

I am using Ubuntu 12.04 x64

I would appreciate any help. Thanks

1
"I don't have lib files in /usr/local/lib" - you don't make any libraries. - Galik
I've edited my post (actually I've edited my Makefile.am). I still don't have lib in /usr/local/lib. - golobitch
The noinst_ part of noinst_LIBRARIES means "do not install". Try using lib_LIBRARIES instead. - Galik
Yes, that worked. Thank you very much. But is it posible to create folder inside /usr/local/lib and to put lib in that folder? For example I would like lib file to be in /usr/local/lib/algatorc/ . Is that possible? If not, then this is ok ;) Do you also know how to do this? create folder my_program inside /opt (example: /opt/my_program/) and in this folder I must also have all static libraries and source files - golobitch
@golobich: A non-standard target directory (like /opt/my_program) is usually selected at configure time via --prefix. I'd be pretty miffed by a package that overruled that selection with a hardcoded path. - DevSolar

1 Answers

0
votes

Autotools is not really designed to put things in specific locations. The idea is that programs go in the programs directory $(bindir), libraries in the libraries directory $(libdir) etc and that the person installing everything gets to decide where those locations are.

So you should really only care about installing things relative to wherever the person running the installer wants them to be.

They do this by adding arguments to the configure script like:

configure --prefix=/opt/myprog

That will typically install programs in /opt/myprog/bin and libraries in /opt/myprog/lib etc...

You can add to the places that things get installed by setting special dir variables. For example to put libraries in a sub-directory of $(libdir) (default /usr/local/lib) you caan do:

myprog_librarydir = $(libdir)/myprog

And its not uncommon to do the same for the header files:

myprog_includedir = $(prefix)/include/myprog

That defines some destination folders you can refer to instead of the defaults:

myprog_include_HEADERS = \
    Timer.hpp \
    TestSetIterator.hpp \
    TestCase.hpp \
    ETestSet.hpp \
    EParameter.hpp \
    Entity.hpp \
    ParameterSet.hpp \
    AbsAlgorithm.hpp \
    Log.hpp \
    JSON.hpp

Those will now get installed into $(prefix)/include/myprog.

Similarly with the corresponding library:

myprog_library_LIBRARIES = libmyprog.a

libmyprog_a_SOURCES = \
    ParameterSet.cpp \
    TestCase.cpp \
    EParameter.cpp \
    ETestSet.cpp \
    TestSetIterator.cpp \
    Entity.cpp \
    Timer.cpp \
     JSON.cpp \
    JSONValue.cpp

So basically you create a destination (installation) directory using:

mynamedir = $(prefix)/path/... whatever

That allows you to set destinations other than bin_, lib_ and include_ etc...

So instead of saying lib_LIBRARIES you can say myname_LIBRARIES.

Hope that helps.