Use a convenience library

This commit is contained in:
Ruben Laguna 2015-02-09 22:21:18 +01:00
parent d310872077
commit 4135ef2c84
6 changed files with 29 additions and 1 deletions

View File

@ -2,10 +2,19 @@ include $(top_srcdir)/build-aux/glib-tap.mk
AM_CFLAGS = # CFLAGS applicable to all executables (products)
# Convenience library so that it can be resued
# between my_executable and the tests
noinst_LIBRARIES = libcommon.a
libcommon_a_SOURCES = src/common.c
# The main product
bin_PROGRAMS = myexecutable # make all will generate ./my_executable
myexecutable_SOURCES = \
src/main.c
myexecutable_CFLAGS = #--std=c11 # CFLAGS applicable to myexecutable_SOURCES
myexecutable_LDADD = libcommon.a
# Tests
# 'check' comes from 'make check'
@ -19,7 +28,8 @@ testsuite_SOURCES = tests/test.c
# CFLAGS and -l options that are retrieved from pkg-config (configure.ac)
# DEPS_CFLAGS and DEPS_LIBS are filled by PKG_CHECK_MODULES (configure.ac)
testsuite_CPPFLAGS = -I$(top_srcdir)/src
testsuite_CFLAGS = $(GLIB_CFLAGS) # DEPS_* are filled by PKG_CHECK_MODULES
testsuite_LDADD = $(GLIB_LIBS) # in configure.ac
testsuite_LDADD = $(GLIB_LIBS) libcommon.a # in configure.ac

View File

@ -30,6 +30,8 @@ AC_PROG_CC
AC_PROG_CC_C99 # or AC_PROG_CC_89 to force C89 mode or AC_PROG_CC_STDC to go to latest supported standard (currently C99)
AC_PROG_INSTALL
AC_PROG_CC_C_O # Need to have per product flags myexecutable_CFLAG
AC_PROG_RANLIB # Need for to create libraries: .a
# Checks for libraries.

6
src/common.c Normal file
View File

@ -0,0 +1,6 @@
#include <stdio.h>
#include "common.h"
void myfunc()
{
printf("myfunc() called\n");
}

5
src/common.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef COMMON_H
#define COMMON_H
void myfunc();
#endif /* COMMON_H */

View File

@ -1,7 +1,9 @@
#include <stdio.h>
#include "common.h"
int main(int argc, char *argv[])
{
printf ("Hello world\n");
myfunc();
return 0;
}

View File

@ -3,6 +3,8 @@
#include <stdlib.h>
#include <stdbool.h>
#include "common.h"
typedef struct {
int a; /* usually some other data structure that you
* need for your tests */
@ -26,6 +28,7 @@ void my_second_test(dfixture *df, gconstpointer ignored) {
}
void my_third_test(dfixture *df, gconstpointer ignored) {
myfunc();
g_test_incomplete("incomplete means that there is some functionality missing");
}