当前位置: 技术问答>linux和unix
关于makefile的问题?
来源: 互联网 发布时间:2015-03-24
本文导语: 我的程序里面include了,这2个头文件 怎么样在makefile里写啊? 谢谢各位了。 | 我的程序里面include了,这2个头文件 编译带参数: -lpthread -lghttp | 假设,这2个头文件在路径/usr/my/include下 ...
我的程序里面include了,这2个头文件
怎么样在makefile里写啊?
谢谢各位了。
怎么样在makefile里写啊?
谢谢各位了。
|
我的程序里面include了,这2个头文件
编译带参数:
-lpthread -lghttp
编译带参数:
-lpthread -lghttp
|
假设,这2个头文件在路径/usr/my/include下
加编译参数:
-I/usr/my/include
可能的cc语句如下:
cc -g -c -I/usr/my/include a.c
加编译参数:
-I/usr/my/include
可能的cc语句如下:
cc -g -c -I/usr/my/include a.c
|
试试看这个:
#Makefile
####################################################################
# Customising :
#
# Adjust the following if necessary; EXECUTABLE is the target
# executable's filename, and LIBS is a list of libraries to link in
# (e.g. alleg, stdcx, iostr, etc). You can override these on make's
# command line of course, if you prefer to do it that way.
####################################################################
PACKAGE := mysqlsync
VERSION := 1.0
EXECUTABLE := mysqlsync # EXE file
TARGETLIB := # library file
INCLUDES := -I/usr/include/mysql
LIBS += -L/usr/lib/mysql -lmysqlclient #-lm
DEMOS := download.c upload.c test.c docreate.c
DISTFILES := $(TARGETLIB)
DISTFILES += $(DEMOS)
exclude_from_build := $(DEMOS)
exclude_from_mklib := $(DEMOS) # for create library, filter out the main(), and so on.
profiling := off # enable profiling (eg: use 'gprof')
CFLAGS := -Wall
CFLAGS += -DLINUX
CFLAGS += -I/usr/include/mysql
####################################################################
# You shouldn't need to change anything below this point.
####################################################################
srcdir = .
top_srcdir = .
top_builddir = .
distdir := $(PACKAGE)-$(VERSION)_$(shell date +%y%m%d_%H%M%S)
# for compile
CC := gcc
override CFLAGS += $(patsubst %,-I%,$(subst :, ,$(VPATH)))
ifeq "$(strip $(profiling))" "on"
build: CFLAGS += -pg # enable profiling
endif
mklib: CFLAGS += -fPIC # for create library
SOURCES := $(wildcard *.c)
BUD_OBJS := $(patsubst %.c,%.o,$(filter-out $(exclude_from_build),$(SOURCES)))
LIB_OBJS := $(patsubst %.c,%.o,$(filter-out $(exclude_from_mklib),$(SOURCES)))
vpath %.c src/:Src/:SRC/
vpath %.h header/
# for create library
AR := ar
ARFLAGS := r
# for release library
TAR = gtar
GZIP_ENV = --best
########################################################
# rules
########################################################
all: build
build: $(EXECUTABLE)
mklib: $(TARGETLIB)
rebuild:clean build
remklib:clean cleanlib mklib
$(EXECUTABLE): $(BUD_OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) $(INCLUDES)
$(TARGETLIB): $(LIB_OBJS)
$(AR) $(ARFLAGS) $@ $^
dist: distdir
-chmod -R a+r $(distdir)
GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
-rm -rf $(distdir)
distdir: $(DISTFILES)
-rm -rf $(distdir)
mkdir $(distdir)
-chmod 777 $(distdir)
here=`cd $(top_builddir) && pwd`;
top_distdir=`cd $(distdir) && pwd`;
distdir=`cd $(distdir) && pwd`
@for file in $(DISTFILES); do
cp -pr $(srcdir)/$$file $(distdir)/$$file;
done
########################################################
# depends
########################################################
#depends.d:$(SOURCES)
# $(CC) -MM $^ > $@
#include depends.d
mkdep: %.d
%.d: %.c
set -e; $(CC) -MM $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $ $@;
[ -s $@ ] || rm -f $@
include $(SOURCES:.c=.d)
########################################################
# clean
########################################################
cleanall: cleanbin cleanlib cleandep
clean: cleanbin
cleanbin:
rm -f $(EXECUTABLE) *.o *~
cleanlib:
rm -f *.a *.o *~
cleandep:
rm -f *.d
.PHONY: all build mklib rebuild remklib
dist distdir mkdep
cleanall clean cleanbin cleanlib cleandep
#Makefile
####################################################################
# Customising :
#
# Adjust the following if necessary; EXECUTABLE is the target
# executable's filename, and LIBS is a list of libraries to link in
# (e.g. alleg, stdcx, iostr, etc). You can override these on make's
# command line of course, if you prefer to do it that way.
####################################################################
PACKAGE := mysqlsync
VERSION := 1.0
EXECUTABLE := mysqlsync # EXE file
TARGETLIB := # library file
INCLUDES := -I/usr/include/mysql
LIBS += -L/usr/lib/mysql -lmysqlclient #-lm
DEMOS := download.c upload.c test.c docreate.c
DISTFILES := $(TARGETLIB)
DISTFILES += $(DEMOS)
exclude_from_build := $(DEMOS)
exclude_from_mklib := $(DEMOS) # for create library, filter out the main(), and so on.
profiling := off # enable profiling (eg: use 'gprof')
CFLAGS := -Wall
CFLAGS += -DLINUX
CFLAGS += -I/usr/include/mysql
####################################################################
# You shouldn't need to change anything below this point.
####################################################################
srcdir = .
top_srcdir = .
top_builddir = .
distdir := $(PACKAGE)-$(VERSION)_$(shell date +%y%m%d_%H%M%S)
# for compile
CC := gcc
override CFLAGS += $(patsubst %,-I%,$(subst :, ,$(VPATH)))
ifeq "$(strip $(profiling))" "on"
build: CFLAGS += -pg # enable profiling
endif
mklib: CFLAGS += -fPIC # for create library
SOURCES := $(wildcard *.c)
BUD_OBJS := $(patsubst %.c,%.o,$(filter-out $(exclude_from_build),$(SOURCES)))
LIB_OBJS := $(patsubst %.c,%.o,$(filter-out $(exclude_from_mklib),$(SOURCES)))
vpath %.c src/:Src/:SRC/
vpath %.h header/
# for create library
AR := ar
ARFLAGS := r
# for release library
TAR = gtar
GZIP_ENV = --best
########################################################
# rules
########################################################
all: build
build: $(EXECUTABLE)
mklib: $(TARGETLIB)
rebuild:clean build
remklib:clean cleanlib mklib
$(EXECUTABLE): $(BUD_OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) $(INCLUDES)
$(TARGETLIB): $(LIB_OBJS)
$(AR) $(ARFLAGS) $@ $^
dist: distdir
-chmod -R a+r $(distdir)
GZIP=$(GZIP_ENV) $(TAR) chozf $(distdir).tar.gz $(distdir)
-rm -rf $(distdir)
distdir: $(DISTFILES)
-rm -rf $(distdir)
mkdir $(distdir)
-chmod 777 $(distdir)
here=`cd $(top_builddir) && pwd`;
top_distdir=`cd $(distdir) && pwd`;
distdir=`cd $(distdir) && pwd`
@for file in $(DISTFILES); do
cp -pr $(srcdir)/$$file $(distdir)/$$file;
done
########################################################
# depends
########################################################
#depends.d:$(SOURCES)
# $(CC) -MM $^ > $@
#include depends.d
mkdep: %.d
%.d: %.c
set -e; $(CC) -MM $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $ $@;
[ -s $@ ] || rm -f $@
include $(SOURCES:.c=.d)
########################################################
# clean
########################################################
cleanall: cleanbin cleanlib cleandep
clean: cleanbin
cleanbin:
rm -f $(EXECUTABLE) *.o *~
cleanlib:
rm -f *.a *.o *~
cleandep:
rm -f *.d
.PHONY: all build mklib rebuild remklib
dist distdir mkdep
cleanall clean cleanbin cleanlib cleandep
|
自己写个简单的吧,上面的makefile文件是用专用的工具写出来的。