make how create scripting makefile build-automation progress-bar

scripting - how - Indicación de progreso make/makefile



makefile linux c (3)

¡Buen truco! (-:

Pero no es realmente escalable para proyectos en crecimiento que se distribuyen en muchos directorios con muchos archivos make.

Me inclinaría más a tener el registro rociado a través de [Mm] akefiles * en su proyecto y usarlo para realizar un seguimiento del progreso.

Solo un pensamiento. Por cierto, gracias por compartir esto.

Editar: Solo tuve un pensamiento. Esto podría ser útil en una forma modificada para mostrar una pulsación para mostrar el progreso mientras se desarrolla una tarea larga, por ejemplo, desempaquetar una tarball de distribución grande en lugar de simplemente especificar la opción -v para el comando tar. Todavía un poco de capa de azúcar, pero un poco de diversión también. (-:

aclamaciones,

Robar

Mire este archivo MAKE, tiene algún tipo de indicación de progreso primitivo (podría haber sido una barra de progreso).

Por favor dame sugerencias / comentarios sobre eso!

# BUILD is initially undefined ifndef BUILD # max equals 256 x''s sixteen := x x x x x x x x x x x x x x x x MAX := $(foreach x,$(sixteen),$(sixteen)) # T estimates how many targets we are building by replacing BUILD with a special string T := $(shell $(MAKE) -nrRf $(firstword $(MAKEFILE_LIST)) $(MAKECMDGOALS) / BUILD="COUNTTHIS" | grep -c "COUNTTHIS") # N is the number of pending targets in base 1, well in fact, base x :-) N := $(wordlist 1,$T,$(MAX)) # auto-decrementing counter that returns the number of pending targets in base 10 counter = $(words $N)$(eval N := $(wordlist 2,$(words $N),$N)) # BUILD is now defined to show the progress, this also avoids redefining T in loop BUILD = @echo $(counter) of $(T) endif # dummy phony targets .PHONY: all clean all: target @echo done clean: @rm -f target *.c # dummy build rules target: a.c b.c c.c d.c e.c f.c g.c @touch $@ $(BUILD) %.c: @touch $@ $(BUILD)

Todas las sugerencias son bienvenidas!


Este es menos intrusivo y más impresionante.

ifneq ($(words $(MAKECMDGOALS)),1) .DEFAULT_GOAL = all %: @$(MAKE) $@ --no-print-directory -rRf $(firstword $(MAKEFILE_LIST)) else ifndef ECHO T := $(shell $(MAKE) $(MAKECMDGOALS) --no-print-directory / -nrRf $(firstword $(MAKEFILE_LIST)) / ECHO="COUNTTHIS" | grep -c "COUNTTHIS") N := x C = $(words $N)$(eval N := x $N) ECHO = echo "`expr " [/`expr $C ''*'' 100 / $T/`" : ''.*/(..../)$$''`%]" endif .PHONY: all clean all: target @$(ECHO) All done clean: @rm -f target *.c # @$(ECHO) Clean done target: a.c b.c c.c d.c e.c @$(ECHO) Linking $@ @sleep 0.1 @touch $@ %.c: @$(ECHO) Compiling $@ @sleep 0.1 @touch $@ endif


Esta es una pequeña modificación a la excelente respuesta de @ GiovanniFunchal.

Así que quería entender esto mejor y hacerlo funcionar por <10%, así que busqué en la documentación y aprendí más sobre expr .

# PLACE AT THE TOP OF YOUR MAKEFILE #--------------------------------- # Progress bar defs #-------------------------------- # words = count the number of words ifneq ($(words $(MAKECMDGOALS)),1) # if no argument was given to make... .DEFAULT_GOAL = all # set the default goal to all # http://www.gnu.org/software/make/manual/make.html # $@ = target name # %: = last resort recipe # --no-print-directory = don''t print enter/leave messages for each output grouping # MAKEFILE_LIST = has a list of all the parsed Makefiles that can be found *.mk, Makefile, etc # -n = dry run, just print the recipes # -r = no builtin rules, disables implicit rules # -R = no builtin variables, disables implicit variables # -f = specify the name of the Makefile %: # define a last resort default rule @$(MAKE) $@ --no-print-directory -rRf $(firstword $(MAKEFILE_LIST)) # recursive make call, else ifndef ECHO # execute a dry run of make, defining echo beforehand, and count all the instances of "COUNTTHIS" T := $(shell $(MAKE) $(MAKECMDGOALS) --no-print-directory / -nrRf $(firstword $(MAKEFILE_LIST)) / ECHO="COUNTTHIS" | grep -c "COUNTTHIS") # eval = evaluate the text and read the results as makefile commands N := x # Recursively expand C for each instance of ECHO to count more x''s C = $(words $N)$(eval N := x $N) # Multipy the count of x''s by 100, and divide by the count of "COUNTTHIS" # Followed by a percent sign # And wrap it all in square brackets ECHO = echo -ne "/r [`expr $C ''*'' 100 / $T`%]" endif #------------------ # end progress bar #------------------ # REST OF YOUR MAKEFILE HERE #----- Progressbar endif at end Makefile endif

Me deshice de la parte : ''.*/(..../)$$'' . Devolvería los últimos 4 caracteres del comando interno expr , pero fallaría si fuera menor a 4. ¡Y ahora funciona para menos del 10%!

Y aquí está la versión gratuita de comentarios:

ifneq ($(words $(MAKECMDGOALS)),1) # if no argument was given to make... .DEFAULT_GOAL = all # set the default goal to all %: # define a last resort default rule @$(MAKE) $@ --no-print-directory -rRf $(firstword $(MAKEFILE_LIST)) # recursive make call, else ifndef ECHO T := $(shell $(MAKE) $(MAKECMDGOALS) --no-print-directory / -nrRf $(firstword $(MAKEFILE_LIST)) / ECHO="COUNTTHIS" | grep -c "COUNTTHIS") N := x C = $(words $N)$(eval N := x $N) ECHO = echo -ne "/r [`expr $C ''*'' 100 / $T`%]" endif # ... endif

Espero que ayude.