Skip to content

Commit

Permalink
Add linux package script
Browse files Browse the repository at this point in the history
  • Loading branch information
Izzatbek committed Mar 17, 2016
1 parent 3ca08e0 commit f6c32cf
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,22 @@ before_script:
script:
- make

before_deploy:
- |
if [ $TRAVIS_OS_NAME == linux ] ; then
./building-and-packaging/linux/create-deb
fi
deploy:
provider: releases
api_key:
secure: DBrLbyfJ/+x+wT93pq7w3CPt0TU7AE9nx4UlK7sVdA2WWbyEUukH5vahA3mbgvn+WRAmi3Y2ssmiwee1+ujlZ912wBy7iWOCY0kRWJZK30Kjlh3GSPVlsXgHN5fJMlvHlGzyHasJdMP3sL/wgpXwxeoy+P0XwEw5/RWTu1JVtxwGvZC/N8Gam6CFTaKz7nDe4hk8qO8Th9sVBYzk+2sFpPXEDUb8IQn1kiU1231QeYGYtuf/Qg75Cnr6AokR5S61aQlVQEW9nSmC3KrDiR++OFt50I7xtyjIg6ToI8ZKzAdgB/VidmtFo6+uh7xCZZsdSwKHtK4QFlYO2ozkTsiuEb3njg1aqNiFPH7rXK4ZyhtLpMupLMWnKlmaRQl3cwzwVOk/WYCP0+dK2zKPypKtpf9qUjXaMNH7BRnlfL1ZgP8yOE7Lt/jYMBIhAgSst9XGEfOhV1IDrit4bhemKEXYJUsKUoKDB3JcJ17dnoRAfsCR035R75mhi95ttXDfocByqRVcIzS1YWB6LCWgIZVkcK64FWxujvNxDzHvjVCn33ZK3ez53cu23loaXUIOXeqZnGcbWVFGgAa6XPVNfEcBm/kF8hqERDz/5j+BBT2oN9HjLbsm4niN+duyUgAlV4NSp4gM50YrAPwY4IbpqO9M4HdzK/6I5C8EMM/+n9s9gPo=
file: "building-and-packaging/linux/debian/*.deb"
file_glob: true
skip_cleanup: true
on:
tags: true
repo: INRIA/libpointing

notifications:
email: false
85 changes: 85 additions & 0 deletions building-and-packaging/linux/create-deb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# building-and-packaging/linux/create_deb
#
# Initial software
# Authors: Izzatbek Mukhanov
# Copyright © Inria

import os
import sys
import shutil
import distutils.dir_util
import subprocess
import platform

# --------------------------------------------------------------------------------

HERE = os.path.dirname(os.path.abspath(sys.argv[0]))
ROOT = os.path.relpath(os.path.abspath(os.path.join(HERE, "../..")), os.getcwd())

def copyFile(src, dst):
parent = os.path.dirname(dst)
if not os.path.exists(parent): os.makedirs(parent)
shutil.copy2(src, dst)

def getVersion():
defines = {
"LIBPOINTING_VER_MAJOR":None,
"LIBPOINTING_VER_MINOR":None,
"LIBPOINTING_VER_RELEASE":None,
}
with open(os.path.join(ROOT, "pointing/pointing.h"), "r") as header:
for line in header:
for key in defines.keys():
if line.find(key)!=-1 and not defines[key]:
defines[key] = line.split()[2].strip()
version = ""
if defines["LIBPOINTING_VER_MAJOR"]:
version = version+defines["LIBPOINTING_VER_MAJOR"]
if defines["LIBPOINTING_VER_MINOR"]:
if version: version = version+"."
version = version+defines["LIBPOINTING_VER_MINOR"]
if defines["LIBPOINTING_VER_RELEASE"]:
if version: version = version+"."
version = version+defines["LIBPOINTING_VER_RELEASE"]
return version

VERSION = getVersion()
ARCH = platform.machine()

# Generate and copy files neccessary to build libpointing
subprocess.call("python prepare", stdout=subprocess.PIPE, shell=True)
DIST = os.path.relpath(os.path.join(HERE, "libpointing-dist"), os.getcwd())
os.chdir(DIST)
subprocess.call("make")
os.chdir("..")
distutils.dir_util.copy_tree(os.path.join(DIST, "include"), "./libpointing/usr/local/include")
distutils.dir_util.copy_tree(os.path.join(DIST, "lib"), "./libpointing/usr/local/lib")

PACKAGE_NAME = "libpointing"
DEPENDS = ["libudev-dev", "xorg-dev", "libpthread-stubs0-dev"]

if not os.path.exists('./libpointing/DEBIAN/'):
os.makedirs('./libpointing/DEBIAN/')

