欢迎光临散文网 会员登陆 & 注册

Autotools (automake)

2023-03-02 01:37 作者:小粉丝8  | 我要投稿

// src/autogen.sh

# Usage:

# bash ./autogen

# bash ./autogen clean

# ./configure # --enable-ndebug

# make

# make clean

# make DESTDIR=~/foo instal

# ./main/.libs/main

# autogen

if (( $# == 0 )); then

  [[ ! -d m4 ]] && mkdir m4

  autoreconf -i

fi

# clean

if [[ $1 == "clean" ]]; then

  # temporaries by autoreconf -i

  rm -fr aclocal.m4 compile config.* configure \

    configure~ depcomp install-sh m4 missing ar-lib \

    autom4te.cache ltmain.sh

  find . -name "Makefile.in" -exec rm -fr {} \;

  # temporaries by ./configure

  rm -fr libtool stamp-h1

  find . -name ".deps" -type d -exec rm -fr {} \;

  find . -name "Makefile" -exec rm -fr {} \;

  # temporaries by make

  find . \( -name "*.la" -o -name "*.lai" -o -name "*.lo" \

    -o -name "*.d" -o -name "*.o" \) -exec rm -fr {} \;

fi


---


// src/configure.ac

AC_PREREQ([2.69])

AC_INIT([Hello], [0.9.0], [support@email])

AM_INIT_AUTOMAKE([foreign])

AC_CONFIG_MACRO_DIRS([m4])

AM_PROG_AR

LT_INIT

AC_PROG_CC # CXX

AC_CONFIG_HEADERS([config.h])

# ./configure --enable-ndebug

AC_ARG_ENABLE(

  [ndebug],

  [AS_HELP_STRING([--enable-ndebug],

    [ndebug means release and turns off assert])],

  [enable_ndebug=yes]

)

AM_CONDITIONAL([NDEBUG], [test x$enable_ndebug = xyes])

AC_CONFIG_FILES([

  Makefile

  main/Makefile

  foo/Makefile

])

AC_OUTPUT


---


// src/Makefile.am

ACLOCAL_AMFLAGS = -I m4

# put dependencies first

SUBDIRS = ./foo ./main


---


// src/main/Makefile.am

bin_PROGRAMS = main

main_SOURCES = main.c # .cpp

CFLAGS = -std=c99 # -g -O3 -fPIC # CXXFLAGS for .cpp

CPPFLAGS = -I../foo

LDFLAGS = -L../foo/.libs -lfoo # -shared

LDFLAGS += -Wl,-rpath,'$$ORIGIN/../../foo/.libs'

LDFLAGS += -Wl,-rpath,'$$ORIGIN/../lib'

if NDEBUG

CPPFLAGS += -D NDEBUG

CFLAGS += -O3 # .cpp

else

CFLAGS += -g # .cpp

LDFLAGS += -fsanitize=address

endif


---


// src/foo/Makefile.am

lib_LTLIBRARIES = libfoo.la

libfoo_la_SOURCES = foo.c foo.h # .cpp

libfoo_la_CFLAGS = -std=c99 # -g -O3 -fPIC # CXXFLAGS for .cpp

libfoo_la_CPPFLAGS = # -I../bar

libfoo_la_LDFLAGS = -shared # -L../bar/.libs/ -lbar

libfoo_la_LDFLAGS += -Wl,-rpath,'$$ORIGIN/../../bar/.libs'

libfoo_la_LDFLAGS += -Wl,-rpath,'$$ORIGIN/../lib'

libfoo_la_LDFLAGS += -version-number 5:2:3

if NDEBUG

libfoo_la_CPPFLAGS += -D NDEBUG

libfoo_la_CFLAGS += -O3 # .cpp

else

libfoo_la_CFLAGS += -g # .cpp

libfoo_la_LDFLAGS += -fsanitize=address

endif


Autotools (automake)的评论 (共 条)

分享到微博请遵守国家法律