wiki:Makefile

Version 15 (modified by Mattia Monga, 8 years ago) ( diff )

--

Un piccolo progetto in cui make semplifica molto lo sviluppo.

Abbiamo 2 file sorgente:

  • sommaf.asm
section .text
global somma

somma:
  ; prologo
  push ebp
  mov ebp, esp

  mov eax, [ebp+8]
  add eax, [ebp+12]

  ; epilogo
  mov esp, ebp
  pop ebp
  ret
  • somma.c (usa la funzione di cui sopra)
#include <stdio.h>

int somma(int, int);


int main(){
  int x = somma(42, 24);
  printf("La somma e': %d\n", x);
  return 0;
}

A questo punto si può automatizzare la produzione di somma con un Makefile in modo da poter "costruire" somma con un make all

  • Makefile
.PHONY: all clean


all: somma


clean:
        rm -f *.o somma

somma: somma.o sommaf.o
        gcc -o somma somma.o sommaf.o

somma.o: somma.c
        gcc -c somma.c

sommaf.o: sommaf.asm
        nasm -f elf32 sommaf.asm

Note: See TracWiki for help on using the wiki.