2012-02-27 64 views
0

我想編譯並鏈接到一個單一的目標文件根據menuconfig選擇標誌來編譯不同的源文件。linux kbuild makefile

like;

OBJ - $(CONFIG1):sample.o(但應建立從sample_1.c) OBJ - $(CONFIG2):sample.o(但應建立從sample_2.c)

是有可能通過makefile或者如果通過linux kbuild無法實現這一點,任何技巧都是非常值得讚賞的。

RGDS, Sharanu

+0

有幾種方法可以做到這一點,沒有完美的。我們需要更多關於您的意圖/優先事項的信息。爲什麼你想爲兩個不同的文件使用'sample.o'這個名字? – Beta 2012-02-27 14:03:10

+0

我不想更改加載模塊的腳本文件,因爲存在很多依賴關係。相反,它必須加載一個模塊,但根據編譯指令進行構建。 – 2012-02-27 14:28:05

+0

任何解決方案,甚至不完美... – 2012-02-27 16:28:35

回答

0

沒有什麼,我知道的,自動做到這一點,但是,kbuild的文件是Makefile文件,這樣你就可以在他們使用的Makefile條件句。你可以做這樣的事情:

ifneq ($(findstring $(config1),"ym"),) 
    $(obj)sample.o: $(obj)sample_1.o 
     $(Q)$(CC) $(CFLAGS) $< -c -o [email protected] 
else 
ifneq ($(findstring $(config2),"ym"),) 
    $(obj)sample.o: $(obj)sample_2.o 
     $(Q)$(CC) $(CFLAGS) $< -c -o [email protected] 
endif 
endif 

obj-($config1) += sample.o 
obj-($config2) += sample.o 

希望這有助於

約翰