-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
239 lines (205 loc) · 8.18 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
## PiFunk Makefile
## should run with sudo or root rights
USER=sudo
$(USER)
CC=gcc ## gcc 8.3.0-6
$(CC)
CXX=g++
$(CXX)
## general infos
MAKEINFO=pifunk
$(MAKEINFO)
VERSION=0.1.7.6
$(VERSION)
STATUS=experimental
$(STATUS)
SOURCE=pifunk.c
$(SOURCE)
SOURCECXX=pifunk.cpp
$(SOURCECXX)
## default paths
INIT=/bin/sh ## init-shell
$(INIT)
HOME=/home/pi ## std-path
$(HOME)
KERNEL_DIR:=/lib/modules/$(shell uname -r)/build/
$(KERNEL_DIR)
RM=rm -f ## remove files or folder
#$(RM)
## use gnu c compiler, -std=gnu99 is c99 -std=iso9899:1999 with extra gnu extentions, flags see below
## environment variable C_INCLUDE_PATH
## https://renenyffenegger.ch/notes/development/languages/C-C-plus-plus/GCC/options/index
CINC:=-Iinclude -I/opt/vc/include/ -I/usr/include/linux/ -I/usr/src/include/linux/ -I/usr/src/linux-headers-4.19.97+/include/ -I/usr/src/linux-headers-4.19.97+/include/linux/ ## kernel now 4.19.97+
$(CINC)
CMA=-D_USE_MATH_DEFINES -D_GNU_SOURCE
$(CMA)
CFLAGS=-std=gnu99 -O2 ## gnu extention & highest optimization level
$(CFLAGS)
CXXFLAGS=-std=gnu++17 -O3 ## for c++
$(CXXFLAGS)
ASFLAGS=-S -CC ## upper case assembler code without linker
$(ASFLAGS)
PPFLAGS=-E -CC ## c-preproccessor, -C or CC keeps the comments in preprocessor
$(PPFLAGS)
LIFLAGS=-c ## no linker used
$(LIFLAGS)
SHFLAGS=-shared -fPIC ## make shared big libraries
$(SHFLAGS)
DEBUG=-Wall -v -g3 -ggdb3 -pg ##-Q
$(DEBUG)
## -pg makes profiles for object code for analysis with gprof
## -Wall shows all errors & warnings, -w inhibits warnings
LDLIBS=-Llib -L/opt/vc/lib/ -L/usr/src/lib/
$(LDLIBS)
PFLIBS=-L$(HOME)/PiFunk/lib/
$(PFLIBS)
LDFLAGS=-lgnu -lpthread -lbcm_host -lbcm2835 -lsndfile -lm
$(LDFLAGS)
PFFLAGGS=-llibpifunk ## own pifunk library, gcc assumes lib beginns with prefix "lib"
$(PFFLAGS)
#AOFLAGGS=-arm-none-eabi-objdump ## objdump gnu tools
#$(AOFLAGS)
## other optional macros if necessary
##-isystem $(KERNEL_DIR) : You must use the kernel headers of the kernel you're compiling against. Using the default /usr/include/linux won't work.
##-D__KERNEL__ : Defining this symbol tells the header files that the code will be run in kernel mode, not as a user process.
##-DMODULE: This symbol tells the header files to give the appropriate definitions for a kernel module.
## Determine the hardware/software platform
UNAME:=$(shell uname -m) ## processor: armv6l
$(UNAME)
KERNEL:=$(shell uname -a) ## kernel: Linux raspberrypi 4.19.97+ #1294 Thu Jan 30 13:10:54 GMT 2020 armv6l GNU/Linux
$(KERNEL)
RVERSION:=$(shell uname -r) ## vervion number: 4.19.97+
$(RVERSION)
VCGVERSION:=$(shell vcgencmd version) ## vcg firmware: version 53a54c778c493957d99bf49762dfabc4eee80e45
$(VCGVERSION)
OSVERSION:=$(shell cat /etc/rpi-issue) ## os Date, http://github.com/RPi-Distro/pi-gen, MD5, stage5
$(OSVERSION)
RPIVERSION:=$(shell cat /proc/device-tree/model) ## grab revision: | grep -a -o "Raspberry\sPi\sModel\s[A-Z]\sPlus" | grep -a -o "Rev\s[0-9].[0-9]" : Raspberry Pi Model B Plus Rev 1.2
$(RPIVERSION)
PCPUI:=$(shell cat /proc/cpuinfo) ## cpuinfos my rev: 0010 -> 1.2 B+: | grep Revision | cut -c16-
$(PCPUI)
## Enable ARM-specific options only
## old/special pi versions
ifeq ($(UNAME), armv5)
PFLAGS=-march=native -mtune=native -mfloat-abi=soft -mfpu=vfp -ffast-math -DRPI
TARGET=RPI ## alternative1
endif
ifeq ($(UNAME), armv5l)
PFLAGS=-march=native -mtune=native -mfloat-abi=softfp -mfpu=vfp -ffast-math -DRASPBERRY
TARGET=RASPBERRY ## alternative2
endif
ifeq ($(UNAME), armv6)
PFLAGS=-march=armv6 -mtune=arm1176jzf-s -mfloat-abi=softfp -mfpu=vfp -ffast-math -DRASPI0
TARGET=RASPI0 ## & Pi W
endif
ifeq ($(UNAME), armv6l)
PFLAGS=-march=armv6 -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=vfp -ffast-math -DRASPI1
TARGET=RASPI1
endif
ifeq ($(UNAME), armv7l)
PFLAGS=-march=armv7-a -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=neon-vfpv4 -ffast-math -DRASPI2
TARGET=RASPI2
endif
ifeq ($(UNAME), armv8l)
PFLAGS=-march=armv7-a -mtune=arm1176jzf-s -mfloat-abi=hard -mfpu=neon-vfpv4 -ffast-math -DRASPI3
TARGET=RASPI3
endif
ifeq ($(UNAME), armv8l && $(shell expr $(RPIVERSION) | grep -a -o "Raspberry\sPi\sModel\s[A-Z]" | grep -o "[0-9]" = 4), 1)
PFLAGS=-march=armv8-a -mtune=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -ffast-math -DRASPI4
TARGET=RASPI4
endif
$(TARGET)
$(PFLAGS)
#@echo Compiling PiFunk
## Generating objects in gcc specific order, -save-temps
## translated assembler/c-code
pifunk.s: $(SOURCE) pifunk.h
$(USER) $(CC) $(SOURCE) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(ASFLAGS) $(LIFLAGS) -o src/pifunk.s ## for arm
$(USER) $(CC) $(SOURCE) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(ASFLAGS) $(LIFLAGS) -o src/pifunk.asm ## normal assembler suffix
## precompiled/processor c-code
pifunk.i: $(SOURCE) pifunk.h
$(USER) $(SOURCE) $(CC) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(PPFLAGS) -o lib/pifunk.i
## precompiled object/machine-code
pifunk.o: $(SOURCE) pifunk.h
$(USER) $(CC) $(DEBUG) $(SOURCE) $(CFLAGS) $(CINC) $(LDLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(LIFLAGS) -o lib/pifunk.o
## static archive
libpifunk.a: libpifunk.o
$(USER) $(CC) $(SOURCE) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(LIFLAGS) -o lib/libpifunk.a
$(USER) ar rcs -t $@ $^
$(USER) ranlib libpifunk.a
## static library
libpifunk.lib: libpifunk.o
$(USER) $(CC) $(SOURCE) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(LIFLAGS) -o lib/libpifunk.lib
$(USER) ar rcs -t $@ $^
$(USER) ranlib libpifunk.lib
## shared object
libpifunk.so: libpifunk.o
$(USER) $(CC) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(SHFLAGS) -o lib/libpifunk.so lib/libpifunk.o
$(USER) ar rcs -t $@ $^
$(USER) ranlib libpifunk.so
## dynamic linked library
libpifunk.dll: libpifunk.o
$(USER) $(CC) $(SOURCE) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(LIFLAGS) -o lib/libpifunk.dll
$(USER) ar rcs -t $@ $^
$(USER) ranlib libpifunk.dll
## lib object list
OBJECTS=pifunk.s pifunk.i pifunk.o libpifunk.a libpifunk.lib libpifunk.so libpifunk.dll
$(OBJECTS)
## generating standard binarys
pifunk.out: $(SOURCE) pifunk.h
$(USER) $(CC) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(PFLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(PFFLAGS) -save-temps -o bin/pifunk.out
## explicit binary
pifunk.bin: $(SOURCE) pifunk.h
$(USER) $(CC) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(PFLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) -save-temps -o bin/pifunk.bin
## normal binary
pifunk: $(SOURCE) pifunk.h
$(USER) $(CC) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(PFLIBS) $(LDFLAGS) $(PFFLAGS) $(CMA) $(PFLAGS) -save-temps -o bin/pifunk
## executable list
#allbin: pifunk.out pifunk.bin pifunk
EXECUTABLES=pifunk.out pifunk.bin pifunk
$(EXECUTABLES)
.PHONY: pifunklib
pifunk.so: $(SOURCE)
$(USER) $(CC) $(DEBUG) $(CFLAGS) $(CINC) $(LDLIBS) $(LDFLAGS) $(CMA) $(PFLAGS) $(SHFLAGS) -o lib/libpifunk.so libpifunk.o
.PHONY: pifunk+
pifunk+: $(SOURCECXX) $(OBJECTS)
$(USER) $(CXX) $(DEBUG) $(CXXFLAGS) $(CINC) $(LDLIBS) $(PFLIBS) $(LDFLAGS) $(PFFLAGS) $(CMA) $(PFLAGS) -o bin/pifunk+
## generate info file
.PHONY: info
info: pifunk.info
pifunk.info: pifunk.texi
$(MAKEINFO)
.PHONY: piversion
piversion: $(USER) $(UNAME)
$(USER) $(KERNEL)
$(USER) $(RVERSION)
$(USER) $(VCGVERSION)
$(USER) $(OSVERSION)
$(USER) $(RPIVERSION)
$(USER) $(PCPUI)
.PHONY: install
install: cd $(HOME)/PiFunk/
$(USER) install -m 0755 pifunk $(HOME)/bin/
.PHONY: uninstall
uninstall: $(USER) $(RM) $(HOME)/PiFunk/bin/pifunk.out
$(USER) $(RM) $(HOME)/PiFunk/bin/pifunk.bin
$(USER) $(RM) $(HOME)/PiFunk/bin/pifunk
.PHONY: clean
clean: cd $(HOME)/PiFunk/
$(USER) $(RM) $(OBJECTS)
$(USER) $(RM) $(EXECUTABLES)
.PHONY: assistant
assistent: cd $(HOME)/PiFunk/bin/
$(USER) ./pifunk -a
.PHONY: menu
menu: cd $(HOME)/PiFunk/bin/
$(USER) ./pifunk -u
.PHONY: help
help: cd $(HOME)/PiFunk/bin/
$(USER) ./pifunk -h
.PHONY: run
run: cd $(HOME)/PiFunk/bin/
$(USER) ./pifunk -n sound.wav -f 26.9650 -s 22050 -m fm -p 7 -c callsign -g 7 -d 14 -b 15.0 -t 1 -x off -l 0
.PHONY: run+
run+: cd $(HOME)/PiFunk/bin/
$(USER) ./pifunk+ -n sound.wav -f 26.9650 -s 22050 -m fm -p 7 -c callsign -g 7 -d 14 -b 15.0 -t 1 -x off -l 0