I created a Makefile in which there is a comand that calculates the time of execution of a program,
but I want to use that comand with a different input each time.
This is the Makefile, I want to test different inputs on the gprof comand, but I don’t want to change the Makefile every time.
#=========================================
CC=gcc
OPTS=-O2
CFLAGS=-Wall -Wextra $(OPTS) -pedantic-errors
#-----------------------------------------
SRC_DIR=src
BLD_DIR=build
INC_DIR=includes
# BIN_DIR = bin
#-----------------------------------------
SRC=$(wildcard $(SRC_DIR)/*.c)
OBJS=$(patsubst $(SRC_DIR)/%.c,$(BLD_DIR)/%.o,$(SRC))
#-----------------------------------------
PROGRAM = main
#=========================================
.DEFAULT_GOAL = all
all: setup $(PROGRAM)
setup:
@mkdir -p $(BLD_DIR)
$(PROGRAM): $(OBJS)
$(CC) -I $(INC_DIR) $(CFLAGS) -o $@ $^
$(BLD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) -c -I $(INC_DIR) $(CFLAGS) -o $@ $^
complexidade:
@echo Only printing when Modified McCabe Cyclomatic Complexity is above 5
@echo | pmccabe -v
@pmccabe $(SRC_DIR)/*.c| sort -nr | awk '{if($$1>5)print}'
check:
@cppcheck --enable=all --suppress=missingIncludeSystem .
fmt:
@echo -n "Running formatter... "
@find $(SRC_DIR) -type f -name "*.c" | xargs clang-format -i
.PHONY: debug
debug: CFLAGS = -Wall -Wextra -pedantic -O0 -g
debug: all
gdb ./$(PROGRAM)
.PHONY: gprof
gprof: CFLAGS = -pg -g -O
gprof: all
/usr/bin/time -f"%U s" ./main < files/link/input1
clean:
rm -r $(BLD_DIR)
rm $(PROGRAM)
My idea was to call make gprof
and then tell which file I want to use as input
2