1#!/usr/bin/make 2 3DEFAULT_VERSION := $(shell grep 'define NXT_VERSION' ../../src/nxt_main.h \ 4 | sed -e 's/^.*"\(.*\)".*/\1/') 5 6DEFAULT_RELEASE := 1 7 8VERSION ?= $(DEFAULT_VERSION) 9RELEASE ?= $(DEFAULT_RELEASE) 10 11SRCDIR= unit-$(VERSION) 12 13CODENAME = $(shell lsb_release -cs) 14 15BUILD_DEPENDS = debhelper devscripts libxml2-utils lintian lsb-release xsltproc 16 17MODULES= 18 19# Ubuntu 17.04 20ifeq ($(CODENAME),zesty) 21include Makefile.php 22include Makefile.python27 23include Makefile.python35 24include Makefile.go17 25include Makefile.go18 26endif 27 28# Ubuntu 16.04 29ifeq ($(CODENAME),xenial) 30include Makefile.php 31include Makefile.python27 32include Makefile.python35 33include Makefile.go 34endif 35 36# Ubuntu 14.04 37ifeq ($(CODENAME),trusty) 38include Makefile.php 39include Makefile.python 40endif 41 42# Debian 9 43ifeq ($(CODENAME),stretch) 44include Makefile.php 45include Makefile.python27 46include Makefile.python35 47include Makefile.go17 48include Makefile.go18 49endif 50 51# Debian 8 52ifeq ($(CODENAME),jessie) 53include Makefile.php 54include Makefile.python27 55endif 56 57CONFIGURE_ARGS=\ 58 --prefix=/usr \ 59 --state=/var/lib/unit \ 60 --control="unix:/var/run/control.unit.sock" \ 61 --pid=/var/run/unit.pid \ 62 --log=/var/log/unit.log \ 63 --tests 64 65export CR=\\n 66 67default: 68 @echo "valid targets: all modules unit $(addprefix unit-, $(MODULES)) clean" 69 70all: check-build-depends unit modules 71 72modules: $(addprefix unit-, $(MODULES)) 73 74check-build-depends: 75 @{ \ 76 not_installed= ; \ 77 for pkg in $(BUILD_DEPENDS); do \ 78 dpkg -s $${pkg} >/dev/null 2>&1 ; \ 79 if [ $$? -ne 0 ]; then \ 80 not_installed="$${not_installed} $${pkg}" ; \ 81 fi ; \ 82 done ; \ 83 if test -n "$${not_installed}" ; then \ 84 echo "" >&2 ; \ 85 echo "The following packages are required in order to proceed:" >&2 ; \ 86 echo "" >&2 ; \ 87 echo $${not_installed} >&2 ; \ 88 echo "" >&2 ; \ 89 exit 1 ; \ 90 fi \ 91 } 92 93debuild/$(SRCDIR)/debian: 94 @{ \ 95 set -e ; \ 96 mkdir -p debuild/$(SRCDIR) ; \ 97 cp -pr debian debuild/$(SRCDIR) ; \ 98 echo '9' > debuild/$(SRCDIR)/debian/compat ; \ 99 mkdir -p debuild/$(SRCDIR)/debian/source ; \ 100 echo '3.0 (quilt)' > debuild/$(SRCDIR)/debian/source/format ; \ 101 cat debian/rules.in | sed \ 102 -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \ 103 > debuild/$(SRCDIR)/debian/rules ; \ 104 } 105 106debuild/$(SRCDIR)/debian/changelog: ../../docs/changes.xml | debuild/$(SRCDIR)/debian 107 cd ../../docs && make ../build/unit.deb-changelog 108ifneq ($(DEFAULT_VERSION)$(DEFAULT_RELEASE), $(VERSION)$(RELEASE)) 109 cat ../../build/unit.deb-changelog | sed \ 110 -e "s/unit ($(DEFAULT_VERSION)-$(DEFAULT_RELEASE)~/unit ($(VERSION)-$(RELEASE)~/" \ 111 -e "s#%%CODENAME%%#$(CODENAME)#g" \ 112 > debuild/$(SRCDIR)/debian/changelog 113else 114 cat ../../build/unit.deb-changelog | sed \ 115 -e "s#%%CODENAME%%#$(CODENAME)#g" \ 116 > debuild/$(SRCDIR)/debian/changelog 117endif 118 119debuild/unit_$(VERSION).orig.tar.gz: | debuild/$(SRCDIR)/debian 120 cd ../.. && tar -czf pkg/deb/debuild/$(SRCDIR).tar.gz \ 121 --transform "s#^#$(SRCDIR)/#" \ 122 LICENSE NOTICE CHANGES README configure auto src test 123 mv debuild/$(SRCDIR).tar.gz debuild/unit_$(VERSION).orig.tar.gz 124 cd debuild && tar zxf unit_$(VERSION).orig.tar.gz 125 126unit: debuild/unit_$(VERSION).orig.tar.gz debuild/$(SRCDIR)/debian/changelog 127 @echo "===> Building $@ package" 128 cd debuild/$(SRCDIR) && debuild -us -uc 129 mkdir -p debs 130 find debuild/ -maxdepth 1 -type f -exec cp {} debs/ \; 131 ln -s debuild/$(SRCDIR)/build $@ 132 133debuild-%: debuild/unit_$(VERSION).orig.tar.gz ../../docs/changes.xml 134 mkdir $@ 135 cp debuild/unit_$(VERSION).orig.tar.gz debuild-$*/unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz 136 cd $@ && tar zxf unit-$(MODULE_SUFFIX_$*)_$(VERSION).orig.tar.gz 137 mkdir $@/$(SRCDIR)/debian 138 echo '9' > $@/$(SRCDIR)/debian/compat 139 mkdir $@/$(SRCDIR)/debian/source 140 echo '3.0 (quilt)' > $@/$(SRCDIR)/debian/source/format 141 cd ../../docs && make ../build/unit-$(MODULE_SUFFIX_$*).deb-changelog 142 cat ../../build/unit-$(MODULE_SUFFIX_$*).deb-changelog | sed \ 143 -e "s#%%CODENAME%%#$(CODENAME)#g" \ 144 > $@/$(SRCDIR)/debian/changelog 145 cp debian/copyright debuild-$*/$(SRCDIR)/debian/ 146 @{ \ 147 set -e ; \ 148 for src in $(MODULE_SOURCES_$*); do \ 149 cp debian.module/$${src} $@/$(SRCDIR)/debian/ ; \ 150 done ; \ 151 definitions=`echo "$$MODULE_DEFINITIONS_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \ 152 prebuild=`echo "$$MODULE_PREBUILD_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \ 153 preinstall=`echo "$$MODULE_PREINSTALL_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \ 154 post=`echo "$$MODULE_POST_$*" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \ 155 cat debian.module/$(if $(MODULE_NOARCH_$*),control-noarch.in,control.in) | sed \ 156 -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \ 157 -e "s#%%SUMMARY%%#$(MODULE_SUMMARY_$*)#g" \ 158 -e "s#%%CODENAME%%#$(CODENAME)#g" \ 159 -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \ 160 -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \ 161 -e "s#%%VERSION%%#$(MODULE_VERSION_$*)#g" \ 162 -e "s#%%RELEASE%%#$(MODULE_RELEASE_$*)#g" \ 163 -e "s#%%MODULE_BUILD_DEPENDS%%#$(MODULE_BUILD_DEPENDS_$*)#g" \ 164 -e "s#%%MODULE_DEPENDS%%#$(MODULE_DEPENDS_$*)#g" \ 165 > $@/$(SRCDIR)/debian/control ; \ 166 cat debian.module/$(if $(MODULE_NOARCH_$*),rules-noarch.in,rules.in) | sed \ 167 -e "s#%%NAME%%#unit-$(MODULE_SUFFIX_$*)#g" \ 168 -e "s#%%CODENAME%%#$(CODENAME)#g" \ 169 -e "s#%%UNIT_VERSION%%#$(VERSION)#g" \ 170 -e "s#%%UNIT_RELEASE%%#$(RELEASE)#g" \ 171 -e "s#%%CONFIGURE_ARGS%%#$(CONFIGURE_ARGS)#g" \ 172 -e "s#%%MODULE_CONFARGS%%#$(MODULE_CONFARGS_$*)#g" \ 173 -e "s#%%MODULE_MAKEARGS%%#$(MODULE_MAKEARGS_$*)#g" \ 174 -e "s#%%MODULE_INSTARGS%%#$(MODULE_INSTARGS_$*)#g" \ 175 -e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \ 176 -e "s#%%MODULE_PREBUILD%%#$${prebuild}#g" \ 177 -e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \ 178 > $@/$(SRCDIR)/debian/rules ; \ 179 cat debian.module/preinst.in | sed \ 180 -e "s#%%MODULE_POST%%#$$post#g" \ 181 > $@/$(SRCDIR)/debian/preinst ; \ 182 chmod +x $@/$(SRCDIR)/debian/rules ; \ 183 } 184 185unit-%: | debuild-% 186 @echo "===> Building $@ package" 187 cd debuild-$*/$(SRCDIR) && debuild -us -uc 188 mkdir -p debs 189 find debuild-$*/ -maxdepth 1 -type f -exec cp {} debs/ \; 190 ln -s debuild-$*/$(SRCDIR)/build $@ 191 192clean: 193 rm -rf debuild debuild-* debs ../../build 194 find . -maxdepth 1 -type l -delete 195 196.PHONY: default all modules check-build-depends clean 197 198.SECONDARY: 199