我可以为C项目重新生成一个makefile,具有正确的链接顺序和依赖关系吗?

GMa*_*cci 5 c unix linux makefile

我有源代码我最后一次工作在90年代后期 - 2000并且全部备份,除了makefile(是的,谴责,坏备份几乎和没有备份一样好):所以......我想知道是否有是生成makefile的自动方式还是快速分析依赖关系的好方法?

具体我正在寻找:

  • 一个可以分析依赖关系并为我纠正链接顺序的工具.
  • 如果不存在,那么建议非常感谢如何从过去遇到类似问题的人那里最好地解决这个问题
  • 如果上述两个选项中的任何一个失败,我认为最好的方法是创建一个分析/生成文件创建工具,它可以自动生成链接的依赖关系顺序(由于时间总是供不应求,我已经暂停了这种方法在另一个项目中).

这个寻求帮助/建议的原因是代码库是300,000行代码(不包括注释)并且跨越数百个C/O文件,并且我经常尝试手工创建一个make文件,这令人沮丧并且混淆,因此我最后一次尝试寻求帮助并在这里提出要求.

供参考:我过去曾尝试过Cmake,AutoMake,GenMake和类似的工具来生成makefile,但都无济于事,因为依赖是可怕的.


通用makefile脚本

因为它可能对其他人有用,这里是我通常用于较少复杂的C和C++项目的makefile,因为它节省了我每次都要担心创建一个新的:

$(VERBOSE).SILENT:
PROGRAMNAME = prog
CC = gcc
CC += -c
CPP = g++
CPP += -c
ASM = nasm
ASM += -f elf -d ELF_TYPE
LD = g++
OBJFILES = $(patsubst %.c,%.o,$(wildcard *.c))
OBJFILES += $(patsubst %.s,%.o,$(wildcard *.s))
OBJFILES += $(patsubst %.cpp,%.o,$(wildcard *.cpp))

all: $(PROGRAMNAME)

clean:
    @echo "Cleaning object files"
    @echo "    rm -f     *.o"
    rm -f *.o
    @echo "Cleaning backups"
    @echo "    rm -f     *~"
    rm -f *~
    @echo "Removing program file"
    @echo "    rm -f     "$(PROGRAMNAME)
    rm -f $(PROGRAMNAME)

%.o: %.s
    @echo "Assembling ASMs "$@
    @echo "    ASM       "$<
    $(ASM) $<

%.o: %.c
    @echo "(C)ompiling "$@
    @echo "    CC        "$<
    $(CC) $<

%.o: %.cpp
    @echo "(C++)ompiling "$@
    @echo "    CPP       "$<
    $(CPP) $<

$(PROGRAMNAME): $(OBJFILES)
    @echo "Get ready...."
    @echo "Linking "$@
    @echo "    LD        -o "$(PROGRAMNAME)"        "$(OBJFILES)
    $(LD) -o $(PROGRAMNAME) $(OBJFILES)
    @echo "Cry if it worked! Scream swear and cry if it did not..."

strip: $(PROGRAMNAME)
    @echo "Stripping "$(PROGRAMNAME)
    echo -n "Size of "$(PROGRAMNAME)" before stripping is "
    ls -sh $(PROGRAMNAME) | cut -d' ' -f1
    @echo "    Stripping     "$(PROGRAMNAME)
    strip $(PROGRAMNAME)
    echo -n "Size of "$(PROGRAMNAME)" after stripping is "
    ls -sh $(PROGRAMNAME) | cut -d' ' -f1

nothing:
    @echo "Nothing to do; see you later - I'm going home!!!"
    @echo "Hey, try some of these:"
    @echo "make all   - this would be the one you want"
    @echo "make strip - does not work in the real world, only in computers"
    @echo "make clean - will help clean your mind up"
Run Code Online (Sandbox Code Playgroud)

lib*_*rik 4

您正在寻找来自 MIT 的经典 Unix 工具makedepend