This repository has been archived by the owner on Feb 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
125 lines (94 loc) · 3.35 KB
/
makefile
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#********************************************************
#* Aluno : Paulo Mateus Moura da Silva
#* Matricula : 20132045050248
#* Avaliacao 04: Trabalho Final
#* UDM−255 − 2014.1 − Prof . Daniel Ferreira
#*
#* Roda em:
#* Linux : GNU Make 3.81
#* Windows : (cygwin64) make (GNU texinfo) 5.2
#*********************************************************/
# Como gerar um makefile simples
# https://aulasdec.wordpress.com/2011/07/28/utilitarios-make-makefiles-e-sua-importancia/
# Pseudo Wildcard recursivo
# http://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make#answer-2483203
# Detecção de sistema operacional
# http://stackoverflow.com/questions/714100/os-detecting-makefile
# Variáveis
# http://www.chemie.fu-berlin.de/chemnet/use/info/make/make_6.html
####################################
# Parâmetros principais
####################################
COMPILADOR = gcc
NOME_PROGRAMA := Main
EXTENSAO_WINDOWS = exe
EXTENSAO_LINUX = e
EXTENSAO_MAC = app
PARAMETROS = -lm -std=c89
#PARAMETROS_OBJETO =-std=c89 -fPIC -Wall
PARAMETROS_OBJETO =-fPIC -Wall
PARAMETROS_RASPBERRY = -lwiringPi
# http://www.faqs.org/faqs/C-faq/faq/
# "a longstanding bug in Unix and Linux systems, you usually need to use an explicit -lm flag"
####################################
# Configurando programa
####################################
ifeq ($(OS), Windows_NT)
ARQUITETURA := $(PROCESSOR_ARCHITECTURE)
EXTENSAO := $(EXTENSAO_WINDOWS)
else
SYSTEM := $(shell uname -s)
ifeq ($(SYSTEM), Linux)
EXTENSAO := $(EXTENSAO_LINUX)
endif
ifeq ($(SYSTEM), Darwin)
EXTENSAO := $(EXTENSAO_MAC)
endif
ARQUITETURA := $(shell uname -p)
endif
# Raspberry
ifeq ($(ARQUITETURA), unknown)
PARAMETROS += $(PARAMETROS_RASPBERRY)
PARAMETROS_OBJETO += $(PARAMETROS_RASPBERRY)
endif
NOME_PROGRAMA := $(NOME_PROGRAMA)_$(ARQUITETURA).$(EXTENSAO)
NOME_PROGRAMA_SO := lib$(NOME_PROGRAMA)_$(ARQUITETURA).$(EXTENSAO).so
####################################
# Compilando e limpando
####################################
# Buscar todas as imagens que possuem... neste diretório
#HEADERS=$(wildcard *.h)
#FONTES=$(wildcard *.c)
#OBJECTS=$(wildcard *.o)
# Buscar todas as imagens que possuem... (recursivo: Neste e em outros subdiretórios)
HEADERS=$(shell find -type f -name '*.h')
FONTES=$(shell find -type f -name '*.c')
OBJECTS=$(shell find -type f -name '*.o')
# Para cada arquivo .c encontrado, vai chamar o %.o
all: $(FONTES:.c=.o) clean_programa clean_programa_so $(NOME_PROGRAMA) $(NOME_PROGRAMA_SO) clean
$(NOME_PROGRAMA): $(OBJECTS)
$(COMPILADOR) -o $(NOME_PROGRAMA) $(OBJECTS) $(PARAMETROS)
$(NOME_PROGRAMA_SO): $(OBJECTS)
$(COMPILADOR) -o $(NOME_PROGRAMA_SO) $(OBJECTS) $(PARAMETROS) -shared
%.o: %.c $(HEADERS)
$(COMPILADOR) -c $< -o $@ $(PARAMETROS_OBJETO)
clean_programa:
rm $(NOME_PROGRAMA) || true
clean_programa_so:
rm $(NOME_PROGRAMA_SO) || true
clean:
rm -f $(OBJECTS)
####################################
# Compilando em utf8
####################################
# Execute no terminal
#find -name \*.c -type f | \
# (while read file; do
# iconv -f ISO-8859-15 -t UTF-8 "$file" > "${file%.c}.cutf8";
# done)
FONTES_UTF8=$(shell find -type f -name '*.cutf8')
utf8: $(FONTES_UTF8:.cutf8=.o) NOME_PROGRAMA_UTF8 clean_utf8 clean
NOME_PROGRAMA_UTF8: $(OBJECTS)
$(COMPILADOR) -o $(NOME_PROGRAMA) $(OBJECTS) $(PARAMETROS)
clean_utf8:
rm -f $(FONTES_UTF8)