Open7

調べもの:Makefile

nukopynukopy

Makefile の基本

by Claude 4 Sonnet

Makeの基本原理

Makeは依存関係タイムスタンプに基づいてファイルを自動的にビルドします。

1. 基本的なルール構文

ターゲット: 依存ファイル1 依存ファイル2
	コマンド

このMakefileの例で見てみましょう:

# 28-29行目
$(APPS): %.exe : %.o $(OBJS) $(DRIVERS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

これは:

  • ターゲット: *.exeファイル(実行ファイル)
  • 依存関係: *.oファイル、$(OBJS)$(DRIVERS)
  • コマンド: $(CC)でリンクして実行ファイルを作成

2. タイムスタンプによる自動判定

Makeは以下のロジックで動作します:

  1. ターゲットファイルが存在しない → コマンドを実行
  2. 依存ファイルの方が新しい → コマンドを実行
  3. ターゲットの方が新しい → 何もしない(最新)

3. 依存関係の連鎖

例えば:

# .c → .o のルール(34-35行目)
.c.o:
	$(CC) $(CFLAGS) -c $< -o $@

# .o → .exe のルール(28-29行目)  
$(APPS): %.exe : %.o $(OBJS) $(DRIVERS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

make test.exeを実行すると:

  1. test.exetest.oに依存
  2. test.otest.cに依存
  3. test.cが更新されていれば、自動的にtest.c → test.o → test.exeの順でビルド

4. デフォルトターゲット

# 26行目
all: $(APPS) $(TESTS)

makeコマンド(引数なし)を実行すると、最初に定義されたターゲット(all)が実行されます。

なぜ自動的にビルドされるのか?

  1. 変数展開: $(APPS)$(TESTS)が具体的なファイル名に展開
  2. パターンマッチング: %.exe : %.oで複数のファイルに対応
  3. 依存関係の解析: 必要なファイルを順番に作成

.PHONYとの違い

  • 通常のターゲット: 実際のファイルを作成・更新
  • .PHONYターゲット: ファイルとは無関係のコマンド実行

これがMakeの「賢さ」の正体です!変更されたファイルだけを効率的にビルドできる仕組みなんです。

nukopynukopy

Q. これ早速基本ルールから逸脱してない?

# 28-29行目
$(APPS): %.exe : %.o $(OBJS) $(DRIVERS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

Answer

これは基本ルールの拡張記法です。

基本ルール vs 拡張記法

基本ルール(静的)

ターゲット: 依存ファイル
	コマンド

このMakefileの記法(パターンルール)

$(APPS): %.exe : %.o $(OBJS) $(DRIVERS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

この記法の意味

これは静的パターンルールという記法で:

$(APPS): %.exe : %.o $(OBJS) $(DRIVERS)

分解すると:

  • $(APPS) = 対象となるファイルリスト(変数)
  • %.exe = ターゲットのパターン(%は任意の文字列)
  • %.o = 依存ファイルのパターン(同じ%部分)
  • $(OBJS) $(DRIVERS) = 追加の依存ファイル

comment: 要するにターゲットのファイル名のパターンマッチができるってことね

具体例

もしAPPS = app1.exe app2.exeだとすると、これは以下と同等:

app1.exe: app1.o $(OBJS) $(DRIVERS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

app2.exe: app2.o $(OBJS) $(DRIVERS)  
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

なぜこの記法を使うのか?

  1. DRY原則: 同じルールを何度も書かなくて済む
  2. 保守性: ファイルが増えても自動的に対応
  3. 変数の活用: $(APPS)を変更するだけで対象を変更可能

確かに基本ルールから見ると複雑に見えますが、実際は複数の基本ルールを一括で定義する便利記法なんです!

nukopynukopy

Q. APPS = app1.exe app2.exeeeex app3.exe だったらどうなる?

APPS = app1.exe app2.exeeeex app3.exeの場合を見てみましょう。

パターンマッチングの動作

$(APPS): %.exe : %.o $(OBJS) $(DRIVERS)

この静的パターンルールは、ターゲットが%.exeパターンにマッチするものだけに適用されます。

具体的な結果

  • app1.exe%.exeにマッチ → ルール適用
  • app2.exeeeex%.exeにマッチしない → ルール適用されない
  • app3.exe%.exeにマッチ → ルール適用

実際の展開

# マッチするものだけ展開される
app1.exe: app1.o $(OBJS) $(DRIVERS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

app3.exe: app3.o $(OBJS) $(DRIVERS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

# app2.exeeeex はルールが定義されない

make allを実行すると?

all: $(APPS)  # = app1.exe app2.exeeeex app3.exe
  • app1.exe, app3.exe → 正常にビルド
  • app2.exeeeexビルドルールが存在しないためエラー
make: *** No rule to make target 'app2.exeeeex', needed by 'all'.  Stop.

まとめ

パターンルールは厳密なパターンマッチングを行うので、ファイル名の命名規則が重要です。%.exeパターンに合わないファイルは自動的に除外されます。

nukopynukopy

Q. CC の定義なくない?

microps の初期の Makefile では変数 CC の定義がない。よく CC := gcc とか CC := clang とか見かけるのでなぜだろうと思ったら、Makefile には暗黙に定義される変数があるらしい。公式がリンク切れだったので以下のブログから。

https://tex2e.github.io/blog/makefile/automatic-variables

make -p コマンドで現在の Makefilemake を実行したときにどのようなルールが適用されているか(database と呼ばれている)を出力することができる。その中に CC に何が割り当てられているかも出力される。

make --help
Usage: make [options] [target] ...
Options:
  ...
  -p, --print-data-base       Print make's internal database.

実際に実行してみる。Makefile は以下の通り:

Makefile
APPS = 

DRIVERS = 

OBJS = util.o \

TESTS = test/step0.exe \

CFLAGS := $(CFLAGS) -g -W -Wall -Wno-unused-parameter -iquote .

ifeq ($(shell uname),Linux)
  # Linux specific settings
  BASE = platform/linux
  CFLAGS := $(CFLAGS) -pthread -iquote $(BASE)
endif

ifeq ($(shell uname),Darwin)
  # macOS specific settings
endif

.SUFFIXES:
.SUFFIXES: .c .o

.PHONY: all clean

all: $(APPS) $(TESTS)

$(APPS): %.exe : %.o $(OBJS) $(DRIVERS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

$(TESTS): %.exe : %.o $(OBJS) $(DRIVERS) test/test.h
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

.c.o:
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -rf $(APPS) $(APPS:.exe=.o) $(OBJS) $(DRIVERS) $(TESTS) $(TESTS:.exe=.o)

make -p コマンドの出力を以下に示す。かなり長いので詳細は「出力全体」に。出力の中に、# Variables というブロックがあり、その中に CC が何に割り当てられているかが書かれている。

以下の出力によると、CC = cc がデフォルトで割り当てられているようだ。

make -p

# --- 出力 ---
# Variables
...
# こっちは Makefile で定義されているもの
# makefile (from 'Makefile', line 14)
CFLAGS :=  -g -W -Wall -Wno-unused-parameter -iquote . -pthread -iquote platform/linux
...
# こっちは Makefile で定義されていない
# default
CC = cc

Makefile の中で CC := gcc と追加すると、以下のように書き換わる。

CC の上の行のコメントがdefault から「Makefile のどの行由来のルールなのか」に書き換わっているのがわかる。

make -p

# --- 出力 ---
# Variables
...
# makefile (from 'Makefile', line 9)
CC := gcc
nukopynukopy

文字数制限のため分割

`make -p` 出力全体(前半)

make: Nothing to be done for 'all'.

GNU Make 4.3

Built for aarch64-unknown-linux-gnu

Copyright (C) 1988-2020 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

Make data base, printed on Sun Sep 21 14:26:17 2025

Variables

default

PREPROCESS.S = $(CC) -E $(CPPFLAGS)

default

COMPILE.m = $(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c

default

ARFLAGS = rv

default

AS = as

default

AR = ar

default

OBJC = cc

default

LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)

default

LINK.s = $(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)

default

MAKE_COMMAND := make

environment

VSCODE_GIT_ASKPASS_EXTRA_ARGS =

automatic

@D = (patsubst %/,%,(dir $@))

default

COFLAGS =

default

COMPILE.mod = $(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)

default

.VARIABLES :=

environment

PWD = /home/vagrant/toy-tcpip-rs/docs/ref/microps

automatic

%D = (patsubst %/,%,(dir $%))

environment

XDG_DATA_DIRS = /usr/local/share:/usr/share:/var/lib/snapd/desktop

default

LINK.o = $(CC) $(LDFLAGS) $(TARGET_ARCH)

default

TEXI2DVI = texi2dvi

automatic

^D = (patsubst %/,%,(dir $^))

automatic

%F = $(notdir $%)

default

LEX.l = $(LEX) $(LFLAGS) -t

environment

LANG = en_US.UTF-8

default

.LOADED :=

default

.INCLUDE_DIRS = /usr/local/include /usr/include /usr/include

default

COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c

makefile

MAKEFLAGS = p

default

LINK.f = $(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)

default

TANGLE = tangle

makefile

CURDIR := /home/vagrant/toy-tcpip-rs/docs/ref/microps

default

PREPROCESS.F = $(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F

environment

LESSOPEN = | /usr/bin/lesspipe %s

automatic

D = (patsubst %/,%,(dir $))

environment

MFLAGS = -p

default

COMPILE.p = $(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c

default

.SHELLFLAGS := -c

default

M2C = m2c

default

COMPILE.cpp = $(COMPILE.cc)

default

TEX = tex

automatic

+D = (patsubst %/,%,(dir $+))

environment

GIT_ASKPASS = /home/vagrant/.cursor-server/bin/5911e9593196a000b1c00553aaf03b0b32042b90/extensions/git/dist/askpass.sh

makefile (from 'Makefile', line 1)

MAKEFILE_LIST := Makefile

default

F77FLAGS = $(FFLAGS)

makefile (from 'Makefile', line 1)

APPS =

automatic

@F = $(notdir $@)

environment

XDG_SESSION_TYPE = tty

automatic

?D = (patsubst %/,%,(dir $?))

default

COMPILE.def = $(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)

default

CTANGLE = ctangle

automatic

F = $(notdir $)

environment

DBUS_SESSION_BUS_ADDRESS = unix:path=/run/user/1000/bus

automatic

<D = (patsubst %/,%,(dir $<))

default

COMPILE.C = $(COMPILE.cc)

default

YACC.m = $(YACC) $(YFLAGS)

default

LINK.C = $(LINK.cc)

default

MAKE_HOST := aarch64-unknown-linux-gnu

default

LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)

makefile (from 'Makefile', line 5)

OBJS = util.o

makefile

SHELL = /bin/sh

default

LINK.F = $(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)

environment

SHLVL = 1

environment

MAKELEVEL := 0

default

MAKE = $(MAKE_COMMAND)

default

FC = f77

environment

PATH = /home/vagrant/.cursor-server/bin/5911e9593196a000b1c00553aaf03b0b32042b90/bin/remote-cli:/home/vagrant/.cursor-server/bin/5911e9593196a000b1c00553aaf03b0b32042b90/bin/remote-cli:/home/vagrant/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

default

LINT = lint

default

PC = pc

default

MAKEFILES :=

environment

VSCODE_GIT_IPC_HANDLE = /run/user/1000/vscode-git-0c8a39644d.sock

environment

VSCODE_GIT_ASKPASS_NODE = /home/vagrant/.cursor-server/bin/5911e9593196a000b1c00553aaf03b0b32042b90/node

automatic

^F = $(notdir $^)

default

LEX.m = $(LEX) $(LFLAGS) -t

makefile (from 'Makefile', line 3)

DRIVERS =

environment

VSCODE_GIT_ASKPASS_MAIN = /home/vagrant/.cursor-server/bin/5911e9593196a000b1c00553aaf03b0b32042b90/extensions/git/dist/askpass-main.js

default

.LIBPATTERNS = lib%.so lib%.a

environment

SSH_CLIENT = 10.0.2.2 52870 22

default

CPP = $(CC) -E

default

LINK.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)

environment

TERM_PROGRAM = vscode

default

CHECKOUT,v = +(if $(wildcard $@),,(CO) $(COFLAGS) $< $@)

default

COMPILE.f = $(FC) $(FFLAGS) $(TARGET_ARCH) -c

default

COMPILE.r = $(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c

environment

LESSCLOSE = /usr/bin/lesspipe %s %s

default

COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c

automatic

?F = $(notdir $?)

default

GET = get

default

LINK.r = $(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)

environment

LS_COLORS = rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:.tar=01;31:.tgz=01;31:.arc=01;31:.arj=01;31:.taz=01;31:.lha=01;31:.lz4=01;31:.lzh=01;31:.lzma=01;31:.tlz=01;31:.txz=01;31:.tzo=01;31:.t7z=01;31:.zip=01;31:.z=01;31:.dz=01;31:.gz=01;31:.lrz=01;31:.lz=01;31:.lzo=01;31:.xz=01;31:.zst=01;31:.tzst=01;31:.bz2=01;31:.bz=01;31:.tbz=01;31:.tbz2=01;31:.tz=01;31:.deb=01;31:.rpm=01;31:.jar=01;31:.war=01;31:.ear=01;31:.sar=01;31:.rar=01;31:.alz=01;31:.ace=01;31:.zoo=01;31:.cpio=01;31:.7z=01;31:.rz=01;31:.cab=01;31:.wim=01;31:.swm=01;31:.dwm=01;31:.esd=01;31:.avif=01;35:.jpg=01;35:.jpeg=01;35:.mjpg=01;35:.mjpeg=01;35:.gif=01;35:.bmp=01;35:.pbm=01;35:.pgm=01;35:.ppm=01;35:.tga=01;35:.xbm=01;35:.xpm=01;35:.tif=01;35:.tiff=01;35:.png=01;35:.svg=01;35:.svgz=01;35:.mng=01;35:.pcx=01;35:.mov=01;35:.mpg=01;35:.mpeg=01;35:.m2v=01;35:.mkv=01;35:.webm=01;35:.webp=01;35:.ogm=01;35:.mp4=01;35:.m4v=01;35:.mp4v=01;35:.vob=01;35:.qt=01;35:.nuv=01;35:.wmv=01;35:.asf=01;35:.rm=01;35:.rmvb=01;35:.flc=01;35:.avi=01;35:.fli=01;35:.flv=01;35:.gl=01;35:.dl=01;35:.xcf=01;35:.xwd=01;35:.yuv=01;35:.cgm=01;35:.emf=01;35:.ogv=01;35:.ogx=01;35:.aac=00;36:.au=00;36:.flac=00;36:.m4a=00;36:.mid=00;36:.midi=00;36:.mka=00;36:.mp3=00;36:.mpc=00;36:.ogg=00;36:.ra=00;36:.wav=00;36:.oga=00;36:.opus=00;36:.spx=00;36:.xspf=00;36:~=00;90:#=00;90:.bak=00;90:.crdownload=00;90:.dpkg-dist=00;90:.dpkg-new=00;90:.dpkg-old=00;90:.dpkg-tmp=00;90:.old=00;90:.orig=00;90:.part=00;90:.rej=00;90:.rpmnew=00;90:.rpmorig=00;90:.rpmsave=00;90:.swp=00;90:.tmp=00;90:.ucf-dist=00;90:.ucf-new=00;90:*.ucf-old=00;90:

automatic

+F = $(notdir $+)

default

MAKEINFO = makeinfo

'override' directive

GNUMAKEFLAGS :=

environment

BROWSER = /home/vagrant/.cursor-server/bin/5911e9593196a000b1c00553aaf03b0b32042b90/bin/helpers/browser.sh

default

PREPROCESS.r = $(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F

default

LINK.m = $(OBJC) $(OBJCFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)

environment

LOGNAME = vagrant

default

LINK.p = $(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)

default

YACC = yacc

makefile

.DEFAULT_GOAL := all

default

RM = rm -f

default

WEAVE = weave

environment

USER = vagrant

default

MAKE_VERSION := 4.3

makefile (from 'Makefile', line 7)

TESTS = test/step0.exe

'override' directive

.SHELLSTATUS := 0

default

F77 = $(FC)

makefile (from 'Makefile', line 13)

BASE = platform/linux

default

CWEAVE = cweave

environment

_ = /usr/bin/make

default

YACC.y = $(YACC) $(YFLAGS)

default

MAKE_TERMOUT := /dev/pts/2

default

LINK.cpp = $(LINK.cc)

default

CO = co

environment

XDG_RUNTIME_DIR = /run/user/1000

makefile (from 'Makefile', line 14)

CFLAGS := -g -W -Wall -Wno-unused-parameter -iquote . -pthread -iquote platform/linux

environment

COLORTERM = truecolor

default

OUTPUT_OPTION = -o $@

default

COMPILE.s = $(AS) $(ASFLAGS) $(TARGET_MACH)

environment

VSCODE_IPC_HOOK_CLI = /run/user/1000/vscode-ipc-38b717be-258d-41d7-bf0a-aa5260490c2c.sock

default

MAKE_TERMERR := /dev/pts/2

environment

XDG_SESSION_CLASS = user

environment

HOME = /home/vagrant

default

LEX = lex

environment

TERM = xterm-256color

environment

XDG_SESSION_ID = 30

default

LINT.c = $(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)

default

COMPILE.F = $(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c

default

.RECIPEPREFIX :=

automatic

<F = $(notdir $<)

default

SUFFIXES := .out .a .ln .o .c .cc .C .cpp .p .f .F .m .r .y .l .ym .yl .s .S .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo .w .ch .web .sh .elc .el

default

LD = ld

default

.FEATURES := target-specific order-only second-expansion else-if shortest-stem undefine oneshell nocomment grouped-target extra-prereqs archives jobserver output-sync check-symlink load

default

CXX = g++

default

CC = cc

environment

TERM_PROGRAM_VERSION = 1.6.42

default

COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c

environment

SSH_CONNECTION = 10.0.2.2 52870 10.0.2.15 22

variable set hash-table stats:

Load=136/1024=13%, Rehash=0, Collisions=9/185=5%

Pattern-specific Variable Values

No pattern-specific variable values.

Directories

RCS: could not be stat'd.

SCCS: could not be stat'd.

test/SCCS: could not be stat'd.

. (device 50, inode 51035363): 13 files, 4 impossibilities.

test (device 50, inode 51035471): 6 files, 4 impossibilities.

test/RCS: could not be stat'd.

19 files, 8 impossibilities in 6 directories.

Implicit Rules

%.c:

%: %.c

recipe to execute (built-in):

    $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@

%.o: %.c

recipe to execute (from 'Makefile', line 35):

    $(CC) $(CFLAGS) -c $< -o $@

%.o:

%: %.o

recipe to execute (built-in):

    $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@

(%): %

recipe to execute (built-in):

    $(AR) $(ARFLAGS) $@ $<

%.out: %

recipe to execute (built-in):

    @rm -f $@ 
     cp $< $@

%.c: %.w %.ch

recipe to execute (built-in):

    $(CTANGLE) $^ $@

%.tex: %.w %.ch

recipe to execute (built-in):

    $(CWEAVE) $^ $@

%:: %,v

recipe to execute (built-in):

    $(CHECKOUT,v)

%:: RCS/%,v

recipe to execute (built-in):

    $(CHECKOUT,v)

%:: RCS/%

recipe to execute (built-in):

    $(CHECKOUT,v)

%:: s.%

recipe to execute (built-in):

    $(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<

%:: SCCS/s.%

recipe to execute (built-in):

    $(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<

14 implicit rules, 5 (35.7%) terminal.

Files

Not a target:

.cpp:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@

.c.o:

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (from 'Makefile', line 35):

    $(CC) $(CFLAGS) -c $< -o $@

Not a target:

.h:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.sh:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    cat $< >$@ 
     chmod a+x $@

Not a target:

.ch:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.r.f:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(PREPROCESS.r) $(OUTPUT_OPTION) $<

Not a target:

.dvi:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.def.sym:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.def) -o $@ $<

Not a target:

.m.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.m) $(OUTPUT_OPTION) $<

Not a target:

.lm.m:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    @$(RM) $@ 
     $(LEX.m) $< > $@

Not a target:

.p.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.p) $(OUTPUT_OPTION) $<

Not a target:

.texinfo:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.ln:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.C:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.web:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.elc:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.y.ln:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(YACC.y) $< 
     $(LINT.c) -C$* y.tab.c 
     $(RM) y.tab.c

Not a target:

.l.c:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    @$(RM) $@ 
     $(LEX.l) $< > $@

Not a target:

Makefile:

Implicit rule search has been done.

Last modified 2025-09-21 13:53:25.431023344

File has been updated.

Successfully updated.

Not a target:

.sym:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

nukopynukopy
`make -p` 出力全体(後半)

Not a target:

.r.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.r) $(OUTPUT_OPTION) $<

Not a target:

.mod:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.mod) -o $@ -e $@ $^

Not a target:

.def:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.S:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.texi.dvi:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(TEXI2DVI) $(TEXI2DVI_FLAGS) $<

util.o: util.c

Implicit rule search has been done.

Implicit/static pattern stem: 'util'

Last modified 2025-09-21 15:52:18.296740588

File has been updated.

Successfully updated.

automatic

@ := util.o

automatic

* := util

automatic

< := util.c

automatic

+ := util.c

automatic

% :=

automatic

^ := util.c

automatic

? := util.c

automatic

| :=

variable set hash-table stats:

Load=8/32=25%, Rehash=0, Collisions=2/15=13%

recipe to execute (from 'Makefile', line 35):

    $(CC) $(CFLAGS) -c $< -o $@

Not a target:

.txinfo.dvi:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(TEXI2DVI) $(TEXI2DVI_FLAGS) $<

Not a target:

.y.c:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(YACC.y) $< 
     mv -f y.tab.c $@

clean:

Phony target (prerequisite of .PHONY).

Implicit rule search has not been done.

File does not exist.

File has not been updated.

recipe to execute (from 'Makefile', line 38):

    rm -rf $(APPS) $(APPS:.exe=.o) $(OBJS) $(DRIVERS) $(TESTS) $(TESTS:.exe=.o)

Not a target:

.cpp.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.cpp) $(OUTPUT_OPTION) $<

Not a target:

.el:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

util.c:

Implicit rule search has been done.

Last modified 2025-09-21 15:21:38.785885946

File has been updated.

Successfully updated.

Not a target:

.cc:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.tex:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.m:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.m) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.F:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.web.tex:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(WEAVE) $<

Not a target:

.texinfo.info:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@

test/step0.exe: test/step0.o util.o test/test.h

Implicit rule search has not been done.

Implicit/static pattern stem: 'test/step0'

Last modified 2025-09-21 15:52:20.946820952

File has been updated.

Successfully updated.

automatic

@ := test/step0.exe

automatic

* := test/step0

automatic

< := test/step0.o

automatic

+ := test/step0.o util.o test/test.h

automatic

% :=

automatic

^ := test/step0.o util.o test/test.h

automatic

? := test/step0.o util.o test/test.h

automatic

| :=

variable set hash-table stats:

Load=8/32=25%, Rehash=0, Collisions=2/26=8%

recipe to execute (from 'Makefile', line 32):

    $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

Not a target:

.ym.m:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(YACC.m) $< 
     mv -f y.tab.c $@

Not a target:

.l:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.f:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.texi:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.DEFAULT:

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

test/step0.o: test/step0.c

Implicit rule search has been done.

Implicit/static pattern stem: 'test/step0'

Last modified 2025-09-21 15:52:17.836982525

File has been updated.

Successfully updated.

automatic

@ := test/step0.o

automatic

* := test/step0

automatic

< := test/step0.c

automatic

+ := test/step0.c

automatic

% :=

automatic

^ := test/step0.c

automatic

? := test/step0.c

automatic

| :=

variable set hash-table stats:

Load=8/32=25%, Rehash=0, Collisions=2/15=13%

recipe to execute (from 'Makefile', line 35):

    $(CC) $(CFLAGS) -c $< -o $@

Not a target:

.r:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.a:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

all: test/step0.exe

Phony target (prerequisite of .PHONY).

Implicit rule search has not been done.

File does not exist.

File has been updated.

Successfully updated.

variable set hash-table stats:

Load=0/32=0%, Rehash=0, Collisions=0/16=0%

Not a target:

.w.tex:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(CWEAVE) $< - $@

Not a target:

.s.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.s) -o $@ $<

Not a target:

.txinfo:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.c.ln:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINT.c) -C$* $<

Not a target:

.tex.dvi:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(TEX) $<

Not a target:

.info:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.out:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.texinfo.dvi:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(TEXI2DVI) $(TEXI2DVI_FLAGS) $<

Not a target:

.F.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.F) $(OUTPUT_OPTION) $<

Not a target:

.yl:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.s:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.S.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.S) -o $@ $<

Not a target:

.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

test/step0.c:

Implicit rule search has been done.

Last modified 2025-09-21 15:21:39.174747006

File has been updated.

Successfully updated.

Not a target:

.C.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.C) $(OUTPUT_OPTION) $<

Not a target:

.c:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.txinfo.info:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@

Not a target:

.texi.info:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@

Not a target:

.y:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

format:

Phony target (prerequisite of .PHONY).

Implicit rule search has not been done.

File does not exist.

File has not been updated.

recipe to execute (from 'Makefile', line 41):

    find . -name "*.c" -o -name "*.h" | xargs clang-format -i --sort-includes

Not a target:

.l.r:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LEX.l) $< > $@ 
     mv -f lex.yy.r $@

