PACKAGE = C_CAM.hex BASE_DIR ?= ../../SylphideCAM/C8051/ BIN_PATH = /usr/bin:/usr/local/bin CXX = sdcc AS = asx8051 CPPFLAGS = -V --use-stdout -D__SDCC__ #-DR13_LEAVE_OPEN CFLAGS = $(CPPFLAGS) --debug --stack-auto --nooverlay --model-small --use-stdout --opt-code-speed #-mmcs51 LFLAGS = -V --debug --use-stdout --stack-auto --model-small --iram-size 0x0100 --xram-loc 0x0800 --xram-size 0x0800 --code-size 0xfc00 #-mmcs51 ASFLAGS = -plosgff INCLUDES += -I. $(patsubst %,-I%,$(BASE_DIR)) LIBS = #-L BUILD_DIR ?= build_by_sdcc DEPEND_INC ?= depend.inc SRCS_C = \ $(shell ls *.c) SRCS_ASM = \ $(shell ls *.asm) EXCLUDE_OBJS ?= "" OBJS = $(filter-out $(EXCLUDE_OBJS),$(SRCS_C:.c=.rel) $(SRCS_ASM:.asm=.rel)) all : $(BUILD_DIR) base depend $(PACKAGE) objs : $(BUILD_DIR) depend $(patsubst %,$(BUILD_DIR)/%,$(OBJS)) # 基礎となるオブジェクトの構築 base : $(BASE_DIR) i=0; \ for f in $^; do \ (cd $$f && \ BUILD_DIR=$(CURDIR)/$(BUILD_DIR) \ INCLUDES=-I$(CURDIR) \ DEPEND_INC=$(patsubst %,%.base$${i},$(DEPEND_INC)) \ EXCLUDE_OBJS="$(EXCLUDE_OBJS) $(OBJS)" \ make objs); \ let i="$$i + 1"; \ done # ヘッダーファイルの依存関係 depend: $(SRCS_C) export PATH=$(BIN_PATH):$$PATH; \ rm -f $(BUILD_DIR)/$(DEPEND_INC); \ for i in $^; do \ $(CXX) -E -MM $(INCLUDES) $(CPPFLAGS) $$i >> tempfile; \ if ! [ $$? = 0 ]; then \ rm -f tempfile; \ exit 1; \ fi; \ done; \ cat tempfile | sed -e 's/^+.*//g' -e 's/[^\.]*\.rel/$(subst /,\/,$(BUILD_DIR))\/&/g' >> $(BUILD_DIR)/$(DEPEND_INC); \ rm -f tempfile -include $(BUILD_DIR)/$(DEPEND_INC) $(BUILD_DIR)/%.rel : %.c export PATH=$(BIN_PATH):$$PATH; \ $(CXX) -c $(CFLAGS) $(INCLUDES) -o $@ $< $(BUILD_DIR)/%.rel : %.asm export PATH=$(BIN_PATH):$$PATH; \ cp $< $(BUILD_DIR)/; \ cd $(BUILD_DIR); \ $(AS) $(ASFLAGS) $< $(PACKAGE) : $(patsubst %,$(BUILD_DIR)/%,$(PACKAGE)) $(BUILD_DIR)/$(PACKAGE) : $(patsubst %,$(BUILD_DIR)/%,$(OBJS)) export PATH=$(BIN_PATH):$$PATH; \ $(CXX) $(LFLAGS) $(INCLUDES) -o $@ $(LIBS) $(shell ls $(BUILD_DIR)/*.rel) $(BUILD_DIR) : mkdir $@ clean : rm -f $(PACKAGE:.hex=*) $(BUILD_DIR)/* run : all .PHONY : clean all depend objs base