Makefile写法之一

2015/01/0520:57:33 发表评论

 


INC = -I./
TARGET = myprogram


BASEDIR=./
OBJDIR=./obj/

SRCDIR=$(BASEDIR)
SRCDIR+=$(shell ls -F $(BASEDIR) | grep "/")

VPATH=$(SRCDIR)

SOURCE=$(foreach subdir, ${SRCDIR}, $(wildcard ${subdir}*.c))

SRC=$(notdir $(SOURCE))

SRCOBJ=$(patsubst %.c,%.o,$(SRC))
OBJ=$(addprefix $(OBJDIR), $(SRCOBJ))

.PHONY:clean

all: $(OBJDIR) $(TARGET)

$(OBJDIR):
	@if [ ! -d $(OBJDIR) ]; then mkdir $(OBJDIR); fi

$(OBJDIR)%.o: %.c
	gcc  -c  $< -o $@  $(INC) 
	@echo Compile $< ... $@ 

$(TARGET): $(OBJ)
	gcc -L. -Bstatic -pthread  $^ -o $(TARGET) $(INC)  $(LIB)  
	@echo Build... $(TARGET) 

install:
	@cp $(TARGET) ../bin
clean:
	@$(RM) $(OUTPUT) $(OBJDIR) -rf
	@$(RM) $(TARGET) 
tar:
	./install.sh

 

  • 微信扫码赞助
  • weinxin
  • 支付宝赞助
  • weinxin

发表评论

您必须才能发表评论!