aboutsummaryrefslogtreecommitdiffstats
path: root/configure.ac
blob: 65f58e64c2170673a1ac370dda71e6c7d03768d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_INIT([sctjudge], [1.0-rc3], [lantw44@gmail.com])
AM_INIT_AUTOMAKE([foreign -Wall])
AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_FILES([Makefile sctjudge.spec src/Makefile src/version.h])

releasedate="2012-11-15"
rpmversion="1.0"

# Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O

# 寫入版本資訊
AC_SUBST([PROGRAM_NAME], [AC_PACKAGE_NAME])
AC_SUBST([PROGRAM_VERSION], [AC_PACKAGE_VERSION])
AC_SUBST([PROGRAM_RPMVERSION], $rpmversion)
AC_SUBST([PROGRAM_DATE], $releasedate)

# 提早離開 configure 的途徑
AC_ARG_ENABLE([check],
    [AS_HELP_STRING([--disable-check],
        [skip all checks])],
    [opt_check=$enableval], [opt_check=yes])

if test x"${opt_check}" = xno; then \
  AC_OUTPUT
  echo "WARNING: ALL CHECKS ARE SKIPPED!"
  echo "WARNING: Generated Makefile(s) cannot be used to build the package!"
  exit 0
fi

# 和預設的 CFLAGS 說再見
test -n "${CFLAGS}" && CFLAGS="-g"

# 偵錯很重要,但使用者應該不需要
AC_ARG_ENABLE([debug],
    [AS_HELP_STRING([--enable-debug],
        [produce debugging information and disable 
        optimization in binary files])],
    [opt_debug=$enableval], [opt_debug=no])

if test -n "${CFLAGS}"; then
  if test x"${opt_debug}" = xyes; then
    CFLAGS="-g"
  else
    CFLAGS="-O2"
  fi
fi

# 靜態連結,如果想做 portable 版本的話
AC_ARG_ENABLE([static],
    [AC_HELP_STRING([--enable-static],
        [statically link all executables])],
    [opt_static=$enableval], [opt_static=no])

AM_CONDITIONAL([STATIC_EXEC], [test x"${opt_static}" = xyes])

# 有些功能是選用的......
AC_ARG_ENABLE([procmon], 
    [AS_HELP_STRING([--enable-procmon], 
        [enable process monitor using Linux proc filesystem])],
    [opt_procmon=$enableval], [opt_procmon=no])

test x"${opt_procmon}" = xyes && \
         AC_DEFINE([HAVE_CONF_PROCMON], [1], [Process Monitor])

AC_ARG_ENABLE([cap],
    [AS_HELP_STRING([--enable-cap],
        [using Linux capabilities instead of standard UNIX permission])],
    [opt_cap=$enableval], [opt_cap=no])

test x"${opt_cap}" = xyes && \
        AC_DEFINE([HAVE_CONF_CAP], [1], [Linux Capabilities])

# 可以設定 /dev/null 名稱
AC_ARG_WITH([null], 
        AS_HELP_STRING([--with-null=NULL],
            [set the path of the data sink (default: /dev/null)]),
        [with_null=$withval], [with_null=/dev/null])

AC_CHECK_FILE([${with_null}],
        [AC_DEFINE_UNQUOTED([NULL_DEVICE], ["${with_null}"],
            [Path of the data sink])],
        [AC_MSG_ERROR([${with_null} does not exist])])

# 可以設定 proc filesystem 在哪裡
AC_ARG_WITH([proc], 
        AS_HELP_STRING([--with-proc=PROC],
            [set the location of your Linux proc file system]),
        [with_proc=$withval], [with_proc=/proc])

if test x"${opt_procmon}" = xyes; then \
    AC_CHECK_FILES([${with_proc}/stat ${with_proc}/$$/stat ${with_proc}/$$/statm ${with_proc}/$$/status],
        [AC_DEFINE_UNQUOTED([PROC_PATH], ["${with_proc}"], 
            [Location of Linux proc file system])], 
        [AC_MSG_ERROR([Linux proc file system support is incomplete])])
fi

# Checks for libraries.

AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread -lrt"], 
        [test_nort=yes], [-lrt])

if test x"$test_nort" = xyes; then 
    AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
        [AC_MSG_ERROR([POSIX Thread Library is required])])
fi

AC_CHECK_LIB([c], [sem_timedwait], [true],
    [AC_MSG_ERROR([Semaphore support is required])], ["$LIBS"])


if test x"${opt_cap}" = xyes; then
  checkliblist="cap_init cap_clear_flag cap_set_proc"
  for i in $checkliblist; do
    AC_CHECK_LIB([cap], $i, [true],
        AC_MSG_ERROR(You must install libcap-devel or use --disable-cap))
  done
# Checks for programs
  AC_CHECK_PROG([have_prog_setcap],[setcap],[yes],[no])
  test x"${have_prog_setcap}" = xno && 
    AC_MSG_ERROR(setcap does not exist in your PATH)
  LIBS="$LIBS -lcap"
fi

AM_CONDITIONAL([USING_SETCAP], [test x"${opt_cap}" = xyes])

# Checks for header files.
AC_CHECK_HEADERS([fcntl.h locale.h stdlib.h string.h sys/time.h unistd.h])

if test x"${opt_cap}" = xyes; then
  AC_CHECK_HEADERS([sys/prctl.h sys/capability.h], [], 
    [AC_MSG_ERROR(You must install these files or use --disable-cap)])
fi

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UID_T
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_CHECK_FUNCS([clock_gettime dup2 memset setlocale strchr strerror strrchr getuid getpid setpgid wait4 fcntl fchown open close setrlimit chmod unlink],
        [], AC_MSG_ERROR(This program requires all these functions!))

AC_CHECK_FUNCS([getpwnam getgrnam getpwuid getgrgid],
        opt_ugidname=yes, opt_ugidname=no)

test x"${opt_ugidname}" = xyes && \
         AC_DEFINE([HAVE_CONF_UGIDNAME], [1], 
        [Conversion between user or group ID and name])

AC_OUTPUT

confmsgsave="config.msg"

echo "" | tee "$confmsgsave"
echo "Optional Features:" | tee -a "$confmsgsave"
echo "(1) Conversion between user or group ID and name .... $opt_ugidname" | tee -a "$confmsgsave"
echo "(2) Process monitor using Linux proc filesystem ..... $opt_procmon" | tee -a "$confmsgsave"
echo "(3) Linux capabilities support ...................... $opt_cap" | tee -a "$confmsgsave"
echo "-------------------------------------------------------------" | tee -a "$confmsgsave"
echo "Compiling and Linking Options:" | tee -a "$confmsgsave"
echo "(1) Debugging information ........................... $opt_debug" | tee -a "$confmsgsave"
echo "(2) Statically linked executable .................... $opt_static" | tee -a "$confmsgsave"
echo "-------------------------------------------------------------" | tee -a "$confmsgsave"
echo "Strings:" | tee -a "$confmsgsave"
echo "(1) Linux proc filesystem path ...................... $with_proc" | tee -a "$confmsgsave"
echo "(2) Data sink path .................................. $with_null" | tee -a "$confmsgsave"
echo "The above messages has been written to $confmsgsave"