Skip to content

Instantly share code, notes, and snippets.

@akafael
Created February 12, 2014 01:18
Show Gist options
  • Save akafael/8948090 to your computer and use it in GitHub Desktop.
Save akafael/8948090 to your computer and use it in GitHub Desktop.
Looping and text file editing with makefile
##
# This a test for looping and edit files by makefile,
# it copy some program in diferents folders and run
# it with a litle diference between some text file
#
# @author: Rafael Lima
# @version: 0.2
##
# Number of experiments to create
FIRST = 1
LAST = 10
# Command to run the simulation
CC = ls # luac
CCFLAGS = -la #
# Use shell command to create a sequence of numbers stating on FIRST
# and with end on LAST and store it into variable:
NUMBERS := $(shell seq $(FIRST) $(LAST))
# Create the name of the folders:
PREFIX = exp
JOBS := $(addprefix $(PREFIX),${NUMBERS})
# Main files names:
MAIN_FOLDER = ./program
DATA_FILE = waveSimulation.dat
SIM_PROGRAM = waveSimulation.exe
# Echo formating settings:
COLOR1 = '\e[0;33m' #Set echo color to orange
COLOR2 = '\e[1;30m' #Set echo color to gray
ECHO_RESET = '\e[0m' # Reset all formating atributes
##
# Recipes:
##
.PHONY: all simulation
all: simulution; @echo -e "${COLOR1}$@ success! ${ECHO_RESET}"
${JOBS}: $(PREFIX)%: ; @echo -e "${COLOR1}[$*] Preparing $(@)";\
mkdir $(@)
cp $(MAIN_FOLDER)/@(DATA_FILE) $(@D)/$(@)
cp $(MAIN_FOLDER)/@(SIM_PROGRAM) $(@D)/$(@)
# Substitute the sequence '99' with the exp number
data_edit: $(NUMBERS)
$(NUMBERS): $(PREFIX)%
sed -i 's/99/$(@)'
simulution: data_edit
@echo -e "${COLOR1}[Starting Simulation:]"
@$(foreach dir,$(JOBS),\
cd $(dir) ; echo -e "${ECHO_RESET}__Simulation on $(dir):__";\
$(CC) $(CCFLAGS) @(SIM_PROGRAM);\
cd ..;\
)
# Comand to clear all the directories
.PHONY= clean
clean:
rm -r exp*
# Command to test the make file in a empty folder
.PHONY= test
test:
mkdir @(MAIN_FOLDER)
touch @(MAIN_FOLDER)/@(SIM_PROGRAM) @(MAIN_FOLDER)/@(DATA_FILE)
make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment