Personal tools

Difference between revisions of "Makefile CCCP"

From MohidWiki

Jump to: navigation, search
 
m (1 revision)
(No difference)

Revision as of 10:27, 3 December 2008

This section describes a cross-platform, cross-compiler makefile development methodology. The syntax to use would be:

make platform.action

(ex: make win, make unix.clean, etc...).

The project filetree

The project should split the code into modules, and each module should be assigned a folder from the root folder. Therefore there would only be a two-level folders tree:

  1. The root
  2. The modules

The project makefiles distribution

The root folder must contain:

  • The Makefile (Makefile)
  • One specific makefile per platform and per compiler (ex: win.mk, unix.mk, etc...)
  • An auxiliary file included in the latter (aux.mk)

And each module must contain:

  • The module standard Makefile (module/Makefile)
  • The dependencies file included in the latter (module/Dependencies.mk)
  • The local environment variables file included in the former (module/Vars.mk)

The makefile's global variables

The idea is to use global variables to pass arguments to the different modules makefiles. Thus, each specific platform makefile in the root folder defines these global variables. Then, it calls the modules makefiles who will use the global variables in their syntax. If a systematic approach of using global variables is implemented, then it is fairly easy to have a cross-platform makefile project implemented; and easily extended.

The Mohid Makefile Project

A sample project for Mohid2D

Here we apply the methodology described above.

Makefile

SHELL = /bin/sh

export MAKE = make
PLATCLEAN = win.clean nix.clean
PLAT = $(PLATCLEAN:.clean=)

.PHONY: default $(PLATCLEAN) $(PLAT)

default:
	@echo Please choose your platform from:
	@echo $(PLAT).
	@echo Type "make win(.clean)" or "make nix(.clean)".

$(PLAT):
	$(MAKE) -f $@.mk all

$(PLATCLEAN) : 
	$(MAKE) -f $(@:.clean=).mk clean

win.mk

SHELL = /bin/sh

###### WIN Exported variables #########
export DEL = del /Q
export O = obj
export F = f90
export MOD = mod
export CC= ifort
export CCFLAGS  = -c -fpp -nologo # Debug: -g Profiling: -p
export LFLAGS   = -fpp -nologo # Profiling: -p
export AR = ar rc
export HDF5 = D:/Projectos/Mohid_v4/IntelLibs
export LIBS = \
       ../Library/Library.lib \
       ../Modulos/Modulos.lib \
       ../Boxdif_hidrodin/Boxdif_hidrodin.lib \
       ../Mohid_Base/Mohid_Base.lib \
       $(HDF5)/hdf5.lib \
       $(HDF5)/hdf5_hl.lib \
       $(HDF5)/hdf5c.lib \
       $(HDF5)/hdf5f90.lib \
       $(HDF5)/szlib.lib \
       $(HDF5)/zlib.lib
#### End of exported variables ####

include aux.mk

nix.mk

SHELL = /bin/sh

###### NIX Exported variables #########
export DEL = rm
export O = o
export F = f90
export MOD = mod
export CC= ifort
export CCFLAGS  = -c -fpp -nologo # Debug: -g Profiling: -p
export LFLAGS   = -fpp -nologo # Profiling: -p
export AR = ar rc
export HDF5 = /opt/hdf5/hdf5/lib
export LIBS = \
       ../Boxdif_hidrodin/Boxdif_hidrodin.lib \
       ../Mohid_Base/Mohid_Base.lib \
       ../Modulos/Modulos.lib \
       ../Library/Library.lib \
       $(HDF5)/libhdf5_fortran.a \
       $(HDF5)/libhdf5.a \
       $(HDF5)/libhdf5_hl.a
#### End of exported variables ####

include aux.mk

aux.mk

MODCLEAN = Modulos.clean Boxdif_hidrodin.clean Library.clean Mohid_Base.clean Mohid2D.clean
MODULES = $(MODCLEAN:.clean=.all)

.PHONY: all clean $(MODULES) $(MODCLEAN)

all: $(MODULES)

clean: $(MODCLEAN)

$(MODULES):
	$(MAKE) -C $(@:.all=) all

$(MODCLEAN):
	$(MAKE) -C $(@:.clean=) clean

#Modules dependencies
Mohid2D.all: Mohid_Base Library.all
Mohid_Base.all: Boxdif_hidrodin.all
Library.all: Modulos.all

ModuleA/Vars.mk

SHELL = /bin/sh 

INCS = -I../ -I$(HDF5)
SRCS = \
       ModuleGlobalData.$(F) \
       ModuleHDF5.$(F) \
       ModuleTime.$(F) \
       Module_EnterData.$(F) \
       ModuleOilSpill.$(F) \
       ModuleAppPART3D.$(F) \
       ModuleEuler.$(F) \
       ModuleOxygenSaturation.$(F)
TARGET = Modulos.lib

ModuleA/Makefile

include Vars.mk

OBJS = $(SRCS:.$(F)=.$(O)) 

.PHONY: all clean

all: $(TARGET)

$(TARGET) : $(OBJS)
	@$(AR) $@ $^
	@echo Finished building $@.

clean:
	@-$(DEL) *.$(O) *.$(MOD) $(TARGET)
	@echo Erased $(TARGET) files.
 
%.$(O) : %.$(F)
	@$(CC) $(CCFLAGS) $(INCS) $<
	@echo $* .............. [OK]

include Dependencies.mk

ModuleA/Dependencies.mk

#Dependencies
ModuleHDF5.$(O) : ModuleGlobalData.$(O)
Module_EnterData.$(O) : ModuleTime.$(O)
ModuleOilSpill.$(O) : Module_EnterData.$(O)
ModuleAppPART3D.$(O) : ModuleOilSpill.$(O)
ModuleEuler.$(O) : ../param.cmb

See also