linux 应用软件 通用的makefile
0赞
一般开发应用软件时,常考虑文件的增减而需要修改makefile,或采用autoconf,都比较麻烦,
这里提供一个相对通用的,使用时把所有的文件都放在一个目录,然后编译即可。
自动编译当前目录所有的文件。
文件内容如下:
TARGET = hello.out
CROSS_COMPILE = arm-linux-
#
# include the make variable (CC, etc...)
#
CC = $(CROSS_COMPILE)gcc
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
LDR = $(CROSS_COMPILE)ldr
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB = $(CROSS_COMPILE)RANLIB
CFLAGS =
LDFLAGS = -static
SRC_LST = $(shell find -name "*.c")
OBJECTS = $(subst .c,.o,$(SRC_LST))
LOBJECTS = $(OBJECTS)
all: BUILD_START $(TARGET) BUILD_END
BUILD_START:
@clear
@$(CC) --v
@echo "-------------------Build Start-------------------"
BUILD_END:
cp $(TARGET) /home/dev/application/appImage/usr/sbin/pro/
@echo "-------------------Build End-------------------"
$(TARGET): $(LOBJECTS)
$(CC) $(LDFLAGS) $(LOBJECTS) -o $@
$(OBJECTS): %.o : %.c
$(CC) -c $(CFLAGS) $< -o $@
clean:
rm -rf *.o
rm -rf $(TARGET)