ChinaNet

标题: Linux下编译Fortran代码的Makefile示例模板 [打印本页]

作者: Evan    时间: 2015-4-8 10:53
标题: Linux下编译Fortran代码的Makefile示例模板
  由于很多人现在利用Linux下的Fortran编译器,但同时每次键入编译命令很麻烦.
    在Linux下提供了make自动编译系统,在代码编写好以后,在同一个目录下再编写好一个Makefile文件,只要在命令行下键入make就可以了,非常的好用.

这里提供2个模板,望给诸君工作带来便利.

1.针对f77格式代码的,编译器f77
#setting of the compiler parameters
CC=f77
OBJECTS=main.o
TARGET=demo
CFLAGS=-c -g

#linking the objects
$(TARGET)(OBJECTS)
    $(CC) -o $@ $^

#compiler the objects
%.o:%.f
    $(CC) $(CFLAGS) -o $@ $^

#remove all the middle files and rubbish files
.PHONY:clean purge style
clean:
    rm -f *.o *.*~ *~

purge:clean
    rm -f $(TARGET)

2,针对f90格式代码的,编译器ifort(intel fortran compiler)
#cal some nucleus' half death time in fortran language.
#setting of the compiler parameters
CC=ifort
OBJECTS=main.o
TARGET=demo
CFLAGS=-c -g

#linking the objects
$(TARGET)(OBJECTS)
    $(CC) -o $@ $^

#compiler the objects
%.o:%.f90
    $(CC) $(CFLAGS) -o $@ $^

#remove all the middle files and rubbish files
.PHONY:clean purge
clean:
    rm -f *.o *.*~ *~

purge:
    rm -f $(TARGET)


最后在附件里提供一个具体的实例.想进一步学习Makefile编写请参考本区的<如何使用linux下的fortran编译器>的贴子.

祝诸君工作愉快.........


转自52mc






欢迎光临 ChinaNet (http://www.nuclear.net.cn/) Powered by Discuz! X3.1