#簡單的Makefile
#一些安裝的Shell 都改用 Makefile寫了
# ----------------------------------------------
#
# Sample for Makefile
# usage: make -f sample.mk
# default search path: GNUmakefile makefile Makefile
#
# ----------------------------------------------
# ----------------------------------------------
# include file
# export variable
# ----------------------------------------------
ifeq (.config,$(wildcard .config))
-include .config
endif
export F_PLATFORM=arm
CFLAGS += -Os -I./ -Wall
LDFLAGS += -L/usr/lib
LIBS += -lpthread
# ----------------------------------------------
#
# # : comment
# variable
# := current value
# ?= set if no value
# = last value
# += add value
# ----------------------------------------------
#
# dir setting
#
R_DIR = $(shell pwd)
#
# file
#
SAMPLE_TAR := sample.tar.gz
#
# config
#
CONFIG_A := y
#
# obj
#
OBJ =
ifeq ($(wildcars $(R_DIR)/unpacked),)
OBJ += unpacked
endif
ifeq ($(strip $(CONFIG_A)), y)
OBJ += a
endif
ifeq ($(strip $(CONFIG_A)), y)
OBJ += b
endif
# ----------------------------------------------
# format:
# target: prerequisites(dependency)
# <tab>command
# - : ignore error
# @ : no marco
# ----------------------------------------------
all:$(OBJ)
@echo "-------------------- $@ --------------------"
-ech $(R_DIR)
@echo $(R_DIR)
a.o:
a:a.o
b:b.o
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
# ----------------------------------------------
#
# $@ : target
# $? : prerequisites needed to recompile
# $< : first(current) dependency
# $^ : all dependency
# $* : first(current) dependency , no suffix
#
# ----------------------------------------------
# hidden rule
# %.o:%.c
# $(CC) -c -o $@ $<
# old rule
# .c.o:
# $(CC) -c -o $*.o $<
# ----------------------------------------------
# compile execute
# gcc -o a a.c
# gcc -o a a.o
# gcc a.c -o a
#
# compile .o
# gcc -c a.c -o a.o
# gcc -c -o a.o a.c
# gcc -c a.c
#
# ----------------------------------------------
unpacked:
@echo "-------------------- $@ --------------------"
tar -zxvf $(SAMPLE_TAR)
touch $(R_DIR)/unpacked
clean:
# rm -r *.o
# ----------------------------------------------
#
# .PHONY: for fake target
#
# ----------------------------------------------
.PHONY: all clean
# ----------------------------------------------
# function
# ----------------------------------------------
define dep1
@echo "Hello i am $(0),$(1)"
endef
dep2 = ls -l
ftest:
$(call dep1,"arg1")
$(call dep2,"arg1")
# ----------------------------------------------
# Built-in variables
# ----------------------------------------------
vtest:
@echo "-------------------- $@ --------------------"
@echo AR $(AR)
@echo AS $(AS)
@echo CC $(CC)
@echo CXX $(CXX)
@echo RM $(RM)
@echo ARFLAGS $(ARFLAGS)
@echo CFLAGS $(CFLAGS)
@echo LDFLAGS $(LDFLAGS)
# ----------------------------------------------
# Built-in function
# ----------------------------------------------
# $(patsubst <pattern>,<replacement>,<text>)
# $(strip <string>)
# $(findstring <find>,<in>) ... search by yourself
留言列表