如何在C文件中删除Makefile依赖项

时间:2011-12-15 00:15:19

标签: makefile swig

我有下面的Makefile,由于某种原因它依赖于文件ewapi.c。此文件执行一些SWIG命令并使用ewapi.i文件。我清除了ewapi.c的所有内容,并且Makefile成功运行。如果我删除ewapi.c文件,make文件将无法完成。如果有帮助,异常堆栈在下面。关于如何更改Makefile以使其不依赖于ewapi.c的任何想法?

# BUILD_DIR and DIST_DIR are exported by build.xml
#
CMODE=

SWIG = swig
CC = $(PREFIX)gcc
LD = $(CC) 

OBJ_DIR = $(BUILD_DIR)/obj
AUTOGEN_DIR = $(BUILD_DIR)/auto-generated
PACKAGE_DIR = $(AUTOGEN_DIR)/com/sample/jni

PACKAGE = com.sample.jni

INCLUDES = -I$(JAVA_INCLUDE) \
           -I$(SAMPLE_SDK_DIR)/include \
           -I$(JDK_HOME)/include

LIB_INCLUDES = -L$(SAMPLE_SDK_DIR)/lib

LIBS = /lib/libssl.so.4 \
       /lib/libcrypto.so.4 \
       -lSampleApi \
       -lm

DIRS = $(PACKAGE_DIR) $(DIST_DIR) $(OBJ_DIR) $(AUTOGEN_DIR)

CFLAGS = $(CMODE) -Wall -fpic $(INCLUDES) -O0 -g3
SFLAGS = -java $(INCLUDES) -package $(PACKAGE) -outdir $(PACKAGE_DIR)
LDFLAGS = -shared $(LIB_INCLUDES) $(LIBS)

OBJECTS = $(OBJ_DIR)/ewapi_wrap.o $(OBJ_DIR)/ewapi.o
TARGET = $(DIST_DIR)/libSample.so

all: $(DIRS) $(TARGET)

%_wrap.c: %.i
    $(SWIG) $(SFLAGS) $< 

$(OBJ_DIR)/%.o: %.c
    $(CC) $(CFLAGS) -c $< -o $@

$(TARGET): $(OBJECTS)
    $(LD) $(OBJECTS) $(LDFLAGS) -o $@

$(DIRS):
    mkdir -p $@

clean:
    rm -rf $(TARGET) $(PACKAGE_DIR)/* $(TARGET) $(AUTOGEN_DIR) $(OBJ_DIR)

异常堆栈(当我删除ewapi.c时):

[exec] rm ewapi_wrap.c
[exec] make-3.79.1-p7: *** No rule to make target `/test/build/obj/ewapi.o', needed by `/test/dist/libSample.so'.  Stop.

2 个答案:

答案 0 :(得分:1)

OBJECTS包括$(OBJ_DIR)/ewapi.o; $(TARGET)的规则说明取决于$(OBJECTS); all的规则说明取决于$(TARGET)。因此,需要有一种方法可以从某些内容创建ewapi.o - 如果没有ewapi.c,则无法构建ewapi.o,因此您会得到投诉。

可能的修复:

  • 替换ewapi.c
  • 从宏ewapi.o移除$(OBJECTS)

答案 1 :(得分:1)

$(OBJ_DIR)/ewapi.o删除OBJECTS