Makefile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #-------------------------------------------------------------------------------
  2. #
  3. # A very basic Makefile to compile USB CDC ACM v1.1 for PIC18F4550
  4. # with SDCC 3.2.0 C-compiler
  5. #
  6. # Copyright (c) 2009,2013 Kustaa Nyholm
  7. #
  8. # NOTE because of I maintain multiple parallel SDCC installations
  9. # the paths to the compiler (see SDCC below) and
  10. # the non free libraries (see SDCCFLAGS below) are
  11. # hard coded, modify or remove as necessary
  12. #
  13. # Features:
  14. # - Automatic generation of dependencies for explicitly named files in SRCS
  15. # - All generated files goes to a separate object directory
  16. # - Automatic creation of object directory
  17. #
  18. # Notes
  19. # - Requires GNU Make version 3.81 or later
  20. # - SDCC standard libs nor Makefile are not used as prerequisites (use 'clean' build if they change)
  21. #
  22. # Everyone should have this
  23. .SUFFIXES:
  24. # This is necessary so that pk2cmd (used by 'load' script) is found and for the
  25. # pk2cmd to find its support files (it seems to search current dir which is wrong)
  26. PATH := ${PATH}:~/pk2cmd/pk2cmd
  27. # The output file name
  28. TARGET = cdcacm.hex
  29. # The source files that make up the project go here
  30. SRCS = main.c usbcdc.c printft.c
  31. # The libraries that are used go here
  32. LIBS = libc18f.lib libio18f2550.lib libm18f.lib libsdcc.lib
  33. # Where to find the compiler
  34. #SDCC = /Users/nyholku/sdcc-3.2.0/bin/sdcc
  35. SDCCHOME = /home/arsene/pd-externals/Fraise/bin
  36. # Where to find the compiler
  37. SDCC = $(SDCCHOME)/bin/sdcc
  38. # Compiler flags go here
  39. SDCCFLAGS = -V -Wl,-m,-s18f2550.lkr -mpic16 -p18f2550 --disable-warning 85 --std-sdcc99 --obanksel=3 --use-non-free \
  40. -I$(SDCCHOME)/share/include/pic16 -I$(SDCCHOME)/share/non-free/include/pic16 \
  41. -L$(SDCCHOME)/share/non-free/lib/pic16 -L$(SDCCHOME)/share/lib/pic16
  42. # Where to store the target/intermediate/temporary/object files
  43. OBJDIR = ../obj
  44. #
  45. #-------------------------------------------------------------------------------
  46. #
  47. # This ensures that the object directory exists and re-creates it if necessary
  48. #
  49. # This requires make 3.81 or later, delete this section and all expressions that
  50. # refer to .f if you have an older make
  51. #
  52. .SECONDEXPANSION:
  53. # Uses a .f file as a flag file in each directory
  54. %/.f:
  55. mkdir -p $(dir $@)
  56. touch $@
  57. # dont' let make remove the flag files automatically
  58. .PRECIOUS: %/.f
  59. #
  60. #-------------------------------------------------------------------------------
  61. #
  62. # Actual rules
  63. #
  64. # Compile the C-files
  65. $(OBJDIR)/%.o: %.c $$(@D)/.f
  66. $(SDCC) -c $(SDCCFLAGS) $< -o $@
  67. # Link the compiled files and libraries
  68. $(OBJDIR)/$(TARGET): $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
  69. $(SDCC) $(SDCCFLAGS) -o $(OBJDIR)/$(TARGET) $(addprefix $(OBJDIR)/, $(SRCS:.c=.o)) $(LIBS)
  70. ./load
  71. #
  72. #-------------------------------------------------------------------------------
  73. #
  74. # Automatic generation of dependencies
  75. #
  76. # This magic code fragment from GNU make manual uses the SDCC compiler -M option
  77. # to create a Makefile fragment for each C-source file describing the dependencies.
  78. #
  79. # Traditionally these fragments have the type '.d' but SDCC seems to delete them
  80. # when it compiles files, so I use '.dep' here.
  81. #
  82. # Also SDCC '-M' option produces wrong dependency for the file being compiled
  83. # in the sense that it does not contain the path, only the filename. Hence
  84. # the 'sed' has command has been mangled to inject the missing path to the fragment.
  85. #
  86. # First include the dependencies
  87. include $(addprefix $(OBJDIR)/, $(SRCS:.c=.dep))
  88. # Then recreate them
  89. $(OBJDIR)/%.dep: %.c $$(@D)/.f
  90. @set -e; rm -f $@; \
  91. $(SDCC) -c -M $(SDCCFLAGS) $< > $@.$$$$; \
  92. sed -e '1 s,^,$(OBJDIR)/,' -e 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
  93. rm -f $@.$$$$
  94. #------------------------------------------------------------------------------
  95. #
  96. # pretty standard default target
  97. #
  98. all: $(OBJDIR)/$(TARGET)
  99. #
  100. #-------------------------------------------------------------------------------
  101. #
  102. # pretty standard clean that attempts to delete all that this Makefile may left behind
  103. #
  104. clean:
  105. rm -f $(OBJDIR)/*.rel
  106. rm -f $(OBJDIR)/*.lnk
  107. rm -f $(OBJDIR)/*.S19
  108. rm -f $(OBJDIR)/*.map
  109. rm -f $(OBJDIR)/*.mem
  110. rm -f $(OBJDIR)/*.asm
  111. rm -f $(OBJDIR)/*.rst
  112. rm -f $(OBJDIR)/*.sym
  113. rm -f $(OBJDIR)/*.lst
  114. rm -f $(OBJDIR)/*.o
  115. rm -f $(OBJDIR)/*.dep
  116. rm -f $(OBJDIR)/*.hex
  117. rm -f $(OBJDIR)/$(TARGET)
  118. #
  119. # cleanall deletes all in the object directory, do not use this if target dir == source dir
  120. cleanall:
  121. rm $(OBJDIR)/*
  122. #-------------------------------------------------------------------------------