我有这个简单的结构:
.
test.c
plugins/a.c
plugins/b.c
plugins/c.c
我正在用 bash 脚本编译它:
gcc -o test test.c -std=gnu99 -ldl -Wl,--export-dynamic
gcc -c plugins/a.c -o plugins/a.o -pedantic -g -Wall -std=c99 -fpic -I.
gcc plugins/a.o -o plugins/a.so -shared
...same for b and c...
无论如何,我想将它移植到 Makefile。这是我所拥有的:
CC = gcc
PLUGIN_DIR = plugins
PLUGINS_C = $(wildcard $(PLUGIN_DIR)/*.c)
PLUGINS_O = $(patsubst %.c,%.o, $(PLUGINS_C))
new: clean all
all: test plugins
test: test.o
$(CC) -o $@ $^ -std=gnu99 -ldl -Wl,--export-dynamic
plugins:
???
$(PLUGIN_DIR)/*.c:
$(CC) -c $(PLUGIN_DIR)/$@ $^ -pedantic -g -Wall -std=c99 -fpic -I.
$(PLUGIN_DIR)/*.o:
$(CC) $@ $^ -shared
clean:
rm -rf test *.o *.a plugins/*.o plugins/*.so
但这不起作用,因为plugins
规则是空的,我真的不知道我应该在那里写什么来使它编译plugins
文件夹内的所有插件。另外,我不确定我是否把事情搞砸了$@
and $^
。