fritzkink
2023-12-27 706019354bab81fc3f01995caf1ae1a2dfa346cf
commit | author | age
9074b6 1 #
AL 2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21 # Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
22 # Copyright 2011 EveryCity Ltd. All rights reserved.
23 # Copyright 2013 Aurelien Larcher. All rights reserved.
24 #
25
26 #
27 # Rules and Macros for building open source software that uses the CMake utility
28 # from Kitware (http://www.cmake.org) to configure the build. 
29 # This file implements the same rules as configure.mk and thus uses GNU Make
30 # to build the components with support of multiple version (32/64 bit).
31 #
32 # To use these rules, include ../make-rules/cmake.mk in your Makefile
33 # and define "build", "install", and "test" targets appropriate to building
34 # your component.
35 # Ex:
36 #
37 #     build:        $(SOURCE_DIR)/build/$(MACH32)/.built \
38 #             $(SOURCE_DIR)/build/$(MACH64)/.built
39 #
40 #    install:    $(SOURCE_DIR)/build/$(MACH32)/.installed \
41 #             $(SOURCE_DIR)/build/$(MACH64)/.installed
42 #
43 #    test:        $(SOURCE_DIR)/build/$(MACH32)/.tested \
44 #             $(SOURCE_DIR)/build/$(MACH64)/.tested
45 #
46 # Any additional pre/post configure, build, or install actions can be specified
47 # in your make file by setting them in on of the following macros:
48 #    COMPONENT_PRE_CMAKE_ACTION, COMPONENT_POST_CMAKE_ACTION
49 #    COMPONENT_PRE_BUILD_ACTION, COMPONENT_POST_BUILD_ACTION
50 #    COMPONENT_PRE_INSTALL_ACTION, COMPONENT_POST_INSTALL_ACTION
51 #    COMPONENT_PRE_TEST_ACTION, COMPONENT_POST_TEST_ACTION
52 #
53 # If component specific make targets need to be used for build or install, they
54 # can be specified in
55 #    COMPONENT_BUILD_TARGETS, COMPONENT_INSTALL_TARGETS
56 #    COMPONENT_TEST_TARGETS
57 #
58
59 CMAKE_PREFIX =    /usr
60
61 #
62 # Define path the same way as configure.mk
63 # Ref: http://www.cmake.org/cmake/help/v2.8.12/cmake.html#module:GNUInstallDirs
64 #
65
0b2b25 66 ifeq ($(strip $(PREFERRED_BITS)),64)
AL 67 CMAKE_BINDIR.32 =    bin/$(MACH32)
68 CMAKE_BINDIR.64 =    bin
69 CMAKE_SBINDIR.32 =    sbin/$(MACH32)
70 CMAKE_SBINDIR.64 =    sbin
71 else
9074b6 72 CMAKE_BINDIR.32 =    bin
AL 73 CMAKE_BINDIR.64 =    bin/$(MACH64)
74 CMAKE_SBINDIR.32 =    sbin
75 CMAKE_SBINDIR.64 =    sbin/$(MACH64)
0b2b25 76 endif
9074b6 77 CMAKE_LIBDIR.32 =    lib
AL 78 CMAKE_LIBDIR.64 =    lib/$(MACH64)
b5ddf2 79 CMAKE_LIBEXECDIR.32 =    lib
AP 80 CMAKE_LIBEXECDIR.64 =    lib/$(MACH64)
9074b6 81 CMAKE_INCLUDEDIR =    include
AL 82 CMAKE_DATAROOTDIR =    share
c3a1d7 83 CMAKE_DATADIR =        $(CMAKE_DATAROOTDIR)
33b2d2 84 CMAKE_INFODIR =        $(CMAKE_DATAROOTDIR)/info
AL 85 CMAKE_LOCALEDIR =    $(CMAKE_DATAROOTDIR)/locale
86 CMAKE_MANDIR =        $(CMAKE_DATAROOTDIR)/man
0b2b25 87 CMAKE_DOCDIR =        $(CMAKE_DATAROOTDIR)/doc
9074b6 88
AL 89 CMAKE_ENV = CONFIG_SHELL="$(CONFIG_SHELL)"
90 CMAKE_ENV += CC="$(CC)"
91 CMAKE_ENV += CXX="$(CXX)"
92 CMAKE_ENV += F77="$(F77)"
93 CMAKE_ENV += FC="$(FC)"
94 CMAKE_ENV += CFLAGS="$(CFLAGS)"
95 CMAKE_ENV += CXXFLAGS="$(CXXFLAGS)"
96 CMAKE_ENV += FFLAGS="$(F77FLAGS)"
97 CMAKE_ENV += FCFLAGS="$(FCFLAGS)"
98 CMAKE_ENV += LDFLAGS="$(LDFLAGS)"
99 CMAKE_ENV += PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)"
5282a1 100 CMAKE_ENV += PATH="$(PATH)"
9074b6 101
c5572a 102 # Rewrite absolute source-code paths into relative for ccache, so that any
JK 103 # workspace with a shared CCACHE_DIR can benefit when compiling a component
104 ifneq ($(strip $(CCACHE)),)
105 CMAKE_ENV += CCACHE="$(CCACHE)"
106 CMAKE_ENV += CC_gcc_32="$(CC_gcc_32)"
107 CMAKE_ENV += CC_gcc_64="$(CC_gcc_32)"
108 CMAKE_ENV += CXX_gcc_32="$(CXX_gcc_64)"
109 CMAKE_ENV += CXX_gcc_64="$(CXX_gcc_64)"
110 CMAKE_ENV.$(BITS) += CCACHE_BASEDIR="$(BUILD_DIR_$(BITS))"
111
112 ifneq ($(strip $(CCACHE_DIR)),)
113 CMAKE_ENV += CCACHE_DIR="$(CCACHE_DIR)"
114 endif
115
116 ifneq ($(strip $(CCACHE_LOGFILE)),)
117 CMAKE_ENV += CCACHE_LOGFILE="$(CCACHE_LOGFILE)"
118 endif
119
120 endif
121
9074b6 122 CMAKE_DEFAULT_DIRS?=yes
AL 123
23c6f0 124 CMAKE_OPTIONS += -DCMAKE_C_COMPILER:STRING="$(CC)"
AL 125 CMAKE_OPTIONS += -DCMAKE_CXX_COMPILER:STRING="$(CXX)"
126 CMAKE_OPTIONS += -DCMAKE_Fortran_COMPILER:STRING="$(FC)"
127 CMAKE_OPTIONS += -DCMAKE_C_FLAGS:STRING="$(CFLAGS)"
128 CMAKE_OPTIONS += -DCMAKE_CXX_FLAGS:STRING="$(CXXFLAGS)"
129 CMAKE_OPTIONS += -DCMAKE_Fortran_FLAGS:STRING="$(FCFLAGS)"
9074b6 130
AL 131 CMAKE_OPTIONS += -DCMAKE_INSTALL_PREFIX:PATH=$(CMAKE_PREFIX)
132 ifeq ($(CMAKE_DEFAULT_DIRS),yes)
133 CMAKE_OPTIONS += -DCMAKE_INSTALL_BINDIR:PATH=$(CMAKE_BINDIR.$(BITS))
134 CMAKE_OPTIONS += -DCMAKE_INSTALL_LIBDIR:PATH=$(CMAKE_LIBDIR.$(BITS))
b5ddf2 135 CMAKE_OPTIONS += -DCMAKE_INSTALL_SBINDIR:PATH=$(CMAKE_SBINDIR.$(BITS))
9074b6 136 CMAKE_OPTIONS += -DCMAKE_INSTALL_DATAROOTDIR:PATH=$(CMAKE_DATAROOTDIR)
AL 137 CMAKE_OPTIONS += -DCMAKE_INSTALL_DATADIR:PATH=$(CMAKE_DATAROOTDIR)
138 CMAKE_OPTIONS += -DCMAKE_INSTALL_INFODIR:PATH=$(CMAKE_INFODIR)
139 CMAKE_OPTIONS += -DCMAKE_INSTALL_LOCALEDIR:PATH=$(CMAKE_LOCALEDIR)
140 CMAKE_OPTIONS += -DCMAKE_INSTALL_MANDIR:PATH=$(CMAKE_MANDIR)
b5ddf2 141
AP 142 CMAKE_OPTIONS += -DLIBEXEC_INSTALL_DIR="$(CMAKE_PREFIX)/$(CMAKE_LIBEXECDIR.$(BITS))"
143
144 # Some components use LIB_INSTALL_DIR or CMAKE_INSTALL_LIBDIR, as-is,
145 # others forcibly ignore it and set
146 # based on CMAKE_INSTALL_PREFIX.  Those usually instead offer a LIB_SUFFIX
147 # variable that we can generally use to accomplish the same result.  Setting
148 # them both shouldn't harm anything.
149 CMAKE_OPTIONS += -DLIB_INSTALL_DIR="$(CMAKE_PREFIX)/$(CMAKE_LIBDIR.$(BITS))"
15fd05 150 CMAKE_OPTIONS.64 += -DCMAKE_LIBRARY_ARCHITECTURE=$(MACH64)
b5ddf2 151 CMAKE_OPTIONS.64 += -DLIB_SUFFIX="/$(MACH64)"
9074b6 152 endif
AL 153 CMAKE_OPTIONS += $(CMAKE_OPTIONS.$(BITS))
154
155 COMPONENT_INSTALL_ARGS +=    DESTDIR=$(PROTO_DIR)
156
157 $(BUILD_DIR_32)/.configured:    BITS=32
158 $(BUILD_DIR_64)/.configured:    BITS=64
159
160 CMAKE_ENV += $(CMAKE_ENV.$(BITS))
161
51eb1d 162 COMPONENT_TEST_CMD=ctest
AP 163 COMPONENT_TEST_TARGETS=
164
9074b6 165 # configure the unpacked source for building 32 and 64 bit version
AL 166 CMAKE =    cmake
ced62a 167
AW 168 # provide test transforms for ctest
169 CMAKE_TEST_TRANSFORMS = \
170     ' -e "s/[0-9]*\.[0-9]* sec//" ' \
171     ' -n ' \
d7f395 172     ' -e "/Not Run/p" ' \
ced62a 173     ' -e "/Start/p" ' \
67036b 174     ' -e "/Skipped/p" ' \
ced62a 175     ' -e "/Failed/p" ' \
AW 176     ' -e "/Passed/p" ' \
177     ' -e "/failed/p" '
178
179 USE_DEFAULT_TEST_TRANSFORMS?=no
180 ifeq ($(strip $(USE_DEFAULT_TEST_TRANSFORMS)),yes)
181 COMPONENT_TEST_TRANSFORMS += $(CMAKE_TEST_TRANSFORMS)
182 endif
183
9074b6 184 $(BUILD_DIR)/%/.configured:    $(SOURCE_DIR)/.prep
AL 185     ($(RM) -rf $(@D) ; $(MKDIR) $(@D))
186     $(COMPONENT_PRE_CMAKE_ACTION)
187     (cd $(@D) ; $(ENV) $(CMAKE_ENV) \
188         $(CMAKE) $(CMAKE_OPTIONS) $(SOURCE_DIR))
189     $(COMPONENT_POST_CMAKE_ACTION)
190     $(TOUCH) $@
191
192 # build the configured source
193 $(BUILD_DIR)/%/.built:    $(BUILD_DIR)/%/.configured
194     $(COMPONENT_PRE_BUILD_ACTION)
195     (cd $(@D) ; $(ENV) $(COMPONENT_BUILD_ENV) \
196         $(GMAKE) $(COMPONENT_BUILD_GMAKE_ARGS) $(COMPONENT_BUILD_ARGS) \
197         $(COMPONENT_BUILD_TARGETS))
198     $(COMPONENT_POST_BUILD_ACTION)
199     $(TOUCH) $@
200
201 # install the built source into a prototype area
202 $(BUILD_DIR)/%/.installed:    $(BUILD_DIR)/%/.built
203     $(COMPONENT_PRE_INSTALL_ACTION)
204     (cd $(@D) ; $(ENV) $(COMPONENT_INSTALL_ENV) $(GMAKE) \
205             $(COMPONENT_INSTALL_ARGS) $(COMPONENT_INSTALL_TARGETS))
206     $(COMPONENT_POST_INSTALL_ACTION)
207     $(TOUCH) $@
208
209 # test the built source
940b86 210 $(BUILD_DIR)/%/.tested-and-compared:    $(BUILD_DIR)/%/.built
237543 211     $(RM) -rf $(COMPONENT_TEST_BUILD_DIR)
AP 212     $(MKDIR) $(COMPONENT_TEST_BUILD_DIR)
940b86 213     $(COMPONENT_PRE_TEST_ACTION)
AP 214     -(cd $(COMPONENT_TEST_DIR) ; \
215         $(COMPONENT_TEST_ENV_CMD) $(COMPONENT_TEST_ENV) \
216         $(COMPONENT_TEST_CMD) \
217         $(COMPONENT_TEST_ARGS) $(COMPONENT_TEST_TARGETS)) \
218         &> $(COMPONENT_TEST_OUTPUT)
219     $(COMPONENT_POST_TEST_ACTION)
220     $(COMPONENT_TEST_CREATE_TRANSFORMS)
221     $(COMPONENT_TEST_PERFORM_TRANSFORM)
222     $(COMPONENT_TEST_COMPARE)
223     $(COMPONENT_TEST_CLEANUP)
224     $(TOUCH) $@
225
89aae0 226 $(BUILD_DIR)/%/.tested:    SHELLOPTS=pipefail
9074b6 227 $(BUILD_DIR)/%/.tested:    $(BUILD_DIR)/%/.built
89aae0 228     $(RM) -rf $(COMPONENT_TEST_BUILD_DIR)
MT 229     $(MKDIR) $(COMPONENT_TEST_BUILD_DIR)
9074b6 230     $(COMPONENT_PRE_TEST_ACTION)
940b86 231     (cd $(COMPONENT_TEST_DIR) ; \
AP 232         $(COMPONENT_TEST_ENV_CMD) $(COMPONENT_TEST_ENV) \
233         $(COMPONENT_TEST_CMD) \
89aae0 234         $(COMPONENT_TEST_ARGS) $(COMPONENT_TEST_TARGETS)) \
MT 235         |& $(TEE) $(COMPONENT_TEST_OUTPUT)
9074b6 236     $(COMPONENT_POST_TEST_ACTION)
89aae0 237     $(COMPONENT_TEST_CREATE_TRANSFORMS)
MT 238     $(COMPONENT_TEST_PERFORM_TRANSFORM)
940b86 239     $(COMPONENT_TEST_CLEANUP)
9074b6 240     $(TOUCH) $@
AL 241
242 clean::
243     $(RM) -r $(BUILD_DIR) $(PROTO_DIR)