# [Makefile] Mise au point

## jaypeche

Salut,

Je cherche actuellement à créer un Makefile pour un logiciel écrit en Ruby, qui ne nécessite pas de compilation, mais simplement la copie de fichiers avec les bons droits vers un "PATH" d'installation.

Le but en fait est de remplacer la section src_install de mon ebuild par un src_compile où Makefile donnerait les directives d'installation.

L'idée à terme serait de créer un Makefile multi OS qui permette d'installer le bouzin sur différentes distributions. Ce serait un fichier Makefile.defs qui définirait les "PATH" qui vont bien pour chaque distro.

Pour le moment je m'attele juste à Gentoo, je vous poste les fichiers ebuild, Makefile, Makefile.defs afin d'y voir un peu plus clair.

Je serais vraiment content si quelqu'un pouvait m'apporter des précisions sur la manière de faire...

Fichier ebuild original et fonctionnel :

```
# Copyright 1999-2011 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: $

EAPI="2"

inherit eutils git-2

DESCRIPTION="This utility is used to create a low cost home automation system controlled by computer"

HOMEPAGE="http://openplacos.tuxfamily.org/"

EGIT_REPO_URI="git://github.com/openplacos/openplacos.git"

EGIT_BRANCH="master"

EGIT_COMMIT="a68afd6621dc8db2672f5ab3561c895d1387d76f"

OPOS_PATH="/usr/lib/ruby/openplacos"

LICENSE="GPL-3"

SLOT="0"

KEYWORDS="x86 amd64"

IUSE="-arduino -debug -gtk2"

DEPEND="dev-vcs/git

   sys-apps/dbus

   dev-lang/ruby

   dev-db/mysql

   >=dev-ruby/rubygems-1.3.7-r1

   arduino? ( dev-embedded/arduino )

   gtk2? ( dev-ruby/ruby-gnome2

   >=x11-libs/gtk+-2.20.1 )"

pkg_setup() {

   enewgroup dialout

   enewuser openplacos -1 -1 -1 dialout

}

src_unpack () {

   git-2_src_unpack ${A}

      cd "${S}"

      if use debug; then

         epatch "${FILESDIR}/${P}-debug.diff" || die "epatch failed !"

      else

            epatch "${FILESDIR}/${P}-gentoo.diff" || die "epatch failed !"

      fi

}

src_install () {

   # Copying files

   einfo

   einfo "Copying files"

   insinto ${OPOS_PATH}

   cp -dpR * ${D}/${OPOS_PATH} || die "copy failed !"

   # Ruby on Rails files (TODO: fix upstream)

   dodir ${OPOS_PATH}/plugins/rorplacos/{tmp,log} || die "dodir failed !"

   fowners -R openplacos ${OPOS_PATH}/plugins/rorplacos/{tmp,log} || die "fowners failed !"

   einfo "Linking common executables files"

   # OPOS Server

   dohard ${OPOS_PATH}/server/main.rb /usr/bin/openplacos-server || die

   fperms +x /usr/bin/openplacos-server || die

   # CLI Client

   dohard ${OPOS_PATH}/clients/CLI_client/opos-client.rb /usr/bin/openplacos || die

   fperms +x /usr/bin/openplacos || die

   # XML-RPC Client

   dohard ${OPOS_PATH}/clients/xml-rpc/xml-rpc-client.rb /usr/bin/openplacos-xmlrpc || die

   fperms +x /usr/bin/openplacos-xmlrpc || die

   # SOAP Client

   dohard ${OPOS_PATH}/clients/soap/soap-client.rb /usr/bin/openplacos-soap || die

   fperms +x /usr/bin/openplacos-soap || die

   # GTK Client

   if use gtk2 ; then

      dohard ${OPOS_PATH}/clients/deprecated/gtk/gtk.rb /usr/bin/openplacos-gtk || die

      fperms +x /usr/bin/openplacos-gtk || die

   fi

   einfo "Checking default drivers permissions"

   fperms a+x ${OPOS_PATH}/drivers/VirtualPlacos/{VirtualPlacos.rb,compensation_hygro.rb} || die "fperms failed !"

   einfo "Copying default configuration"

   insinto /etc/default

          doins server/config_with_VirtualPlacos_and_RoR.yaml || die "doins failed"

   mv -f ${D}/etc/default/config_with_VirtualPlacos_and_RoR.yaml ${D}/etc/default/openplacos || die "move failed !"

   einfo "Copying Dbus integration files"

   insinto /usr/share/dbus-1/system-services

   doins setup_files/*.service || die "doins failed !"

   insinto /etc/dbus-1/system.d

   doins setup_files/openplacos.conf || die

   insinto /etc/udev/rules.d/

   doins setup_files/10-openplacos.rules || die

   einfo "Installing daemon file"

   doinitd setup_files/openplacos || die "doinitd failed !"

}

pkg_postinst() {

   # Gems Bundler install for opos

        einfo

        einfo "OpenplacOS bundle install"

        einfo "This could take a while.. please wait..."

        gem install bundler --bindir /usr/bin --no-ri --no-rdoc ||  die "gem install failed !"

        cd ${OPOS_PATH} && bundle install || die "bundle install failed !"

        einfo

        einfo "Rails bundle install"

        einfo "This could take a while.. please wait..."

        cd ${OPOS_PATH}/plugins/rorplacos/ && bundle install || die "bundle install failed !"

   einfo

   /etc/init.d/dbus reload || die

   einfo

   einfo "Before running OpemplacOS for first time"

   einfo "You should proceed your database configuration"

   einfo "Please provide MySQL root password"

   einfo

   einfo "# /etc/init.d/mysql start"

   einfo "# /usr/bin/mysqladmin -u root -h localhost password 'new-password'"

   einfo

   einfo "# mysql -u root -p < /usr/lib/ruby/openplacos/setup_files/install.sql"

   einfo "# rc-update add mysql default"

   einfo

   einfo "Start OpenplacOS daemon"

   einfo "# /etc/init.d/openplacos start"

   einfo "# rc-update add openplacos default"

   if use gtk2 ; then

      einfo

      einfo "Now, you can launch GTK client for example"

      einfo "$ /usr/bin/openplacos-gtk"

   else

      einfo

      einfo "Now, you can launch web interface for example,"

      einfo "URL: http://localhost:3000/login"

   fi

   einfo

   einfo "Look at http://openplacos.tuxfamily.org for more information"

   einfo

}
```

