Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / package / linux / deb.mk
blob42c31eeebb62ebbf4ee6ca7bdbc8ba55acf49bee
1 DEB_DIST := $(shell lsb_release -c -s)
2 # Instead of RELEASE-15.01-RC1 debian wants 15.01~RC1
3 UPSTREAM_VER := $(subst -,~,$(subst RELEASE-,,$(PACKAGE_LBL)))
4 ifeq ($(DEB_DIST), unstable) # This should be set manually for a submission to Debian or similar
5 DEB_REV := 1
6 else
7 DEB_REV := 0$(DEB_DIST)1
8 endif
9 DEB_NAME := $(ORG_SMALL_NAME)
10 DEB_ORIG_SRC := $(PACKAGE_DIR)/$(DEB_NAME)_$(UPSTREAM_VER).orig.tar.gz
11 DEB_ORIG_FW := $(PACKAGE_DIR)/$(DEB_NAME)_$(UPSTREAM_VER).orig-firmware.tar.gz
12 DEB_SRC_CHANGES := $(PACKAGE_DIR)/$(DEB_NAME)_$(UPSTREAM_VER)-$(DEB_REV)_source.changes
13 DEB_PACKAGE_DIR := $(PACKAGE_DIR)/$(DEB_NAME)-$(UPSTREAM_VER)
14 DEB_ARCH := $(shell dpkg --print-architecture)
15 DEB_PACKAGE_NAME := $(DEB_NAME)_$(UPSTREAM_VER)-$(DEB_REV)_$(DEB_ARCH)
16 DEB_DIR := package/linux/debian
18 SED_DATE_STRG := $(shell date -R)
19 SED_SCRIPT := $(SED_SCRIPT)' \
20 s/<VERSION>/$(UPSTREAM_VER)-$(DEB_REV)/g; \
21 s/<DATE>/$(SED_DATE_STRG)/g; \
22 s/<DIST>/$(DEB_DIST)/g; \
23 s/<NAME>/$(DEB_NAME)/g; \
24 s/<DESCRIPTION>/$(DESCRIPTION_SHORT)\n $(subst ','"'"',$(subst $(NEWLINE),\n ,$(DESCRIPTION_LONG)))/g; \
27 # Ubuntu 14.04 (Trusty Tahr) use qt in /opt PPA
28 TRUSTY_DEPS_SED := s/qml-module-.*/$(OPT_QT)quickcontrols/g; \
29 s/qt5-default.*/$(OPT_QT)-meta-minimal, $(OPT_QT)svg, $(OPT_QT)script, $(OPT_QT)serialport, $(OPT_QT)multimedia, $(OPT_QT)translations, $(OPT_QT)tools/g;
31 # Leave off Qt and OSG dependencies if calling package target under the assumption that
32 # OP is providing them or the user already has them installed because OP is already built.
33 PACKAGE_DEPS_SED := s/python.*/python/;s/{misc:Depends}.*/{misc:Depends}/;
35 .PHONY: package
36 package: debian
37 @$(ECHO) "Building Linux package, please wait..."
38 $(V1) sed -i -e "$(PACKAGE_DEPS_SED)" debian/control
39 $(V1) sed -i -e 's,config_new.*, --help > /dev/null,' debian/rules
40 $(V1) dpkg-buildpackage -b -us -uc -nc
41 $(V1) mv $(ROOT_DIR)/../$(DEB_PACKAGE_NAME).deb $(BUILD_DIR)
42 $(V1) mv $(ROOT_DIR)/../$(DEB_PACKAGE_NAME).changes $(BUILD_DIR)
43 $(V1) rm -r debian
45 DEBIAN_DIR_FILES := changelog compat control copyright rules source/format
46 .PHONY: debian
47 debian: $(DEB_DIR)
48 $(V1) rm -rf debian && mkdir debian
49 $(V1) cd $(DEB_DIR) $(foreach file,$(DEBIAN_DIR_FILES), && cp --parents $(file) $(ROOT_DIR)/debian)
50 $(V1) cp -T package/linux/45-uav.rules debian/$(DEB_NAME).udev
51 $(V1) $(SED_SCRIPT) debian/changelog debian/control
52 ifeq ($(DEB_DIST), trusty)
53 $(V1) sed -i -e '$(TRUSTY_DEPS_SED)' debian/control
54 endif
56 .PHONY: package_src
57 package_src: $(DEB_SRC_CHANGES)
59 .PHONY: package_src_upload
60 package_src_upload: $(DEB_SRC_CHANGES)
61 $(V1) debsign $(DEB_SRC_CHANGES)
62 $(V1) dput $(DPUT_URL) $(DEB_SRC_CHANGES)
64 # Only include the orig if it we haven't alreadly built it,
65 # because if we have it is likely to be uploaded already
66 ifeq ($(wildcard $(DEB_ORIG_SRC)),)
67 DPKG_INCLUDE_ORIG := -sa
68 else
69 DPKG_INCLUDE_ORIG := -sd
70 endif
72 $(DEB_SRC_CHANGES): $(DEB_ORIG_SRC_NAME) $(DEB_PACKAGE_DIR)
73 $(V1) cd $(DEB_PACKAGE_DIR) && dpkg-buildpackage -S -us -uc $(DPKG_INCLUDE_ORIG)
75 $(DEB_ORIG_SRC): $(DIST_TAR_GZ) | $(PACKAGE_DIR)
76 $(V1) cp $(DIST_TAR_GZ) $(DEB_ORIG_SRC)
78 $(DEB_ORIG_FW): $(FW_DIST_TAR_GZ) | $(PACKAGE_DIR)
79 $(V1) cp $(FW_DIST_TAR_GZ) $(DEB_ORIG_FW)
81 $(DEB_PACKAGE_DIR): $(DEB_ORIG_SRC) $(DEB_ORIG_FW) debian | $(PACKAGE_DIR)
82 $(V1) tar -xf $(DEB_ORIG_SRC) -C $(PACKAGE_DIR)
83 $(V1) tar -xf $(DEB_ORIG_FW) -C $(PACKAGE_DIR)/$(PACKAGE_NAME)
84 $(V1) mv debian $(PACKAGE_DIR)/$(PACKAGE_NAME)
85 $(V1) rm -rf $(DEB_PACKAGE_DIR) && mv $(PACKAGE_DIR)/$(PACKAGE_NAME) $(DEB_PACKAGE_DIR)