@@ -4,29 +4,69 @@ BUILDDIR = $(shell pwd)
44PACKAGE_NAME_CLEAN = $(shell echo "{{package_name}}" | sed -e 's/-/_/g')
55BUILD_STAGE_DIR = $(BUILDDIR ) /$(PACKAGE_NAME_CLEAN )
66
7+ # # Version Information
8+ # # ## pkgsrc version mapping to SmartOS version
9+ # # SmartOS pkgsrc
10+ # # 1.6 2011Q4
11+ # # 1.8 2012Q2
12+ # # 13.1 2013Q1
13+ # # ## Erlang Deps by version
14+ # # SmartOS openssl ncurses
15+ # # 1.6 0.9.8knb1 5.4nb1
16+ # # 1.8 0.9.8knb1 5.4nb1
17+ # # 13.1 1.0.1c 5.4nb1
18+ # # ## Additional Deps for runner
19+ # # sudo (same for all versions)
20+ # #
21+ # # ## SMF Manifest Mapping
22+ # # SmartOS Manifest File
23+ # # 1.6 manifest.xml
24+ # # 1.8 manifest18.xml
25+ # # 13.1 manifest18.xml
26+
27+ PKGSRC_VERSION = $(shell head -1 /etc/pkgsrc_version 2>/dev/null | cut -d' ' -f2)
28+
29+ ifeq ($(PKGSRC_VERSION ) ,2011Q4) # SmartOS 1.6
30+ NCURSES_DEP = ncurses-5*
31+ OPENSSL_DEP = openssl-0.9.8*
32+ GCC_DEP = gcc-runtime-4.6.2
33+ SMF_MANIFEST = manifest.xml
34+ endif
35+ ifeq ($(PKGSRC_VERSION ) ,2012Q2) # SmartOS 1.8
36+ NCURSES_DEP = ncurses-5*
37+ OPENSSL_DEP = openssl-0.9.8*
38+ GCC_DEP = gcc47-runtime>=4.7.0
39+ SMF_MANIFEST = manifest18.xml
40+ endif
41+ ifeq ($(PKGSRC_VERSION ) ,2013Q1) # SmartOS 13.1
42+ NCURSES_DEP = ncurses-5*
43+ OPENSSL_DEP = openssl-1.0.1*
44+ GCC_DEP = gcc47-libs>=4.7.0
45+ SMF_MANIFEST = manifest131.xml
46+ endif
747
8- # SmartOS changed pkgsrc versions which majorly changed
9- # the layout of the filesystem. SmartOS 1.6 uses a
10- # different SMF manifest file than newer versions
11- SMF_MANIFEST = $(shell head -1 /etc/pkgsrc_version | \
12- grep -c 2011Q4 2> /dev/null | awk \
13- '{if ($$1 == "1") {print "manifest.xml"} else {print "manifest18.xml"}}')
1448
1549# Where we install things (based on vars.config)
1650# /opt/local based dirs
51+ # /var based dirs are handled in the +INSTALL file and dirs_file target
1752PMAN_DIR := $(BUILD_STAGE_DIR ) /man
1853PBIN_DIR := $(BUILD_STAGE_DIR ) /{{bin_or_sbin}}
1954PETC_DIR := $(BUILD_STAGE_DIR ) /etc/{{package_install_name}}
2055PLIB_DIR := $(BUILD_STAGE_DIR ) /lib/{{package_install_name}}
2156PSMF_DIR := $(BUILD_STAGE_DIR ) /share/smf/{{package_install_name}}
2257ESMF_DIR := $(BUILD_STAGE_DIR ) /share/smf/{{package_install_name}}-epmd
58+ PDATA_DIR := $(BUILD_STAGE_DIR ) /{{platform_data_dir}}
59+
60+ # For scanning later, grab the first dirname
61+ # '/var/db/server' becomes 'var'
62+ PDATA_ROOT_DIR = $(shell echo "{{platform_data_dir}}" | cut -d'/' -f 2)
63+
64+
2365
2466# Recursive assignment of ERTS version
2567# We will know this after building the rel
2668ERTS_PATH = $(shell ls $(BUILDDIR ) /rel/{{package_install_name}} | egrep -o "erts-.* ")
2769
28- # /var based dirs are handled in the +INSTALL file
29-
3070TARNAME := $(PACKAGE_NAME_CLEAN ) -$(PKG_VERSION ) -$(OSNAME ) -$(ARCH ) .tar
3171PKGNAME := $(PACKAGE_NAME_CLEAN ) -$(PKG_VERSION ) -$(OSNAME ) -$(ARCH ) .tgz
3272
@@ -36,7 +76,7 @@ PKGNAME := $(PACKAGE_NAME_CLEAN)-$(PKG_VERSION)-$(OSNAME)-$(ARCH).tgz
3676# particular order to not anger pkg_add.
3777# This is done by piping the file listings into tar
3878# in the same manner we did with the +CONTENTS file
39- build : packing_list_files
79+ build : packing_list_files dirs_file
4080 @echo " Building package $( PKGNAME) "
4181 mkdir -p packages
4282 cd $(BUILD_STAGE_DIR ) && \
@@ -58,6 +98,7 @@ build: packing_list_files
5898 shasum -a 256 $${tarfile} > $${tarfile}.sha \
5999 ; done
60100
101+
61102# Where most of the magic (horror?) happens
62103# Create a packing list according to pkg_create(1)
63104# Write initial settings to a local plist then copy
@@ -68,19 +109,23 @@ packing_list_files: $(BUILD_STAGE_DIR) templates
68109 echo " @name $( PACKAGE_NAME_CLEAN) -$( PKG_VERSION) " >> plist
69110 echo " @pkgcfl $( PACKAGE_NAME_CLEAN) -*" >> plist
70111 echo " @pkgdep sudo-[0-9]*" >> plist
71- echo " @pkgdep openssl-0.9.8*" >> plist
112+ echo " @pkgdep $( OPENSSL_DEP) " >> plist
113+ echo " @pkgdep $( NCURSES_DEP) " >> plist
114+ echo " @pkgdep $( GCC_DEP) " >> plist
72115
73116 @echo "Copying staging package listing to +CONTENTS"
74117 mv plist $(BUILD_STAGE_DIR)/+CONTENTS
75118
76119 @echo "Packaging /opt/local files"
77120 cd $(BUILD_STAGE_DIR) && \
121+ echo "@comment Packing manpage files" >> +CONTENTS && \
78122 echo "@cwd /opt/local" >> +CONTENTS && \
79123 echo "@owner root" >> +CONTENTS && \
80124 echo "@group root" >> +CONTENTS && \
81125 find man -type f >> +CONTENTS
82126
83127 cd $(BUILD_STAGE_DIR) && \
128+ echo "@comment Packing /opt/local/etc files" >> +CONTENTS && \
84129 echo "@cwd /opt/local" >> +CONTENTS && \
85130 echo "@owner root" >> +CONTENTS && \
86131 echo "@group {{package_install_user}}" >> +CONTENTS && \
@@ -90,17 +135,22 @@ packing_list_files: $(BUILD_STAGE_DIR) templates
90135 echo "@exec chmod -R g+r+X {{platform_etc_dir}}" >> +CONTENTS
91136
92137 cd $(BUILD_STAGE_DIR) && \
138+ echo "@comment Packing lib files" >> +CONTENTS && \
93139 echo "@cwd /opt/local" >> +CONTENTS && \
94140 echo "@owner {{package_install_user}}" >> +CONTENTS && \
95141 echo "@group {{package_install_group}}" >> +CONTENTS
142+
96143 cd $(BUILD_STAGE_DIR) && \
97144 find lib -type f >> +CONTENTS && \
98145 echo "@exec chown -R {{package_install_user}}:{{package_install_group}} {{platform_base_dir}}" >> +CONTENTS
146+
99147 cd $(BUILD_STAGE_DIR) && \
148+ echo "@comment Packing /usr/local {{bin_or_sbin}} files" >> +CONTENTS && \
100149 echo "@owner {{package_install_user}}" >> +CONTENTS && \
101150 echo "@group {{package_install_group}}" >> +CONTENTS && \
102151 echo "@mode 0755" >> +CONTENTS && \
103152 find {{bin_or_sbin}} -type f >> +CONTENTS
153+
104154 cd $(BUILD_STAGE_DIR) && \
105155 echo "@owner {{package_install_user}}" >> +CONTENTS && \
106156 echo "@group {{package_install_group}}" >> +CONTENTS && \
@@ -110,11 +160,33 @@ packing_list_files: $(BUILD_STAGE_DIR) templates
110160 echo "@display +DISPLAY" >> +CONTENTS
111161
112162
163+ # Creates a variable to be read by the +INSTALL script to
164+ # create directories not supported by the +CONTENTS file
165+ # such as log and data directories.
166+ # platform_log_dir and platform_data_dir are always added
167+ # This is black magic appending the directories to the
168+ # to a variable inside of the makefile target
169+ # and then using sed to insert that list into
170+ # the +INSTALL script.
171+ # I feel dirty now.
172+ dirs_file : $(BUILD_STAGE_DIR )
173+ @echo " Adding data and log directories to directory list"
174+ $(eval DIRS_INSTALL = {{platform_data_dir}})
175+ $(eval DIRS_INSTALL += {{platform_log_dir}})
176+ @echo " Scanning var directory for any additional install paths"
177+ $(eval DIRS_INSTALL += $(shell cd $(BUILD_STAGE_DIR ) && find $(PDATA_ROOT_DIR ) -type d -exec printf "/% s " {} \;) )
178+ cd $(BUILD_STAGE_DIR ) && \
179+ cp +INSTALL +INSTALL.tmp && \
180+ sed -e ' s|%DIRS_CREATE%|${DIRS_INSTALL}|' < \
181+ +INSTALL.tmp > +INSTALL && \
182+ rm +INSTALL.tmp
183+
184+
113185# These are static files that should not have to change often
114186templates : $(BUILD_STAGE_DIR )
115187 @echo " Copying metadata files to package"
116188 cp $(PKGERDIR ) /+DESC $(PKGERDIR ) /+COMMENT $(PKGERDIR ) /+DEINSTALL \
117- $(PKGERDIR)/+INSTALL $(PKGERDIR)/+BUILD_INFO \
189+ $(PKGERDIR ) /+INSTALL $(PKGERDIR ) /+BUILD_INFO \
118190 $(PKGERDIR ) /+DISPLAY $(BUILD_STAGE_DIR )
119191 mkdir -p $(PSMF_DIR )
120192 cp $(PKGERDIR ) /$(SMF_MANIFEST ) $(PSMF_DIR ) /manifest.xml
@@ -131,6 +203,8 @@ templates: $(BUILD_STAGE_DIR)
131203# The data and log directories need to go into /var, but the
132204# smartos pkg_add doesn't allow this to be in the +CONTENTS
133205# file so the directories are created in the +INSTALL script
206+ # We copy the data and log directories if they exist to make
207+ # scanning them easier later
134208$(BUILD_STAGE_DIR ) : buildrel
135209 @echo " Copying rel directory to staging directory"
136210 mkdir -p $@
@@ -143,19 +217,30 @@ $(BUILD_STAGE_DIR): buildrel
143217 cp -R $(BUILDDIR ) /rel/{{package_install_name}}/lib $(PLIB_DIR )
144218 cp -R $(BUILDDIR ) /rel/{{package_install_name}}/erts-* $(PLIB_DIR )
145219 cp -R $(BUILDDIR ) /rel/{{package_install_name}}/releases $(PLIB_DIR )
146- echo " Copying man pages to staging directory"
220+ @ echo " Copying man pages to staging directory"
147221 mkdir -p $(PMAN_DIR )
148222 if [ -d $( BUILDDIR) /doc/man/man1 ]; then \
149- cp -R $(BUILDDIR ) /doc/man/man1 $(PMAN_DIR ) ; fi
223+ cp -R $(BUILDDIR ) /doc/man/man1 $(PMAN_DIR ) ; fi
224+ @echo " Copying data and log directories to staging directory"
225+ if [ -d $( BUILDDIR) /rel/{{package_install_name}}/data ]; then \
226+ mkdir -p $(PDATA_DIR ) && \
227+ cp -R $(BUILDDIR ) /rel/{{package_install_name}}/data/* $(PDATA_DIR ) ; fi
150228
151229
230+ # If we can read the PKGSRC_VERSION we should fail
231+ # If NCURSES_DEP wasn't set, we know it was an unknown PKGSRC version
232+ smartos_check :
233+ @echo " Checking SmartOS Version"
234+ $(if $(PKGSRC_VERSION ) ,,$(error "Cannot find pkgsrc version from /etc/pkgsrc_version, cannot continue") )
235+ $(if $(NCURSES_DEP ) ,,$(error "Unsupported SmartOS version, please add to github.com/basho/node_package") )
236+ @echo " Building for pkgsrc version $( PKGSRC_VERSION) "
152237
153238# Build the release we need to package
154239# * Patch rel/files/riak with our version
155240# * Ensure all binaries are executable
156241# * copy the vars.config over for build config
157242# TODO, solve the .patch issue we have in riak
158- buildrel : $(BUILDDIR )
243+ buildrel : $(BUILDDIR ) smartos_check
159244 OVERLAY_VARS=" overlay_vars=../smartos/vars.config" $(MAKE ) deps rel
160245 chmod 0755 $(BUILDDIR ) /rel/{{package_install_name}}/bin/* $(BUILDDIR ) /rel/{{package_install_name}}/erts-* /bin/*
161246
0 commit comments