如何去除Makefile对C文件的依赖

发布于 2024-12-21 02:02:59 字数 1501 浏览 0 评论 0原文

我有下面的 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.

I have the below Makefile and for some reason it's dependent on a file, ewapi.c. This file executes some SWIG commands and uses the ewapi.i file. I've clear out all the contents of ewapi.c and the Makefile successfully runs. If I remove the ewapi.c file the make file will not complete. The exception stack is below if that helps. Any ideas on how to change the Makefile so its not dependent on 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) 
lt; 

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

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

$(DIRS):
    mkdir -p $@

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

Exception Stack (when I remove 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彡翼 2024-12-28 02:02:59

OBJECTS包括$(OBJ_DIR)/ewapi.o$(TARGET) 的规则表示它取决于 $(OBJECTS)all 的规则表示它取决于 $(TARGET)。因此,需要有一种方法可以从某些东西创建 ewapi.o - 并且在没有 ewapi.c 的情况下,就无法构建 ewapi。 o,因此您会收到投诉。

可能的修复:

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

The macros OBJECTS includes $(OBJ_DIR)/ewapi.o; the rule for $(TARGET) says it depends on $(OBJECTS); and the rule for all says it depends on $(TARGET). So, there needs to be a way to create ewapi.o from something - and in the absence of ewapi.c, there is no way to build ewapi.o, hence the complaint you get.

Possible fixes:

  • Replace ewapi.c.
  • Remove ewapi.o from the macro $(OBJECTS).
凉墨 2024-12-28 02:02:59

OBJECTS 中删除 $(OBJ_DIR)/ewapi.o

Remove $(OBJ_DIR)/ewapi.o from OBJECTS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文