docsによると、main()
個別に含まれているファイル以外のファイルをコンパイルしてファイルを生成.rel
し、それらをメインファイルのコンパイルコマンドに含める必要があります。それを行う方法にはいくつかのバリエーションがあります。以下は、GNU make に固有の機能を回避します。
# We're assuming POSIX conformance
.POSIX:
CC = sdcc
# In case you ever want a different name for the main source file
MAINSRC = $(PMAIN).c
# These are the sources that must be compiled to .rel files:
EXTRASRCS = \
../../src/gpio.c \
../../src/timers.c \
../../src/i2c.c
# The list of .rel files can be derived from the list of their source files
RELS = $(EXTRASRCS:.c=.rel)
INCLUDES = -I../../headers
CFLAGS = -mstm8
LIBS = -lstm8
# This just provides the conventional target name "all"; it is optional
# Note: I assume you set PNAME via some means not exhibited in your original file
all: $(PNAME)
# How to build the overall program
$(PNAME): $(MAINSRC) $(RELS)
$(CC) $(INCLUDES) $(CFLAGS) $(MAINSRC) $(RELS) $(LIBS)
# How to build any .rel file from its corresponding .c file
# GNU would have you use a pattern rule for this, but that's GNU-specific
.c.rel:
$(CC) -c $(INCLUDES) $(CFLAGS) $<
# Suffixes appearing in suffix rules we care about.
# Necessary because .rel is not one of the standard suffixes.
.SUFFIXES: .c .rel
ところで、注意深く見ると、ファイルがソース ファイルのループなどを明示的に実行していないことがわかります。中間ターゲットを含む各ターゲットのビルド方法を説明するだけです。 make
これらのルールを組み合わせて、ソースから最終的なプログラム (または、ビルドするように教えたものの中から指定した他のターゲット) に進む方法を独自に見つけ出します。