<div dir="ltr">Hi Valdis,<div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 26, 2013 at 12:48 PM, <span dir="ltr"><<a href="mailto:Valdis.Kletnieks@vt.edu" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=Valdis.Kletnieks@vt.edu&cc=&bcc=&su=&body=','_blank');return false;">Valdis.Kletnieks@vt.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On Fri, 26 Apr 2013 11:11:09 -0700, Henrique Rodrigues said:<br>
<br>
> I have the one .c source file that I want to create multiple kernel modules<br>
> out of it by setting macros using the makefile.<br>
<br>
</div>Generally considered ugly by the mainstream kernel.<br></blockquote><div><br></div><div style>I agree. I'm actually trying to split the code that was given to me into three modules with minimal effort (without having to rewrite new code).</div>
<div style>The behavior of the code is defined by lots of #if macros in it, and I wanted to take advantage of that by rewriting only the makefile.</div><div style><br></div><div style>The problem is that if I set the obj-m variable within a make target (instead of defining it globally), the kernel build system doesn't compile anything. </div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im"><br>
> The idea is that if -DMODULE1 is set, I'll build module1.ko and if<br>
> -DMODULE2 is set, I'll build module 2.<br>
<br>
</div>The way this would usually be done is splitting your module into 3<br>
parts - one common, one for device 1 and one for device 2.<br>
<br>
Then something like this (cut-n-paste from drivers/net/wireless/hostap/Makefile:<br>
<br>
hostap-y := hostap_80211_rx.o hostap_80211_tx.o hostap_ap.o hostap_info.o \<br>
hostap_ioctl.o hostap_main.o hostap_proc.o<br>
obj-$(CONFIG_HOSTAP) += hostap.o<br>
<br>
obj-$(CONFIG_HOSTAP_CS) += hostap_cs.o<br>
obj-$(CONFIG_HOSTAP_PLX) += hostap_plx.o<br>
obj-$(CONFIG_HOSTAP_PCI) += hostap_pci.o<br>
<br>
Which will build 3 different modules (_cs, _plx, _pci) using the common C files<br>
and 1 device-specific C file for each one.<br>
</blockquote></div><div class="gmail_extra"><br></div>I checked the hostap code and it looks like each file (_cs, _plx, _pci) defines a different module. I believe that is not exactly what I wanted, but I understand that it works.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Thanks,<br>-- <br>Henrique Rodrigues<br><div><a href="http://www.dcc.ufmg.br/~hsr" target="_blank">http://www.dcc.ufmg.br/~hsr</a></div>
</div></div></div>