当你编译好整个firefox3.7 源码后,是不是想自己改例子程序以自用呢?
那么在新加入的代码中难免会碰到C的调用了,下面就告诉你如何做,以让自带的Makefile能处理好新加入的C的调用代码
本人的源代码根目录在/opt/firefox-3.7,例子程序的Makefile在
/opt/firefox-3.7/obj-i686-pc-linux-gnu/modules/plugin/sdk/samples/npruntime/Makefile,修改这个Makefile为
DEPTH = /opt/firefox-3.7/obj-i686-pc-linux-gnu topsrcdir = /opt/firefox-3.7 #srcdir = /opt/firefox-3.7/modules/plugin/sdk/samples/npruntime oldsrcdir = /opt/firefox-3.7/modules/plugin/sdk/samples/npruntime srcdir = /win/firefox/3.7/npruntime VPATH = /opt/firefox-3.7/modules/plugin/sdk/samples/npruntime include $(DEPTH)/config/autoconf.mk MODULE = plugin LIBRARY_NAME = epson-local-printer ifeq ($(OS_ARCH),WINNT) RESFILE = nprt.res DEFFILE = $(srcdir)/nprt.def endif # plugins should always be shared, even in the "static" build FORCE_SHARED_LIB = 1 # Force use of PIC FORCE_USE_PIC = 1 NO_DIST_INSTALL = 1 NO_INSTALL = 1 CPPSRCS = / $(srcdir)/cmdBase.cpp / $(srcdir)/printCmd.cpp / $(srcdir)/np_entry.cpp / $(srcdir)/npn_gate.cpp / $(srcdir)/npp_gate.cpp / $(srcdir)/plugin.cpp / $(NULL) LOCAL_INCLUDES = -I$(oldsrcdir)/.. -I$(oldsrcdir)/../../public / -I/usr/lib/glib/include include $(topsrcdir)/config/rules.mk install-plugin: $(SHARED_LIBRARY) ifdef SHARED_LIBRARY $(INSTALL) $(SHARED_LIBRARY) $(DIST)/bin/plugins endif libs:: install-plugin install:: $(SHARED_LIBRARY) ifdef SHARED_LIBRARY $(SYSINSTALL) $(IFLAGS2) $< $(DESTDIR)$(mozappdir)/plugins endif
简单的做法是,我的例子程序源代码在/win/firefox/3.7/npruntime,要让此自带的makefile 找到我的源代码即可,这样就不用写Makefile了嘿嘿
编译插件实例NPRuntime
cd /opt/firefox-3.7/obj-i686-pc-linux-gnu/modules/plugin/sdk/samples/npruntime && make
成功后/opt/firefox-3.7/obj-i686-pc-linux-gnu/modules/plugin/sdk/samples/npruntime/libnprt.so就是所要的插件目标代码
打开/opt/firefox-3.7/obj-i686-pc-linux-gnu/dist/bin/firefox来测试看你的实例是不是可装载成功了~~
注意mimetypes3者一致性:
nprt.rc
VALUE "MIMEType", "application/mozilla-npruntime-scriptable-plugin/0"
里面的VALUE "MIMEType"值和
test.html:
<embed id="embed1" type="application/mozilla-npruntime-scriptable-plugin" width=600 height=40><br>
里面的type 和
npp_gate.cpp
return "application/mozilla-npruntime-scriptable-plugin:.foo:Scriptability Demo Plugin";
在其中加入.c调用
对于要加入的tty.c:
若是C++代码,即.cpp,则在CPPSRCS = 后面添加行,添加你的要加入的源文件即可,但是若是c代码,即.c,不管加入的是 tty.c tty.cpp在此行都不行,报错:
c的部分函数找不到
只好另某它路了-:(
折腾来去都不能将C代码加入编译,无意看到这个标志CPPSRCS,灵机一动,想,也许会有CSRC这样的标志也说不定!
我找到调试命令(好久没用过了)
make -qp > /win/info
分析这个makefile找 CPPSRCS果然有:
# makefile (从'/opt/firefox-3.7/config/rules.mk',行 379) _OBJS = $(JRI_STUB_CFILES) $(addsuffix .$(OBJ_SUFFIX), $(JMC_GEN)) $(CSRCS:.c=.$(OBJ_SUFFIX)) $(patsubst %.cc,%.$(OBJ_SUFFIX),$(CPPSRCS:.cpp=.$(OBJ_SUFFIX))) $(CMSRCS:.m=.$(OBJ_SUFFIX)) $(CMMSRCS:.mm=.$(OBJ_SUFFIX)) $(ASFILES:.$(ASM_SUFFIX) =.$(OBJ_SUFFIX))
当看到
$(CPPSRCS:.cpp=.$(OBJ_SUFFIX)))
就立马会想到要找
$(CSRCS:.c=.$(OBJ_SUFFIX))
对了就是这个!下面就好写了:
将下面的行加入到Makefile
CSRCS = / $(srcdir)/tty.c / $(NULL)
是不是很简单?