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)
归档时间: |
|
查看次数: |
1194 次 |
最近记录: |