gpt4 book ai didi

c++ - 添加选项以显示百分比时生成文件问题

转载 作者:行者123 更新时间:2023-11-30 05:49:21 28 4
gpt4 key购买 nike

我试图在我的 Makefile 中添加一个选项来显示编译进程的百分比。但是它现在编译不正确,似乎我以某种方式创建了一个循环。

我的生成文件:

SHELL = /bin/sh
SYSTEM = $(shell uname)
C++ = g++
CC = gcc
DFLAGS = -DGHOST_MYSQL
OFLAGS = -O3
LFLAGS = -L. -L../bncsutil/src/bncsutil/ -L../StormLib/stormlib/ -L/usr/local/lib/Poco/ -lPocoNet -lPocoFoundation -lbncsutil -lpthread -ldl -lz -lStorm -lmysqlclient_r -lboost_date_time -lboost_thread -lboost_system -lboost_filesystem -lgmp
CFLAGS =

ifeq ($(SYSTEM),Darwin)
DFLAGS += -D__APPLE__
OFLAGS += -flat_namespace
else
LFLAGS += -lrt
endif

ifeq ($(SYSTEM),FreeBSD)
DFLAGS += -D__FREEBSD__
endif

ifeq ($(SYSTEM),SunOS)
DFLAGS += -D__SOLARIS__
LFLAGS += -lresolv -lsocket -lnsl
endif

CFLAGS += $(OFLAGS) $(DFLAGS) -I. -I../bncsutil/src/ -I../StormLib/

ifeq ($(SYSTEM),Darwin)
CFLAGS += -I../mysql/include/
endif

## PRINT_PROGRESS is initially undefined
ifndef PRINT_PROGRESS
# T estimates how many targets we are building by replacing PRINT_PROGRESS with a special string
T := $(shell $(MAKE) $(MAKECMDGOALS) --no-print-directory \
-rRf $(firstword $(MAKEFILE_LIST)) \
PRINT_PROGRESS="echo COUNTTHIS" BUILD="test x ||" | grep -c "COUNTTHIS")
N := 1
## PRINT_PROGRESS is now defined to show the progress and update N
PRINT_PROGRESS = echo "`expr " [\`expr $N '*' 100 / $T\`" : '.*\(....\)$$'`%]"$(eval N := $(shell expr $N + 1))
endif

OBJS = bncsutilinterface.o bnet.o bnetprotocol.o bnlsclient.o bnlsprotocol.o commandpacket.o config.o crc32.o csvparser.o game.o game_base.o gameplayer.o gameprotocol.o gameslot.o ghost.o ghostdb.o ghostdbmysql.o gpsprotocol.o language.o map.o packed.o replay.o savegame.o sha1.o socket.o stats.o statsdota.o util.o
COBJS =
PROGS = ./ghost++

all: $(OBJS) $(COBJS) $(PROGS)

./ghost++: $(OBJS) $(COBJS)
$(C++) -o ./ghost++ $(OBJS) $(COBJS) $(LFLAGS)

clean:
rm -f $(OBJS) $(COBJS) $(PROGS)

$(OBJS): %.o: %.cpp
@$(PRINT_PROGRESS) $(C++) -o $@ $(CFLAGS) -c $<

$(COBJS): %.o: %.c
@$(PRINT_PROGRESS) $(CC) -o $@ $(CFLAGS) -c $<

./ghost++: $(OBJS) $(COBJS)

all: $(PROGS)

