autotools 관련 질문입니다.

superkkt의 이미지

uint8_t, uint16_t, uint32_t 때문에 계속 삽질하다가 autotools를 사용해봤습니다. http://www.opengroup.org 사이트에서 확인해보면 위 타입들은 stdint.h에 있다고 되어 있는데 리눅스에서는 이 헤더가 있는데 솔라리스에서는 없더군요.

autoconf를 사용해서 아래와 같이 체크를 하니까 잘되네요..

Quote:

AC_CHECK_TYPES([uint8_t, uint16_t, uint32_t])

그런데 autotools를 쓰지않고 소스만 그냥 컴파일을 하면 분명히 위 타입들이 정의되어 있지 않다고 에러가 났습니다. autotools를 쓰면 잘 되구요..

그럼 autotools가 위 타입이 정의되어 있는 헤더를 찾아내서 그걸 자동으로 인클루드 시켜주는건가요? 만약 그렇다면 시스템마다 헤더 파일 이름이 틀릴수도 있는데요.. 존재하는 모든 헤더를 다 검사해서 찾는건가요?

cinsk의 이미지

물고기 대신 gentoo 호수 낚시법을 알려드리지요. :oops:

$ epm -ql autoconf
/usr/bin/autoconf-2.13
/usr/bin/autoheader-2.13
...
/usr/share/info/autoconf-2.13.info.gz
/usr/share/autoconf/autoconf.m4f
/usr/share/autoconf/autoheader.m4f
...
$ _

대충 /usr/share/autoconf 밑에 관련 파일이 설치되는 것을 알 수 있습니다.
이제 이 디렉토리에 가서 AC_CHECK_TYPES를 찾아 봅시다:

$ cd /usr/share/autoconf
$ grep AC_CHECK_TYPES *
acgeneral.m4:dnl AC_CHECK_TYPE(TYPE, DEFAULT)
acgeneral.m4:AC_DEFUN(AC_CHECK_TYPE,
acspecific.m4:[AC_CHECK_TYPE(size_t, unsigned)])
acspecific.m4:[AC_CHECK_TYPE(pid_t, int)])
acspecific.m4:[AC_CHECK_TYPE(off_t, long)])
...
$ _

LISP이나 Scheme을 해 보셨거나, 아니면 눈치가 빠르다면 대충 DEFUN이 DEfine FUNtion의 약자라는 것을 알 수 있습니다. 이제 less나 more로 acgeneral.m4를 열어서 훑어보면 다음과 같은 내용이 있습니다:
AC_DEFUN(AC_CHECK_TYPE,
[AC_REQUIRE([AC_HEADER_STDC])dnl
AC_MSG_CHECKING(for $1)
AC_CACHE_VAL(ac_cv_type_$1,
[AC_EGREP_CPP(dnl
changequote(<<,>>)dnl
<<(^|[^a-zA-Z_0-9])$1[^a-zA-Z_0-9]>>dnl
changequote([,]), [#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif], ac_cv_type_$1=yes, ac_cv_type_$1=no)])dnl
AC_MSG_RESULT($ac_cv_type_$1)
if test $ac_cv_type_$1 = no; then
  AC_DEFINE($1, $2)
fi
])

자세히 보시면 C 표준 헤더가 있다면 <stdlib.h>와 <stddef.h>를 포함하며, 모든 경우에 <sys/types.h>를 포함시켜 test하는 것을 볼 수 있습니다.