On Sat, Nov 30, 2013 at 4:47 AM, Qingping Hou <dave2008713@xxxxxxxxx> wrote: > From: Yicheng Qin <qycqycqycqycqyc@xxxxxxxxx> > > This patch adds rule to build ffi module into ktap. > Also, it introduces FFI flag to enable/disable FFI funtionality. > > Signed-off-by: Yicheng Qin <qycqycqycqycqyc@xxxxxxxxx> > Signed-off-by: Qingping Hou <qingping.hou@xxxxxxxxx> > --- > Makefile | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/Makefile b/Makefile > index 621e125..ee7e8da 100644 > --- a/Makefile > +++ b/Makefile > @@ -3,6 +3,9 @@ > # Define NO_LIBELF if you do not want libelf dependency (e.g. cross-builds) > # (this will also disable resolve resolving symbols in DSO functionality) > # > +# Define FFI if you want to compile ktap with FFI support. By default This > +# toggle is off. > +# > # Define amalg to enable amalgamation build, This compiles the ktapvm as > # one huge C file and allows GCC to generate faster and shorter code. Alas, > # this requires lots of memory during the build. > @@ -20,20 +23,35 @@ all: mod ktap > INC = include > INTP = interpreter > > + > +FFIDIR = $(INTP)/ffi > KTAP_LIBS = -lpthread > > LIB_OBJS += $(INTP)/lib_base.o $(INTP)/lib_kdebug.o $(INTP)/lib_timer.o \ > $(INTP)/lib_ansi.o > > ifndef amalg > +ifdef FFI > +FFI_OBJS += $(FFIDIR)/ffi_call.o $(FFIDIR)/ffi_type.o $(FFIDIR)/ffi_symbol.o > \ > + $(FFIDIR)/call_x86_64.o $(FFIDIR)/cdata.o $(FFIDIR)/ffi_util.o > +INTP_OBJS += $(FFI_OBJS) > +LIB_OBJS += $(INTP)/lib_ffi.o > +endif > INTP_OBJS += $(INTP)/ktap.o $(INTP)/kp_load.o $(INTP)/kp_obj.o \ > $(INTP)/kp_str.o $(INTP)/kp_tab.o $(INTP)/kp_vm.o \ > $(INTP)/kp_opcode.o $(INTP)/kp_transport.o \ > $(LIB_OBJS) > else > +ifdef FFI > +INTP_OBJS += $(FFIDIR)/call_x86_64.o > +endif Why not include ffi/call_x86_64.c into kp_amalg.c? > INTP_OBJS += $(INTP)/kp_amalg.o > endif > > +ifdef FFI > +ccflags-y += -DCONFIG_KTAP_FFI > +endif > + > obj-m += ktapvm.o > ktapvm-y := $(INTP_OBJS) > > @@ -48,6 +66,7 @@ modules_install: > > KTAPC_CFLAGS = -Wall -O2 > > + > # try-cc > # Usage: option = $(call try-cc, source-to-build, cc-options, msg) > ifneq ($(V),1) > @@ -117,6 +136,16 @@ ifndef NO_LIBELF > $(UDIR)/symbol.o: $(UDIR)/symbol.c > $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< > endif > +ifdef FFI > +KTAPC_CFLAGS += -DCONFIG_KTAP_FFI > +$(UDIR)/ffi_type.o: $(INTP)/ffi/ffi_type.c $(INC)/* > + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< > +$(UDIR)/ffi/cparser.o: $(UDIR)/ffi/cparser.c $(INC)/* > + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< > +$(UDIR)/ffi/ctype.o: $(UDIR)/ffi/ctype.c $(INC)/* > + $(QUIET_CC)$(CC) $(DEBUGINFO_FLAG) $(KTAPC_CFLAGS) -o $@ -c $< > +endif > + > > KTAPOBJS = > KTAPOBJS += $(UDIR)/lex.o > @@ -134,6 +163,11 @@ KTAPOBJS += $(UDIR)/kp_obj.o > ifndef NO_LIBELF > KTAPOBJS += $(UDIR)/symbol.o > endif > +ifdef FFI > +KTAPOBJS += $(UDIR)/ffi_type.o > +KTAPOBJS += $(UDIR)/ffi/cparser.o > +KTAPOBJS += $(UDIR)/ffi/ctype.o > +endif > > ktap: $(KTAPOBJS) > $(QUIET_LINK)$(CC) $(KTAPC_CFLAGS) -o $@ $(KTAPOBJS) $(KTAP_LIBS) > -- > 1.8.1.2 >