Makefile builds and test shared libraries, added unit_test.sh

This commit is contained in:
CaioRS 2015-06-23 22:20:17 -03:00
parent 9c5602e8c9
commit 7b24ccd083
2 changed files with 57 additions and 14 deletions

View File

@ -3,33 +3,55 @@
#
#
#
#
#
#
#
#
#
#####################################################
# #
# This Makefile builds the Unit test executable and the #
# shared library: libslre.so #
# #
################################################################
CC=gcc
all: unit_test lib
libname=libslre.so
unit_test=unit_test.bin
unit_test_shared=unit_test_shared.bin
unit_test:
all: $(unit_test) $(libname) $(unit_test_shared)
# Unit test compiled without shared library
#
$(unit_test):
$(CC) -c slre.c
$(CC) -c unit_test.c
$(CC) -o unit_test.bin slre.o unit_test.o
@echo "Done. OK! run $ make test"
# Unit Test compiled with shared library
#
$(unit_test_shared): $(libname)
gcc -c unit_test.c
gcc -L$(shell pwd) -Wall -o unit_test_shared.bin unit_test.o -lslre
lib:
# Build shared library
#
$(libname):
$(CC) -fPIC -g -c slre.c
$(CC) -shared -Wl,-soname,libslre.so -o libslre.so slre.o -lc
$(CC) -shared -Wl,-soname,$(libname) -o $(libname) slre.o -lc
test:
@echo "Running unit_test.bin"
./unit_test.bin
tests: $(unit_test) $(unit_test_shared)
bash unit_test.sh
install:
sudo cp slre.h /usr/include/slre.h
sudo cp $(lib) /usr/lib/$(lib)
uninstall:
rm -rf /usr/include/slre.h
rm -rf /usr/lib/$(lib)
clean:
@rm -rf *.o *.bin *.out *.so

21
unit_test.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Test library
#
#--------------------------
echo "Running Unit test"
echo ""
./unit_test.bin
echo ""
echo ""
# Test shared library Wrapper
#
export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
echo "Running Shared Library Unit Test"
echo ""
./unit_test_shared.bin
echo ""
echo ""