Re: Script to compile all files with a given extension?



sk8terg1rl <sk8terg1rl_2006@xxxxxxxxxxx> writes:

On Jun 29, 11:39 pm, The Natural Philosopher <a...@xxx> wrote:
sk8terg1rl wrote:
Hi everyone,

Quite often I move source codes between CPU architectures and need to
recompile it, otherwise I get the error:

-bash: ./program_binary: cannot execute binary file

Since discovering the joys of bootstrapping my programs, I no longer
have one big program but many smaller interconnected ones (easier
debugging, allows you to edit/recompile one even while your doing a
run, greater flexibility, etc.)

How can I write a script that would:
Identify all the files with .for and .f90 extensions

Execute the commands:
'ifort program.for -o program'
'ifort program2.f90 -o program2'

Thanks :-)

skate

Wtite a Makefile and use make?

Hi NP,

Found out what make does with man make just now ;-)

Unfortunately I don't think this would help much. Depending on the
purpose of the programs, they have different names. This would mean I
would need a makefile for each subset of programs.

Currently I 'ls *.for; ls *.f90' and pipe the output into a script
file. Then with some vi magic I edit it to effectively get my own
makefile. This is less than convenient as it doesn't automatically
detect any new files to be compiled and isn't very flexible. Each
collection of programs for a single purpose must have its own
compilation script or pseudo-makefile.

Sorry about not being clear before but what I was really asking for
was to have a program that would automatically detect and compile all
files with some given extensions.

A Makefile is still the right answer.
This should get you started, put this in the Makefile:

FOR:=$(wildcard *.for)
F90:=$(wildcard *.f90)

TARGFOR:=$(subst .for,,$(FOR))
TARGF90:=$(subst .f90,,$(F90))

TARGETS:=$(TARGFOR) $(TARGF90)

all: $(TARGETS)



(Sorry, not tested but should be close enough.)
.



Relevant Pages

  • Re: Using Makefile rather than GreenHills (GHS) Multi .GPJ files
    ... you've done something weird if you are dependant on the order files are passed to the linker - it is better to make use of specific sections or specific linker control files as needed. ... A random C file appearing in the source tree (e.g. a temporary copy of one of the source files) shouldn't become part of the build just like that. ... Relevant files are in the correct place, the symbol definitions are collected together in a single "configuration" header file, and it's easy to see which parts of the project are included in the compilation, and easy to change those choices. ... Changing dependant headers shouldn't require changes to the makefile, ...
    (comp.arch.embedded)
  • Re: Need help with cleaning up a working GNU Autotools setup
    ... Peter T. Breuer skrev: ... Automake and compiles from the source base directory he may well be ... > in ones Makefile. ... > of compilation in ONE subdirectory. ...
    (comp.os.linux.misc)
  • Re: Need help with cleaning up a working GNU Autotools setup
    ... Peter T. Breuer skrev: ... Automake and compiles from the source base directory he may well be ... > in ones Makefile. ... > of compilation in ONE subdirectory. ...
    (comp.os.linux.development.system)
  • Re: javac vs Makefile problem ...
    ... > In order to compile everything easily, I did a Makefile. ... here is my compilation chain: ... > Is there a way to disable the "javac" automatic dependency resolution ... If all of your .java files live in one directory (or are contained in ...
    (comp.lang.java.programmer)
  • Re: kernel module options
    ... :>> IPDIVERT but w/o IPFIREWALL is was working anyway. ... :> could possibly effect the compilation of the ipfw2 module. ... :> I could see doing it was to modify the Makefile for the module. ... you can't eliminat ethe opt_*.h rules in the ...
    (freebsd-current)