Hi.
There are few ways to do what you want.
gfortran has native preprocessing support (enabled with -cpp option). You can define a macro on command line using -D option:
Code:
$ cat test.f
program hello
print *, X
end program hello
$ gfortran -cpp -D X='"hello"' test.f && ./a.out
hello
$ gfortran -cpp -D X=3.1415 test.f && ./a.out
3.1415000
If your compiler does not support preprocessing, you can just use cpp (the C PreProcessor) manually:
Code:
$ cpp -P -D X=15 ./test.f > test2.f
$ gfortran test2.f && ./a.out
15
The `-P' flag inhibits generation of linemarkers in the output from the preprocessor which may confuse your compiler.
If you
really need to use `make', try something like (in case of gfortran)
Code:
$ cat Makefile
.PHONY: test
test: test.f
gfortran $(CPPFLAGS) $< -o $@
$ make CPPFLAGS='-cpp -DX=5'
gfortran -cpp -DX=5 test.f -o test
$ ./test
5
Use make only if your program consists of multiple files.
Now you can change parameter in a loop as follows:
Code:
$ for x in Hello cruel world; do gfortran -cpp -D X="'$x'" test.f ; ./a.out; done
Hello
cruel
world
Here we comple and run the program three times.
Hope this helps.
PS: Mature programs usually use command line options and/or configuration files to alter its behaviour (so that recompilation is not necessary), but I understand that it is overkill for smaller projects.