toge's diary

コンピュータ関連の趣味をつらつらと。

gcc -MMの困ったところ

ご存知の通り gcc にはMakefile用の依存情報を吐き出してくれる M とか MMとかのオプションがあるのですが、個人的な使い方にちと合わないのよね。

% gcc -M src/hoge.c
hoge.o: src/hoge.c /usr/include/stdio.h /usr/include/features.h \
  /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h \
  /usr/include/bits/wordsize.h /usr/include/gnu/stubs-32.h \
  /usr/lib/gcc/i386-redhat-linux/4.0.2/include/stddef.h \
  /usr/include/bits/types.h /usr/include/bits/typesizes.h \
  /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \
  /usr/include/bits/wchar.h /usr/include/gconv.h \
  /usr/lib/gcc/i386-redhat-linux/4.0.2/include/stdarg.h \
  /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
  /usr/include/math.h /usr/include/bits/huge_val.h \
  /usr/include/bits/mathdef.h /usr/include/bits/mathcalls.h \
  /usr/include/string.h 

でも私としては、次みたいにhoge.oはsrc/hoge.oになっていて欲しいわけです。

% gcc -M src/hoge.c
src/hoge.o: src/hoge.c /usr/include/stdio.h /usr/include/features.h 
... 

gccのオプションでうまくできるのかもしれんが、どうも無さそうです。解決策としてはMTオプションでhoge.oの所を直接指定するっていう技もあります。

テーブルの各要素を弄る

さる用事でデータ構造を示すだけでなく、処理をするためにLuaを使ってみました。
おおっなんか勝手が変わっているぞ、table.foreachiはもう古いのね・・・。知識がLua3.2 + ちょびっとLua4.0だから、知らないこと多いです。

今はこうするらしい。

for index, pathentry in ipairs(pathlist)
do
   foobar(pathentry);
end 

なるほど、自然な書き方になっていいね。