Makefile pour developpement multi-OS, multi-variants

crabs_makefile - 5.2 (c) 2003-2008 - Christophe Cazajus (crabs-mettre_le_signe_at-crabs-world.com)

Navigation

Présentation

Installation

Journal des Modifications

Feuille de route

Téléchargement

Fichiers Sources

--==--

Retour au site

Accueil du site

Man Pages

makefile

Intro

Binaires

Bibliotheque

PinfoGpl.sh

Pinfo

Objectif

Nous avons créé 2 binaires qui font le même traitement. Ce traitement nous allons le mettre dans une bibliothèque statique 'hello.a' et utiliser cette bibliothèque pour la compilation.

Afin d'être correct, nous créerons un fichier include 'hello.h' qui contient le protoype des fonctions contenues dans 'hello.a'.

Le mode de gestion de crabs_makefile présente les avantages suivants :

Préparation

# cd $PROJET/SRC
# mkdir HELLO
# vi Makefile

On met HELLO en premier car il doit être 'compilé' avant les binaires

SHELL=/bin/sh
DIR=HELLO BIN1 BIN2
include $(PROJET_MK)/include.$(OS)

Les sources de la bibliothèque et le Makefile

# cd HELLO
# vi Makefile
SHELL=/bin/sh
LIB=libhello.a
SRC=hello.h hello.c

include $(PROJET_MK)/include.$(OS)
# vi hello.h
#ifndef __HELLO__H__
#define __HELLO__H__

void hello() ;

#endif
# vi hello.c
#include "hello.h"
#include <stdio.h>

void hello()
        {
        printf( "Hello World !!!\n" ) ;
        }

Modification pour BIN1

# cd $PROJET/SRC/BIN1
# vi main.c
#include "stdio.h"

int main( int argc, char** argv )
        {
        hello() ;
        return 0 ;
        }
# vi Makefile
SHELL=/bin/sh
BIN=projet1_bin
SRC=main.c
PLIB=libhello.a
LD=gcc

include $(PROJET_MK)/include.$(OS)

Faire la même chose pour BIN2.

La compilation

# cd $PROJET/SRC
# make
== MAKE: ~~/SRC/HELLO
Install INCLUDE hello.h
   --(Pdepend hello.c)--
--- C: hello.c
ar: creating .../PROJET1/LIB/LINUX/NORMAL/libhello.a
a - .obj/LINUX/NORMAL/_info.o
a - hello.h
a - hello.c
a - .obj/LINUX/NORMAL/hello.o
== LIB: libhello.a

== MAKE: ~~/SRC/BIN1
   --(Pdepend main.c)--
--- C: main.c
-=> Edition des liens: projet1_bin
== BIN: projet1_bin

== MAKE: ~~/SRC/BIN2
   --(Pdepend main.c)--
--- C: main.c
-=> Edition des liens: projet1_bin2
== BIN: projet1_bin2

Où sont les bibliothèques

Un peu comme les binaires, dans le dossier $PROJET/LIB/$OS/$VARIANT vous trouverez les bibliothèques de votre projet.

Vérification des signatures

# cd $PROJET
# Pinfo LIB/LINUX/NORMAL/libhello.a
05/11/2005 14:12:16 LINUX NORMAL crabs tuto 1 libhello
# Pinfo BIN/LINUX/NORMAL/projet1_bin
05/11/2005 14:12:16 LINUX NORMAL crabs tuto 1 projet1_bin
05/11/2005 14:12:16 LINUX NORMAL crabs tuto 1 libhello

La variables PLIB du Makefile accepte plusieurs bibliothèques.

Haut de Page

Contacter crabs