Not a target:

.p:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@

Not a target:

.l.ln:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    @$(RM) $*.c
     $(LEX.l) $< > $*.c
    $(LINT.c) -i $*.c -o $@
     $(RM) $*.c

Not a target:

.w:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

.SUFFIXES: .c .o

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

.PHONY: all clean format

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.mod.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.mod) -o $@ $<

Not a target:

.web.p:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(TANGLE) $<

Not a target:

.S.s:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(PREPROCESS.S) $< > $@

Not a target:

.f.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.f) $(OUTPUT_OPTION) $<

Not a target:

test/test.h:

Implicit rule search has been done.

Last modified 2025-09-21 15:21:39.055277786

File has been updated.

Successfully updated.

Not a target:

.ym:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

Not a target:

.cc.o:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(COMPILE.cc) $(OUTPUT_OPTION) $<

Not a target:

.F.f:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(PREPROCESS.F) $(OUTPUT_OPTION) $<

Not a target:

.w.c:

Builtin rule

Implicit rule search has not been done.

Modification time never checked.

File has not been updated.

recipe to execute (built-in):

    $(CTANGLE) $< - $@

files hash-table stats:

Load=83/1024=8%, Rehash=0, Collisions=17/243=7%

VPATH Search Paths

No 'vpath' search paths.

