如何编写shell脚本来编译C文件(.sqc)中的多个嵌入sql?
我已经编写了 3 个 .sqc 文件,即用主机语言 C 嵌入 sql。我需要制作一个(Unix)shell 脚本来简单地连续编译所有 3 个 sqc 文件。我怎样才能做到这一点?现在,我可以使用 Makefile 单独运行每个 .sqc 文件,该文件基本上将 .sqc 文件转换为 ac 文件,然后编译它。我可以制作 3 个单独的 Makefile 并通过 shell 脚本运行它们吗?如果是这样,那又如何呢?我可以制作一个可以独立编译所有 3 个 .sqc 的 Makefile,然后通过 shell 脚本编译它们吗?如果是这样,那又如何呢?还有其他选择吗?
这是只能编译单个 .sqc 文件的 Makefile:
NAME=sample
DB2PATH = /sqllib
CC=gcc
CFLAGS=-I$(DB2PATH)/include
LIBS=-L$(DB2PATH)/lib -R$(DB2PATH)/lib -ldb2
all: $(NAME)
$(NAME): $(NAME).sqc util.o
db2 connect to sampleDB
db2 prep $(NAME).sqc bindfile
db2 bind $(NAME).bnd
db2 connect reset
$(CC) $(CFLAGS) -c $(NAME).c
$(CC) $(CFLAGS) -o $(NAME) $(NAME).o util.o $(LIBS)
clean:
rm -f $(NAME) $(NAME).c $(NAME).o $(NAME).bnd
util.o : util.c
$(CC) -c util.c $(CFLAGS)
一个可能的 (Unix) shell 脚本和 Makefile 示例足以提供帮助。
谢谢。
I have written 3 .sqc files i.e. embedded sql in host language C. I need to make a (Unix) shell script to simply compile all 3 sqc files in a row. How can I do that? Right now, I can individually run each .sqc file using a Makefile that basically converts the .sqc file to a c file and then compiles it. Can I make 3 individual Makefiles and run all of them through a shell script? If so, then how? Can I make one Makefile that can compile all 3 .sqc independently and compile them thereafter through a shell script? If so, then how? Any other options?
Here is the Makefile that can only compile a single .sqc file:
NAME=sample
DB2PATH = /sqllib
CC=gcc
CFLAGS=-I$(DB2PATH)/include
LIBS=-L$(DB2PATH)/lib -R$(DB2PATH)/lib -ldb2
all: $(NAME)
$(NAME): $(NAME).sqc util.o
db2 connect to sampleDB
db2 prep $(NAME).sqc bindfile
db2 bind $(NAME).bnd
db2 connect reset
$(CC) $(CFLAGS) -c $(NAME).c
$(CC) $(CFLAGS) -o $(NAME) $(NAME).o util.o $(LIBS)
clean:
rm -f $(NAME) $(NAME).c $(NAME).o $(NAME).bnd
util.o : util.c
$(CC) -c util.c $(CFLAGS)
A possible (Unix) shell script and Makefile example would suffice to help.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个 Makefile 应该一步完成所有三件事,只需输入“make”即可。请注意,您必须更改第二行以反映真实的 .sqc 文件的名称。
另请注意,我不熟悉 sqc 并且我还没有测试过这个,我只是根据您的 Makefile 进行工作。
This Makefile should do all three in one step, just type "make". Note that you'll have to change the second line to reflect the names of your real .sqc files.
Also note that I'm not familiar with sqc and I haven't tested this, I'm just working from your Makefile.
假设您有三个文件: file1.sqc file2.sqc file3.sqc,并且您的 makefile 保存为 mksqc.mk
脚本:
suppose you have three files: file1.sqc file2.sqc file3.sqc, and your makefile is saved as mksqc.mk
Script: