如何编写shell脚本来编译C文件(.sqc)中的多个嵌入sql?

发布于 2024-09-08 01:51:14 字数 869 浏览 0 评论 0原文

我已经编写了 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 技术交流群。

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

发布评论

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

评论(2

明媚殇 2024-09-15 01:51:14

这个 Makefile 应该一步完成所有三件事,只需输入“make”即可。请注意,您必须更改第二行以反映真实的 .sqc 文件的名称。

另请注意,我不熟悉 sqc 并且我还没有测试过这个,我只是根据您的 Makefile 进行工作。

# THIS IS THE ONLY LINE YOU'LL HAVE TO CHANGE:
NAMES = file1 file2 file3

DB2PATH = /sqllib
CC=gcc
CFLAGS=-I$(DB2PATH)/include
LIBS=-L$(DB2PATH)/lib -R$(DB2PATH)/lib -ldb2

all: $(NAMES)

# This will convert .sqc into .c
%.c: %.sqc
    db2 connect to sampleDB
    db2 prep 
lt; bindfile
    db2 bind $*.bnd
    db2 connect reset

# This will compile .c into .o, whether it's fileN.c or util.c
%.o: %.c
    $(CC) $(CFLAGS) -c 
lt; -o $@

# This will link fileN.o and util.o into fileN
$(NAMES): % : %.o util.o
    $(CC) $(CFLAGS) -o $@ $^ $(LIBS)

# This is just to assure Make that that isn't really a file called "clean"
.PHONY: clean

clean:
    rm -f $(NAMES) $(NAMES:=.c) $(NAMES:=.o) $(NAMES:=.bnd)

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.

# THIS IS THE ONLY LINE YOU'LL HAVE TO CHANGE:
NAMES = file1 file2 file3

DB2PATH = /sqllib
CC=gcc
CFLAGS=-I$(DB2PATH)/include
LIBS=-L$(DB2PATH)/lib -R$(DB2PATH)/lib -ldb2

all: $(NAMES)

# This will convert .sqc into .c
%.c: %.sqc
    db2 connect to sampleDB
    db2 prep 
lt; bindfile
    db2 bind $*.bnd
    db2 connect reset

# This will compile .c into .o, whether it's fileN.c or util.c
%.o: %.c
    $(CC) $(CFLAGS) -c 
lt; -o $@

# This will link fileN.o and util.o into fileN
$(NAMES): % : %.o util.o
    $(CC) $(CFLAGS) -o $@ $^ $(LIBS)

# This is just to assure Make that that isn't really a file called "clean"
.PHONY: clean

clean:
    rm -f $(NAMES) $(NAMES:=.c) $(NAMES:=.o) $(NAMES:=.bnd)
雄赳赳气昂昂 2024-09-15 01:51:14
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) 

假设您有三个文件: file1.sqc file2.sqc file3.sqc,并且您的 makefile 保存为 mksqc.mk

脚本:

make -f mksqc.mk NAME=file1
make -f mksqc.mk NAME=file2
make -f mksqc.mk NAME=file3
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) 

suppose you have three files: file1.sqc file2.sqc file3.sqc, and your makefile is saved as mksqc.mk

Script:

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