当前位置: 技术问答>linux和unix
如何在便编写一个makefile,使其编译时能产生可执行文件?急!谢谢帮忙!
来源: 互联网 发布时间:2015-03-10
本文导语: 我的makefile.bak是这样写的 all: gtk_pizza message_box mkphone clean: rm -f *.o gtk_pizza CC = gcc -g -Wall -m486 `gtk-config --cflags` -I/usr/local/pgsql/include PGLIBS = -L/usr/local/pgsql/lib -lpq -lcrypt OBJS = data_entry.o gtkinput.o pizza_utils.o...
我的makefile.bak是这样写的
all: gtk_pizza message_box mkphone
clean:
rm -f *.o gtk_pizza
CC = gcc -g -Wall -m486 `gtk-config --cflags` -I/usr/local/pgsql/include
PGLIBS = -L/usr/local/pgsql/lib -lpq -lcrypt
OBJS = data_entry.o gtkinput.o pizza_utils.o
cust_maint.o
suburb_maint.o
date_setter.o
item_maint.o
store_maint.o
user_maint.o
cat_maint.o
seat_maint.o
select_screen.o
select_cust.o
merge_cust.o
cust_details.o
dockets.o
order_entry.o
display_file.o
inform_all.o
changed_report.o
language.o
reports.o
HEADERS = cust_maint.h
suburb_maint.h
item_maint.h
store_maint.h
user_maint.h
cat_maint.h
seat_maint.h
select_screen.h
select_cust.h
merge_cust.h
cust_details.h
dockets.h
order_entry.h
language.h
reports.h
date_setter.o: date_setter.c date_setter.h
${CC} -c date_setter.c
reports.o: reports.c reports.h display_file.h
${CC} -c reports.c
inform_all.o: inform_all.c inform_all.h
${CC} -c inform_all.c
changed_report.o: changed_report.c reports.h order_entry.h
${CC} -c changed_report.c
order_entry.o: order_entry.c order_entry.h pizza_utils.h select_screen.h dockets.h
cust_details.h inform_all.h display_file.h
${CC} -c order_entry.c
display_screen.o: display_screen.c order_entry.h
${CC} -c display_screen.c
dockets.o: dockets.c dockets.h pizza_utils.h order_entry.h
${CC} -c dockets.c
cust_details.o: cust_details.c pizza_utils.h select_screen.h dockets.h order_entry.h select_cust.h
${CC} -c cust_details.c
merge_cust.o: merge_cust.c pizza_utils.h select_screen.h cust_details.h
${CC} -c merge_cust.c
select_cust.o: select_cust.c pizza_utils.h select_screen.h cust_details.h
${CC} -c select_cust.c
select_screen.o: select_screen.c pizza_utils.h cust_details.h order_entry.h reports.h date_setter.h
${CC} -c select_screen.c
cat_maint.o: cat_maint.c pizza_utils.h
${CC} -c cat_maint.c
user_maint.o: user_maint.c pizza_utils.h
${CC} -c user_maint.c
store_maint.o: store_maint.c pizza_utils.h
${CC} -c store_maint.c
item_maint.o: item_maint.c pizza_utils.h
${CC} -c item_maint.c
suburb_maint.o: suburb_maint.c pizza_utils.h
${CC} -c suburb_maint.c
cust_maint.o: cust_maint.c pizza_utils.h
${CC} -c cust_maint.c
pizza_utils.o: pizza_utils.c pizza_utils.h
${CC} -c pizza_utils.c
gtk_pizza: gtk_pizza.o pizza_utils.h ${HEADERS} ${OBJS}
${CC} -Wall -o gtk_pizza gtk_pizza.o ${OBJS} ${GTKLIBS} ${PGLIBS}
`gtk-config --libs`
-lgdk_imlib -ljpeg -lgif -lpng -ltiff -lX11 -lz
mkphone: mkphone.c
${CC} -Wall -o mkphone mkphone.c ${PGLIBS}
message_box: message_box.c
${CC} -o message_box message_box.c `gtk-config --cflags` `gtk-config --libs`
denom: denom.c
${CC} -o denormalize denom.c ${PGLIBS}
denormalize
如何修改,才能生成可执行文件,一旦生成可执行文件,即刻送分!因为这个文件是网上下的,所以我不是很看的懂,希望指教!
all: gtk_pizza message_box mkphone
clean:
rm -f *.o gtk_pizza
CC = gcc -g -Wall -m486 `gtk-config --cflags` -I/usr/local/pgsql/include
PGLIBS = -L/usr/local/pgsql/lib -lpq -lcrypt
OBJS = data_entry.o gtkinput.o pizza_utils.o
cust_maint.o
suburb_maint.o
date_setter.o
item_maint.o
store_maint.o
user_maint.o
cat_maint.o
seat_maint.o
select_screen.o
select_cust.o
merge_cust.o
cust_details.o
dockets.o
order_entry.o
display_file.o
inform_all.o
changed_report.o
language.o
reports.o
HEADERS = cust_maint.h
suburb_maint.h
item_maint.h
store_maint.h
user_maint.h
cat_maint.h
seat_maint.h
select_screen.h
select_cust.h
merge_cust.h
cust_details.h
dockets.h
order_entry.h
language.h
reports.h
date_setter.o: date_setter.c date_setter.h
${CC} -c date_setter.c
reports.o: reports.c reports.h display_file.h
${CC} -c reports.c
inform_all.o: inform_all.c inform_all.h
${CC} -c inform_all.c
changed_report.o: changed_report.c reports.h order_entry.h
${CC} -c changed_report.c
order_entry.o: order_entry.c order_entry.h pizza_utils.h select_screen.h dockets.h
cust_details.h inform_all.h display_file.h
${CC} -c order_entry.c
display_screen.o: display_screen.c order_entry.h
${CC} -c display_screen.c
dockets.o: dockets.c dockets.h pizza_utils.h order_entry.h
${CC} -c dockets.c
cust_details.o: cust_details.c pizza_utils.h select_screen.h dockets.h order_entry.h select_cust.h
${CC} -c cust_details.c
merge_cust.o: merge_cust.c pizza_utils.h select_screen.h cust_details.h
${CC} -c merge_cust.c
select_cust.o: select_cust.c pizza_utils.h select_screen.h cust_details.h
${CC} -c select_cust.c
select_screen.o: select_screen.c pizza_utils.h cust_details.h order_entry.h reports.h date_setter.h
${CC} -c select_screen.c
cat_maint.o: cat_maint.c pizza_utils.h
${CC} -c cat_maint.c
user_maint.o: user_maint.c pizza_utils.h
${CC} -c user_maint.c
store_maint.o: store_maint.c pizza_utils.h
${CC} -c store_maint.c
item_maint.o: item_maint.c pizza_utils.h
${CC} -c item_maint.c
suburb_maint.o: suburb_maint.c pizza_utils.h
${CC} -c suburb_maint.c
cust_maint.o: cust_maint.c pizza_utils.h
${CC} -c cust_maint.c
pizza_utils.o: pizza_utils.c pizza_utils.h
${CC} -c pizza_utils.c
gtk_pizza: gtk_pizza.o pizza_utils.h ${HEADERS} ${OBJS}
${CC} -Wall -o gtk_pizza gtk_pizza.o ${OBJS} ${GTKLIBS} ${PGLIBS}
`gtk-config --libs`
-lgdk_imlib -ljpeg -lgif -lpng -ltiff -lX11 -lz
mkphone: mkphone.c
${CC} -Wall -o mkphone mkphone.c ${PGLIBS}
message_box: message_box.c
${CC} -o message_box message_box.c `gtk-config --cflags` `gtk-config --libs`
denom: denom.c
${CC} -o denormalize denom.c ${PGLIBS}
denormalize
如何修改,才能生成可执行文件,一旦生成可执行文件,即刻送分!因为这个文件是网上下的,所以我不是很看的懂,希望指教!
|
如果你确实看到了gtk_pizza这个可执行文件,我怀疑你没有加路径,不如用./gtk_pizza来执行试试
|
你的这个Makefile也太累了!
试试看这个:
#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