【发布时间】:2021-05-14 13:21:52
【问题描述】:
我一直在尝试将多个大型 ada 编译从基于脚本的方法转换为使用 gnu make 3.82 makefile,并且可以使用一些经验丰富的知识。
一些背景:
- 红帽企业 Linux 7.9 版上的 GNAT 4.8.5
- 每次编译都以约 1000 个 .ada 文件的源列表开始
- 不同的版本使用一些相同的文件,在每个源列表中大约 14k 的文件总数中只有大约 7000 个唯一文件
- 每个文件都需要准备、切碎,然后编译 - 绑定和链接在别处完成
我的做法:
- 方法 1:对于每个文件,将文件准备到 src/foo/prepped 中,然后切入 src/foo/chopped 中
- 配方 2:将配方 1 中创建的每个切碎文件复制到模块 SRC/ 文件夹中
- 配方 3:将配方 2 中的每个切碎的文件编译到 SRC/ 文件夹中,并放在 OBJ/ 文件夹中
问题:
- 切碎阶段会导致问题,因为文件名已更改,并且在某些情况下会创建更多文件。为了解决这个问题,我尝试为每个 src/foo/prepped 文件夹的内容添加通配符,并将它们复制到 SRC/ 文件夹中进行编译。由于此列表在 prep/chop 阶段之前是未知的,因此需要再次调用 make 以获取这些文件名。
- 在编译阶段,我盲目地运行 SRC/ 文件夹中的每个文件以使用双冒号规则进行编译,因为我不确定在编译阶段输出的文件(.ali 或 .o)
- 如果文件已经从之前的编译中进行了准备/截断,它将不会进行双重工作准备/截断,但不会将文件复制到 SRC/
问题:
- 在事先不知道的情况下,如何解释使用 gnatchop 输出的文件?
- 在编译阶段,如何编写可以从 .adb 或 .ads 文件创建 .o 或 .ali 文件的规则?
FILE:= 'input' #read input from file
OBJECTS:=$(shell cat ${FILE}) #need to do this, no file function in gnu make 3.82
FPOBJECTS:= $(addprefix ../../src/, $(OBJECTS)) # path + source name from pwd
OBJFILE:=$(notdir $(OBJECTS)) #just get out source file name
PDIR:=$(addprefix ../../src/, $(addsuffix prepped/ , $(dir $(OBJECTS)))) #just get out directory part of objects, add prepped/ suffix and ../../src to beginning
CDIR:= $(addprefix ../../src/, $(addsuffix chopped/ , $(dir $(OBJECTS))))# same as PDIR but with chopped/ instead of prepped/
CDIR2:= $(sort $(CDIR)) # unique directories in CDIR for folder creation
PDIR2:= $(sort $(PDIR)) # unique directories in PDIR for folder creation
DIRS:= OBJ TMP SRC #directories inside lib/version*
POBJECTS:= $(basename $(join $(PDIR), $(OBJFILE))) # join prepped directory with objects
COBJECTS = $(addprefix OBJ/, $(notdir $(wildcard SRC/*))) # this is an incorrect way to generate the objects needed, but does allow me to pass each source file for compilation
GNATOPTIONS:= -c -O1 -w -fPIC -gnatE -gnatv -LSRC/ # gcc flags
CDIRwld:=$(shell echo $(addsuffix *, $(CDIR2))) #append * to each unique chopped directory, to try and get names of each chopped file
.RECIPEPREFIX = >
#compile creates the COBJECTS in the pwd and moves them where they belong
compile : $(COBJECTS)
>mv *.ali OBJ/
>mv *.o OBJ/
$(COBJECTS)::
>gcc $(GNATOPTIONS) SRC/$(@F)
copy : $(CDIRwld)
>cp $? SRC/
prep : $(POBJECTS)
$(POBJECTS):$(FPOBJECTS) | $(DIRS) $(PDIR2) $(CDIR2)
>gnatprep -cru -Dlil $(addsuffix .ada, $(subst prepped/,,$@)) $(basename $@)
>gnatchop -rw $@ $(subst prepped/,chopped/,$(dir $@))
$(DIRS):
>mkdir -p $@
$(PDIR2):
>mkdir -p $@
$(CDIR2):
>mkdir -p $@
.PHONY: clean move
clean :
>rm -f -r $(DIRS)
>rm -f -r $(PDIR2)
>rm -f -r $(CDIR2)
move :
>mv *.ali OBJ/
>mv *.o OBJ/
【问题讨论】:
-
哪个操作系统?您使用的是什么版本的 GNAT?
-
感谢您的询问 Simon - 我们在 Red Hat Enterprise Linux 7 版本 7.9 上使用 GNAT 4.8.5
标签: makefile compilation gnu-make ada gnat