4

I believe I have a problem with the cpp preprocessor used by my Makefile (which compiles Fortran code). I have recently changed operating systems, and now compilation does not work, and I do not know enough about Makefiles or preprocessors to fix it (the Makefile was given to me many years ago).

I have recently updated from Fedora 10 to Fedora 19 (yes, should've done so earlier). After copying my code to the new system, and running gmake, I found out I was having problems with compilation. From what I have understood, what is supposed to happen is that my .F files are preprocessed and written as .f files. Apparently, the cpp preprocessor is now adding some sort of GNU disclaimer ("/* Copyright (C) 1991-2012 Free Software Foundation, Inc. This file is part of the GNU C Library.... "), which the compiler (f77) does not like. In principle, I could erase this text from each of the generated .f files, but seriously, this takes too much time.

I really don't know what is the cause of the problem. I'd like to tell cpp not output this text, or f77 to ignore it, but haven't found any flag that manages this. Considered re-writing the Makefile (using more modern compilers, for instance), but I'm a bit hopeless on this at the moment. Hopefully someone can help me with this. I'm copying the Makefile below, as well as the output.

Thanks in advance.


Makefile


# Make sure the SHELL is right
SHELL = /bin/sh
MAKE  = gmake

 # Define several root directories       
 LEP_ROOT    := /home/stilgar/SUSY/NeutrinoModel2
 CERN_ROOT   := /usr/lib64/cernlib/2006
 INCLUDES    := $(LEP_ROOT)/include 
 INCLUDES    := $(strip $(INCLUDES))
 incpath     := $(subst $(space),:,$(INCLUDES))

 vpath %.inc $(incpath)

 # Define tree       
 BIN_DIR := $(LEP_ROOT)/bin

 # Define source directory
 SRCDIR := $(LEP_ROOT)/src

 # Libraries
 libs :=  $(CERN_ROOT)/lib
 libs :=  $(addprefix -L, $(libs)) 
 libs += `cernlib packlib,mathlib,packlib,kernlib`

 #Source files
 #Main Program
 src_files += $(wildcard $(SRCDIR)/main_lfv.F)
 #SM Parameters 
 src_files += $(wildcard $(SRCDIR)/param_basic.F)
 src_files += $(wildcard $(SRCDIR)/numajmass.F)
 #SUSY Spectrum
 src_files += $(wildcard $(SRCDIR)/texture2.F)
 src_files += $(wildcard $(SRCDIR)/minserts.F)
 #SUSY Flavour
 src_files += $(wildcard $(SRCDIR)/gmin2.F)
 src_files += $(wildcard $(SRCDIR)/lfv.F)
 #Bounds
 src_files += $(wildcard $(SRCDIR)/experiment.F)
 src_files += $(wildcard $(SRCDIR)/directsearch.F)
 #Loop Functions
 src_files += $(wildcard $(SRCDIR)/fedm.F)
 src_files += $(wildcard $(SRCDIR)/gedm.F)
 #Mathematical Tools
 src_files += $(wildcard $(SRCDIR)/biunitary3.F)

 main_obj_files += $(src_files:%.F=%.o)
 main_ofiles    += $(notdir $(main_obj_files))
 main_files     += $(src_files:%.F=%.f)
 depend         += $(main_obj_files:.o=.d)

 # Name of the executable to be created
 exectry := $(BIN_DIR)/RunStuff

 # Define flags 
 FC = f77
 #FC = gfortran
 #FC = g95
 FFLAGS += -c 
 FFLAGS += $(addprefix -I, $(INCLUDES))  

 # Define cpp options
 CPP = cpp
 CPPFLAGS += -C -P -E
 CPPFLAGS += $(addprefix -I, $(INCLUDES))

 .PHONY : all clean cleanall help
 .PHONY : sclean 

 all: $(exectry)

 $(exectry): $(main_obj_files) $(main_files) 
 @echo '==================================================='
 @echo '    Building executable ' $(exectry)
 @echo '    '
 @-rm -f $@
 $(FC) -o $@ $(main_obj_files) $(LFLAGS) $(libs)
 @echo '    Done '
 @echo '==================================================='

 clean : sclean
 @echo
 @echo Cleaning up  *.o  *~ core
 @echo
 @-rm -f *.o  core 
 @echo done.
 sclean :
 @find . -name "*.bak" -exec rm -f '{}' ';'
 @find . -name "*~" -exec rm -f '{}' ';'
 @find . -name "#*#"             -exec rm -f '{}' ';'

 cleanall : 
 @echo '**********************************************************'
 @echo ' Clean all : '
 @find . -name "*.bak" -exec rm -f '{}' ';'
 @find . -name "*~" -exec rm -f '{}' ';'
 @find . -name "*.log"           -exec rm -f '{}' ';'
 @find . -name "*.out"           -exec rm -f '{}' ';'
 @find . -name "core"            -exec rm -f '{}' ';'
 @find . -name "#*#"             -exec rm -f '{}' ';'
 @-rm -f *.o *.d
 @echo done.
 @echo '**********************************************************'
 help:
 @echo 
 @echo '  The possible options are :'
 @echo '  ========================  '
 @echo 
 @echo '  gmake         -- build batch executable'  
 @echo '  gmake sclean   -- simple clean up '    
 @echo '  gmake clean    -- clean up a bit more '
 @echo '  gmake cleanall -- clean everything'
 @echo

 %.f:%.F
 @echo Preprocessing ... $<
 @$(CPP) $(CPPFLAGS)  $< > $@

 %.o:%.f
 @echo Compiling ... $<
 @$(FC) $(FFLAGS) -o $@ $<

 %.d:%.F
 @touch $@
 @echo Updating ... $@        
 @makedepend -- $(CPPFLAGS) -- $< -f $@
 @-rm $@.bak

Output


 Preprocessing ... /home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.F
 Compiling ... /home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.f
 /home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.f:2: 
       This file is part of the GNU C Library.
       ^
 Non-numeric character at (^) in label field [info -f g77 M LEX]
 /home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.f:4: 
       The GNU C Library is free software; you can redistribute it and/or
       ^
 Non-numeric character at (^) in label field [info -f g77 M LEX]
 /home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.f:5: 
       modify it under the terms of the GNU Lesser General Public
       ^
 Non-numeric character at (^) in label field [info -f g77 M LEX]

 (...)

 gmake: *** [/home/stilgar/SUSY/NeutrinoModel2/src/main_lfv.o] Error 1
4

1 回答 1

4

我认为问题在于变量中的-C选项。CPPFLAGS的手册页cpp说这会导致预处理器不丢弃注释。我不认为你想要那个。删除该标志。

另一个缺点:你永远不想MAKE在你的makefile中设置变量。

于 2013-10-24T16:54:59.057 回答