bncsutilinterface.o: ghost.h includes.h util.h bncsutilinterface.h
bnet.o: ghost.h includes.h util.h config.h language.h socket.h commandpacket.h ghostdb.h bncsutilinterface.h bnlsclient.h bnetprotocol.h bnet.h map.h packed.h savegame.h replay.h gameprotocol.h game_base.h
bnetprotocol.o: ghost.h includes.h util.h bnetprotocol.h
bnlsclient.o: ghost.h includes.h util.h socket.h commandpacket.h bnlsprotocol.h bnlsclient.h
bnlsprotocol.o: ghost.h includes.h util.h bnlsprotocol.h
commandpacket.o: ghost.h includes.h commandpacket.h
config.o: ghost.h includes.h config.h
crc32.o: ghost.h includes.h crc32.h
csvparser.o: csvparser.h
game.o: ghost.h includes.h util.h config.h language.h socket.h ghostdb.h bnet.h map.h packed.h savegame.h gameplayer.h gameprotocol.h game_base.h game.h stats.h statsdota.h
game_base.o: ghost.h includes.h util.h config.h language.h socket.h ghostdb.h bnet.h map.h packed.h savegame.h replay.h gameplayer.h gameprotocol.h game_base.h next_combination.h
gameplayer.o: ghost.h includes.h util.h language.h socket.h commandpacket.h bnet.h map.h gameplayer.h gameprotocol.h gpsprotocol.h game_base.h
gameprotocol.o: ghost.h includes.h util.h crc32.h gameplayer.h gameprotocol.h game_base.h
gameslot.o: ghost.h includes.h gameslot.h
ghost.o: ghost.h includes.h util.h crc32.h sha1.h csvparser.h config.h language.h socket.h ghostdb.h ghostdbmysql.h bnet.h map.h packed.h savegame.h gameplayer.h gameprotocol.h gpsprotocol.h game_base.h game.h
ghostdb.o: ghost.h includes.h util.h config.h ghostdb.h
ghostdbmysql.o: ghost.h includes.h util.h config.h ghostdb.h ghostdbmysql.h
gpsprotocol.o: ghost.h util.h gpsprotocol.h
language.o: ghost.h includes.h config.h language.h
map.o: ghost.h includes.h util.h crc32.h sha1.h config.h map.h
packed.o: ghost.h includes.h util.h crc32.h packed.h
replay.o: ghost.h includes.h util.h packed.h replay.h gameprotocol.h
savegame.o: ghost.h includes.h util.h packed.h savegame.h
sha1.o: sha1.h
socket.o: ghost.h includes.h util.h socket.h
stats.o: ghost.h includes.h stats.h
statsdota.o: ghost.h includes.h util.h ghostdb.h gameplayer.h gameprotocol.h game_base.h stats.h statsdota.h
util.o: ghost.h includes.h util.h

我在这里添加的部分是:

## PRINT_PROGRESS is initially undefined
ifndef PRINT_PROGRESS
# T estimates how many targets we are building by replacing PRINT_PROGRESS with a special string
T := $(shell $(MAKE) $(MAKECMDGOALS) --no-print-directory \
-rRf $(firstword $(MAKEFILE_LIST)) \
PRINT_PROGRESS="echo COUNTTHIS" BUILD="test x ||" | grep -c "COUNTTHIS")
N := 1
## PRINT_PROGRESS is now defined to show the progress and update N
PRINT_PROGRESS = echo "`expr " [\`expr $N '*' 100 / $T\`" : '.*\(....\)$$'`%]"$(eval N := $(shell expr $N + 1))
endif

以及这些行的变化:

$(OBJS): %.o: %.cpp
$(C++) -o $@ $(CFLAGS) -c $<

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

$(OBJS): %.o: %.cpp
@$(PRINT_PROGRESS) $(C++) -o $@ $(CFLAGS) -c $<

$(COBJS): %.o: %.c
@$(PRINT_PROGRESS) $(CC) -o $@ $(CFLAGS) -c $<

现在编译时显示的输出是这样的:

