Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #----------------------------------------------------------
- # This is first version of makefile for STM8 and SDCC
- #----------------------------------------------------------
- # Project name
- PROJECT := freq_meter
- # Define mcu used in project according to "stm8s.h"
- MCU := STM8S003
- # Set --max-allocs-per-node option. Note: bigger value results
- # more optimised code, but dramatically increases compilation
- # time and PC resources. Default is 3000.
- MAX_ALLOCS := 100000
- # List user sources and headers directories.
- # "." is current directory, where Makefile is.
- SRC_DIRS := . inc src
- # Set build root directory
- BUILD_DIR := ./build
- # Set object files directory
- OBJ_DIR := $(BUILD_DIR)/obj
- # Set dependencies directory
- DEP_DIR := $(OBJ_DIR)
- # Set output directory
- OUT_DIR := $(BUILD_DIR)
- # Automatically generate list of source and object files, found in SRC_DIRS
- # Name of source file will be path/to/file.c, name of object file -- file.rel
- SRC_FILES := $(wildcard $(addsuffix /*.c, $(SRC_DIRS)))
- OBJ_FILES := $(addprefix $(OBJ_DIR)/, $(patsubst %.c, %.rel, $(SRC_FILES)))
- DEP_FILES := $(addprefix $(DEP_DIR)/,$(patsubst %.c, %.d, $(SRC_FILES)))
- CLEAN_FILES := $(OBJ_FILES) $(DEP_FILES) $(OBJ_FILES:.rel=.rst) $(OBJ_FILES:.rel=.lst) $(OBJ_FILES:.rel=.sym) $(OBJ_FILES:.rel=.map) $(OBJ_FILES:.rel=.adb) $(OBJ_FILES:.rel=.cdb) $(OBJ_FILES:.rel=.asm) $(OBJ_FILES:.rel=.lk)
- # Define where make should look for dependencies
- #vpath %.c $(SRC_DIRS)
- #vpath %.h $(SRC_DIRS)
- #vpath %.rel $(OBJ_DIR)
- #vpath %.d $(DEP_DIR)
- vpath %.ihx $(OUT_DIR)
- # Specify the compiler
- CC = sdcc
- # Compile flags
- # --peep-file trv-peeph.def
- CFLAGS = -mstm8 --fverbose-asm --std-sdcc99 -D$(MCU) --max-allocs-per-node $(MAX_ALLOCS)
- # Linker flag. Here we can specify additional libraries
- LDFLAGS = -mstm8 --out-fmt-ihx -lstm8
- all: project
- project: $(PROJECT).ihx
- # Link all object files in OBJ_DIR and put result in OUT_DIR with name $(PROJECT).ihx
- $(PROJECT).ihx: $(OBJ_FILES)
- @echo '=================================='
- @echo ' list of objects files to link:'
- @echo '* $(notdir $(OBJ_FILES))'
- @echo '----------------------------------'
- $(CC) $(LDFLAGS) $^ -o $(OUT_DIR)/$@
- @echo '=================================='
- $(OBJ_DIR)/%.rel: %.c $(DEP_DIR)/%.d
- @echo '=================================='
- # @echo ' list of source files to rebuild:'
- # @echo '* $(SRC_FILES)'
- # @echo '----------------------------------'
- -mkdir -p $(@D)
- $(CC) $(CFLAGS) $(addprefix -I, $(SRC_DIRS)) -c $< -o $@
- @echo '=================================='
- $(DEP_DIR)/%.d: %.c
- @echo '$@'
- -mkdir -p $(@D)
- $(CC) $(CFLAGS) $(addprefix -I, $(SRC_DIRS)) -MM $< > $@
- @mv -f $@ $@.tmp
- @sed -e 's|.*:|$(patsubst $(DEP_DIR)/%.d, $(OBJ_DIR)/%.rel, $@):|' < $@.tmp > $@
- @sed -e 's/.*://' -e 's/\\$$//' < $@.tmp | fmt -1 | \
- sed -e 's/^ *//' -e 's/$$/:/' >> $@
- @rm -f $@.tmp
- -include $(DEP_FILES)
- clean:
- rm -f $(CLEAN_FILES)
- rm -f $(OUT_DIR)/$(PROJECT).ihx $(OUT_DIR)/$(PROJECT).adb $(OUT_DIR)/$(PROJECT).cdb $(OUT_DIR)/$(PROJECT).lk $(OUT_DIR)/$(PROJECT).map
- list_sources:
- @echo '=================================='
- @echo ' list of source files were found:'
- @echo '+ $(SRC_FILES)'
- @echo '=================================='
- list_deps:
- @echo '$(DEP_FILES)'
- .PHONY: clean list_sources list_deps
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement