-
Notifications
You must be signed in to change notification settings - Fork 26
/
pxp-agent.rb
161 lines (144 loc) · 7.02 KB
/
pxp-agent.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
component 'pxp-agent' do |pkg, settings, platform|
pkg.load_from_json('configs/components/pxp-agent.json')
toolchain = '-DCMAKE_TOOLCHAIN_FILE=/opt/pl-build-tools/pl-build-toolchain.cmake'
cmake = '/opt/pl-build-tools/bin/cmake'
boost_static_flag = ''
if platform.is_windows?
pkg.environment 'PATH', "$(shell cygpath -u #{settings[:prefix]}/lib):$(shell cygpath -u #{settings[:gcc_bindir]}):$(shell cygpath -u #{settings[:ruby_bindir]}):/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0"
elsif platform.is_aix?
pkg.environment 'PATH', '/opt/freeware/bin:$(PATH)'
else
pkg.environment 'PATH', "#{settings[:bindir]}:/opt/pl-build-tools/bin:$(PATH)"
end
if settings[:system_openssl]
pkg.build_requires 'openssl-devel'
else
pkg.build_requires 'puppet-runtime' # Provides openssl
end
pkg.build_requires 'leatherman'
pkg.build_requires 'cpp-pcp-client'
pkg.build_requires 'cpp-hocon'
make = platform[:make]
special_flags = " -DCMAKE_INSTALL_PREFIX=#{settings[:prefix]} "
if platform.is_aix?
cmake = '/opt/freeware/bin/cmake'
toolchain = ''
special_flags += '-DENABLE_CXX_WERROR=OFF'
elsif platform.is_macos?
cmake = '/usr/local/bin/cmake'
toolchain = ''
special_flags += "-DCMAKE_CXX_FLAGS='#{settings[:cflags]}' -DENABLE_CXX_WERROR=OFF"
boost_static_flag = '-DBOOST_STATIC=OFF'
if platform.is_cross_compiled?
pkg.environment 'CXX', 'clang++ -target arm64-apple-macos11' if platform.name =~ /osx-11/
pkg.environment 'CXX', 'clang++ -target arm64-apple-macos12' if platform.name =~ /osx-12/
end
if platform.os_version.to_i >= 13 && platform.architecture == 'arm64'
cmake = '/opt/homebrew/bin/cmake'
pkg.environment 'CXX', 'clang++'
end
elsif platform.is_cross_compiled_linux?
cmake = '/opt/pl-build-tools/bin/cmake'
toolchain = "-DCMAKE_TOOLCHAIN_FILE=/opt/pl-build-tools/#{settings[:platform_triple]}/pl-build-toolchain.cmake"
elsif platform.is_solaris?
if !platform.is_cross_compiled? && platform.architecture == 'sparc'
cmake = '/opt/pl-build-tools/bin/cmake'
toolchain = ''
special_flags += " -DCMAKE_CXX_COMPILER=/opt/pl-build-tools/bin/g++ -DCMAKE_CXX_FLAGS='-pthreads' -DENABLE_CXX_WERROR=OFF "
else
cmake = "/opt/pl-build-tools/i386-pc-solaris2.#{platform.os_version}/bin/cmake"
toolchain = "-DCMAKE_TOOLCHAIN_FILE=/opt/pl-build-tools/#{settings[:platform_triple]}/pl-build-toolchain.cmake"
# PCP-87: If we build with -O3, solaris segfaults due to something in std::vector
special_flags += " -DCMAKE_CXX_FLAGS_RELEASE='-O2 -DNDEBUG' "
special_flags += if platform.name =~ /^solaris-10-sparc/
" -DCMAKE_EXE_LINKER_FLAGS=' /opt/puppetlabs/puppet/lib/libssl.so /opt/puppetlabs/puppet/lib/libgcc_s.so /opt/puppetlabs/puppet/lib/libcrypto.so' "
else
" -DCMAKE_EXE_LINKER_FLAGS=' /opt/puppetlabs/puppet/lib/libssl.so /opt/puppetlabs/puppet/lib/libcrypto.so' "
end
end
elsif platform.is_windows?
make = "#{settings[:gcc_bindir]}/mingw32-make"
pkg.environment 'CYGWIN', settings[:cygwin]
cmake = 'C:/ProgramData/chocolatey/bin/cmake.exe -G "MinGW Makefiles"'
toolchain = "-DCMAKE_TOOLCHAIN_FILE=#{settings[:tools_root]}/pl-build-toolchain.cmake"
elsif platform.name =~ /el-[67]|redhatfips-7|sles-12|ubuntu-18.04-amd64/
# use default that is pl-build-tools
elsif platform.name =~ /sles-11/
special_flags += "-DCMAKE_CXX_FLAGS='#{settings[:cflags]}' -DENABLE_CXX_WERROR=OFF"
else
# These platforms use the default OS toolchain, rather than pl-build-tools
toolchain = ''
special_flags += " -DCMAKE_CXX_FLAGS='#{settings[:cflags]} -Wno-deprecated -Wimplicit-fallthrough=0' "
special_flags += ' -DENABLE_CXX_WERROR=OFF ' unless platform.name =~ /sles-15/
cmake = if platform.name =~ /amazon-2-aarch64/
'/usr/bin/cmake3'
else
'cmake'
end
end
# Boost_NO_BOOST_CMAKE=ON was added while upgrading to boost
# 1.73 for PA-3244. https://cmake.org/cmake/help/v3.0/module/FindBoost.html#boost-cmake
# describes the setting itself (and what we are disabling). It
# may make sense in the future to remove this cmake parameter and
# actually make the boost build work with boost's own cmake
# helpers. But for now disabling boost's cmake helpers allow us
# to upgrade boost with minimal changes.
# - Sean P. McDonald 5/19/2020
pkg.configure do
[
"#{cmake}\
#{toolchain} \
-DLEATHERMAN_GETTEXT=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCMAKE_PREFIX_PATH=#{settings[:prefix]} \
-DCMAKE_INSTALL_RPATH=#{settings[:libdir]} \
-DCMAKE_SYSTEM_PREFIX_PATH=#{settings[:prefix]} \
-DMODULES_INSTALL_PATH=#{File.join(settings[:install_root], 'pxp-agent', 'modules')} \
#{special_flags} \
#{boost_static_flag} \
-DBoost_NO_BOOST_CMAKE=ON \
."
]
end
cores = if platform.name =~ /solaris-11-sparc/ && !platform.is_cross_compiled?
'2' # limit to 2 so we don't run out of memory
else
"$(shell expr $(shell #{platform[:num_cores]}) + 1)"
end
pkg.build do
["#{make} -j#{cores}"]
end
pkg.install do
["#{make} -j#{cores} install"]
end
service_conf = settings[:service_conf]
platform.get_service_types.each do |servicetype|
case servicetype
when 'systemd'
pkg.install_file('ext/systemd/pxp-agent.service', "#{service_conf}/systemd/pxp-agent.service")
pkg.install_file('ext/redhat/pxp-agent.sysconfig', "#{service_conf}/redhat/pxp-agent.sysconfig")
pkg.install_file('ext/systemd/pxp-agent.logrotate', "#{service_conf}/systemd/pxp-agent.logrotate")
when 'sysv'
if platform.is_deb?
pkg.install_file('ext/debian/pxp-agent.init', "#{service_conf}/debian/pxp-agent.init")
pkg.install_file('ext/debian/pxp-agent.default', "#{service_conf}/debian/pxp-agent.default")
elsif platform.is_sles?
pkg.install_file('ext/suse/pxp-agent.init', "#{service_conf}/suse/pxp-agent.init")
pkg.install_file('ext/redhat/pxp-agent.sysconfig', "#{service_conf}/redhat/pxp-agent.sysconfig")
elsif platform.is_rpm?
pkg.install_file('ext/redhat/pxp-agent.init', "#{service_conf}/redhat/pxp-agent.init")
pkg.install_file('ext/redhat/pxp-agent.sysconfig', "#{service_conf}/redhat/pxp-agent.sysconfig")
end
pkg.install_file('ext/pxp-agent.logrotate', "#{service_conf}/pxp-agent.logrotate")
when 'launchd'
pkg.install_file('ext/osx/pxp-agent.plist', "#{service_conf}/osx/pxp-agent.plist")
pkg.install_file('ext/osx/pxp-agent.newsyslog.conf', "#{service_conf}/osx/pxp-agent.newsyslog.conf")
when 'smf'
pkg.install_file('ext/solaris/smf/pxp-agent.xml', "#{service_conf}/solaris/smf/pxp-agent.xml")
when /windows|aix/
# nothing to do
else
raise "need to know where to put #{pkg.get_name} service files"
end
end
end