我正试图在这里做一些棘手的事情。
目前,我的makefile将可执行文件命名为父目录,这很好。但我想改进它。例如,/home/Daniel/project1/**files here**
中的文件很少,可执行文件名为project1
假设我在目录中有10个文件,只有其中一个,“main.c”获得了主要功能 - 我希望makefile命名可执行文件“main”。
这是我当前的makefile:
# Declaration of variables
COMPILE = gcc -m32 -g -ansi -Wall -c
COMPILE_ASM = nasm -g -f elf -w+all
LINK = gcc -m32 -g -Wall -o
# File names
EXEC = $(notdir $(shell pwd))
SOURCES_C = $(wildcard *.c)
SOURCES_ASM = $(wildcard *.s)
OBJECTS = $(SOURCES_C:.c=.o) $(SOURCES_ASM:.s=.o)
all: clean $(EXEC)
# Main target
$(EXEC): $(OBJECTS)
$(LINK) $(EXEC) $(OBJECTS)
# To obtain object files from .c files
%.o: %.c
$(COMPILE) $< -o $@
# To obtain object files from .s files
%.o: %.s
$(COMPILE_ASM) $< -o $@
# To remove generated files
clean:
rm -rf $(EXEC) $(OBJECTS)