Search code examples
pythondebiandeb

Compiling C code with python setuptools 'bdist_deb'


I have to convert my RPM packages to DEB package to install it on Ubuntu. Since I don't have any experience of building DEB packages, googling suggests 'bdist_rpm' from stdeb package

The code is mostly python, config files etc. But there is one C code which needs to be built. The RPM installs the binary in /usr/bin

Code in setup.py for creating the binary is

if sys.argv and len(sys.argv) > 1 and sys.argv[1].strip().startswith('bdist'):
try:
    compiler = UnixCCompiler(verbose=1)
    compiler.compile(['cutility/chown_sudo.c'])
    compiler.link_executable((['cutility/chown_sudo.o']), 'bin/sudoown')
except CompileError as compileError:
    print "Failed to compile the binary file."
    raise

bdist_rpm understands this code and creates the C. But bdist_deb ignores it :(

Searching over the net, debuild utility suggests to create some Makefile for this and whole lot of other complex stuff

Is it that complicated ? Some searches also suggest using 'alien' tool instead ?

Till now my thought is, use the following command

python setup.py --command-packages=stdeb.command debianize

Then adjust debian directory postint, control etc. But I don't know how to build the C code


Solution

  • I turns out that the 'bdist' check which I was using with 'bdist_rpm' was causing the issue when using 'bdist_deb' option. The script is called with 'build' argument when using 'bdist_deb' option. After I added an OR for startswith('build'), things progressed