# Automake to build module for LIRC with several source files?

## Fitzcarraldo

I'm trying to add a new module to LIRC. I have obtained the LIRC 0.8.6 source code from the LIRC Web site and modified it to add new sub-directories and source code for the new hardware I want to add (it's the built-in IR receiver in an ASRock 330HT nettop).

LIRC uses GNU Automake, and this is where I am having trouble.

For example, the existing LIRC module lirc_wpc8769l.ko only has one C source code file:

```
# ls drivers/lirc_wpc8769l/

lirc_wpc8769l.c  lirc_wpc8769l.h  Makefile.am
```

and the GNU automake Makefile.am for the module lirc_wpc8769l.ko looks like this:

```

## $Id: Makefile.am,v 1.1 2009/01/03 17:30:35 lirc Exp $

## Process this file with automake to produce Makefile.in

## this is so that Automake includes the C compiling definitions, and

## includes the source files in the distribution.

EXTRA_PROGRAMS = automake_dummy

automake_dummy_SOURCES = lirc_wpc8769l.c lirc_wpc8769l.h

## there is no *just* object file support in automake.  This is close enough

module_DATA = lirc_wpc8769l.o

include ../Makefile.common
```

That results in a single module lirc_wpc8769l.ko as expected. Simple enough.

However, the new module lirc_wb677.ko I want to build has more than one C source file:

```
# ls drivers/lirc_wb677/

lirc_wb677_main.c  lirc_wb677_mouse_kbd.c  lirc_wb677_common_extern.h  lirc_wb677_mouse_kbd.h lirc_wb677.h  wb83677hg_ir.h
```

If I were to create a Makefile.am as follows:

```
## $Id: Makefile.am,v 1.1 2009/01/03 17:30:35 lirc Exp $

## Process this file with automake to produce Makefile.in

## this is so that Automake includes the C compiling definitions, and

## includes the source files in the distribution.

EXTRA_PROGRAMS = automake_dummy

automake_dummy_SOURCES = lirc_wb677_main.c lirc_wb677.h lirc_wb677_mouse_kbd.c lirc_wb677_mouse_kbd.h lirc_wb677_common_extern.h wb83677hg_ir.h

## there is no *just* object file support in automake.  This is close enough

module_DATA = lirc_wb677_main.o lirc_wb677_mouse_kbd.o

include ../Makefile.common
```

then two modules (lirc_wb677_main.ko and lirc_wb677_mouse_kbd.ko) would be created instead of one (lirc_wb677.ko). So my question is: what should the GNU automake Makefile.am for the module lirc_wb677.ko look like? Basically, I would like to achieve the following but in a Makefile.am instead of a Makefile:

```
obj-m += lirc_wb677.o

lirc_wb677-objs := lirc_wb677_main.o lirc_wb677_mouse_kbd.o
```

The above Makefile syntax does not work in a Makefile.am file. Is anyone able to tell me what the correct syntax is in the case of GNU Automake? Thanks in advance for your help.

----------

## Hu

As the LIRC developers seem to have discovered, using automake for kernel modules is not easy.  In my opinion, it would be better to use a simple Makefile for this portion of the build.  Do you plan to submit this change upstream when complete?  If so, ask them how to do this.  If they cannot identify a way to do it right, now might be the time to convert that directory to use kernel-style building and leave the user tools directories doing GNU autotools building.

----------

## Fitzcarraldo

Never mind, I built the module separately after building LIRC. It appears that what I wanted to do is impossible with Automake. I thought perhaps _LDADD would do it:

```
## $Id: Makefile.am,v 1.1 2009/01/03 17:30:35 lirc Exp $

## Process this file with automake to produce Makefile.in

## this is so that Automake includes the C compiling definitions, and

## includes the source files in the distribution.

EXTRA_PROGRAMS = automake_dummy

automake_dummy_SOURCES = lirc_wb677_main.c lirc_wb677.h lirc_wb677_mouse_kbd.c lirc_wb677_mouse_kbd.h lirc_wb677_common_extern.h wb83677hg_ir.h

## there is no *just* object file support in automake.  This is close enough

module_DATA = lirc_wb677.o

automake_dummy_LDADD = lirc_wb677_main.o  lirc_wb677_mouse_kbd.o

include ../Makefile.common
```

but Automake wants a lirc_wb677.c, which doesn't exist. According to the comments in lirc_wb677_mouse_kbd.c, the creator of these source files split the module source code into lirc_wb677_main.c and lirc_wb677_mouse_kbd.c based on the recommendation of the LIRC developers:

```
/*   Notice:

   Do NOT merge this file with other file.

   According to lirc group's suggestion, they hope that

   we should put keyboard/mouse decoding into a separate file if we want to preserve it.

*/
```

If the LIRC developers include the lirc_wb677 module in a future release of LIRC, I will be interested to see how they achieve it given the apparent limitation of Automake.

