Search code examples
pythonc++autotoolsautomakedistutils

Are there any disadvantages in using a Makefile.am over setup.py?


I'm working on transitioning a project from scons to autotools, since I it seems to automatically generate a lot of features that are annoying to write in a SConscript (e.g. make uninstall).

The project is mostly c++ based, but also includes some modules that have been written in python. After a lot of reading autotools, I can finally create a shared library, compile and link an executable against it, and install c++ header files. Lovely. Now comes they python part. By including AM_PYTHON_PATH in configure.ac, I'm also installing the python modules with Makefile.am files such as

autopy_PYTHON=autopy/__init__.py autopy/noindent.py autopy/auto.py submoda_PYTHON=autopy/submoda/moda.py autopy/submoda/modb.py autopy/submoda/modc.py autopy/submoda/__init__.py submodb_PYTHON=autopy/submodb/moda.py autopy/submodb/modb.py autopy/submodb/modc.py autopy/submodb/__init__.py

autopydir=$(pythondir)/autopy submodadir=$(pythondir)/submoda submodbdir=$(pythondir)/submodb

dist_bin_SCRIPTS=scripts/script1 scripts/script2 scripts/script3

This seems to place all my modules and scripts in the appropriate locations, but I wonder if this is "correct", because the way to install python modules seems to be through a setup.py script via distutils. I do have setup.py scripts inside the python modules and scons was invoking them until I marched in with autotools. Is one method preferred over the other? Should I still be using setup.py when I build with autotools? I'd like to understand how people usually resolve builds with c++ and python modules using autotools. I've got plenty of other autotools questions, but I'll save those for later.


Solution

  • Based on your description, I would suggest that you have your project built using stock autotools-generated configure and Makefile, i.e. autoconf and automake, and have either your configure or your Makefile take care of executing your setup.py, in order to set up your Python bits.

    I have a project that's mostly C/C++ code, together with a Perl module. This is very similar to what you're trying to do, except that it's Perl instead of Python.

    In my Makefile (generated from Makefile.am) I have a target that executes the Perl module's Makefile.PL, which is analogous to Python's setup.py, and in that manner I build the Perl module together with the rest of the C++ code, seamlessly together, as a single build. Works fairly well.

    automake's Makefile.am is very open-ended and flexible, and can be easily adapted and extended to incorporate foreign bits, like these.