-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
63 lines (50 loc) · 1.96 KB
/
Makefile
File metadata and controls
63 lines (50 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# gcc configuracion
INCLUDE= -Iinclude/
CFLAGS = -Wall -fPIC
CC = gcc
SHARED = -shared
CCFLAGS = -Wl
# folder estructura
SRCDIR = src
OBJDIR = obj
BINDIR = bin
LIBDIR = lib
BIN_NAME = bin/prueba
# objects
MAIN_OBJ= obj/main.o
PRUEBA_OBJ= obj/pruebaLista.o
MAIN=src/pruebaLista.c
# sources list
CURRENT_FOLDER := $(shell pwd)
SOURCES := $(shell ls src | sed 's/\b.c\b/.o/'| egrep '^[A-Z]'| tr "\n" " ")
OBJECTS := $(shell ls src | egrep '^[A-Z]' | sed 's/\b.c\b/.o/'| sed 's/^/obj\//' | tr "\n" " ")
SOURCES_DINAMICO := $(shell ls src | egrep '^[A-Z]'| sed 's/^/src\//' | tr "\n" " ")
all: prueba
help:
@fgrep -h "####" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/pruebaLista.o//' | sed -e 's/(SOURCES)//' | sed -e 's/####//'
prueba: libmilista.so include/miLista.h pruebaLista.o
@ echo "Creado el ejecutable prueba"
@ gcc -L$(CURRENT_FOLDER)/$(LIBDIR) $(CCFLAGS),-rpath=$(CURRENT_FOLDER)/$(LIBDIR) -Wall -o $(BIN_NAME) $(PRUEBA_OBJ) -lmilista
@ # gcc $(CFLAGS) $(INCLUDE) -L$(CURRENT_FOLDER)/lib $(MAIN) -lmilista -o $(BIN_NAME)
# Usado para pruebas locales
test: $(SOURCES) main.o
gcc $(OBJECTS) $(MAIN_OBJ) -o $(BIN_NAME)
# Generar archivo objecto compartido
libmilista.so: $(SOURCES)
@ $(CC) $(CFLAGS) $(INCLUDE) $(SHARED) $(OBJECTS) -o $(LIBDIR)/$@
@ echo "Creada la libreria compartida milista"
# Generar pruebaLista.o
pruebaLista.o: $(MAIN)
@ $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $(OBJDIR)/$@
# Generar los archivos .o
%.o : $(SRCDIR)/%.c
@ $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $(OBJDIR)/$@
# Limpiar todos los archivos
.PHONY: clean
clean:
@ rm -f obj/*.o bin/prueba lib/*.so
@ echo "Borrado los archivos .o .so y ejecutables"
# https://stackoverflow.com/questions/7004702/how-can-i-create-a-makefile-for-c-projects-with-src-obj-and-bin-subdirectories
# http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html#fn:1
# https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_10.html
# http://www.adp-gmbh.ch/cpp/gcc/create_lib.html#calc_mean_h