Makefile.test 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 chip
  30. CHIP = 18f2550
  31. CRT = crt0iz-rloc
  32. # The source files that make up the project go here
  33. SRCS =main.c usbcdc.c printft.c $(CRT).c
  34. # The libraries that are used go here
  35. LIBS = libc18f.lib libio$(CHIP).lib libm18f.lib libsdcc.lib
  36. SDCCHOME = /home/arsene/pd-externals/Fraise/bin
  37. # Where to find the compiler
  38. SDCC = $(SDCCHOME)/bin/sdcc
  39. # The bootloader programmer :
  40. FSUSB = fsusb
  41. # Compiler flags go here
  42. SDCCFLAGS = -V -Wl,-m,-s$(CHIP).lkr -mpic16 -p$(CHIP) --disable-warning 85 \
  43. --ivt-loc=0x0800 --std-sdcc99 --obanksel=3 --use-non-free --no-crt \
  44. -I$(SDCCHOME)/share/include/pic16 -I$(SDCCHOME)/share/non-free/include/pic16 \
  45. -L$(SDCCHOME)/share/non-free/lib/pic16 -L$(SDCCHOME)/share/lib/pic16
  46. #--use-crt=$(OBJDIR)/$(CRT).o
  47. #-L $(SDCCHOME)/share/sdcc/non-free/lib/pic16
  48. # Where to store the target/intermediate/temporary/object files
  49. OBJDIR = ../obj
  50. #
  51. #-------------------------------------------------------------------------------
  52. #
  53. # This ensures that the object directory exists and re-creates it if necessary
  54. #
  55. # This requires make 3.81 or later, delete this section and all expressions that
  56. # refer to .f if you have an older make
  57. #
  58. .SECONDEXPANSION:
  59. # Uses a .f file as a flag file in each directory
  60. %/.f:
  61. mkdir -p $(dir $@)
  62. touch $@
  63. # dont' let make remove the flag files automatically
  64. .PRECIOUS: %/.f
  65. #
  66. #-------------------------------------------------------------------------------
  67. #
  68. # Actual rules
  69. #
  70. # Compile the C-files
  71. $(OBJDIR)/%.o: %.c $$(@D)/.f
  72. $(SDCC) -c $(SDCCFLAGS) $< -o $@
  73. # Link the compiled files and libraries
  74. $(OBJDIR)/$(TARGET): $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
  75. $(SDCC) $(SDCCFLAGS) -o $(OBJDIR)/$(TARGET) $(addprefix $(OBJDIR)/, $(SRCS:.c=.o)) $(LIBS)
  76. # make prog
  77. #
  78. #-------------------------------------------------------------------------------
  79. #
  80. # Automatic generation of dependencies
  81. #
  82. # This magic code fragment from GNU make manual uses the SDCC compiler -M option
  83. # to create a Makefile fragment for each C-source file describing the dependencies.
  84. #
  85. # Traditionally these fragments have the type '.d' but SDCC seems to delete them
  86. # when it compiles files, so I use '.dep' here.
  87. #
  88. # Also SDCC '-M' option produces wrong dependency for the file being compiled
  89. # in the sense that it does not contain the path, only the filename. Hence
  90. # the 'sed' has command has been mangled to inject the missing path to the fragment.
  91. #
  92. # First include the dependencies
  93. include $(addprefix $(OBJDIR)/, $(SRCS:.c=.dep))
  94. # Then recreate them
  95. $(OBJDIR)/%.dep: %.c $$(@D)/.f
  96. @set -e; rm -f $@; \
  97. $(SDCC) -c -M $(SDCCFLAGS) $< > $@.$$$$; \
  98. sed -e '1 s,^,$(OBJDIR)/,' -e 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
  99. rm -f $@.$$$$
  100. #------------------------------------------------------------------------------
  101. #
  102. # pretty standard default target
  103. #
  104. all: $(OBJDIR)/$(TARGET)
  105. #
  106. #-------------------------------------------------------------------------------
  107. #
  108. # pretty standard clean that attempts to delete all that this Makefile may left behind
  109. #
  110. clean:
  111. rm -f $(OBJDIR)/*.rel
  112. rm -f $(OBJDIR)/*.lnk
  113. rm -f $(OBJDIR)/*.S19
  114. rm -f $(OBJDIR)/*.map
  115. rm -f $(OBJDIR)/*.mem
  116. rm -f $(OBJDIR)/*.asm
  117. rm -f $(OBJDIR)/*.rst
  118. rm -f $(OBJDIR)/*.sym
  119. rm -f $(OBJDIR)/*.lst
  120. rm -f $(OBJDIR)/*.o
  121. rm -f $(OBJDIR)/*.dep
  122. rm -f $(OBJDIR)/*.hex
  123. rm -f $(OBJDIR)/$(TARGET)
  124. #
  125. # cleanall deletes all in the object directory, do not use this if target dir == source dir
  126. cleanall:
  127. rm $(OBJDIR)/*
  128. #-------------------------------------------------------------------------------
  129. prog:
  130. # su root -c " $(FSUSB) --program $(PROJ).hex "
  131. $(FSUSB) --program $(OBJDIR)/$(TARGET)