├── .gitignore ├── AUTHORS ├── ChangeLog ├── Makefile.am ├── NEWS ├── README ├── README.md ├── common ├── Makefile.am ├── jupcommon.h ├── print.c └── test_print.c ├── configure.ac ├── include ├── Makefile.am └── libjupiter.h ├── libjup ├── Makefile.am └── jup_print.c ├── src ├── Makefile.am ├── main.c ├── module.h └── modules │ └── hithere │ ├── Makefile.am │ └── hithere.c └── tests ├── Makefile.am ├── atlocal.in ├── jupiter.at ├── local.at ├── print.at └── testsuite.at /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NSP-Autotools/jupiter/d80ff786465b7ab90908e8b979edb55b30160eb7/AUTHORS -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NSP-Autotools/jupiter/d80ff786465b7ab90908e8b979edb55b30160eb7/ChangeLog -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = common include libjup src tests 2 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NSP-Autotools/jupiter/d80ff786465b7ab90908e8b979edb55b30160eb7/NEWS -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jupiter 2 | The Jupiter project source code repository for the No Starch Press book, Autotools, 2nd Edition 3 | -------------------------------------------------------------------------------- /common/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libjupcommon.la 2 | libjupcommon_la_SOURCES = jupcommon.h print.c 3 | 4 | check_PROGRAMS = test_print 5 | test_print_SOURCES = test_print.c 6 | -------------------------------------------------------------------------------- /common/jupcommon.h: -------------------------------------------------------------------------------- 1 | int print_routine(const char * salutation, const char * name); 2 | -------------------------------------------------------------------------------- /common/print.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include "jupcommon.h" 4 | 5 | #include 6 | #include 7 | 8 | #if HAVE_PTHREAD_H 9 | # include 10 | #endif 11 | 12 | static void * print_it(void * data) 13 | { 14 | const char ** strings = data; 15 | printf("%s from %s!\n", strings[0], strings[1]); 16 | return 0; 17 | } 18 | 19 | int print_routine(const char * salutation, const char * name) 20 | { 21 | const char * strings[] = {salutation, name}; 22 | #if ASYNC_EXEC 23 | pthread_t tid; 24 | pthread_create(&tid, 0, print_it, strings); 25 | pthread_join(tid, 0); 26 | #else 27 | print_it(strings); 28 | #endif 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /common/test_print.c: -------------------------------------------------------------------------------- 1 | #define printf mock_printf 2 | #include "print.c" 3 | 4 | #include 5 | #include 6 | 7 | static char printf_buf[512]; 8 | 9 | int mock_printf(const char * format, ... ) 10 | { 11 | int rc; 12 | va_list ap; 13 | va_start(ap, format); 14 | rc = vsnprintf(printf_buf, sizeof printf_buf, format, ap); 15 | va_end(ap); 16 | return rc; 17 | } 18 | 19 | int main(void) 20 | { 21 | const char *args[] = { "Hello", "test" }; 22 | int rc = print_it(args); 23 | return rc != 0 || strcmp(printf_buf, "Hello from test!\n") != 0; 24 | } 25 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([Jupiter], [1.0], [jupiter-bugs@example.org]) 6 | AM_INIT_AUTOMAKE 7 | LT_PREREQ([2.4.6]) 8 | LT_INIT([dlopen]) 9 | AC_CONFIG_SRCDIR([src/main.c]) 10 | AC_CONFIG_HEADERS([config.h]) 11 | 12 | AC_CONFIG_TESTDIR([tests]) 13 | AC_CONFIG_FILES([tests/Makefile 14 | tests/atlocal]) 15 | 16 | # Checks for programs. 17 | AC_PROG_CC 18 | AC_PROG_INSTALL 19 | 20 | # Checks for header files. 21 | AC_CHECK_HEADERS([stdlib.h ltdl.h]) 22 | 23 | # Checks for command-line options 24 | AC_ARG_ENABLE([async-exec], 25 | [AS_HELP_STRING([--disable-async-exec], 26 | [disable asynchronous execution @<:@default: no@:>@])], 27 | [async_exec=${enableval}], [async_exec=yes]) 28 | 29 | if test "x${async_exec}" = xyes; then 30 | have_pthreads=no 31 | AC_SEARCH_LIBS([pthread_create], [pthread], [have_pthreads=yes]) 32 | 33 | if test "x${have_pthreads}" = xyes; then 34 | AC_CHECK_HEADERS([pthread.h], [], [have_pthreads=no]) 35 | fi 36 | 37 | if test "x${have_pthreads}" = xno; then 38 | AC_MSG_WARN([ 39 | ------------------------------------------ 40 | Unable to find pthreads on this system. 41 | Building a single-threaded version. 42 | ------------------------------------------]) 43 | async_exec=no 44 | fi 45 | fi 46 | 47 | AC_SUBST([async_exec]) 48 | if test "x${async_exec}" = xyes; then 49 | AC_DEFINE([ASYNC_EXEC], [1], [async execution enabled]) 50 | fi 51 | 52 | # Checks for libraries. 53 | 54 | # Checks for typedefs, structures, and compiler characteristics. 55 | 56 | # Checks for library functions. 57 | AC_SEARCH_LIBS([lt_dlopen], [ltdl]) 58 | 59 | AC_CONFIG_FILES([Makefile 60 | common/Makefile 61 | include/Makefile 62 | libjup/Makefile 63 | src/Makefile 64 | src/modules/hithere/Makefile]) 65 | AC_OUTPUT 66 | 67 | cat << EOF 68 | ------------------------------------------------- 69 | 70 | ${PACKAGE_NAME} Version ${PACKAGE_VERSION} 71 | 72 | Prefix: '${prefix}'. 73 | Compiler: '${CC} ${CFLAGS} ${CPPFLAGS}' 74 | Libraries: '${LIBS}' 75 | 76 | Package features: 77 | Async Execution: ${async_exec} 78 | 79 | Now type 'make @<:@@:>@' 80 | where the optional is: 81 | all - build all binaries 82 | install - install everything 83 | 84 | -------------------------------------------------- 85 | EOF 86 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | include_HEADERS = libjupiter.h 2 | -------------------------------------------------------------------------------- /include/libjupiter.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBJUPITER_H_INCLUDED 2 | #define LIBJUPITER_H_INCLUDED 3 | 4 | int jupiter_print(const char * salutation, const char * name); 5 | 6 | #endif /* LIBJUPITER_H_INCLUDED */ 7 | -------------------------------------------------------------------------------- /libjup/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libjupiter.la 2 | libjupiter_la_SOURCES = jup_print.c 3 | libjupiter_la_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/common 4 | libjupiter_la_LIBADD = ../common/libjupcommon.la 5 | -------------------------------------------------------------------------------- /libjup/jup_print.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include "libjupiter.h" 4 | #include "jupcommon.h" 5 | 6 | int jupiter_print(const char * salutation, const char * name) 7 | { 8 | return print_routine(salutation, name); 9 | } 10 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = modules/hithere 2 | 3 | bin_PROGRAMS = jupiter 4 | jupiter_SOURCES = main.c module.h 5 | jupiter_CPPFLAGS = -I$(top_srcdir)/include 6 | jupiter_LDADD = ../libjup/libjupiter.la -dlopen modules/hithere/hithere.la 7 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include "libjupiter.h" 4 | #include "module.h" 5 | 6 | #if HAVE_LTDL_H 7 | # include 8 | #endif 9 | 10 | #define DEFAULT_SALUTATION "Hello" 11 | 12 | int main(int argc, char * argv[]) 13 | { 14 | int rv; 15 | const char * salutation = DEFAULT_SALUTATION; 16 | 17 | #if HAVE_LTDL_H 18 | int ltdl; 19 | lt_dlhandle module; 20 | get_salutation_t * get_salutation_fp = 0; 21 | 22 | LTDL_SET_PRELOADED_SYMBOLS(); 23 | 24 | ltdl = lt_dlinit(); 25 | if (ltdl == 0) 26 | { 27 | module = lt_dlopen("modules/hithere/hithere.la"); 28 | if (module != 0) 29 | { 30 | get_salutation_fp = (get_salutation_t *)lt_dlsym(module, GET_SALUTATION_SYM); 31 | if (get_salutation_fp != 0) 32 | salutation = get_salutation_fp(); 33 | } 34 | } 35 | #endif 36 | 37 | rv = jupiter_print(salutation, argv[0]); 38 | 39 | #if HAVE_LTDL_H 40 | if (ltdl == 0) 41 | { 42 | if (module != 0) 43 | lt_dlclose(module); 44 | lt_dlexit(); 45 | } 46 | #endif 47 | 48 | return rv; 49 | } 50 | -------------------------------------------------------------------------------- /src/module.h: -------------------------------------------------------------------------------- 1 | #ifndef MODULE_H_INCLUDED 2 | #define MODULE_H_INCLUDED 3 | 4 | #define GET_SALUTATION_SYM "get_salutation" 5 | 6 | typedef const char * get_salutation_t(void); 7 | const char * get_salutation(void); 8 | 9 | #endif /* MODULE_H_INCLUDED */ 10 | -------------------------------------------------------------------------------- /src/modules/hithere/Makefile.am: -------------------------------------------------------------------------------- 1 | pkglib_LTLIBRARIES = hithere.la 2 | hithere_la_SOURCES = hithere.c 3 | hithere_la_LDFLAGS = -module -avoid-version 4 | -------------------------------------------------------------------------------- /src/modules/hithere/hithere.c: -------------------------------------------------------------------------------- 1 | #define get_salutation hithere_LTX_get_salutation 2 | #include "../../module.h" 3 | 4 | const char * get_salutation(void) 5 | { 6 | return "Hi there"; 7 | } 8 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = testsuite.at local.at jupiter.at print.at \ 2 | $(TESTSUITE) atconfig package.m4 3 | 4 | TESTSUITE = $(srcdir)/testsuite 5 | TESTSOURCES = $(srcdir)/local.at $(srcdir)/testsuite.at \ 6 | $(srcdir)/jupiter.at $(srcdir)/print.at 7 | AUTOM4TE = $(SHELL) $(top_srcdir)/missing --run autom4te 8 | AUTOTEST = $(AUTOM4TE) --language=autotest 9 | 10 | check-local: atconfig atlocal $(TESTSUITE) 11 | $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) 12 | 13 | installcheck-local: atconfig atlocal $(TESTSUITE) 14 | $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(DESTDIR)$(bindir)' $(TESTSUITEFLAGS) 15 | 16 | clean-local: 17 | test ! -f '$(TESTSUITE)' || $(SHELL) '$(TESTSUITE)' --clean 18 | rm -rf atconfig 19 | 20 | atconfig: $(top_builddir)/config.status 21 | cd $(top_builddir) && $(SHELL) ./config.status tests/$@ 22 | 23 | $(srcdir)/package.m4: $(top_srcdir)/configure.ac 24 | $(AM_V_GEN) :;{ \ 25 | echo '# Signature of the current package.' && \ 26 | echo 'm4_define([AT_PACKAGE_NAME], [$(PACKAGE_NAME)])' && \ 27 | echo 'm4_define([AT_PACKAGE_TARNAME], [$(PACKAGE_TARNAME)])' && \ 28 | echo 'm4_define([AT_PACKAGE_VERSION], [$(PACKAGE_VERSION)])' && \ 29 | echo 'm4_define([AT_PACKAGE_STRING], [$(PACKAGE_STRING)])' && \ 30 | echo 'm4_define([AT_PACKAGE_BUGREPORT], [$(PACKAGE_BUGREPORT)])'; \ 31 | echo 'm4_define([AT_PACKAGE_URL], [$(PACKAGE_URL)])'; \ 32 | } >'$(srcdir)/package.m4' 33 | 34 | $(TESTSUITE): $(TESTSOURCES) $(srcdir)/package.m4 35 | $(AM_V_GEN) $(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at; mv $@.tmp $@ 36 | -------------------------------------------------------------------------------- /tests/atlocal.in: -------------------------------------------------------------------------------- 1 | async_exec=@async_exec@ 2 | -------------------------------------------------------------------------------- /tests/jupiter.at: -------------------------------------------------------------------------------- 1 | AT_SETUP([jupiter-execution]) 2 | FIND_JUPITER 3 | AT_CHECK_UNQUOTED(["${jupiter}"],, 4 | [Hello from ${compare}! 5 | ]) 6 | AT_CLEANUP 7 | -------------------------------------------------------------------------------- /tests/local.at: -------------------------------------------------------------------------------- 1 | AT_INIT 2 | AT_COLOR_TESTS 3 | 4 | m4_define([FIND_JUPITER], [[set -x 5 | if test "x${AUTOTEST_PATH}" == "x${at_testdir}"; then 6 | jupiter="${abs_top_builddir}/src/jupiter" 7 | compare="$(dirname "${jupiter}")/.libs/lt-jupiter" 8 | else 9 | LD_LIBRARY_PATH="${AUTOTEST_PATH}/../lib" export LD_LIBRARY_PATH 10 | jupiter="${AUTOTEST_PATH}/jupiter" 11 | compare="${jupiter}" 12 | fi]]) 13 | -------------------------------------------------------------------------------- /tests/print.at: -------------------------------------------------------------------------------- 1 | AT_SETUP([print]) 2 | AT_CHECK(["${abs_top_builddir}/common/test_print"]) 3 | AT_CLEANUP 4 | -------------------------------------------------------------------------------- /tests/testsuite.at: -------------------------------------------------------------------------------- 1 | m4_include([jupiter.at]) 2 | m4_include([print.at]) 3 | --------------------------------------------------------------------------------