with open("./libpointing/DEBIAN/control", "w") as cfile:
print >> cfile, "Package:", PACKAGE_NAME
print >> cfile, "Version:", VERSION
print >> cfile, """Section: custom
Priority: optional
Architecture: all
Essential: no
Installed-Size: 1024
Maintainer: libpointing.org
Description: An open-source cross-platform library to get raw events from pointing devices and master transfer functions."""
print >> cfile, "Depends:", ", ".join(DEPENDS)

subprocess.call("dpkg-deb --build libpointing", stdout=subprocess.PIPE, shell=True)
package_name = "libpointing-%s_%s.deb"%(VERSION, ARCH)
os.rename("libpointing.deb", package_name)
if not os.path.exists('debian'):
os.mkdir("debian")
shutil.move(package_name, "debian/" + package_name)
subprocess.call("dpkg-scanpackages debian /dev/null | gzip -9c > debian/Packages.gz", stdout=subprocess.PIPE, shell=True)
202 changes: 202 additions & 0 deletions building-and-packaging/linux/prepare
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# building-and-packaging/linux/prepare
#
# Initial software
# Authors: Izzatbek Mukhanov
# Copyright © Inria

import os
import sys
import shutil

# --------------------------------------------------------------------------------

HERE = os.path.dirname(os.path.abspath(sys.argv[0]))
ROOT = os.path.relpath(os.path.abspath(os.path.join(HERE, "../..")), os.getcwd())

DIST = os.path.relpath(os.path.join(HERE, "libpointing-dist"), os.getcwd())
SRC = "src"
INC = "include"
LIB = "lib"

CPPFLAGS = [
"-I%s"%INC,
"-fPIC",
]
CXXFLAGS = [
]

LDFLAGS = [
]
LIBS = [
"-ludev",
"-lpthread",
"-lXrandr",
"-lX11",
"-lXi",
]

HEADERS = [
# --------------------------------------------------------------
# Generic stuff
# --------------------------------------------------------------
"pointing/pointing.h",
"pointing/utils/Base64.h",
"pointing/utils/ByteOrder.h",
"pointing/utils/Correlation.h",
"pointing/utils/FileUtils.h",
"pointing/utils/TimeStamp.h",
"pointing/utils/URI.h",
"pointing/utils/ConfigDict.h",
"pointing/utils/HIDReportParser.h",
"pointing/utils/HIDItem.h",
"pointing/utils/HIDTags.h",
"pointing/utils/PointingCursor.h",
"pointing/input/DummyPointingDevice.h",
"pointing/input/PointingDevice.h",
"pointing/output/DisplayDevice.h",
"pointing/output/DisplayDeviceManager.h",
"pointing/output/DummyDisplayDevice.h",
"pointing/transferfunctions/Composition.h",
"pointing/transferfunctions/ConstantFunction.h",
"pointing/transferfunctions/NaiveConstantFunction.h",
"pointing/transferfunctions/SigmoidFunction.h",
"pointing/transferfunctions/TransferFunction.h",
"pointing/transferfunctions/SubPixelFunction.h",
"pointing/transferfunctions/Interpolation.h",
"pointing/input/PointingDeviceManager.h",
# --------------------------------------------------------------
# Linux specifics
# --------------------------------------------------------------
"pointing/input/linux/linuxHIDPointingDevice.h",
"pointing/output/linux/xorgDisplayDevice.h",
"pointing/transferfunctions/linux/xorgSystemPointerAcceleration.h",
"pointing/input/linux/linuxPointingDeviceManager.h",
"pointing/output/linux/xorgDisplayDeviceManager.h",
]

SOURCES = [
# --------------------------------------------------------------
# Generic stuff
# --------------------------------------------------------------
"pointing/utils/Base64.cpp",
"pointing/utils/ByteOrder.cpp",
"pointing/utils/FileUtils.cpp",
"pointing/utils/TimeStamp.cpp",
"pointing/utils/URI.cpp",
"pointing/utils/ConfigDict.cpp",
"pointing/utils/HIDItem.cpp",
"pointing/utils/HIDReportParser.cpp",
"pointing/utils/PointingCursor.cpp",
"pointing/input/PointingDevice.cpp",
"pointing/input/DummyPointingDevice.cpp",
"pointing/output/DisplayDevice.cpp",
"pointing/output/DisplayDeviceManager.cpp",
"pointing/output/DummyDisplayDevice.cpp",
"pointing/transferfunctions/Composition.cpp",
"pointing/transferfunctions/ConstantFunction.cpp",
"pointing/transferfunctions/NaiveConstantFunction.cpp",
"pointing/transferfunctions/SigmoidFunction.cpp",
"pointing/transferfunctions/TransferFunction.cpp",
"pointing/transferfunctions/SubPixelFunction.cpp",
"pointing/transferfunctions/Interpolation.cpp",
"pointing/input/PointingDeviceManager.cpp",
# --------------------------------------------------------------
# Linux specifics
# --------------------------------------------------------------
"pointing/input/linux/linuxHIDPointingDevice.cpp",
"pointing/output/linux/xorgDisplayDevice.cpp",
"pointing/transferfunctions/linux/xorgSystemPointerAcceleration.cpp",
"pointing/input/linux/linuxPointingDeviceManager.cpp",
"pointing/output/linux/xorgDisplayDeviceManager.cpp",
]

