Ing. Ignacio Javier Bonelli
hellomake.c
#include "hellomake.h"
int main() {
// call a function in another file
myPrintHelloMake();
return(0);
}
hellomake.h
/* Example include file */
void myPrintHelloMake(void);
hellofunc.c
#include "hellomake.h"
#include <stdio.h>
void myPrintHelloMake(void) {
printf("Hello makefiles!\n");
return;
}
Normalmente esto lo compilariamos haciendo:
$ gcc -o hellomake hellomake.c hellofunc.c -Wall
Compilar de esta manera tiene dos desventajas:
hellomake: hellomake.c hellofunc.c
gcc -o hellomake hellomake.c hellofunc.c -Wall
target: dependencia/s
comando/s
$ make ; ls -l hellomake
gcc -o hellomake hellomake.c hellofunc.c -Wall
-rwxr-xr-x 1 ignacio ignacio 4997 Jul 4 18:49 hellomake
CC=gcc
CFLAGS=-Wall
hellomake: hellomake.c hellofunc.c
$(CC) -o hellomake hellomake.c hellofunc.c $(CFLAGS)
Ahora al compilador lo llamamos por referencia en una variable y los flags del compilador los pasamos de la misma manera.
CC = gcc
CFLAGS = -Wall
DEPS = hellomake.h
all: hellomake.o hellofunc.o
$(CC) hellomake.o hellofunc.o -o app $(CFLAGS)
hellomake.o: hellomake.c $(DEPS)
$(CC) -c -o hellomake.o hellomake.c $(CFLAGS)
hellofunc.o: hellofunc.c $(DEPS)
$(CC) -c -o hellofunc.o hellofunc.c $(CFLAGS)
Tenemos mas targets, y mas dependencias:
CC = gcc
CFLAGS = -Wall
DEPS = hellomake.h
all: hellomake.o hellofunc.o
$(CC) hellomake.o hellofunc.o -o app $(CFLAGS)
hellomake.o: hellomake.c $(DEPS)
$(CC) -c -o hellomake.o hellomake.c $(CFLAGS)
hellofunc.o: hellofunc.c $(DEPS)
$(CC) -c -o hellofunc.o hellofunc.c $(CFLAGS)
clean:
rm -f *.o app
Podemos tener targets sin dependencias. El mas comun es el que limpia todo lo creado.
Lo podemos ejecturar invocando directamente el target:
$ make clean
CC=gcc
CFLAGS=-Wall
DEPS = hellomake.h
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
hellomake: hellomake.o hellofunc.o
gcc -o hellomake hellomake.o hellofunc.o $(CFLAGS)
Es muy similar al Makefile 3, pero ahora parametrizamos las dependencias...
CC=gcc
CFLAGS=-Wall
DEPS = hellomake.h
OBJ = hellomake.o hellofunc.o
LIBS = -lm
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
hellomake: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
clean:
rm -f *.o hellomake
Que es similar al Makefile 5, pero ahora parametrizamos todo y agregamos la librería math.h.
Ejemplos: make_files.zip
Sin importar el estado del archivo fuente
make -B <target>
o también:
make --always-make <target>
¿Esto es todo lo que hay?
#ifndef __ARCHIVO_H__
#define __ARCHIVO_H__
/*... declaraciones de funciones, etc. ...*/
#endif
#define __unix__
#ifdef __unix__ /* __unix__ is usually defined by compilers targeting Unix systems */
#include <unistd.h>
#elif defined _WIN32 /* _WIN32 is usually defined by compilers targeting 32 bit Windows systems */
#include <windows.h>
#elif defined _WIN64 /* _WIN64 targeting 64 bit Windows systems */
#include <win64.h>
#endif
#define PI 3.14159
#define RADAGRA(x) ((x) * 57.29578)
#define MIN(a,b) ((a)>(b)?(b):(a))
El problema:
Si trabajamos en equipo y en un repositorio comun es muy fácil tener conflictos y "pisar" el trabajo de otros.
Hay varias razones para usar un sistema de control de versiones:
Como trabajamos con versiones:
Comandos para arrancar
$ sudo apt-get install git gitk
$ git clone https://github.com/ibonelli/info1_presentations.git
$ gitk
$ git status
Subiendo cambios
$ git pull
$ git add .
$ git commit -m "Descripción del cambios"
$ git push
Usando branches
$ git branch mi-new-branch
$ git push -u origin mi-new-branch
$ git checkout master
$ git checkout mi-new-branch
Usaremos los apuntes del Ing. Jerónimo F. Atencio:
doxygen_atencio_v1.2.2_IBmod.odp
Para instalarlo:
$ sudo apt-get install doxygen doxygen-gui
Ejemplo: doxygen_template.zip
Corriendo el GUI: doxywizard
Doxygen para C: doxygen_QuickReferenceLenguajeC.pdf