-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile
executable file
·142 lines (121 loc) · 4.04 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
#!/usr/bin/make -f
# -*- makefile -*-
# SPDX-License-Identifier: GPL-2.0-only
# SPDX-FileCopyrightText: 2008-2019, Sven Eckelmann <[email protected]>
# SPDX-FileCopyrightText: 2012-2014, Simon Wunderlich <[email protected]>
# SPDX-FileCopyrightText: 2013, Janusz Dziedzic <[email protected]>
# SPDX-FileCopyrightText: 2015, Adrian Chadd <[email protected]>
# SPDX-FileCopyrightText: 2015, Steven Pease <[email protected]>
# SPDX-FileCopyrightText: 2017, Nicolas Pace <[email protected]>
# add a new binary and allow to disable/enable it using the CONFIG_$binaryname
# make parameter
# only allow as value y (enable) and n (disable)
define add_command
CONFIG_$(1):=$(2)
ifneq ($$(CONFIG_$(1)),y)
ifneq ($$(CONFIG_$(1)),n)
$$(warning invalid value for parameter CONFIG_$(1): $$(CONFIG_$(1)))
endif
endif
obj-$$(CONFIG_$(1)) += $(1)
endef # add_command
# using the make parameter CONFIG_* (e.g. CONFIG_fft_eval_sdl) with the value
# 'y' enables the related feature and 'n' disables it
$(eval $(call add_command,fft_eval_sdl,y))
fft_eval_sdl-y += fft_eval.o
fft_eval_sdl-y += fft_eval_sdl.o
$(eval $(call add_command,fft_eval_json,y))
fft_eval_json-y += fft_eval.o
fft_eval_json-y += fft_eval_json.o
# fft_eval flags and options
CFLAGS += -Wall -W -std=gnu99 -fno-strict-aliasing -MD -MP
CPPFLAGS += -D_DEFAULT_SOURCE
LDLIBS += -lm
# disable verbose output
ifneq ($(findstring $(MAKEFLAGS),s),s)
ifndef V
Q_CC = @echo ' ' CC $@;
Q_LD = @echo ' ' LD $@;
export Q_CC
export Q_LD
endif
endif
ifeq ($(CONFIG_fft_eval_sdl),y)
# test for presence of SDL
ifeq ($(origin SDL_CFLAGS) $(origin SDL_LDLIBS), undefined undefined)
SDL2_CONFIG = $(CROSS)sdl2-config
ifeq ($(shell which $(SDL2_CONFIG) 2>/dev/null),)
$(error No SDL development libraries found!)
endif
SDL_CFLAGS += $(shell $(SDL2_CONFIG) --cflags)
SDL_LDLIBS += $(shell $(SDL2_CONFIG) --libs)
endif
CFLAGS_fft_eval_sdl.o += $(SDL_CFLAGS)
LDLIBS_fft_eval_sdl += $(SDL_LDLIBS)
ifeq ($(origin PKG_CONFIG), undefined)
PKG_CONFIG = $(CROSS)pkg-config
ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),)
$(error $(PKG_CONFIG) not found)
endif
endif
ifeq ($(origin LIBSDL2TTF_CFLAGS) $(origin LIBSDL2TTF_LDLIBS), undefined undefined)
LIBSDL2TTF_NAME ?= SDL2_ttf
ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBSDL2TTF_NAME) 2>/dev/null),)
$(error No $(LIBSDL2TTF_NAME) development libraries found!)
endif
LIBSDL2TTF_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBSDL2TTF_NAME))
LIBSDL2TTF_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBSDL2TTF_NAME))
endif
CFLAGS_fft_eval_sdl.o += $(LIBSDL2TTF_CFLAGS)
LDLIBS_fft_eval_sdl += $(LIBSDL2TTF_LDLIBS)
endif
CC = $(CROSS)gcc
RM ?= rm -f
INSTALL ?= install
MKDIR ?= mkdir -p
COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH)
# standard install paths
PREFIX = /usr/local
BINDIR = $(PREFIX)/sbin
# default target
all: $(obj-y)
# standard build rules
.SUFFIXES: .o .c
.c.o:
$(COMPILE.c) $(CFLAGS_$(@)) -o $@ $<
$(obj-y):
$(LINK.o) $^ $(LDLIBS) $(LDLIBS_$(@)) -o $@
clean:
$(RM) $(BINARY_NAMES) $(OBJ) $(DEP) samples/*.test
install: $(obj-y)
$(MKDIR) $(DESTDIR)$(BINDIR)
$(INSTALL) -m 0755 $(obj-y) $(DESTDIR)$(BINDIR)
ifeq ($(CONFIG_fft_eval_sdl),y)
test:: fft_eval_sdl
set -e; \
for i in $(wildcard samples/*.dump); do \
echo $$i; \
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=disk $(TESTRUN_WRAPPER) ./fft_eval_sdl $$i; \
done
endif
ifeq ($(CONFIG_fft_eval_json),y)
test:: fft_eval_json
set -e; \
for i in $(wildcard samples/*.dump); do \
echo $$i; \
$(TESTRUN_WRAPPER) ./fft_eval_json $$i > $$i.test; \
cmp $$i.test $$i.json; \
done
endif
# load dependencies
BINARY_NAMES = $(foreach binary,$(obj-y) $(obj-n), $(binary))
OBJ = $(foreach obj, $(BINARY_NAMES), $($(obj)-y))
DEP = $(OBJ:.o=.d)
-include $(DEP)
# add dependency of binary to object
define binary_dependency
$(1): $(2)
endef
$(foreach binary, $(obj-y), $(eval $(call binary_dependency, $(binary), $($(binary)-y))))
.PHONY: all clean install test