linux 通用Makefile模板

Makefile:

EXEC = vdpd
TGTDIR=./


CFLAGS += -Wall -I./include -I../3p/openssl-0.9.8i/linux/x86_64/include -I../3p/lib_quagga-1.0.0/src -D HAVE_CONFIG_H -g
CFLAGS += -I../3p/zlib-1.2.8/linux/include
CFLAGS += -I../libs/base/include
CFLAGS += -I../3p/libxml2-2.9.0/src/include
CFLAGS += -I../3p/libiconv-1.14/linux/include


LDFLAGS += -L../3p/libiconv-1.14/linux/lib
LDFLAGS += -L../3p/libxml2-2.9.0/linux/lib
LDFLAGS += -L../libs/base/src -lvdp_base
LDFLAGS += -L/usr/lib64/mysql -lmysqlclient
LDFLAGS += -L../3p/zlib-1.2.8/linux/lib -lz
LDFLAGS += -L../3p/lib_quagga-1.0.0/linux/lib \
-L../3p/openssl-0.9.8i/linux/x86_64/lib \
-lquagga -lcrypt -lrt -lcap -lssl -lcrypto -lxml2 -liconv


include $(TGTDIR)/Makefile.inc







Makefile.inc



ifeq ($(TGTDIR), )

TGTDIR = $(shell pwd)/..
endif


INSDIR = $(TGTDIR)/rootfs


export TGTDIR LNXDIR INSDIR


CROSS_COMPILE   = 


AS      = $(CROSS_COMPILE)as
LD      = $(CROSS_COMPILE)ld
CC      = $(CROSS_COMPILE)gcc
CPP     = $(CC) -E
AR      = $(CROSS_COMPILE)ar
NM      = $(CROSS_COMPILE)nm
STRIP   = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB  = $(CROSS_COMPILE)ranlib


VERBOSE = 0


ifeq ($(SRCS), )
SRCS    = $(wildcard *.c)
endif


OBJS_DIR=./


OBJS    = $(patsubst %.c, $(OBJS_DIR)%.o, $(SRCS))
DEPS    = $(patsubst %.c, $(OBJS_DIR).%.d, $(SRCS))


#.PHONY: $(SUBDIRS) $(DEPS) $(OBJS) $(EXEC) $(SLIB) $(SHLIB)


all: $(SUBDIRS) $(DEPS) $(OBJS) $(EXEC) $(SLIB) $(SHLIB)


ifeq ($(VERBOSE), 0)


$(OBJS_DIR)%.o : %.c
@echo -e "  CC\t$@"
@$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@


$(OBJS_DIR).%.d : %.c
@echo -e "  DEP\t$@" 
@$(CC) -c -MM $(CFLAGS) $(CPPFLAGS) $< -o $@


$(EXEC): $(OBJS)
@echo -e "  LD\t$@"
@$(CC) $(OBJS) $(LDFLAGS) -o $@


$(SHLIB): $(OBJS)
@echo -e "  LD\t$@"
@$(CC) $(OBJS) $(LDFLAGS) -o $@


$(SLIB): $(OBJS)
@echo -e "  AR\t$@"
@$(AR) cr $@ $<
@$(RANLIB) $@


$(SUBDIRS)::
@echo -e "MAKE\t[$@]"
@$(MAKE) --no-print-directory -C $@ 


else


$(OBJS_DIR)%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@


$(OBJS_DIR).%.d : %.c
$(CC) -c -MM $(CFLAGS) $(CPPFLAGS) $< -o $@


$(EXEC): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $@


$(SHLIB): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $@


$(SLIB): $(OBJS)
$(AR) cr $@ $<
$(RANLIB) $@


$(SUBDIRS)::
$(MAKE) -C $@ 




endif


install_dirs := $(addprefix _install_, $(SUBDIRS))
$(install_dirs):
@$(MAKE) -C $(patsubst _install_%, %, $@) install


install: $(install_dirs)
ifneq ($(EXEC), )
cp $(EXEC) $(INSDIR)/xlrose
endif
ifneq ($(SHLIB), )
cp $(SHLIB) $(INSDIR)/lib
endif


clean_dirs := $(addprefix _clean_, $(SUBDIRS))


$(clean_dirs):
@$(MAKE) -C $(patsubst _clean_%, %, $@) clean


clean: $(clean_dirs)
rm -f $(OBJS_DIR).*.d $(OBJS_DIR)*.o $(OBJS_DIR)*.a $(OBJS_DIR)*.so $(EXEC) $(SHLIB) $(SLIB)




-include $(DEPS)

你可能感兴趣的:(shell,编译器)