%% [EMAIL PROTECTED] writes: w> I'm trying to write a simple makefile and having a few problems. When I w> run it ...
Whew. You have lots of problems here :-). w> 1) It only builds the fileA.f90 file and ignores the others. Unless you specify a specific target on the command line, make always builds the first target it finds in the makefile and ONLY that target. Typically people create a dummy target "all" as the first target in the makefile, and list all the "normal" products of their build as prerequisites of it, like this: all: $(OBJDIR)/fileA.o $(OBJDIR)/fileB.o $(OBJDIR)/fileC.o <...> w> 2) It doesn't put the fileA.o inside my obj dir. Well, that's not make's problem. It's not make that's creating your .o files, it's the Fortran compiler. Make just runs the command: it's up to the command itself to make sure that the output goes to the right place. w> $(OBJDIR)/%.o : $(addprefix $(MODDIR)/, $(MODSRC)) If you say that each .o depends on every source file, then any time _ANY_ source file changes _EVERY_ .o will be recompiled, which kind of defeats the purpose of a makefile... if that's OK with you it's easier to just use a shell script to build your code ;-). You don't want that. However, this is really a no-op, because at the time this line is read the variable MODSRC is empty (you don't set it until later) so this function expands to the empty string anyway. In general it's best to order your makefiles so all variable settings come first, and all rules come afterwards. w> $(FC) $(FFLAGS) -c $< You need to modify your rule above to ensure that the output goes to [EMAIL PROTECTED] If your Fortran compiler has similar arguments to traditional C compilers, then you'd write this command like: $(FC) $(FFLAGS) -o $@ -c $< w> $(OBJDIR)/fileA.o: $(MODDIR)/fileA.f90 w> $(OBJDIR)/fileB.o: $(MODDIR)/fileB.f90 $(MODDIR)/fileD.F w> $(OBJDIR)/fileC.o: $(MODDIR)/fileC.F90 $(MODDIR)/fileE.f90 w> $(OBJDIR)/fileD.o: $(MODDIR)/fileD.F w> $(OBJDIR)/fileE.o: $(MODDIR)/fileE.f90 Because you have different extensions you will need two different patterns: $(OBJDIR)/%.o : $(MODDIR)/%.f90 $(FC) $(FFLAGS) -o $@ -c $< $(OBJDIR)/%.o : $(MODDIR)/%.F $(FC) $(FFLAGS) -o $@ -c $< Make will try the patterns in the order they were defined and use the first one that matches. HTH! -- ------------------------------------------------------------------------------- Paul D. Smith <[EMAIL PROTECTED]> Find some GNU make tips at: http://www.gnu.org http://make.paulandlesley.org "Please remain calm...I may be mad, but I am a professional." --Mad Scientist _______________________________________________ help-gnu-utils mailing list help-gnu-utils@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-utils