Fichiers Makefile à dévelloper :

```
include Makefile.defs

all:

clean:

install:

@echo "Start installing OpenplacOS"

install -d $(DESTDIR)/$(INSTALLDIR)

install -d $(DESTDIR)/$(DBUSCONFDIR)

install -d $(DESTDIR)/$(INITDIR)/

install -d $(DESTDIR)/$(UDEVDIR)/

@cp setup_files/openplacos.conf $(DESTDIR)/$(DBUSCONFDIR)/openplacos.conf

@cp setup_files/openplacos $(DESTDIR)/$(INITDIR)/openplacos

ifeq ($(OS),Linux)

@cp setup_files/10-openplacos.rules $(DESTDIR)/$(UDEVDIR)/10-openplacos.rules

endif

@cp COPYING $(DESTDIR)/$(INSTALLDIR)/COPYING

@cp README $(DESTDIR)/$(INSTALLDIR)/README

@cp Gemfile $(DESTDIR)/$(INSTALLDIR)/Gemfile

@cp -R server $(DESTDIR)/$(INSTALLDIR)

@cp -R clients $(DESTDIR)/$(INSTALLDIR)

@cp -R components $(DESTDIR)/$(INSTALLDIR)

@cp -R plugins $(DESTDIR)/$(INSTALLDIR)

@cp -R drivers $(DESTDIR)/$(INSTALLDIR)

@cp -R setup_files $(DESTDIR)/$(INSTALLDIR)
```

Fichier Makefile.defs qui permettrait de définir les "PATHs" par distro :

```
OS=$(shell uname)

DESTDIR=

INSTALLDIR=/usr/lib/ruby/openplacos

INITDIR=/etc/init.d/

UDEVDIR=/etc/udev/rules.d/

DBUSCONFDIR=/etc/dbus-1/system.d/
```

Fichier ebuild utilisant Makefile :

