Makefile 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # detect OS
  2. ifeq ($(OS),Windows_NT)
  3. RM := del /q
  4. CC := sdcc
  5. COM := COM3
  6. else
  7. RM := rm -rf
  8. UNAME_S := $(shell cat /etc/*-release | grep 'DISTRIB_ID' | sed 's/DISTRIB_ID=\(\w*\)/\1/g')
  9. ifeq ($(UNAME_S),Ubuntu)
  10. CC := sdcc
  11. COM := /dev/ttyUSB0
  12. endif
  13. ifeq ($(UNAME_S),Deepin)
  14. CC := ablrun sdcc
  15. COM := /dev/ttyUSB0
  16. endif
  17. endif
  18. # set uart baudrate
  19. BAUD := 9600
  20. # set CC TOOL
  21. PACKIHX := packihx
  22. CFLAGS := -DUSE_FLOATS=1
  23. LDFLAGS := --iram-size 0x100 --xram-size 0x400 --code-size 0xffff
  24. # set DIR
  25. INCDIR = include
  26. SRCDIR = src
  27. OBJDIR = obj
  28. TARGET = obj/main.ihx
  29. INC := ./include
  30. SRC := $(wildcard $(SRCDIR)/*.c)
  31. # OBJ := $(SRC:%.c=%.rel)
  32. OBJ := $(patsubst src/%.c, obj/%.rel, $(SRC))
  33. .PHONY: all clean
  34. all: main.hex
  35. clean:
  36. -$(RM) obj/*
  37. $(OBJ):obj/%.rel:src/%.c
  38. -$(CC) $(CFLAGS) -I $(INC) -c $^ -o $@
  39. $(TARGET): $(OBJ)
  40. -$(CC) $(LDFLAGS) $^ -o $@
  41. main.hex: $(TARGET)
  42. -$(PACKIHX) $(TARGET) > main.hex
  43. flash:
  44. -sudo chmod 777 $(COM)
  45. -./reset_mcu.sh $(COM) $(BAUD)
  46. -stcgal -P stc89 -p $(COM) main.hex
  47. com:
  48. -minicom -D $(COM) -b $(BAUD)
  49. #led.bin:led.hex
  50. # objcopy -I ihex -O binary led.hex led.bin
  51. #led.hex:main.ihx
  52. # packihx main.ihx > led.hex
  53. # led.bin:main.ihx
  54. # makebin main.ihx led.bin