--==--
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 :
# 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)
# 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" ) ;
}
# 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.
# 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
Un peu comme les binaires, dans le dossier $PROJET/LIB/$OS/$VARIANT vous trouverez les bibliothèques de votre projet.
# 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.