LoginSignup
0
0

More than 5 years have passed since last update.

FreeBSDでconfigureを半自動生成してみた

Posted at

やりたいこと

こんなソースをconfigureしてmakeできるようにしたい。

hello.c
#include <stdio.h>

int main(int argc, const char *argv[]) {
    printf("Hello World!!\n");
    return 0;
}

やったこと

環境準備

ツールがないと始まらない。
必要なパッケージをインストールする。

$ sudo pkg install autoconf automake

修行

自動生成の恩恵を得るにも修行が必要なようです。

hello.c
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#if HAVE_STDIO_H
#include <stdio.h>
#else
int printf(const char *format, ...);
#endif

int main(int argc, const char *argv[]) {
    printf("Hello World!!\n");
    return 0;
}

こんなファイルも用意しておく。

Makefile.am
bin_PROGRAMS=hello
hello_SOURCES=hello.c

autoscanするとconfigure.scanというファイルが生成されるのでリネームして編集。

$ autoscan
$ mv configure.scan configure.ac
configure.ac
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT(hello, 1.0, hello@example.com)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

自動生成

修行の成果を見せる時!!
automakeの前に幾つかファイルを生成しておくのを忘れないように。

$ aclocal
$ autoheader
$ touch NEWS README AUTHORS ChangeLog
$ automake -a -c
$ autoconf
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0