Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 74 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,89 @@
# This is a Makefile for Travis CI, not tested for other purposes
BUILD_DIR := build
PREFIX ?= /usr/local

SOURCES = $(wildcard *.c) \
drivers/serial/pcserialport.c \
drivers/tcpip/tcpclient.c
drivers/tcpip/tcpclient.c \
utils/crc.c

OBJECTS = $(SOURCES:%.c=%.o)
HEADERS = $(wildcard *.h)

#user optionsare the ones starting with -D below
#be sure to check also user_options.h for more
CPPFLAGS = -I. -Iutils/ -DENABLE_BUILT_IN_DRIVERS
CFLAGS = -Wall -Wextra -DENABLE_BUILT_IN_DRIVERS -Iutils/
# Set library type to static or dynamic, used to
# set build directory etc.
ifeq ($(MAKECMDGOALS),libsimplemotionv2.so)
LIBRARY_TYPE = dynamic
else
LIBRARY_TYPE = static
endif

all: libsimplemotionv2.a
OBJECTS = $(SOURCES:%.c=$(BUILD_DIR)/$(LIBRARY_TYPE)/%.o)

libsimplemotionv2.a: $(OBJECTS)
ar rcs $@ $^
# User options are the ones starting with -D below,
# be sure to check also user_options.h for more
CPPFLAGS := -DENABLE_BUILT_IN_DRIVERS
CFLAGS := -g -Wall -Wextra
CFLAGS += -DENABLE_BUILT_IN_DRIVERS

# Include directories
INCLUDES := -I.
INCLUDES += -Idrivers/serial/
INCLUDES += -Idrivers/tcpip/
INCLUDES += -Iutils/

# Linker libraries
LDLIBS := -lm

# Linker flags
LDFLAGS :=

all:
$(MAKE) libsimplemotionv2.a
$(MAKE) libsimplemotionv2.so

libsimplemotionv2.a: $(BUILD_DIR)/libsimplemotionv2.a

libsimplemotionv2.so: CFLAGS += -fPIC
libsimplemotionv2.so: LDFLAGS += -shared
libsimplemotionv2.so: $(BUILD_DIR)/libsimplemotionv2.so

$(BUILD_DIR)/$(LIBRARY_TYPE)/%.o: ./%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<

$(BUILD_DIR)/libsimplemotionv2.a: $(OBJECTS)
@mkdir -p $(@D)
$(AR) rcs $@ $^

$(BUILD_DIR)/libsimplemotionv2.so: $(OBJECTS)
@mkdir -p $(@D)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@

# This target executes the test cases; the test build depends on
# gcc/clang sanitizers and those are not available except on unix alike
# platforms/targets
.PHONY: test
test:
# this target executes the test cases; the test build depends on
# gcc/clag sanitizers and those are not available except on unix alike
# platforms/targets
make -C tests

.PHONY: clean
clean:
rm -f $(OBJECTS)
$(RM) -r $(BUILD_DIR)
make -C tests clean

# Install library. To override desti
.PHONY: install
install:
@mkdir -p $(DESTDIR)$(PREFIX)/lib
@mkdir -p $(DESTDIR)$(PREFIX)/include
cp $(BUILD_DIR)/libsimplemotionv2.so $(DESTDIR)$(PREFIX)/lib/libsimplemotionv2.so
cp $(BUILD_DIR)/libsimplemotionv2.a $(DESTDIR)$(PREFIX)/lib/libsimplemotionv2.a
cp *.h $(DESTDIR)$(PREFIX)/include/
@echo "\nHeader files installed to $(PREFIX)/include"
@echo "Library installed to $(PREFIX)/lib"
@echo "You may need to run ldconfig"

.PHONY: uninstall
uninstall:
cd $(DESTDIR)$(PREFIX)/include && rm -f $(HEADERS) && cd -
rm -f $(DESTDIR)$(PREFIX)/lib/libsimplemotionv2.so
rm -f $(DESTDIR)$(PREFIX)/lib/libsimplemotionv2.a
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,23 @@ To include SM library in Qt project, simply place the library files under projec
include(SimpleMotionV2/SimpleMotionV2.pri)

## Creating shared / dynamic library
It is possible to compile shared and dynamic libraries (i.e. .dll or .a file) from the SM library source package. One of the easiest ways of compiling library is to use Qt Creator, where a ready-to-compile project file is provided. Just open SimpleMotionV2lib.pro in Qt Creator and compile it with the compiler of your choice. The resulting library files may be used in other applications.
It is possible to compile shared and dynamic libraries (i.e. .dll or .a file) from the SM library source package.

Alternatively create a new library project in your favorite programming tool and compile the provided source codes into a libraray. You might need to study workings of the .pri file to succeed.
### QT Creator
One of the easiest cross-platform ways of compiling library is to use Qt Creator, where a ready-to-compile project file is provided. Just open SimpleMotionV2lib.pro in Qt Creator and compile it with the compiler of your choice. The resulting library files may be used in other applications.

### Linux makefile
Linux users can build both static and dynamic libraries using `make libsimplemotionv2.a` and `make libsimplemotionv2.so`. To install library to computer run:

``` shell
make
sudo make install
```
This will install library (both static and dynamic) to `/usr/local` unless variables `DESTDIR` and `PREFIX` are defined. I.e. library can be installed to custom directory running `make DESTDIR=/tmp/simplemotionv2 PREFIX= install`.

Uninstall library by running `make uninstall`.

### Windows note
Windows users notice that a .dll library compiled with MinGW might not be compatible with MSVC. So if you're developing with MSVC, it's best to complile the dll using MSVC compiler. Qt Creator allows using Visual Studio's MSVC as compiler when configured properly.

## In Python, C# & others
Expand Down
10 changes: 4 additions & 6 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,21 @@ LIB_OBJECTS = $(patsubst %.c,$(LIB_OUTDIR)/%.o,$(notdir $(LIB_SOURCES)))
TEST_CASES_SRC = $(wildcard *.c)
TEST_CASES = $(patsubst %.c,%,$(notdir $(TEST_CASES_SRC)))

test: $(LIB_OUTDIR) test_all
test: test_all

test_all: $(TEST_CASES)
@for test in $(TEST_CASES); do retval=0; ./$$test || retval=$?; if [ "$$retval" -ne 0 ]; then echo $$test: failed; exit 1; fi; echo $$test: ok; done

$(TEST_CASES): %: %.c libsimplemotionv2.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< libsimplemotionv2.a

$(LIB_OUTDIR):
mkdir -p $(LIB_OUTDIR)

libsimplemotionv2.a: $(LIB_OBJECTS)
ar rcs $@ $^

$(LIB_OUTDIR)/%.o: ../%.c
@mkdir -p $(@D)
$(CC) $(LIB_CFLAGS) -c -o $@ $<

clean:
rm -f $(OBJ) $(LIB_OBJECTS) $(TEST_CASES) libsimplemotionv2.a
rmdir $(LIB_OUTDIR)
$(RM) $(LIB_OBJECTS) $(TEST_CASES) libsimplemotionv2.a
$(RM) -r $(LIB_OUTDIR)