Skip to content

Commit

Permalink
Add shared library support (for macos, freebsd and several flavours o…
Browse files Browse the repository at this point in the history
…f Linux)
  • Loading branch information
david parsons authored and david parsons committed Jan 4, 2011
1 parent 0af211e commit 992c5b3
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ INCDIR=@prefix@/include
PGMS=markdown
SAMPLE_PGMS=mkd2html makepage
@THEME@SAMPLE_PGMS+= theme
MKDLIB=libmarkdown.a
MKDLIB=libmarkdown.@LIBEXT@
OBJS=mkdio.o markdown.o dumptree.o generate.o \
resource.o docheader.o version.o toc.o css.o \
xml.o Csio.o xmlpage.o basename.o emmatch.o \
setup.o tags.o html5.o flags.o @AMALLOC@

MAN3PAGES=mkd-callbacks.3 mkd-functions.3 markdown.3 mkd-line.3

PIC_FLAGS=@PIC_FLAGS@
SHARED_FLAGS=@SHARED_FLAGS@

CFLAGS += ${PIC_FLAGS}

all: $(PGMS) $(SAMPLE_PGMS)

install: $(PGMS)
Expand Down Expand Up @@ -72,8 +77,9 @@ main.o: main.c mkdio.h config.h
$(CC) -I. -c main.c

$(MKDLIB): $(OBJS)
$(AR) crv $(MKDLIB) $(OBJS)
$(RANLIB) $(MKDLIB)
@MKSTATIC@ $(AR) crv $(MKDLIB) $(OBJS)
@MKSTATIC@ $(RANLIB) $(MKDLIB)
@MKSHARED@ $(CC) $(SHARED_FLAGS) $(PIC_FLAGS) -o $(MKDLIB) $(OBJS)

verify: echo tools/checkbits.sh
@./echo -n "headers ... "; tools/checkbits.sh && echo "GOOD"
Expand Down
52 changes: 52 additions & 0 deletions configure.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,58 @@ EOF
rm -f /tmp/ngc$$ /tmp/ngc$$.c
}
#
# AC_COMPILER_PIC checks for the compiler option to produce position independent
# code. At the moment we assume gcc semantics.
#
AC_COMPILER_PIC () {
AC_PROG_CC
LOGN "checking for C compiler option to produce PIC "
echo "int some_variable = 0;" > /tmp/ngc$$.c
if $AC_CC -c -fPIC -o /tmp/ngc$$ /tmp/ngc$$.c $LIBS; then
AC_PIC_FLAGS="-fPIC"
LOG "($AC_PIC_FLAGS)"
__rc=0
else
LOG "(none)"
__rc=1
fi
rm -f /tmp/ngc$$ /tmp/ngc$$.c
return $__rc
}
#
# AC_CC_SHLIBS checks if the C compiler can produce shared libraries
# note that we compile and link a single object only in one step
#
AC_CC_SHLIBS () {
AC_PROG_CC
LOGN "checking whether the C compiler can build shared libraries "
echo "int some_variable = 0;" > /tmp/ngc$$.c
if $AC_CC $AC_PICFLAG -shared -o /tmp/ngc$$.so /tmp/ngc$$.c; then
AC_SHLIB_FLAGS=-shared
AC_LIB_EXT=so
LOG "(yes; $AC_SHLIB_FLAGS)"
__rc=0
elif $AC_CC $AC_PICFLAG -dynamiclib -o /tmp/ngc$$.so /tmp/ngc$$.c; then
# macosx
AC_SHLIB_FLAGS=' -dynamiclib'
AC_LIB_EXT=dylib
LOG "(yes; macos dylib)"
__rc=0
else
LOG "(no)"
__rc=1
fi
rm -f /tmp/ngc$$.so /tmp/ngc$$.c
return $__rc
}
#
# AC_PROG_INSTALL finds the install program and guesses whether it's a
Expand Down
27 changes: 26 additions & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
ac_help='--enable-amalloc Enable memory allocation debugging
--with-tabstops=N Set tabstops to N characters (default is 4)
--with-dl=X Use Discount, Extra, or Both types of definition list
--enable-all-features Turn on all stable optional features'
--enable-all-features Turn on all stable optional features
--shared Build shared libraries (default is static)'

LOCAL_AC_OPTIONS='
set=`locals $*`;
Expand All @@ -24,6 +25,9 @@ fi'
locals() {
K=`echo $1 | $AC_UPPERCASE`
case "$K" in
--SHARED)
echo TRY_SHARED=T
;;
--ENABLE-ALL|--ENABLE-ALL-FEATURES)
echo WITH_AMALLOC=T
;;
Expand All @@ -48,6 +52,27 @@ BOTH) AC_DEFINE 'USE_EXTRA_DL' 1
esac

AC_PROG_CC
if test "$TRY_SHARED" && AC_COMPILER_PIC && AC_CC_SHLIBS; then
MAKE_SHARED=T
AC_SUB 'MKSHARED' ''
AC_SUB 'MKSTATIC' '#'

if [ "$AC_LIB_EXT" = "dylib" ]; then
# special horrible hack for macos shared library version.
eval `awk -F. '{ printf "COMPAT=%d.%d\n", $1, $2;
printf "VERSION=%d.%d.%d\n", $1, $2, $3; }' VERSION`
AC_SHLIB_FLAGS="$AC_SHLIB_FLAGS -compatibility_version $COMPAT"
AC_SHLIB_FLAGS="$AC_SHLIB_FLAGS -current_version $VERSION"
fi

else
AC_SUB 'MKSHARED' '#'
AC_SUB 'MKSTATIC' ''
fi

AC_SUB 'PIC_FLAGS' "${MAKE_SHARED:+$AC_PIC_FLAGS}"
AC_SUB 'SHARED_FLAGS' "${MAKE_SHARED:+$AC_SHLIB_FLAGS}"
AC_SUB 'LIBEXT' "${AC_LIB_EXT:-a}"

case "$AC_CC $AC_CFLAGS" in
*-Wall*) AC_DEFINE 'while(x)' 'while( (x) != 0 )'
Expand Down

0 comments on commit 992c5b3

Please sign in to comment.