```
# Copyright 1999-2011 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

# $Header: $

EAPI="2"

inherit eutils git-2

DESCRIPTION="This utility is used to create a low cost home automation system controlled by computer"

HOMEPAGE="http://openplacos.tuxfamily.org/"

EGIT_REPO_URI="git://github.com/flagos/openplacos.git"

EGIT_BRANCH="makefile"

EGIT_COMMIT="acd4e3a961cc8145eaeb2b4e5d42496810b2546d"

OPOS_PATH="/usr/lib/ruby/openplacos"

LICENSE="GPL-3"

SLOT="0"

KEYWORDS="x86 amd64"

IUSE="-arduino -debug -gtk2"

DEPEND="dev-vcs/git

   sys-apps/dbus

   dev-lang/ruby

   dev-db/mysql

   >=dev-ruby/rubygems-1.3.7-r1

   arduino? ( dev-embedded/arduino )

   gtk2? ( dev-ruby/ruby-gnome2

   >=x11-libs/gtk+-2.20.1 )"

pkg_setup() {

   enewgroup dialout

   enewuser openplacos -1 -1 -1 dialout

}

src_unpack () {

   git-2_src_unpack ${A}

      cd "${S}"

      epatch "${FILESDIR}/${P}-makefile.diff" || die

      if use debug; then

         epatch "${FILESDIR}/${P}-debug.diff" || die "epatch failed !"

      else

            epatch "${FILESDIR}/${P}-gentoo.diff" || die "epatch failed !"

      fi

}

src_compile () {

      emake install DESTDIR="${D}"

}

pkg_postinst() {

   # Gems Bundler install for opos

        einfo

        einfo "OpenplacOS bundle install"

        einfo "This could take a while.. please wait..."

        gem install bundler --bindir /usr/bin --no-ri --no-rdoc ||  die "gem install failed !"

        cd ${OPOS_PATH} && bundle install || die "bundle install failed !"

        einfo

        einfo "Rails bundle install"

        einfo "This could take a while.. please wait..."

        cd ${OPOS_PATH}/plugins/rorplacos/ && bundle install || die "bundle install failed !"

   einfo

   /etc/init.d/dbus reload || die

   einfo

   einfo "Before running OpemplacOS for first time"

   einfo "You should proceed your database configuration"

   einfo "Please provide MySQL root password"

   einfo

   einfo "# /etc/init.d/mysql start"

   einfo "# /usr/bin/mysqladmin -u root -h localhost password 'new-password'"

   einfo

   einfo "# mysql -u root -p < /usr/lib/ruby/openplacos/setup_files/install.sql"

   einfo "# rc-update add mysql default"

   einfo

   einfo "Start OpenplacOS daemon"

   einfo "# /etc/init.d/openplacos start"

   einfo "# rc-update add openplacos default"

   if use gtk2 ; then

      einfo

      einfo "Now, you can launch GTK client for example"

      einfo "$ /usr/bin/openplacos-gtk"

   else

      einfo

      einfo "Now, you can launch web interface for example,"

      einfo "URL: http://localhost:3000/login"

   fi

   einfo

   einfo "Look at http://openplacos.tuxfamily.org for more information"

   einfo

}

```

Logs de la "compilation"/installation :