----------

## Hu

The simplest way would be to have a separate directory which is managed by a non-Automake Makefile.  That Makefile can then follow standard kernel practices.  It should not be hard to get Automake to recurse into that directory during the main make run.

----------

## Fitzcarraldo

I don't think it's as simple as you make out, if you'll pardon the pun. Below is the Makefile for lirc_wb677.ko:

```
#!/bin/bash

   LIRC_DIR := /usr/src/lirc-0.8.6

   obj-m += lirc_wb677.o

   lirc_wb677-objs := lirc_wb677_main.o lirc_wb677_mouse_kbd.o

   KSRC ?= /lib/modules/$(shell uname -r)/build

   PWD := $(shell pwd)

modules:

   echo KERNELDIR=$(KSRC)

   $(MAKE) -C $(KSRC) -I $(LIRC_DIR) M=$(PWD) modules

install:

   rmmod lirc_wb677 || echo "lirc_wb677.ko is not executing"

   file="lirc_wb677.ko"; \

   dir="/lib/modules/$(shell uname -r)/misc"; \

   if test -d "$$dir"; then echo ""; else mkdir -p $$dir; fi; \

   cp -vf *.ko $$dir

   depmod -a

uninstall:

   ( rmmod lirc_wb677 ) || echo "lirc_wb677.ko is not executing"

   dir="/lib/modules/$(shell uname -r)/misc"; \

   if test -d "$$dir"; then rm -R $$dir; fi;

   depmod -a

clean:

   rm -rf *.o *.ko *.mod.c Module.symvers .tmp_versions .*.cmd
```

Adhering to the structure used in the LIRC sources, the Automake Makefile.am for the driver lirc_wb677.ko would be located in the directory /usr/src/lirc-0.8.6/drivers/lirc_wb677/. How would you call the above Makefile from the Automake file /usr/src/lirc-0.8.6/drivers/lirc_wb677/Makefile.am, and what would /usr/src/lirc-0.8.6/drivers/lirc_wb677/Makefile.am contain in toto, given the requirements dictated by the specific LIRC Makefile.am syntax as illustrated in my earlier posts?

----------

## Fitzcarraldo

Just to expand on my previous post and explain why I don't think it is straightforward (or even possible), my understanding is that Automake cannot build an object file without it being explicitly declared in the corresponding Makefile.am file, irrespective of whether or not Automake looks in a sub-directory. Adhering to the syntax dictated by LIRC for its Makefile.am files if one wants to build an object file lirc_wb677.o, the Makefile.am file needs to contain:

```
module_DATA = lirc_wb677.o
```

The above being the case, Automake looks for lirc_wb677.c in the automake_dummy_SOURCES declaration, and aborts the build if it does not find it, which obviously it will not as no such file exists because the lirc_wb677.ko driver developers have purposely split the source code into the separate C source files lirc_wb677_main.c and lirc_wb677_mouse_kbd.c shown in my previous posts.

Thus, to reiterate, if the LIRC developers and Automake dictate that the Makefile.am file must declare module_DATA to be lirc_wb677.o, and Automake therefore expects lirc_wb677.c (which does not exist) to be declared in the Makefile.am file, how would the use of a sub-directory solve the problem?

----------

## Hu

A subdirectory solves the problem because recursive Automake is not aware of the contents of other directories.  It simply assumes that it can run a sub-make within the subdirectory, pass it the same goal, and get useful results.  Thus, I suggested that you have a subdirectory which contains a plain Makefile with standard Automake targets defined.  In the parent directory, add this subdirectory to SUBDIRS.  Automake will spawn a sub-make within the subdirectory, but will not apply any of the normal Automake rules to it, because Automake will not be run on this subdirectory.  This is documented in info '(automake1.10.info.bz2)Subdirectories'.

----------

## Killerchronic

Did you ever get any further on this?

I've been trying to follow the guides on http://forum.sabayon.org/viewtopic.php?f=56&t=20113&sid=cb2a539894c3d6da859ff573ba993ba5&start=10 and https://bbs.archlinux.org/viewtopic.php?pid=727145 but this is a bit above my level of understanding to convert them to gentoo form.

Edit: Just realised your the same person as on the Sabayon forums lol

----------

## johnny99

How is this going?  

Will there be a new use flag for wb677?  

I don't see a bug in bugs.gentoo.org.

I don't see anything on the lirc project site.

I'd like to help get something going.

Where did you obtain the LIRC 0.8.6 source code? 

Was it from the disassembly of a Debian package?

If I could find a good source, maybe I could start working on an ebuild, but I'd like to set this just get added to the lirc project.

Update: I just read a thread by jarod (IR developer).  Maybe I'll wait for a new driver,  lirc-0.9,  and the 2.6.36 kernel (with ir-core).

http://web.archiveorange.com/archive/v/Xn95HGmzTTFogLW1zKel

----------

