makefile

makefile_第1张图片makefile_第2张图片makefile_第3张图片makefile_第4张图片makefile_第5张图片makefile_第6张图片makefile_第7张图片




************************************************************************************

SRC_DIR = ./src/
LIB_DIR = ./lib/
INC_DIR = ./inc/
DEMO_DIR = ./demo/
BIN_DIR = ./bin/

SRC = $(wildcard $(SRC_DIR)*.c)
OBJ = $(patsubst %.c, %.o, $(SRC))

DEMO_SRC = $(DEMO_DIR)*.c
TARGET_NAME = app

LIB_NAME = libmystr.a

CC = gcc
AR = ar -rs
CP = install -c 

COMPILE = $(CC) -c $(CFLAGS) 
MODULE_LIB = -L $(LIB_DIR)

CFLAGS += -Wall -g -I$(INC_DIR)
LDFLAGS += -lmystr

all:$(LIB_NAME)

$(LIB_NAME):$(OBJ)
	$(AR) $(LIB_NAME) $(OBJ)
	$(CP) $(LIB_NAME) $(LIB_DIR)
	make demo

%.o:%.c
	$(COMPILE) $< -o $@

demo:
	#$(CC) -o $(DEMO_DIR)$(TARGET)  $(DEMO_SRC) $(CFLAGS) $(MODULE_LIB) $(LDFLAGS)
	$(CC) -o $(BIN_DIR)$(TARGET_NAME)  $(DEMO_SRC) $(CFLAGS) $(MODULE_LIB) $(LDFLAGS)

.PHONY: clean all demo

clean:
	$(RM) $(OBJ)
	$(RM) $(BIN_DIR)$(TARGET_NAME)
	$(RM) $(LIB_DIR)$(LIB_NAME)
	$(RM) $(LIB_NAME)


********************************************

src = $(wildcard $(src_path)*.c)
obj = $(patsubst $(src_path)%.c, $(obj_path)%.o, $(src))
target = $(patsubst $(src_path)%.c, $(obj_path)%, $(src))

CC = gcc
CFLAGS = -Wall -g
myflags = -lm
src_path = ./
obj_path = ./

all:$(target)

$(target):%:%.o
	$(CC) $< -o  $@ $(CFLAGS) $(myflags) 


#all: app

#app: $(obj)
#	$(CC) $^ -o $@ $(CFLAGS) $(myflags)

$(obj_path)%.o:$(src_path)%.c
	$(CC) -c $< -o $@ $(CFLAGS)


clean:
	@echo "clean object:"
	-rm -rf $(target) $(obj)
	@echo "clean complete"

.PHONY: clean all


你可能感兴趣的:(makefile)