```
dbox2 openplacos # emerge -v openplacos

 * IMPORTANT: 8 news items need reading for repository 'gentoo'.

 * Use eselect news to read news items.

These are the packages that would be merged, in order:

Calculating dependencies... done!

[ebuild   R    ] app-misc/openplacos-0.3.0-r4  USE="gtk2 -arduino -debug" 0 kB [1]

Total: 1 package (1 reinstall), Size of downloads: 0 kB

Portage tree and overlays:

 [0] /usr/portage

 [1] /usr/local/portage

>>> Verifying ebuild manifests

>>> Emerging (1 of 1) app-misc/openplacos-0.3.0-r4 from x-portage

>>> Unpacking source...

GIT update -->

   repository:               git://github.com/flagos/openplacos.git

   at the commit:            acd4e3a961cc8145eaeb2b4e5d42496810b2546d

   commit:                   acd4e3a961cc8145eaeb2b4e5d42496810b2546d

   branch:                   makefile

   storage directory:        "/usr/portage/distfiles/egit-src/openplacos.git"

   checkout type:            bare repository

Cloning into /var/tmp/portage/app-misc/openplacos-0.3.0-r4/work/openplacos-0.3.0...

done.

Switched to a new branch 'tree-acd4e3a961cc8145eaeb2b4e5d42496810b2546d'

>>> Unpacked to /var/tmp/portage/app-misc/openplacos-0.3.0-r4/work/openplacos-0.3.0

 * Applying openplacos-0.3.0-makefile.diff ...                           [ ok ]

 * Applying openplacos-0.3.0-gentoo.diff ...                             [ ok ]

>>> Source unpacked in /var/tmp/portage/app-misc/openplacos-0.3.0-r4/work

>>> Preparing source in /var/tmp/portage/app-misc/openplacos-0.3.0-r4/work/openplacos-0.3.0 ...

>>> Source prepared.

>>> Configuring source in /var/tmp/portage/app-misc/openplacos-0.3.0-r4/work/openplacos-0.3.0 ...

>>> Source configured.

>>> Compiling source in /var/tmp/portage/app-misc/openplacos-0.3.0-r4/work/openplacos-0.3.0 ...

make -j3 install DESTDIR=/var/tmp/portage/app-misc/openplacos-0.3.0-r4/image/ 

Start installing OpenplacOS

cp: impossible de créer le fichier standard « /var/tmp/portage/app-misc/openplacos-0.3.0-r4/image//etc/init.d/openplacos »: Aucun fichier ou dossier de ce type

make: *** [install] Erreur 1

emake failed

>>> Source compiled.

>>> Test phase [not enabled]: app-misc/openplacos-0.3.0-r4

>>> Install openplacos-0.3.0-r4 into /var/tmp/portage/app-misc/openplacos-0.3.0-r4/image/ category app-misc

>>> Completed installing openplacos-0.3.0-r4 into /var/tmp/portage/app-misc/openplacos-0.3.0-r4/image/

>>> Installing (1 of 1) app-misc/openplacos-0.3.0-r4

 * checking 0 files for package collisions

>>> Merging app-misc/openplacos-0.3.0-r4 to /

>>> Safely unmerging already-installed instance...

No package files given... Grabbing a set.

>>> Regenerating /etc/ld.so.cache...

>>> Original instance of package unmerged safely.

 * 

 * OpenplacOS bundle install

 * This could take a while.. please wait...

Successfully installed bundler-1.1.0

1 gem installed

Could not locate Gemfile

 * ERROR: app-misc/openplacos-0.3.0-r4 failed (postinst phase):

 *   bundle install failed !

 * 

 * Call stack:

 *     ebuild.sh, line  85:  Called pkg_postinst

 *   environment, line 2140:  Called die

 * The specific snippet of code:

 *       cd ${OPOS_PATH} && bundle install || die "bundle install failed !";

 * 

 * If you need support, post the output of 'emerge --info =app-misc/openplacos-0.3.0-r4',

 * the complete build log and the output of 'emerge -pqv =app-misc/openplacos-0.3.0-r4'.

 * This ebuild is from an overlay named 'x-portage': '/usr/local/portage/'

 * The complete build log is located at '/var/tmp/portage/app-misc/openplacos-0.3.0-r4/temp/build.log'.

 * The ebuild environment file is located at '/var/tmp/portage/app-misc/openplacos-0.3.0-r4/temp/environment'.

 * S: '/var/tmp/portage/app-misc/openplacos-0.3.0-r4/work/openplacos-0.3.0'

!!! FAILED postinst: 1

 * Messages for package app-misc/openplacos-0.3.0-r4:

 * ERROR: app-misc/openplacos-0.3.0-r4 failed (postinst phase):

 *   bundle install failed !

 * 

 * Call stack:

 *     ebuild.sh, line  85:  Called pkg_postinst

 *   environment, line 2140:  Called die

 * The specific snippet of code:

 *       cd ${OPOS_PATH} && bundle install || die "bundle install failed !";

 * 

 * If you need support, post the output of 'emerge --info =app-misc/openplacos-0.3.0-r4',

 * the complete build log and the output of 'emerge -pqv =app-misc/openplacos-0.3.0-r4'.

 * This ebuild is from an overlay named 'x-portage': '/usr/local/portage/'

 * The complete build log is located at '/var/tmp/portage/app-misc/openplacos-0.3.0-r4/temp/build.log'.

 * The ebuild environment file is located at '/var/tmp/portage/app-misc/openplacos-0.3.0-r4/temp/environment'.

 * S: '/var/tmp/portage/app-misc/openplacos-0.3.0-r4/work/openplacos-0.3.0'

>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * GNU info directory index is up-to-date.

 * IMPORTANT: 8 news items need reading for repository 'gentoo'.

 * Use eselect news to read news items.

```

Merçi pour votre aide   :Wink: 

----------