$ make
g++: error: bncsutilinterface.o: No such file or directory
g++: error: bnet.o: No such file or directory
g++: error: bnetprotocol.o: No such file or directory
g++: error: bnlsclient.o: No such file or directory
g++: error: bnlsprotocol.o: No such file or directory
g++: error: commandpacket.o: No such file or directory
g++: error: config.o: No such file or directory
g++: error: crc32.o: No such file or directory
g++: error: csvparser.o: No such file or directory
g++: error: game.o: No such file or directory
g++: error: game_base.o: No such file or directory
g++: error: gameplayer.o: No such file or directory
g++: error: gameprotocol.o: No such file or directory
g++: error: gameslot.o: No such file or directory
g++: error: ghost.o: No such file or directory
g++: error: ghostdb.o: No such file or directory
g++: error: ghostdbmysql.o: No such file or directory
g++: error: gpsprotocol.o: No such file or directory
g++: error: language.o: No such file or directory
g++: error: map.o: No such file or directory
g++: error: packed.o: No such file or directory
g++: error: replay.o: No such file or directory
g++: error: savegame.o: No such file or directory
g++: error: sha1.o: No such file or directory
g++: error: socket.o: No such file or directory
g++: error: stats.o: No such file or directory
g++: error: statsdota.o: No such file or directory
g++: error: util.o: No such file or directory
make: *** [ghost++] Error 1
[3%] g++ -o bncsutilinterface.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c bncsutilinterface.cpp
[7%] g++ -o bnet.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c bnet.cpp
[10%] g++ -o bnetprotocol.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c bnetprotocol.cpp
[14%] g++ -o bnlsclient.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c bnlsclient.cpp
[17%] g++ -o bnlsprotocol.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c bnlsprotocol.cpp
[21%] g++ -o commandpacket.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c commandpacket.cpp
[25%] g++ -o config.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c config.cpp
[28%] g++ -o crc32.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c crc32.cpp
[32%] g++ -o csvparser.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c csvparser.cpp
[35%] g++ -o game.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c game.cpp
[39%] g++ -o game_base.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c game_base.cpp
[42%] g++ -o gameplayer.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c gameplayer.cpp
[46%] g++ -o gameprotocol.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c gameprotocol.cpp
[50%] g++ -o gameslot.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c gameslot.cpp
[53%] g++ -o ghost.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c ghost.cpp
[57%] g++ -o ghostdb.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c ghostdb.cpp
[60%] g++ -o ghostdbmysql.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c ghostdbmysql.cpp
[64%] g++ -o gpsprotocol.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c gpsprotocol.cpp
[67%] g++ -o language.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c language.cpp
[71%] g++ -o map.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c map.cpp
[75%] g++ -o packed.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c packed.cpp
[78%] g++ -o replay.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c replay.cpp
[82%] g++ -o savegame.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c savegame.cpp
[85%] g++ -o sha1.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c sha1.cpp
[89%] g++ -o socket.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c socket.cpp
[92%] g++ -o stats.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c stats.cpp
[96%] g++ -o statsdota.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c statsdota.cpp
[100%] g++ -o util.o -O3 -DGHOST_MYSQL -I. -I../bncsutil/src/ -I../StormLib/ -c util.cpp
g++ -o ./ghost++ bncsutilinterface.o bnet.o bnetprotocol.o bnlsclient.o bnlsprotocol.o commandpacket.o config.o crc32.o csvparser.o game.o game_base.o gameplayer.o gameprotocol.o gameslot.o ghost.o ghostdb.o ghostdbmysql.o gpsprotocol.o language.o map.o packed.o replay.o savegame.o sha1.o socket.o stats.o statsdota.o util.o -L. -L../bncsutil/src/bncsutil/ -L../StormLib/stormlib/ -L/usr/local/lib/Poco/ -lPocoNet -lPocoFoundation -lbncsutil -lpthread -ldl -lz -lStorm -lmysqlclient_r -lboost_date_time -lboost_thread -lboost_system -lboost_filesystem -lgmp -lrt
g++: error: bncsutilinterface.o: No such file or directory
g++: error: bnet.o: No such file or directory
g++: error: bnetprotocol.o: No such file or directory
g++: error: bnlsclient.o: No such file or directory
g++: error: bnlsprotocol.o: No such file or directory
g++: error: commandpacket.o: No such file or directory
g++: error: config.o: No such file or directory
g++: error: crc32.o: No such file or directory
g++: error: csvparser.o: No such file or directory
g++: error: game.o: No such file or directory
g++: error: game_base.o: No such file or directory
g++: error: gameplayer.o: No such file or directory
g++: error: gameprotocol.o: No such file or directory
g++: error: gameslot.o: No such file or directory
g++: error: ghost.o: No such file or directory
g++: error: ghostdb.o: No such file or directory
g++: error: ghostdbmysql.o: No such file or directory
g++: error: gpsprotocol.o: No such file or directory
g++: error: language.o: No such file or directory
g++: error: map.o: No such file or directory
g++: error: packed.o: No such file or directory
g++: error: replay.o: No such file or directory
g++: error: savegame.o: No such file or directory
g++: error: sha1.o: No such file or directory
g++: error: socket.o: No such file or directory
g++: error: stats.o: No such file or directory
g++: error: statsdota.o: No such file or directory
g++: error: util.o: No such file or directory
make: *** [ghost++] Error 1

中间部分是实际想要的输出。然而,关键是它显示的时间更少,就像它只是炫耀但不以任何方式编译。

我这里做错了什么?

最佳答案

您将编译命令作为参数传递给 PRINT_PROGRESS 中的 echo

@$(PRINT_PROGRESS) $(C++) -o $@ $(CFLAGS) -c $<

您需要添加一个分号。

@$(PRINT_PROGRESS); $(C++) -o $@ $(CFLAGS) -c $<

话虽这么说,但我认为这种方法可能仅在每个目标必须打印出一个百分比标记时才有效(即使不是所有时间,也可能在很多情况下都是如此)。此外,使用 -j 可能效果不佳。

关于c++ - 添加选项以显示百分比时生成文件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27777882/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com