-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
173 lines (159 loc) · 5.29 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
ECHO ?= echo
STRIP ?= strip
PKGCONFIG ?= pkg-config
# check if user is root
user = $(shell whoami)
ifeq ($(user),root)
INSTALL_DIR = /usr/lib/lv2
else
INSTALL_DIR = ~/.lv2
endif
# check CPU and supported optimization flags
ifneq ($(shell cat /proc/cpuinfo | grep sse3 ) , )
SSE_CFLAGS = -msse3 -mfpmath=sse
else ifneq ($(shell cat /proc/cpuinfo | grep sse2 ) , )
SSE_CFLAGS = -msse2 -mfpmath=sse
else ifneq ($(shell cat /proc/cpuinfo | grep sse ) , )
SSE_CFLAGS = -msse -mfpmath=sse
else ifneq ($(shell cat /proc/cpuinfo | grep ARM ) , )
ifneq ($(shell cat /proc/cpuinfo | grep ARMv7 ) , )
ifneq ($(shell cat /proc/cpuinfo | grep vfpd32 ) , )
SSE_CFLAGS = -march=armv7-a -mfpu=vfpv3
else ifneq ($(shell cat /proc/cpuinfo | grep vfpv3 ) , )
SSE_CFLAGS = -march=armv7-a -mfpu=vfpv3
endif
else
ARMCPU = "YES"
endif
else
SSE_CFLAGS =
endif
# set bundle name
NAME = gx_bajatubedriver
BUNDLE = $(NAME).lv2
VER = 0.1
# check OS specific stuff
OS := $(shell echo $$OS)
UNAME_S := $(shell uname -s)
GUI_PLATFORM_DIR = ./gui
# default library extension
LIB_EXT = so
# cross compilation (e.g.: PKG_CONFIG_PATH=/usr/local/pkgconfig make CROSS=x86_64-w64-mingw32- mod)
ifneq (,$(findstring mingw,$(CROSS)))
# Found
TARGET = Windows
STRIP = $(CROSS)strip
PKGCONFIG = $(CROSS)pkg-config
CC = $(CROSS)cc
CXX = $(CROSS)g++
LD = $(CROSS)ld
else ifneq (,$(findstring mingw,$(CXX)))
# Found
TARGET = Windows
else
# Not found
ifeq ($(UNAME_S), Linux) #LINUX
TARGET = Linux
endif
ifeq ($(OS), Windows_NT) #WINDOWS
TARGET = Windows
endif
ifeq ($(UNAME_S), Darwin) #APPLE
TARGET = Apple
endif
endif
ifeq ($(TARGET), Linux)
ABI_CFLAGS = -Wl,-z,nodelete
ABI_CXXFLAGS = -Wl,-z,relro,-z,now
ABI_LDFLAGS = -Wl,-z,noexecstack
GUI_LIBS = -L/usr/X11/lib -lX11
LIB_EXT = so
GUI_PLATFORM_FILES = $(GUI_PLATFORM_DIR)/gx_platform_linux.c
endif
ifeq ($(TARGET), Windows)
#ECHO += -e
ABI_LDFLAGS = -static -lpthread
GUI_LIBS = -liconv -lstdc++
PKGCONFIG_FLAGS = --static
LIB_EXT = dll
TTLUPDATE = sed -i '/lv2:binary/ s/\.so/\.dll/ ' $(BUNDLE)/manifest.ttl
TTLUPDATEGUI = sed -i '/a guiext:X11UI/ s/X11UI/WindowsUI/ ; /guiext:binary/ s/\.so/\.dll/ ' $(BUNDLE)/$(NAME).ttl
GUI_PLATFORM_FILES = $(GUI_PLATFORM_DIR)/gx_platform_mswin.c
endif
ifeq ($(TARGET), Apple)
LIB_EXT = so
# insert magic here
GUI_PLATFORM_FILES = $(GUI_PLATFORM_DIR)/gx_platform_apple.c
endif
# set compile flags
CXXFLAGS += -std=gnu++11 -D_FORTIFY_SOURCE=2 -I. -I./dsp -I./plugin -fPIC -DPIC -O2 -Wall -fstack-protector -funroll-loops \
-ffast-math -fomit-frame-pointer -fstrength-reduce -fdata-sections -Wl,--gc-sections $(ABI_CXXFLAGS) $(SSE_CFLAGS)
CFLAGS += -D_FORTIFY_SOURCE=2 -I. -I./dsp -I./plugin -fPIC -DPIC -O2 -Wall -fstack-protector -funroll-loops \
-ffast-math -fomit-frame-pointer -fstrength-reduce -fdata-sections -Wl,--gc-sections $(ABI_CXXFLAGS) $(SSE_CFLAGS)
LDFLAGS += -I. -shared $(ABI_LDFLAGS) -lm
GUI_LDFLAGS += -I./gui -shared $(ABI_LDFLAGS) -lm `$(PKGCONFIG) $(PKGCONFIG_FLAGS) --cflags --libs cairo` $(GUI_LIBS)
# invoke build files
OBJECTS = plugin/$(NAME).cpp
GUI_OBJECTS = gui/$(NAME)_gui.c $(GUI_PLATFORM_FILES)
RES_OBJECTS = gui/pedal.o gui/pswitch.o
## output style (bash colours)
LGREEN = "\033[1;92m"
BLUE = "\033[1;34m"
RED = "\033[1;31m"
NONE = "\033[0m"
.PHONY : mod all clean install uninstall
all : check $(NAME)
@mkdir -p ./$(BUNDLE)
@cp ./plugin/*.ttl ./$(BUNDLE)
@mv ./*.$(LIB_EXT) ./$(BUNDLE)
$(TTLUPDATE)
$(TTLUPDATEGUI)
@if [ -f ./$(BUNDLE)/$(NAME).$(LIB_EXT) ]; then $(ECHO) $(BLUE)"build finish, now run make install"; \
else $(ECHO) $(RED)"sorry, build failed"; fi
@$(ECHO) $(NONE)
mod : check clean nogui
@mkdir -p ./$(BUNDLE)
@cp -R ./MOD/* ./$(BUNDLE)
@mv ./*.$(LIB_EXT) ./$(BUNDLE)
$(TTLUPDATE)
@if [ -f ./$(BUNDLE)/$(NAME).$(LIB_EXT) ]; then $(ECHO) $(BLUE)"build finish, now run make install"; \
else $(ECHO) $(RED)"sorry, build failed"; fi
@$(ECHO) $(NONE)
check :
ifdef ARMCPU
@$(ECHO) $(RED)ARM CPU DEDECTED, please check the optimization flags
@$(ECHO) $(NONE)
endif
#@build resource object files
$(RES_OBJECTS) : gui/pedal.png gui/pswitch.png
@$(ECHO) $(LGREEN)"generate resource files,"$(NONE)
-cd ./gui && $(LD) -r -b binary pedal.png -o pedal.o
-cd ./gui && $(LD) -r -b binary pswitch.png -o pswitch.o
clean :
@rm -f $(NAME).$(LIB_EXT)
@rm -rf ./$(BUNDLE)
@$(ECHO) ". ." $(BLUE)", clean up"$(NONE)
dist-clean :
@rm -f $(NAME).$(LIB_EXT)
@rm -rf ./$(BUNDLE)
@rm -rf ./$(RES_OBJECTS)
@$(ECHO) ". ." $(BLUE)", clean up"$(NONE)
install :
ifneq ("$(wildcard ./$(BUNDLE))","")
@mkdir -p $(DESTDIR)$(INSTALL_DIR)/$(BUNDLE)
cp -r ./$(BUNDLE)/* $(DESTDIR)$(INSTALL_DIR)/$(BUNDLE)
@$(ECHO) ". ." $(BLUE)", done"$(NONE)
else
@$(ECHO) ". ." $(BLUE)", you must build first"$(NONE)
endif
uninstall :
@rm -rf $(INSTALL_DIR)/$(BUNDLE)
@$(ECHO) ". ." $(BLUE)", done"$(NONE)
$(NAME) : clean $(RES_OBJECTS)
$(CXX) $(CXXFLAGS) $(OBJECTS) $(LDFLAGS) -o $(NAME).$(LIB_EXT)
$(CC) $(CFLAGS) $(ABI_CFLAGS) $(GUI_OBJECTS) $(RES_OBJECTS) $(GUI_LDFLAGS) -o $(NAME)_ui.$(LIB_EXT)
$(STRIP) -s -x -X -R .note.ABI-tag $(NAME).$(LIB_EXT)
$(STRIP) -s -x -X -R .note.ABI-tag $(NAME)_ui.$(LIB_EXT)
nogui : clean
$(CXX) $(CXXFLAGS) $(OBJECTS) $(LDFLAGS) -o $(NAME).$(LIB_EXT)
$(STRIP) -s -x -X -R .note.ABI-tag $(NAME).$(LIB_EXT)