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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
|
#########################################################################
#
# $Id: Makefile 1.2 2017/07/06 09:45:24 martin REL_M $
#
# Description:
# Makefile for mbgtools which recurses into the subdirectories.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
# Revision 1.2 2017/07/06 09:45:24 martin
# Support quiet build.
# Updated list of target subdirs.
# Also test subdirs for BSDmakefile.
# Optional parameter USE_TIMESPEC.
# Revision 1.1 2011/01/27 15:41:01 martin
# Initial revision
#
#########################################################################
V ?= 0 # set to 1 to build verbosely
# The lines below make the build output non-verbose by default.
# Call make with parameter "V=1" to get verbose output.
.if $(V) != 0
Q :=
QM :=
vecho = @true
.else
Q := @
QM := -s
vecho = @echo
.endif
.ifndef prefix
prefix := /usr/local
.endif
.ifndef bindir
bindir := $(prefix)/bin
.endif
.ifndef sbindir
sbindir := $(prefix)/sbin
.endif
.ifndef sysconfdir
sysconfdir := /etc
.endif
.ifndef includedir
includedir := $(prefix)/include
.endif
.ifndef libdir
CUR_ARCH = $(shell uname -m)
find_libdirname := $(shell \
if [ $(CUR_ARCH) = "ia64" -o $(CUR_ARCH) = "x86_64" ]; then \
if test -d $(prefix)/lib64; \
then echo "lib64"; \
else echo "lib"; \
fi \
else \
if test -d $(prefix)/lib32; \
then echo "lib32"; \
else echo "lib"; \
fi \
fi \
)
libdir := $(prefix)/$(call find_libdirname)
##$(warning $(INFO) libdir set to $(libdir))
.endif
INSTALL_PATHS = DESTDIR=$(DESTDIR) prefix=$(prefix) bindir=$(bindir) sbindir=$(sbindir) includedir=$(includedir) libdir=$(libdir) sysconfdir=$(sysconfdir)
.ifndef SO_BASENAMES
SO_BASENAMES += devio
SO_BASENAMES += util
SO_BASENAMES += serio
SO_BASENAMES += extio
.endif
.ifndef SO_SUBDIRS
# SO_SUBDIRS += $(foreach dir,$(SO_BASENAMES), libmbg_so/mbg$(dir) )
## $(warning $(INFO) **************** SO_SUBDIRS set to $(SO_SUBDIRS))
.endif
##$(warning $(INFO) SO_SUBDIRS set to $(SO_SUBDIRS))
.ifndef BASEDIR
.DEFAULT_GOAL := all
MAKECMDGOALS ?= $(.DEFAULT_GOAL)
# This section is used only if this makefile is called by the top-level
# make. It specifies some common targets and some subdirs in which a
# recursive make will be executed, which may include this make file again
# and evaluate the second part.
INFO=top 1st:
## $(warning $(INFO) reading top level part)
## export COMMON_MAKEFILE := $(CURDIR)/Makefile
## $(warning $(INFO) COMMON_MAKEFILE set to $(COMMON_MAKEFILE))
# The macro function below prints an info string whether a target
# is supported by the kernel Makefile
.ifndef SUBDIRS
chk_subdir = $(shell test -f $(strip $(1))/Makefile || test -f $(strip $(1))/BSDmakefile && echo "$(1)" )
.ifndef DONT_BUILD_LIBS
SUBDIRS += $(SO_SUBDIRS)
## $(foreach dir,$(SO_SUBDIRS),$(eval SUBDIRS += $(call chk_subdir, $(dir))))
SUBDIRS += $(call chk_subdir, "libmbg_so/devel" )
.endif
.ifndef DONT_BUILD_TOOLS
SUBDIRS += $(call chk_subdir, "mbgstatus" )
SUBDIRS += $(call chk_subdir, "mbgsetsystime" )
SUBDIRS += $(call chk_subdir, "mbgctrl" )
SUBDIRS += $(call chk_subdir, "mbgirigcfg" )
SUBDIRS += $(call chk_subdir, "mbgshowsignal" )
SUBDIRS += $(call chk_subdir, "mbggpscap" )
SUBDIRS += $(call chk_subdir, "mbghrtime" )
SUBDIRS += $(call chk_subdir, "mbgfasttstamp" )
SUBDIRS += $(call chk_subdir, "mbgsvcd" )
SUBDIRS += $(call chk_subdir, "mbgxhrtime" )
SUBDIRS += $(call chk_subdir, "test/mbgtestcalrec" )
SUBDIRS += $(call chk_subdir, "test/mbgtestio" )
SUBDIRS += $(call chk_subdir, "test/mbgtestmmio" )
SUBDIRS += $(call chk_subdir, "test/mbgtestxhrt" )
SUBDIRS += $(call chk_subdir, "test/mbgchksystime" )
SUBDIRS += $(call chk_subdir, "test/mbgtestsettime" )
.endif
.ifndef DONT_BUILD_GUI
.ifndef DONT_BUILD_MBGMON
SUBDIRS += $(call chk_subdir, "wxwidgets/mbgmon" )
.endif
.ifndef DONT_BUILD_MBGSTATSVIEWER
SUBDIRS += $(call chk_subdir, "wxwidgets/mbgstatsviewer" )
.endif
.endif
.ifndef DONT_BUILD_DRIVER
SUBDIRS += $(call chk_subdir, "mbgclock" )
##SUBDIRS += $(call chk_subdir, "test/mbgclock-test" )
.endif
## $(warning $(INFO) SUBDIRS = $(SUBDIRS))
## $(warning $(INFO) MAKECMDGOALS = $(MAKECMDGOALS))
.endif
SUBDIRS += mbgstatus
SUBDIRS += mbgsvcd
SUBDIRS += mbgsetsystime
SUBDIRS += mbgctrl
SUBDIRS += mbgirigcfg
SUBDIRS += mbgshowsignal
SUBDIRS += mbggpscap
SUBDIRS += mbghrtime
SUBDIRS += mbgfasttstamp
## SUBDIRS += mbgxhrtime ## not yet tested
SUBDIRS += test/mbgchksystime
## SUBDIRS += test/mbgclock-test
SUBDIRS += test/mbgcmptime
SUBDIRS += test/mbgreadtime
SUBDIRS += test/mbgtcrcal
##SUBDIRS += test/mbgtestcalrec
SUBDIRS += test/mbgtestio
SUBDIRS += test/mbgtestsettime
SUBDIRS += test/mbg_ucap
SUBDIRS += mbgclock
.PHONY: all clean distclean install uninstall
all clean distclean install uninstall:
@for dir in $(SUBDIRS); do \
if test -f $$dir/Makefile || test -f $$dir/BSDmakefile; then \
echo "Making $@ in $$dir"; \
/bin/sh -c "cd $$dir; $(MAKE) $@"; \
fi \
done
.PHONY: dev dev-nodes dev-clean suse_symvers probe ins rm test reload check \
refclocks kernel_config
dev dev-nodes dev-clean suse_symvers probe ins rm test reload check \
refclocks kernel_config:
@echo "Making $(MAKECMDGOALS) in $@"
@cd mbgclock && make $@
.PHONY: cleanreload
cleanreload: clean all install reload
.else # ================================================================
# This section is evaluated only if this makefile is included from
# a subproject's makefile.
.ifndef MBGLIB
MBGLIB := $(BASEDIR)/mbglib
.endif
MBGLIB_DIRS += common linux
# Macros useful to run individual commands as root:
.ifndef CALLED_FROM_SPEC
.ifndef SUDO
SUDO := $(shell which sudo)
.endif
.ifndef SU
SU := $(shell which su)
.endif
UID = $(shell id -u)
.else
#fake running as root
UID = 0
.endif
run_as_root = $(shell echo "$(SUDO) $(1) || $(SU) -c \"$(1)\"" )
make_as_root = $(call run_as_root, make $(1))
.ifndef MODULE_OBJS #===========================================================
# not building a kernel module
CFLAGS += -Wall
.ifdef DEBUG
CFLAGS += -DDEBUG=$(DEBUG)
CFLAGS += -g
.else
CFLAGS += -O2
.endif
.ifdef USE_TIMESPEC
CFLAGS += -DUSE_TIMESPEC=$(USE_TIMESPEC)
.endif
CFLAGS += -I.
CFLAGS += -I$(BASEDIR)
# foreach doesn't seem to work under FreeBSD :-(
# CFLAGS += $(foreach dir,$(MBGLIB_DIRS),-I$(MBGLIB)/$(dir))
CFLAGS += -I$(BASEDIR)/mbglib/common
CFLAGS += -I$(BASEDIR)/mbglib/bsd
LDFLAGS += -lutil
# foreach doesn't seem to work under FreeBSD :-(
# LDFLAGS += $(foreach dir,$(SO_SUBDIRS),-L $(BASEDIR)/$(dir) )
SO_MAJOR_VERSION = 1
SO_MINOR_VERSION = 0
.ifdef SO_TARGET_BASENAME
.ifndef SO_POINT_RELEASE
SO_POINT_RELEASE = 0
.endif
SO_TARGET_NAME = libmbg$(SO_TARGET_BASENAME)
SO_TARGET_LIBNAME = $(SO_TARGET_NAME).so
SO_TARGET_SONAME = $(SO_TARGET_LIBNAME).$(SO_MAJOR_VERSION)
TARGET = $(SO_TARGET_SONAME).$(SO_MINOR_VERSION).$(SO_POINT_RELEASE)
OBJS += mbg$(SO_TARGET_BASENAME).o
CLEAN_FILES += $(SO_TARGET_LIBNAME)
CFLAGS += -fPIC
CFLAGS += -c
LDFLAGS += -shared
LDFLAGS += -lc
LDFLAGS += -Wl,-soname,$(SO_TARGET_SONAME)
.ifndef LIBDIR
LIBDIR := $(shell if [ -d /usr/lib64 ]; then echo /usr/lib64; else echo /usr/lib; fi )
.endif
.endif
CXXFLAGS = $(CFLAGS)
.PHONY: all
all: $(TARGET)
#### VPATH += $(foreach dir,$(MBGLIB_DIRS),$(MBGLIB)/$(dir))
VPATH = $(BASEDIR)/mbglib/common:$(BASEDIR)/mbglib/bsd
.ifndef MBGDEVIO_SIMPLE
MBGDEVIO_SIMPLE = 1
.endif
.ifdef MBGDEVIO_SIMPLE
CFLAGS += -DMBGDEVIO_SIMPLE=$(MBGDEVIO_SIMPLE)
.endif
.ifdef USE_THREAD_API
# Check whether thread affinity is supported by the installed pthread library.
# Newer versions of glibc/pthread (at least glibc 2.5) supports this natively.
# Older versions of glibc/pthread (e.g. glibc 2.3) may not support this natively
# but may provide a NPTL (New Posix Thread Library) library located under separate
# include and lib paths. We try to detect NPTL and add those paths to the search
# paths only if USE_NTPL has been defined e.g. on the make command line.
# Check whether pthread_getaffinity is supported by the standard pthread.h
USE_THREAD_AFFINITY := $(shell grep -q pthread_getaffinity /usr/include/pthread.h && echo 1)
# If it is not, check nptl/pthread.h
.ifndef USE_THREAD_AFFINITY
.ifdef USE_NPTL
USE_THREAD_AFFINITY := $(shell grep -q pthread_getaffinity /usr/include/nptl/pthread.h && echo 1)
.endif
.ifndef USE_THREAD_AFFINITY
##++++ If not found either, don't support thread affinity
USE_THREAD_AFFINITY=0
.else
#if supported via nptl add the associated search paths
CFLAGS += -I /usr/include/nptl -L /usr/lib/nptl
.endif
.endif
# May want to use the result for our program
## CFLAGS += -DUSE_THREAD_AFFINITY=$(USE_THREAD_AFFINITY)
CFLAGS += -DMBGDEVIO_USE_THREAD_API=1
#LDFLAGS += -lpthread
LDFLAGS += -pthread
.endif
.ifdef INST_TO_BIN
INST_DIR = $(DESTDIR)$(bindir)
.else
.ifdef INST_TO_SBIN
INST_DIR = $(DESTDIR)$(sbindir)
.else
.ifdef INST_TO_LIB
INST_DIR = $(DESTDIR)$(libdir)
.else
.ifdef INST_TO_INCLUDE
INST_DIR = $(DESTDIR)$(includedir)/mbglib
.endif
.endif
.endif
.endif
.ifdef DO_GUI_INSTALLATION
EXT_INSTALL += gui_install
EXT_UNINSTALL += gui_uninstall
.endif
## $(warning $(INFO) CFLAGS=$(CFLAGS))
## $(warning $(INFO) EXTRA_CFLAGS=$(EXTRA_CFLAGS))
## $(warning $(INFO) MAKECMDGOALS = $(MAKECMDGOALS))
.c.o:
$(vecho) " $(CC) ${.IMPSRC}"
$(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -o ${.TARGET} -c ${.IMPSRC}
$(TARGET): $(OBJS)
$(vecho) " Linking $@"
$(Q)$(CC) -o $@ $(OBJS) $(LDFLAGS)
.ifdef SO_TARGET_LIBNAME
ln -sf $(TARGET) $(SO_TARGET_LIBNAME)
.endif
.PHONY: install
install: $(EXT_INSTALL)
.ifdef XXX #.ifneq ($(UID),0)
$(call make_as_root, $@)
.else
.ifdef INCLUDE_FILES #include files
mkdir -p $(INST_DIR)
for incfile in $(INCLUDE_FILES); do \
install -m 644 $(BASEDIR)/mbglib/common/$$incfile $(INST_DIR)/; \
done;
for basename in $(SO_BASENAMES); do \
pushd $(DESTDIR)$(libdir); \
ln -sf libmbg$$basename.so.$(SO_MAJOR_VERSION) libmbg$$basename.so; \
popd; \
done;
.else #usual installation
.ifdef CALLED_FROM_SPEC
mkdir -p $(INST_DIR)
.endif
install -s $(TARGET) $(INST_DIR)
.ifndef CALLED_FROM_SPEC
.ifdef INST_TO_LIB
/sbin/ldconfig
.endif
.endif
.endif
.endif
.PHONY: uninstall
uninstall: $(EXT_UNINSTALL)
.ifdef INCLUDE_FILES #remove include files and
rm -rf $(INST_DIR)
.ifndef CALLED_FROM_SPEC #remove symbolic links
for basename in $(SO_BASENAMES); do \
rm -f $(libdir)/libmbg$$basename.so; \
done;
.endif
.else
.ifdef XXX #.ifneq ($(UID),0)
$(call make_as_root, $@)
.else
rm -f $(INST_DIR)/$(TARGET)
.ifndef CALLED_FROM_SPEC
.ifdef INST_TO_LIB
/sbin/ldconfig
.endif
.endif
.endif
.endif
.PHONY: gui_install
gui_install:
.ifdef XXX #.ifneq ($(UID),0)
$(call make_as_root, $@)
.else
mkdir -p $(DESTDIR)$(prefix)/share/$(TARGET)
cp $(TARGET).png $(DESTDIR)$(prefix)/share/$(TARGET)/$(TARGET).png
mkdir -p $(DESTDIR)$(prefix)/share/applications
cp $(TARGET).desktop $(DESTDIR)$(prefix)/share/applications/$(TARGET).desktop
.endif
.PHONY: gui_uninstall
gui_uninstall:
.ifdef XXX #.ifneq ($(UID),0)
$(call make_as_root, $@)
.else
$(Q)rm -rf $(DESTDIR)$(prefix)/share/$(TARGET)
$(Q)rm -f $(DESTDIR)$(prefix)/share/applications/$(TARGET).desktop
.endif
CLEAN_FILES += *.o
CLEAN_FILES += *~
CLEAN_FILES += core
CLEAN_FILES += $(TARGET)
.PHONY: clean
clean:
.ifdef CLEAN_FILES
$(Q)rm -f $(CLEAN_FILES)
.endif
.ifdef CLEAN_DIRS
$(Q)rm -rf $(CLEAN_DIRS)
.endif
.else
# ===== Building module for kernel 2.6 =============================================
.endif # building kernel module
#==================================================================================
# common targets:
.PHONY: distclean
distclean: clean
.endif
|