No general ('VPATH' variable) search path.

strcache buffers: 1 (0) / strings = 193 / storage = 1854 B / avg = 9 B

current buf: size = 8162 B / used = 1854 B / count = 193 / avg = 9 B

strcache performance: lookups = 259 / hit rate = 25%

hash-table stats:

Load=193/8192=2%, Rehash=0, Collisions=2/259=1%

Finished Make data base on Sun Sep 21 15:52:21 2025

nukopynukopy

cc は何を指しているか

cc コマンドが何にリンクされているか見てみる。

gcc にシンボリックリンクが張られていることが分かった。

ls -l $(which cc)
# lrwxrwxrwx 1 root root 20 Jan 31  2024 /usr/bin/cc -> /etc/alternatives/cc

ls -l /etc/alternatives/cc
# lrwxrwxrwx 1 root root 12 Jan 31  2024 /etc/alternatives/cc -> /usr/bin/gcc

# 何に解決されるかのルール(?)
update-alternatives --display cc 2>/dev/null || true
# cc - auto mode
#   link best version is /usr/bin/gcc
#   link currently points to /usr/bin/gcc
#   link cc is /usr/bin/cc
#   slave cc.1.gz is /usr/share/man/man1/cc.1.gz
# /usr/bin/gcc - priority 20
#   slave cc.1.gz: /usr/share/man/man1/gcc.1.gz