forked from sothis/x52control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
230 lines (193 loc) · 5.65 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
VERSION := $(shell ./version)
ifeq ($(shell uname), Linux)
PLAT_LINUX := Yes
PLATFORM := linux
else ifeq ($(shell uname), Darwin)
PLAT_DARWIN := Yes
PLATFORM := darwin
endif
################################################################################
### libx52
SRC += ./libx52/init/init_ctor.c
SRC += ./libx52/usb/usb.c
SRC += ./libx52/usb/error.c
SRC += ./libx52/usb/descriptors.c
SRC += ./libx52/usb/$(PLATFORM).c
SRC += ./libx52/x52device.c
SRC += ./libx52/x52interface.c
SRC += ./libx52/x52session.c
### x52control
SRC += ./src/entry.c
SRC += ./src/control.c
################################################################################
ifeq ($(CONF), debug)
DEBUG := Yes
endif
ifeq ($(CONF), release)
RELEASE := Yes
endif
ifeq ($(CONF), release_dist)
RELEASE := Yes
DIST := Yes
endif
# preprocessor definitions
ifdef RELEASE
DEFINES += -DNDEBUG
endif
DEFINES += -D_GNU_SOURCE=1
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_LARGEFILE64_SOURCE=1
DEFINES += -D_LARGEFILE_SOURCE=1
DEFINES += -D_BSD_SOURCE=1
DEFINES += -D$(PLATFORM)=1
DEFINES += -DVERSION='"$(VERSION)"'
# toolchain configuration
INCLUDES += -I./src
INCLUDES += -I./libx52
INCLUDES += -I./libx52/include
INCLUDES += -I./SDK/CHeaders/XPLM
INCLUDES += -I./SDK/CHeaders/Widgets
OUTDIR := ./build
BUILDDIR := $(OUTDIR)/$(CONF)
# common flags
CFLAGS := -pipe -Wall -g -O3 -fPIC
CFLAGS += -DIBM=0 -DAPL=0 -DLIN=1 -DXPLM200=1
ifdef PLAT_LINUX
CFLAGS += -m64 # 32 bits m32
endif
ifdef PLAT_DARWIN
CFLAGS += -mmacosx-version-min=10.4
CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
endif
# optimization flags
ifdef RELEASE
CFLAGS += -fvisibility=hidden
CFLAGS += -fomit-frame-pointer
CFLAGS += -fstrict-aliasing
ifdef PLAT_DARWIN
ifdef DIST
CFLAGS += -arch i386 -arch x86_64 #32 bits i386 ppc
endif
endif
endif #RELEASE
CXXFLAGS := $(CFLAGS)
# language dependent flags
CFLAGS += -std=c99
ifdef RELEASE
CXXFLAGS += -fvisibility-inlines-hidden
endif
LDFLAGS := $(CFLAGS) -static-libgcc
ifdef PLAT_LINUX
LDFLAGS += -shared
ARFLAGS := cru
endif
ifdef PLAT_DARWIN
LDFLAGS += -bundle -undefined dynamic_lookup
ARFLAGS := -static -o
endif
# determine intermediate object filenames
C_SRC := $(filter %.c, $(SRC))
CXX_SRC := $(filter %.cpp, $(SRC))
DEPS := $(patsubst %.c, $(BUILDDIR)/.obj/%_C.dep, $(C_SRC))
DEPS += $(patsubst %.cpp, $(BUILDDIR)/.obj/%_CXX.dep, $(CXX_SRC))
OBJECTS := $(patsubst %.c, $(BUILDDIR)/.obj/%_C.o, $(C_SRC))
OBJECTS += $(patsubst %.cpp, $(BUILDDIR)/.obj/%_CXX.o, $(CXX_SRC))
BINOBJ := $(filter-out $(BUILDDIR)/.obj/./libx52/%.o, $(OBJECTS))
LIBOBJ := $(filter $(BUILDDIR)/.obj/./libx52/%.o, $(OBJECTS))
# tools
ifdef PLAT_DARWIN
gcc_prefix := -4.0
endif
CC := gcc$(gcc_prefix)
CXX := g++$(gcc_prefix)
ifeq ($(CXX_SRC),)
LD := gcc$(gcc_prefix)
else
LD := g++$(gcc_prefix)
endif
ifdef PLAT_DARWIN
AR := libtool
else
AR := ar
endif
print_ar := echo $(eflags) "AR "
print_tar := echo $(eflags) "TAR"
print_ld := echo $(eflags) "LD "
print_cc := echo $(eflags) "CC "
print_cxx := echo $(eflags) "CXX"
# targets
all: release
help:
@echo "following make targets are available:"
@echo " help - print this"
@echo " release - build an optimized release version (*)"
@echo " debug - build a debug version"
@echo " lib-release - build libx52.a only, optimized"
@echo " lib-debug - build libx52.a only"
@echo " dist - build a version suitable for distribution,"
@echo " on macos x this will create an universal binary"
@echo " clean - recursively delete the output directory" \
"'$(OUTDIR)'"
@echo ""
@echo "(*) denotes the default target if none or 'all' is specified"
debug:
@$(MAKE) CONF=debug -C . all-recursive
release:
@$(MAKE) CONF=release -C . all-recursive
lib-release:
@$(MAKE) CONF=release -C . lib-recursive
lib-debug:
@$(MAKE) CONF=debug -C . lib-recursive
dist:
@$(MAKE) CONF=release_dist -C . dist-recursive
clean:
@echo "deleting '$(OUTDIR)'"
@-rm -rf $(OUTDIR)
dist-recursive: $(OUTDIR)/dist/x52control-$(VERSION)-$(PLATFORM).tar.bz2 \
$(OUTDIR)/dist/x52control-$(VERSION).tar.bz2
all-recursive: $(BUILDDIR)/x52control.xpl
lib-recursive: $(BUILDDIR)/libx52.a
$(OUTDIR)/dist/x52control-$(VERSION)-$(PLATFORM).tar.bz2: \
$(BUILDDIR)/x52control.xpl
@-mkdir -p $(dir $(@))
@$(print_tar) $(subst $(PWD)/, ./, $(abspath $(@)))
@tar -C $(BUILDDIR) -cjf $(@) x52control.xpl
$(OUTDIR)/dist/x52control-$(VERSION).tar.bz2:
@-mkdir -p $(dir $(@))
@$(print_tar) $(subst $(PWD)/, ./, $(abspath $(@)))
@git archive --format=tar --prefix=x52control-$(VERSION)/ \
HEAD^{tree} | \
bzip2 > $(@)
$(BUILDDIR)/libx52.a: $(LIBOBJ)
@$(print_ar) $(subst $(PWD)/, ./, $(abspath $(@)))
@-mkdir -p $(dir $(@))
@$(AR) $(ARFLAGS) $(@) $(LIBOBJ)
$(BUILDDIR)/x52control.xpl: $(BUILDDIR)/libx52.a $(BINOBJ)
@$(print_ld) $(subst $(PWD)/, ./, $(abspath $(@)))
@-mkdir -p $(dir $(@))
@$(LD) $(LDFLAGS) $(LPATH) $(FRAMEWORKS) \
-o $(@) $(BINOBJ) $(BUILDDIR)/libx52.a $(LIBRARIES)
ifdef DIST
ifdef PLAT_LINUX
@strip $(@)
endif
endif
$(BUILDDIR)/.obj/%_C.o: %.c
@$(print_cc) $(subst $(PWD)/, ./, $(abspath $(<)))
@-mkdir -p $(dir $(@))
ifndef DIST
@$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -S -o $(@:.o=.s) $(<)
@$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -M -MT \
"$(@) $(@:.o=.dep)" -o $(@:.o=.dep) $(<)
endif
@$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c -o $(@) $(<)
$(BUILDDIR)/.obj/%_CXX.o: %.cpp
@$(print_cxx) $(subst $(PWD)/, ./, $(abspath $(<)))
@-mkdir -p $(dir $(@))
ifndef DIST
@$(CXX) $(CXXFLAGS) $(DEFINES) $(INCLUDES) -S -o $(@:.o=.s) $(<)
@$(CXX) $(CXXFLAGS) $(DEFINES) $(INCLUDES) -M -MT \
"$(@) $(@:.o=.dep)" -o $(@:.o=.dep) $(<)
endif
@$(CXX) $(CXXFLAGS) $(DEFINES) $(INCLUDES) -c -o $(@) $(<)
-include $(DEPS)