includeされるヘッダファイルのパスを出力
Cのコンパイル時に,gccの-Hオプションを付けることによって,includeされるヘッダファイルを絶対パスで出力することができる.
$ cat main.c #includeint main() { printf("hoge\n"); return 0; } $ gcc main.c -H . /usr/include/stdio.h .. /usr/include/features.h ... /usr/include/sys/cdefs.h ... /usr/include/gnu/stubs.h .. /usr/lib/gcc/i386-redhat-linux/3.4.6/include/stddef.h .. /usr/include/bits/types.h ... /usr/include/bits/wordsize.h ... /usr/lib/gcc/i386-redhat-linux/3.4.6/include/stddef.h ... /usr/include/bits/typesizes.h .. /usr/include/libio.h ... /usr/include/_G_config.h .... /usr/lib/gcc/i386-redhat-linux/3.4.6/include/stddef.h .... /usr/include/wchar.h ..... /usr/lib/gcc/i386-redhat-linux/3.4.6/include/stddef.h ..... /usr/include/bits/wchar.h .... /usr/include/gconv.h ..... /usr/include/wchar.h ...... /usr/lib/gcc/i386-redhat-linux/3.4.6/include/stddef.h ..... /usr/lib/gcc/i386-redhat-linux/3.4.6/include/stddef.h ... /usr/lib/gcc/i386-redhat-linux/3.4.6/include/stdarg.h .. /usr/include/bits/stdio_lim.h .. /usr/include/bits/sys_errlist.h
rubyでパス名を絶対パスに変換する (正規化する).
"../"も正しく展開されるので便利.
$ pwd /tmp/ $ irb irb(main):001:0> File.expand_path("..") => "/" irb(main):002:0> File.expand_path("emacs501/server") => "/tmp/emacs501/server" irb(main):003:0> File.expand_path("emacs501/../emacs501/../emacs501/") => "/tmp/emacs501" irb(main):004:0> File.expand_path("../", "/var/log/") => "/var"