1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the Common Development
5# and Distribution License Version 1.0 (the "License").
6#
7# You can obtain a copy of the license at
8# http://www.opensource.org/licenses/CDDL-1.0.  See the License for the
9# specific language governing permissions and limitations under the License.
10#
11# When distributing Covered Code, include this CDDL HEADER in each file and
12# include the License file in a prominent location with the name LICENSE.CDDL.
13# If applicable, add the following below this CDDL HEADER, with the fields
14# enclosed by brackets "[]" replaced with your own identifying information:
15#
16# Portions Copyright (c) [yyyy] [name of copyright owner]. All rights reserved.
17#
18# CDDL HEADER END
19#
20
21#
22# Copyright (c) 2012, Regents of the University of Minnesota.  All rights reserved.
23#
24# Contributors:
25#    Valeriu Smirichinski
26#    Ryan S. Elliott
27#    Ellad B. Tadmor
28#
29
30#
31# Release: This file is part of the openkim-api-v1.1.1 package.
32#
33
34
35#
36# This make file needs to be included by the makefiles in
37# the KIM_API, MODELs/*/, MODEL_DRIVERs/*/ and TESTs/*/ directories.
38# It loads definitions for the GNU and Intel compiler sets.
39# It also contains definitions for patern compilation rules.
40#
41
42ifndef KIM_DIR
43   $(error The environment variable KIM_DIR is not defined.)
44endif
45
46# The openkim-api subdirectories:
47ifndef KIM_API_DIR
48   KIM_API_DIR :=$(KIM_DIR)/KIM_API
49endif
50ifndef KIM_MODELS_DIR
51   KIM_MODELS_DIR:=$(KIM_DIR)/MODELs
52endif
53ifndef KIM_MODEL_DRIVERS_DIR
54   KIM_MODEL_DRIVERS_DIR:=$(KIM_DIR)/MODEL_DRIVERs
55endif
56ifndef KIM_TESTS_DIR
57   KIM_TESTS_DIR:=$(KIM_DIR)/TESTs
58endif
59
60
61# All Model .o files and library definitions
62
63# setup list of available models
64MODELLST = $(patsubst .%.make-temp,%,$(notdir $(wildcard $(KIM_API_DIR)/.*.make-temp)))
65MODELDRIVERLST = $(notdir $(filter-out $(shell if test -e "$(KIM_MODEL_DRIVERS_DIR)/.kimignore"; then cat "$(KIM_MODEL_DRIVERS_DIR)/.kimignore";fi;),$(filter-out .%,$(shell find "$(KIM_MODEL_DRIVERS_DIR)/" -maxdepth 1 -mindepth 1 -type d -exec basename {} \;))))
66MODELOBJ = $(addprefix $(KIM_MODELS_DIR)/, $(join $(addsuffix /,$(MODELLST)), $(addsuffix .a, $(MODELLST)))) \
67           $(addprefix $(KIM_MODEL_DRIVERS_DIR)/, $(join $(addsuffix /,$(MODELDRIVERLST)), $(addsuffix .a, $(MODELDRIVERLST))))
68
69# Determine whether a 32 bit or 64 bit compile should be use
70ifdef KIM_SYSTEM32
71   MACHINESYSTEM=SYSTEM32
72else
73   MACHINESYSTEM=SYSTEM64
74endif
75
76# Set compiler flag and define lists
77COMMONFLAGS = -I$(KIM_API_DIR)                                      \
78              -D $(MACHINESYSTEM)                                   \
79              -D KIM_DIR_API=\"$(KIM_API_DIR)\"                     \
80              -D KIM_DIR_MODELS=\"$(KIM_MODELS_DIR)\"               \
81              -D KIM_DIR_TESTS=\"$(KIM_TESTS_DIR)\"                 \
82              -D KIM_DIR_MODEL_DRIVERS=\"$(KIM_MODEL_DRIVERS_DIR)\"
83# directory where the kim.log file should be created
84#              -D KIM_DIR=\"$(KIM_DIR)/\"
85
86ifdef KIM_INTEL
87 include $(KIM_API_DIR)/Intel_compiler_settings.mk
88else
89 include $(KIM_API_DIR)/GNU_compiler_settings.mk
90endif
91
92# Set common compiler flags for dynamic linking
93ifdef KIM_DYNAMIC
94   CPPFLAG     += -D KIM_DYNAMIC=\"$(KIM_DYNAMIC)\" -fPIC
95   CFLAG       += -D KIM_DYNAMIC=\"$(KIM_DYNAMIC)\" -fPIC
96   FORTRANFLAG += -fPIC
97endif
98
99# Set correct lib file name depending on type of compilation
100ifdef KIM_DYNAMIC
101   KIM_LIB_FILE = $(KIM_API_DIR)/libkim.so
102else
103   KIM_LIB_FILE = $(KIM_API_DIR)/libkim.a
104endif
105KIM_LIB = -L$(KIM_API_DIR)/ -lkim
106
107ifndef OSTYPE
108  OSTYPE := $(shell echo $$OSTYPE)
109endif
110
111#set default goals allways all
112.DEFAULT_GOAL := all
113
114#build target .a or .so for models
115ifdef KIM_DYNAMIC
116   MODEL_BUILD_TARGET        += $(patsubst %.a,%.so, $(MODEL_BUILD_TARGET))
117   MODEL_DRIVER_BUILD_TARGET += $(patsubst %.a,%.so, $(MODEL_DRIVER_BUILD_TARGET))
118   SHARED_LIB_FLAG = -shared
119   ifeq ($(OSTYPE),FreeBSD)
120      SHARED_LIB_FLAG = -dynamiclib
121   endif
122   LINKSONAME = -Wl,-soname=
123   ifeq ($(findstring darwin,$(OSTYPE)),darwin)
124      LINKSONAME = -Wl,-install_name,
125   endif
126else
127   ifneq ("1","$(MAKELEVEL)")
128     MODEL_BUILD_TARGET += STATIC_COMP_WARNING
129     MODEL_DRIVER_BUILD_TARGET += STATIC_COMP_WARNING
130   endif
131endif
132
133.PHONY: STATIC_COMP_WARNING
134STATIC_COMP_WARNING:
135	@echo ''; \
136        echo '*************************************************************************'; \
137        echo '*******               Compiling in static link mode               *******'; \
138        echo '*******         You probably want to execute make from the        *******'; \
139        echo '*******                     $$KIM_DIR directory                    *******'; \
140        echo '*************************************************************************'; \
141
142# Definition of c and fortran .o file list
143OBJC = KIM_API.o KIM_API_C.o standard_kim_str.o Unit_Handling.o KIM_AUX.o
144OBJF90 = KIM_API_F.o
145
146#fortran on/of
147ifdef KIM_NO_FORTRAN
148   ALLOBJ = $(OBJC)
149else
150   ALLOBJ = $(OBJC) $(OBJF90)
151endif
152
153
154# C/C++ Compiler pattern rules
155%.o:%.c    # C with preprocessing
156	$(CCOMPILER) $(CFLAG) $(COMMONFLAGS) $(OBJONLY) $<
157%.o:%.i    # C without preprocessing
158	$(CCOMPILER) $(CFLAG) $(COMMONFLAGS) $(OBJONLY) $<
159%.o:%.cpp  # C++ with preprocessing
160	$(CPPCOMPILER) $(CPPFLAG) $(COMMONFLAGS) $(OBJONLY) $<
161%.o:%.ii   # C++ without preprocessing
162	$(CPPCOMPILER) $(CPPFLAG) $(COMMONFLAGS) $(OBJONLY) $<
163%.o:%.cc   # C++ with preprocessing
164	$(CPPCOMPILER) $(CPPFLAG) $(COMMONFLAGS) $(OBJONLY) $<
165%.o:%.cxx  # C++ with preprocessing
166	$(CPPCOMPILER) $(CPPFLAG) $(COMMONFLAGS) $(OBJONLY) $<
167%.o:%.cpp  # C++ with preprocessing
168	$(CPPCOMPILER) $(CPPFLAG) $(COMMONFLAGS) $(OBJONLY) $<
169%.o:%.C    # C++ with preprocessing
170	$(CPPCOMPILER) $(CPPFLAG) $(COMMONFLAGS) $(OBJONLY) $<
171
172# Fortran Compiler pattern rules
173# Fixed form code
174%.o:%.f    # FORTRAN 77 without preprocessing
175	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
176%.o:%.for  # FORTRAN 77 without preprocessing
177	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
178%.o:%.ftn  # FORTRAN 77 without preprocessing
179	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
180%.o:%.fpp  # FORTRAN 77 with preprocessing
181	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
182%.o:%.F    # FORTRAN 77 with preprocessing
183	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
184%.o:%.FOR  # FORTRAN 77 with preprocessing
185	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
186%.o:%.FTN  # FORTRAN 77 with preprocessing
187	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
188%.o:%.FPP  # FORTRAN 77 with preprocessing
189	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
190# Free form code
191%.o:%.f90  # Fortran 90 without preprocessing
192	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
193%.o:%.f95  # Fortran 95 without preprocessing
194	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
195%.o:%.f03  # Fortran 2003 without preprocessing
196	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
197%.o:%.f08  # Fortran 2008 without preprocessing
198	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
199%.o:%.F90  # Fortran 90 without preprocessing
200	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
201%.o:%.F95  # Fortran 95 without preprocessing
202	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
203%.o:%.F03  # Fortran 2003 without preprocessing
204	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
205%.o:%.F08  # Fortran 2008 without preprocessing
206	$(FORTRANCOMPILER) $(FORTRANFLAG) $(COMMONFLAGS) $(OBJONLY) $<
207
208
209#
210MODEL_NAME_KIM_STR_H = char* $(strip $(MODEL_NAME))_kim_str'('')'';'
211MODEL_NAME_KIM_STR_CPP = char* $(strip $(MODEL_NAME))_kim_str'('')''{'
212%_kim_str.cpp: %.kim
213	echo "extern \"C\" {"           > $*_kim_str.cpp
214	echo $(MODEL_NAME_KIM_STR_H)   >> $*_kim_str.cpp
215	echo "}"                       >> $*_kim_str.cpp
216	echo $(MODEL_NAME_KIM_STR_CPP) >> $*_kim_str.cpp
217	echo "static char kimstr[] ="  >> $*_kim_str.cpp
218	cat $(strip $(MODEL_NAME)).kim | tr -d '\r' | \
219	sed -e 's,\\,\\\\,g'     \
220            -e 's,",\\",g'       \
221            -e 's,^,      ",g'   \
222            -e 's,$$,\\n",g'           >> $*_kim_str.cpp
223	echo "   ;"                    >> $*_kim_str.cpp
224	echo "return &kimstr[0];"      >> $*_kim_str.cpp
225	echo ""                        >> $*_kim_str.cpp
226	echo "}"                       >> $*_kim_str.cpp
227
228# Library pattern rule
229%.so: %.a
230	$(LINKCOMPILER) $(SHARED_LIB_FLAG) $(OUTPUTIN) $@  *.o -L$(KIM_API_DIR)/ -lkim $(LINKLIBFLAG)
231