summaryrefslogtreecommitdiff
path: root/unix/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'unix/Makefile')
-rw-r--r--unix/Makefile135
1 files changed, 84 insertions, 51 deletions
diff --git a/unix/Makefile b/unix/Makefile
index 9b856d6..dba01df 100644
--- a/unix/Makefile
+++ b/unix/Makefile
@@ -1,41 +1,30 @@
-
#########################################################################
#
-# $Id: Makefile 1.9 2017/04/12 08:49:33 martin TEST $
-#
-# Description:
-# Makefile for gpsxmple for Unix-like systems.
-# Currently supported OSs: Linux, QNX 6.x
-#
-# -----------------------------------------------------------------------
-# $Log: Makefile $
-# Revision 1.9 2017/04/12 08:49:33 martin
-# Changed CFLAGS to CPPFLAGS.
-# Revision 1.8 2017/04/05 16:08:53 martin
-# Added some library modules.
-# Revision 1.7 2014/10/30 13:50:04 martin
-# Added module mbgerror.o.
-# Revision 1.6 2013/02/01 16:11:27 martin
-# Added extiohlp module to the list of object files.
-# Revision 1.5 2011/08/19 07:26:40 martin
-# Modified the way to define targets etc.
-# Revision 1.4 2011/04/18 08:08:41 martin
-# Modified DEBUG handling.
-# Revision 1.3 2009/10/01 14:09:19 martin
-# Added mbgserio.c source module.
-# Revision 1.2 2006/08/22 15:49:27 martin
-# Moved this makefile for Unix-like systems to folder unix.
-# This build environment now supports Linux and QNX 6.x.
-# Network socket I/O is supported for both Linux and QNX.
-# Serial I/O is not yet supprted for QNX, but for Linux.
-# Account for mbglib files having been moved to subdirectory mbglib.
-# Build with debug if make is called with DEBUG=1.
-# Added library modules mbgextio.c and aes128.c.
-# Revision 1.1 2004/06/01 14:55:27 martin
+# Makefile for 'gpsxmple' for Unix-like systems.
+# Currently supported OSs: Linux, QNX 6.x
#
#########################################################################
-TARGET = gpsxmple
+MBG_TARGET_1 = gpsxmple
+MBG_TARGET_2 = set-serial-port
+MBG_TARGETS = $(MBG_TARGET_1) $(MBG_TARGET_2)
+
+
+# Set V to 1 to build verbosely.
+V ?= 0
+
+# The lines below make the build output non-verbose by default.
+# Call make with parameter "V=1" to get verbose output.
+ifneq ("$(V)","0")
+ Q :=
+ QM :=
+ vecho = @true
+else
+ Q := @
+ QM := -s
+ vecho = @echo
+endif
+
MBGLIB = ../mbglib
MBGLIB_DIRS += common
@@ -43,19 +32,30 @@ MBGLIB_DIRS += common
VPATH += ..
VPATH += $(foreach dir,$(MBGLIB_DIRS),$(MBGLIB)/$(dir))
-OBJS = $(TARGET).o
-OBJS += extiohlp.o
-OBJS += xtiocomm.o
-OBJS += cfg_hlp.o
-OBJS += mbgextio.o
-OBJS += mbgserio.o
-OBJS += gpsserio.o
-OBJS += gpsutils.o
-OBJS += aes128.o
-OBJS += mbgerror.o
-OBJS += str_util.o
-OBJS += lan_util.o
-OBJS += xdevfeat.o
+
+# List of object files for an intermediate, static library.
+LIB_OBJS += extiohlp.o
+LIB_OBJS += xtiocomm.o
+LIB_OBJS += cfg_hlp.o
+LIB_OBJS += mbgextio.o
+LIB_OBJS += mbgserio.o
+LIB_OBJS += gpsserio.o
+LIB_OBJS += gpsutils.o
+LIB_OBJS += aes128.o
+LIB_OBJS += mbgerror.o
+LIB_OBJS += str_util.o
+LIB_OBJS += lan_util.o
+LIB_OBJS += xdevfeat.o
+
+
+
+MBG_LIB_BASENAME = mbg
+MBG_LIB_FILE = lib$(MBG_LIB_BASENAME).a
+
+
+LDLIBS += $(MBG_LIB_FILE)
+
+
# Try to determine whether the OS is QNX
OS_IS_QNX := $(shell uname | grep -i QNX && echo "QNX" )
@@ -88,19 +88,52 @@ else
endif
-LD = $(CC)
+
+%.o: %.c
+ $(vecho) " $(CC) $@"
+ $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+
+
+%.o: %.cpp
+ $(vecho) " $(CC) $@"
+ $(Q)$(CC) $(CPPFLAGS) $(CXXLAGS) -c -o $@ $<
+
+
.PHONY: all
-all: $(TARGET)
+all: $(MBG_TARGETS)
+
+
+
+$(MBG_TARGETS): $(MBG_LIB_FILE)
+ $(vecho) " Linking $@"
+ $(Q)$(CC) -o $@ $(LDFLAGS) $@.o $(OBJS) $(LDLIBS)
+
+$(MBG_TARGET_1): $(MBG_TARGET_1).o
+$(MBG_TARGET_2): $(MBG_TARGET_2).o
+
+
+
+# Options for the archiver to build a static library
+ARFLAGS := rcs
+ifneq ("$(V)","0")
+ # In verbose mode we also make the archiver verbose.
+ ARFLAGS := $(ARFLAGS)v
+endif
+
+
+$(MBG_LIB_FILE): $(LIB_OBJS)
+ $(vecho) " $(AR) $@"
+ $(Q)$(AR) $(ARFLAGS) $@ $(LIB_OBJS)
+
-$(TARGET): $(OBJS)
- $(LD) $(LDFLAGS) -o $@ $(OBJS)
.PHONY: clean
clean:
rm -f *.o *~ core
- rm -f $(TARGET)
+ rm -f $(MBG_LIB_FILE)
+ rm -f $(MBG_TARGETS)
.PHONY: distclean
distclean: clean