summaryrefslogtreecommitdiff
path: root/Makefile
blob: 940679916278bfeaa991ce93f5a05493959bbc0f (plain)
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
486
487
488
489
490
491
492
493
494
495
496
497
498

#########################################################################
#
#  $Id: Makefile 1.1.1.8 2017/08/11 10:32:21 martin TEST $
#
#  Description:
#    Makefile for mbgtools which recurses into the subdirectories.
#
# -----------------------------------------------------------------------
#  $Log: Makefile $
#  Revision 1.1.1.8  2017/08/11 10:32:21  martin
#  Cleaned up CPPFLAGS.
#  Revision 1.1.1.7  2017/08/10 15:40:25  martin
#  Cleanup.
#  Revision 1.1.1.6  2017/08/10 15:15:02  martin
#  Merged common kernel module stuff.
#  Revision 1.1.1.5  2017/08/02 12:13:19  martin
#  Re-added mbgclock to SUBDIRS.
#  Revision 1.1.1.4  2017/07/26 14:31:06  martin
#  Removed trailing spaces.
#  Revision 1.1.1.3  2011/11/24 13:59:58  martin
#  Revision 1.1.1.2  2011/07/08 12:10:09  martin
#  Revision 1.1.1.1  2011/03/29 13:54:39  martin
#  Revision 1.1.1.6.1.1  2011/03/28 09:36:56  martin
#  Kardel: exclude subdir mbgclock under NetBSD
#  Revision 1.1.1.6  2011/03/25 11:05:55  martin
#  Optional parameter USE_TIMESPEC.
#  Revision 1.1.1.5  2011/03/21 16:24:12  martin
#  Workaround for recursive make under NetBSD.
#  Revision 1.1.1.4  2011/02/04 10:09:45  martin
#  Revision 1.1.1.3  2011/02/02 12:33:29  martin
#  Revision 1.1.1.2  2011/01/28 09:29:47  martin
#  Revision 1.1.1.1  2011/01/27 16:16:40  martin
#  Revision 1.1  2011/01/27 15:41:01  martin
#  Initial revision
#
#########################################################################

.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 && 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/mbgtestcalrec
# SUBDIRS += test/mbgtestio
# SUBDIRS += test/mbgtestmmio
# SUBDIRS += test/mbgtestxhrt
# SUBDIRS += test/mbgchksystime
SUBDIRS += mbgclock

.PHONY: all clean distclean install uninstall
all clean distclean install uninstall:
	@for dir in $(SUBDIRS); do \
	  if test -f $$dir/Makefile; then \
	    /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:
	@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

MBGLIB_COMMON = ${MBGLIB}/common
MBGLIB_BSD = ${MBGLIB}/bsd

INCLUDES += -I.
INCLUDES += -I$(BASEDIR)

## INCLUDES += $(foreach dir,$(MBGLIB_DIRS),-I$(MBGLIB)/$(dir))

INCLUDES += -I$(MBGLIB_COMMON)
INCLUDES += -I$(MBGLIB_BSD)


# 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))

.ifdef DEBUG
  CPPFLAGS += -DDEBUG=$(DEBUG)
  CPPFLAGS += -g
.endif

.ifndef KMOD  #===========================================================

# not building a kernel module

CPPFLAGS += -Wall
## CPPFLAGS += -W

.ifdef USE_TIMESPEC
  CPPFLAGS += -DUSE_TIMESPEC=$(USE_TIMESPEC)
.endif

CPPFLAGS += $(INCLUDES)

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)

  CPPFLAGS += -fPIC
  CPPFLAGS += -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



.PHONY: all
all: $(TARGET)

## VPATH += $(foreach dir,$(MBGLIB_DIRS),$(MBGLIB)/$(dir))
VPATH = $(MBGLIB_COMMON):$(MBGLIB_BSD)

.ifndef MBGDEVIO_SIMPLE
  MBGDEVIO_SIMPLE = 1
.endif

.ifdef MBGDEVIO_SIMPLE
  CPPFLAGS += -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
      CPPFLAGS += -I /usr/include/nptl -L /usr/lib/nptl
.endif
.endif

  # May want to use the result for our program
  ## CPPFLAGS += -DUSE_THREAD_AFFINITY=$(USE_THREAD_AFFINITY)

  CPPFLAGS += -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) CPPFLAGS=$(CPPFLAGS))
## $(warning $(INFO) EXTRA_CPPFLAGS=$(EXTRA_CPPFLAGS))
## $(warning $(INFO) MAKECMDGOALS = $(MAKECMDGOALS))

$(TARGET): $(OBJS)
	$(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
	rm -rf $(DESTDIR)$(prefix)/share/$(TARGET)
	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
	rm -f $(CLEAN_FILES)
.endif
.ifdef CLEAN_DIRS
	rm -rf $(CLEAN_DIRS)
.endif


.else
# ===== Building a kernel module =============================================

USE_FORT?= yes	# network client/server

# WARNS?=	5

.include <bsd.own.mk>

CPPFLAGS += ${INCLUDES}

## .if defined(DEBUG)
## CPPFLAGS += -DDEBUG=${DEBUG}
## .endif

.if defined(MBG_DEBUG)
CPPFLAGS += -DMBG_DEBUG=${MBG_DEBUG}
.endif

.PATH: ${MBGLIB_COMMON} ${MBGLIB_BSD}

MKMAN=no

.if !defined (MKMODULAR) || ( defined(MKMODULAR) && (${MKMODULAR}!="no") )
.include <bsd.kmodule.mk>
.else
.include <bsd.kmod.mk>
.endif

.endif  # building kernel module
#==================================================================================


# common targets:

.PHONY: distclean
distclean: clean

.endif