02e6f625ff7b6130bc03ef8ad2a979d53561d911
[beamb.git] / pybeamb / Makefile
1 ###########################################################################
2 # Copyright (C) 2011 Swedish Meteorological and Hydrological Institute, SMHI,
3 #
4 # This file is part of beamb.
5 #
6 # beamb is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # beamb is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Lesser General Public License for more details.
15
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with beamb.  If not, see <http://www.gnu.org/licenses/>.
18 # ------------------------------------------------------------------------
19
20 # beamb make file
21 # @file
22 # @author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
23 # @date 2011-11-14
24 ###########################################################################
25 -include ../def.mk
26
27 # beamb specific c flags
28 #
29 CFLAGS= $(SHARED_FLAG) $(CCOPTS) $(DEFS) -I../lib -I. $(PYTHON_INCLUDE_FLAG)\
30                         $(NUMPY_INCLUDE_FLAG) $(RAVE_INCLUDE_FLAG) $(RAVE_INCLUDE_FLAG)/python \
31                         $(HLHDF_INCLUDE_FLAG) $(ZLIB_INCDIR) $(HDF5_INCDIR) $(PROJ_INCLUDE_FLAG)
32
33 # Linker flags
34 #
35 LDFLAGS= -L../lib -L. $(RAVE_LIB_FLAG) $(HLHDF_LIBRARY_FLAG) $(ZLIB_LIBDIR) \
36                         $(HDF5_LIBDIR) $(PROJ_LIB_FLAG) 
37
38 # We need to ensure that raves expat requirements are managed
39 EXPAT_LIBRARY=
40 ifeq ($(EXPAT_SUPPRESSED), no)
41 CPPFLAGS+= $(EXPAT_INCLUDE_DIR) -DRAVE_XML_SUPPORTED
42 CFLAGS+= $(EXPAT_INCLUDE_DIR) -DRAVE_XML_SUPPORTED
43 LDFLAGS+= $(EXPAT_LIB_DIR)
44 EXPAT_LIBRARY=-lexpat
45 endif
46
47 LIBRARIES=-lhlhdf -lproj  $(EXPAT_LIBRARY) -lravetransform -lravepyapi -lbeamb
48
49 # --------------------------------------------------------------------
50 # Fixed definitions
51
52 BEAMBLOCKAGE_SOURCE= pybeamblockage.c
53 BEAMBLOCKAGE_OBJECTS= $(BEAMBLOCKAGE_SOURCE:.c=.o)
54 BEAMBLOCKAGE_TARGET= _beamblockage.so
55
56 BEAMBLOCKAGEMAP_SOURCE= pybeamblockagemap.c
57 BEAMBLOCKAGEMAP_OBJECTS= $(BEAMBLOCKAGEMAP_SOURCE:.c=.o)
58 BEAMBLOCKAGEMAP_TARGET= _beamblockagemap.so
59
60 BBTOPOGRAPHY_SOURCE= pybbtopography.c
61 BBTOPOGRAPHY_OBJECTS= $(BBTOPOGRAPHY_SOURCE:.c=.o)
62 BBTOPOGRAPHY_TARGET= _bbtopography.so
63
64 MAKECDEPEND=$(CC) -MM $(CFLAGS) -MT '$(@D)/$(@F)' -o $(DF).d $<
65
66 DEPDIR=.dep
67 DF=$(DEPDIR)/$(*F)
68
69 # Ensures that the .dep directory exists
70 .PHONY=$(DEPDIR)
71 $(DEPDIR):
72         +@[ -d $@ ] || mkdir -p $@
73
74 # And the rest of the make file targets
75 #
76 .PHONY=all
77 all:            $(BEAMBLOCKAGE_TARGET) $(BEAMBLOCKAGEMAP_TARGET) $(BBTOPOGRAPHY_TARGET)
78
79 $(BEAMBLOCKAGE_TARGET): $(DEPDIR) $(BEAMBLOCKAGE_OBJECTS) ../lib/libbeamb.so
80         $(LDSHARED) -o $@ $(BEAMBLOCKAGE_OBJECTS) $(LDFLAGS) $(LIBRARIES)
81
82 $(BEAMBLOCKAGEMAP_TARGET): $(DEPDIR) $(BEAMBLOCKAGEMAP_OBJECTS) ../lib/libbeamb.so
83         $(LDSHARED) -o $@ $(BEAMBLOCKAGEMAP_OBJECTS) $(LDFLAGS) $(LIBRARIES)
84
85 $(BBTOPOGRAPHY_TARGET): $(DEPDIR) $(BBTOPOGRAPHY_OBJECTS) ../lib/libbeamb.so
86         $(LDSHARED) -o $@ $(BBTOPOGRAPHY_OBJECTS) $(LDFLAGS) $(LIBRARIES)
87         
88 .PHONY=install
89 install:
90         @mkdir -p ${prefix}/share/beamb/pybeamb
91         @cp -v -f $(BEAMBLOCKAGE_TARGET) ${prefix}/share/beamb/pybeamb
92         @cp -v -f $(BEAMBLOCKAGEMAP_TARGET) ${prefix}/share/beamb/pybeamb
93         @cp -v -f $(BBTOPOGRAPHY_TARGET) ${prefix}/share/beamb/pybeamb
94         @cp -v -f *.py ${prefix}/share/beamb/pybeamb
95         @echo "$(prefix)/share/beamb/pybeamb" > "$(SITEPACK_PYTHON)/pybeamb.pth"
96
97 .PHONY=clean
98 clean:
99         @\rm -f *.o core *~
100         @\rm -fr $(DEPDIR)
101
102 .PHONY=distclean                 
103 distclean:      clean
104         @\rm -f $(BEAMBLOCKAGE_TARGET) $(BEAMBLOCKAGEMAP_TARGET) $(BBTOPOGRAPHY_TARGET)
105
106 # --------------------------------------------------------------------
107 # Rules
108
109 # Contains dependency generation as well, so if you are not using
110 # gcc, comment out everything until the $(CC) statement.
111 %.o : %.c
112         @$(MAKECDEPEND); \
113         cp $(DF).d $(DF).P; \
114         sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
115                 -e '/^$$/ d' -e 's/$$/ :/' < $(DF).d >> $(DF).P; \
116         \rm -f $(DF).d
117         $(CC) -c $(CFLAGS) $< -o $@
118
119 # NOTE! This ensures that the dependencies are setup at the right time so this should not be moved
120 -include $(BEAMBLOCKAGE_SOURCE:%.c=$(DEPDIR)/%.P)
121 -include $(BEAMBLOCKAGEMAP_SOURCE:%.c=$(DEPDIR)/%.P)
122 -include $(BBTOPOGRAPHY_SOURCE:%.c=$(DEPDIR)/%.P)