SOURCES_XTRA = []

TEST_PROG_EXEC = "simpletest"
TEST_PROG_SOURCE = "simpletest.cpp"
TEST_PROG = """
#include <pointing/pointing.h>
#include <iostream>
using namespace pointing ;
int
main(int argc, char **argv) {
std::cout << LIBPOINTING_VER_STRING << " |" ;
std::list<std::string> schemes = TransferFunction::schemes() ;
for (std::list<std::string>::iterator i=schemes.begin(); i!=schemes.end(); ++i) {
std::cout << " " << (*i) ;
}
std::cout << std::endl ;
return 0 ;
}
"""

# --------------------------------------------------------------------------------

CPPFLAGS.append("-DPOINTING_XORG")
HEADERS.append("pointing-xorg/transferfunctions/XorgFunction.h")
SOURCES.append("pointing-xorg/transferfunctions/XorgFunction.cpp")
SOURCES_XTRA.append("pointing-xorg/transferfunctions/XorgFunctionPrivate.cpp")

def copyFile(src, dst):
parent = os.path.dirname(dst)
if not os.path.exists(parent): os.makedirs(parent)
shutil.copy2(src, dst)

def prepareFiles(dist):
for header in HEADERS:
copyFile(os.path.join(ROOT, header), os.path.join(dist,os.path.join(INC, header)))
for source in SOURCES:
copyFile(os.path.join(ROOT, source), os.path.join(dist,os.path.join(SRC, source)))
for source in SOURCES_XTRA:
copyFile(os.path.join(ROOT, source), os.path.join(dist,os.path.join(SRC, source)))
lib = os.path.join(dist, LIB)
if not os.path.exists(lib): os.makedirs(lib)
with open(os.path.join(dist,os.path.join(SRC,TEST_PROG_SOURCE)),"w") as fd: print >> fd, TEST_PROG

def generateMakefile(dist):
sources = map(lambda p: os.path.join(SRC,p), SOURCES)
headers = map(lambda p: os.path.join(INC,p), HEADERS)
testsrc = os.path.join(SRC,TEST_PROG_SOURCE)
testexec = os.path.join(SRC,TEST_PROG_EXEC)
with open(os.path.join(dist, "Makefile"), "w") as makefile:
print >> makefile, "ifndef PREFIX\n\tPREFIX = /usr/local\nendif"
print >> makefile
print >> makefile, "LIBPOINTING = libpointing.so"
print >> makefile
print >> makefile, "HEADERS =", " ".join(headers)
print >> makefile
print >> makefile, "SOURCES =", " ".join(sources)
print >> makefile
print >> makefile, "CXX = g++"
print >> makefile, "CPPFLAGS =", " ".join(CPPFLAGS)
print >> makefile, "CXXFLAGS =", " ".join(CXXFLAGS)
print >> makefile, "LDFLAGS =", " ".join(LDFLAGS)
print >> makefile, "LIBS =", " ".join(LIBS)
print >> makefile
print >> makefile, "OBJECTS = $(SOURCES:.cpp=.o)"
print >> makefile
print >> makefile, "lib/$(LIBPOINTING): $(OBJECTS)\n\t$(CXX) -shared -o $@ $^ $(LDFLAGS) $(LIBS)"
print >> makefile
print >> makefile, "%s: %s\n\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS) -lpointing"%(testexec,testsrc)
print >> makefile
print >> makefile, "test: lib/$(LIBPOINTING) %s\n\t%s"%(testexec,testexec)
print >> makefile, "clean:\n\trm -f $(OBJECTS)"
print >> makefile, "distclean: clean\n\trm -f lib/$(LIBPOINTING)"
print >> makefile, "install:"
print >> makefile, "\tmkdir -p $(PREFIX)/include"
print >> makefile, "\tcp -r %s/pointing $(PREFIX)/include/pointing"%INC
print >> makefile, "\tcp -r %s/pointing $(PREFIX)/include/pointing-xorg"%INC
print >> makefile, "\tmkdir -p $(PREFIX)/lib"
print >> makefile, "\tcp -r lib $(PREFIX)"
print >> makefile, "uninstall:"
print >> makefile, "\trm -rf $(PREFIX)/include/pointing"
print >> makefile, "\trm -rf $(PREFIX)/include/pointing-xorg"
print >> makefile, "\trm -f $(PREFIX)/lib/$(LIBPOINTING)"

# --------------------------------------------------------------------------------

prepareFiles(DIST)
generateMakefile(DIST)

0 comments on commit f6c32cf

Please sign in to comment.