Advertisement
Guest User

Makefile

a guest
Sep 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 7.18 KB | None | 0 0
  1. ###############################################################################
  2. # Build script for Raspberry PI C code.
  3. #
  4. ###############################################################################
  5.  
  6. ####################
  7. ### Instructions ###
  8. ####################
  9. #
  10. # Replace PREFIX with the path to your yagarto or linaro install
  11. # Replace ARMGNU with the root name of the compiler binaries
  12. #   For yagarto it's usually $(PREFIX)/bin/arm-none-eabi
  13. #   For linaro it's usually $(PREFIX)/bin/arm-eabi
  14. # Replace SUFFIX with .exe if you're on Windows or just leave it blank for other OSs.
  15. #
  16. #
  17. # Your SOURCE files go in a directory named "source".
  18. # This includes *.c, *.h, *.s files.
  19. # Your files will be compiled in build/ and your kernel will be output into bin/
  20. #
  21. # Example Directory Structure:
  22. #
  23. # lab_1
  24. # | Makefile
  25. # | kernel_c.ld
  26. # | source/
  27. #    | main.c
  28. #    | gpio.c
  29. #    | gpio.h
  30. #    | boot.s
  31. # | build/       <- generated for you
  32. #    | ...
  33. # | bin/         <- generated for you
  34. #    | kernel7.img
  35. #    | kernel7.list
  36. #    | kernel7.map
  37. #
  38.  
  39. ###
  40. # build environment
  41. ###
  42.  
  43. # Replace with the path to your yagarto install directory.
  44. # Note: Any paths with spaces in it must have quotes around them, like below:
  45. PREFIX ?= "/Users/danielcox/yagarto/yagarto-4.7.2"
  46.  
  47. ARMGNU ?= $(PREFIX)/bin/arm-none-eabi
  48. #ARMGNU ?= $(PREFIX)/bin/arm-eabi
  49.  
  50. # Suffix on windows is .exe, other platforms it's nothing
  51. #SUFFIX ?= .exe
  52. #SUFFIX ?=
  53.  
  54. ###########################
  55. # DON'T CHANGE THIS STUFF #
  56. ###########################
  57.  
  58. # Uncomment to create a C assembler listing
  59. CASM_LIST = -Wa,-adhln  > $(BUILD)$*.lst
  60.  
  61. # The intermediate directory for compiled object files.
  62. BUILD = build/
  63.  
  64. OUTPUT = bin/
  65.  
  66. # The directory in which source files are stored.
  67. SOURCE = source/
  68.  
  69. ###
  70. # Targets
  71. ###
  72.  
  73. # The name of the output file to generate.
  74. TARGET = $(OUTPUT)kernel7.img
  75.  
  76. # The name of the assembler listing file to generate.
  77. LIST = $(OUTPUT)kernel7.list
  78.  
  79. # The name of the map file to generate.
  80. MAP = $(OUTPUT)kernel7.map
  81.  
  82. ###
  83. # Sources
  84. ###
  85.  
  86. # The name of the linker script to use.
  87. LINKER = kernel_c.ld
  88.  
  89. # The names of all object files that must be generated. Deduced from the
  90. # assembly code files in source.
  91. OBJECTS := $(patsubst $(SOURCE)%.s,$(BUILD)%.o,$(wildcard $(SOURCE)*.s))
  92. OBJECTS += $(patsubst $(SOURCE)%.c,$(BUILD)%.o,$(wildcard $(SOURCE)*.c))
  93. OBJECTS += $(patsubst $(SOURCE)%.cpp,$(BUILD)%.o,$(wildcard $(SOURCE)*.cpp))
  94.  
  95. ###
  96. # Build flags
  97. ###
  98.  
  99. DEPENDFLAGS := -MD -MP
  100. INCLUDES    := -I source
  101.  
  102. BASEFLAGS   := -pedantic -pedantic-errors -nostdlib
  103. BASEFLAGS   += -nostartfiles -ffreestanding -nodefaultlibs
  104.  
  105. # Pi 1 compile flags
  106. #BASEFLAGS   += -O2 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s
  107.  
  108. # A+ compile flags
  109. # BASEFLAGS   += -O2 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -DPI2
  110.  
  111. # Pi 2 compile flags
  112. BASEFLAGS += -O2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7  -DPI2
  113.  
  114. # Pi 3 compile flags
  115. #BASEFLAGS   += -O2 -march=armv8-a -mtune=cortex-a53 -DPI2
  116.  
  117. ### Warnings ###
  118.  
  119. # -Wall turns on the following flags ( from https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html ):
  120. # -Waddress
  121. # -Warray-bounds=1 (only with -O2)
  122. # -Wbool-compare
  123. # -Wc++11-compat  -Wc++14-compat
  124. # -Wchar-subscripts
  125. # -Wcomment
  126. # -Wduplicate-decl-specifier (C and Objective-C only)
  127. # -Wenum-compare (in C/ObjC; this is on by default in C++)
  128. # -Wformat
  129. # -Wimplicit (C and Objective-C only)
  130. # -Wimplicit-int (C and Objective-C only)
  131. # -Wimplicit-function-declaration (C and Objective-C only)
  132. # -Winit-self (only for C++)
  133. # -Wlogical-not-parentheses
  134. # -Wmain (only for C/ObjC and unless -ffreestanding)
  135. # -Wmaybe-uninitialized
  136. # -Wmemset-elt-size
  137. # -Wmemset-transposed-args
  138. # -Wmisleading-indentation (only for C/C++)
  139. # -Wmissing-braces (only for C/ObjC)
  140. # -Wnarrowing (only for C++)
  141. # -Wnonnull
  142. # -Wnonnull-compare
  143. # -Wopenmp-simd
  144. # -Wparentheses
  145. # -Wpointer-sign
  146. # -Wreorder
  147. # -Wreturn-type
  148. # -Wsequence-point
  149. # -Wsign-compare (only in C++)
  150. # -Wsizeof-pointer-memaccess
  151. # -Wstrict-aliasing
  152. # -Wstrict-overflow=1
  153. # -Wswitch
  154. # -Wtautological-compare
  155. # -Wtrigraphs
  156. # -Wuninitialized
  157. # -Wunknown-pragmas
  158. # -Wunused-function
  159. # -Wunused-label
  160. # -Wunused-value
  161. # -Wunused-variable
  162. # -Wvolatile-register-var
  163.  
  164. # -Wextra turns on the following errors:
  165. # -Wclobbered
  166. # -Wempty-body
  167. # -Wignored-qualifiers
  168. # -Wmissing-field-initializers
  169. # -Wmissing-parameter-type (C only)
  170. # -Wold-style-declaration (C only)
  171. # -Woverride-init
  172. # -Wsign-compare (C only)
  173. # -Wtype-limits
  174. # -Wuninitialized
  175. # -Wshift-negative-value (in C++03 and in C99 and newer)
  176. # -Wunused-parameter (only with -Wunused or -Wall).  Removed below with -Wno-unused-parameter
  177. # -Wunused-but-set-parameter (only with -Wunused or -Wall).  Removed below with -Wno-unused-but-set-parameter
  178.  
  179. WARNFLAGS   := -Wall -Wextra -Wshadow -Wcast-align -Wwrite-strings
  180. WARNFLAGS   += -Wredundant-decls -Winline
  181. WARNFLAGS   += -Wno-attributes -Wno-deprecated-declarations
  182. WARNFLAGS   += -Wno-div-by-zero -Wno-endif-labels -Wfloat-equal
  183. WARNFLAGS   += -Wformat=2 -Wno-format-extra-args -Winit-self
  184. WARNFLAGS   += -Winvalid-pch -Wmissing-format-attribute
  185. WARNFLAGS   += -Wmissing-include-dirs -Wno-multichar
  186. WARNFLAGS   += -Wredundant-decls -Wshadow
  187. WARNFLAGS   += -Wno-sign-compare -Wsystem-headers -Wundef
  188. WARNFLAGS   += -Wno-pragmas -Wno-unused-but-set-parameter
  189. WARNFLAGS   += -Wno-unused-but-set-variable -Wno-unused-result -Wno-unused-parameter
  190. WARNFLAGS   += -Wwrite-strings -Wdisabled-optimization -Wpointer-arith
  191. WARNFLAGS   += -Wno-unused-function -Wno-unused-variable
  192.  
  193. #Warnings are errors.
  194. WARNFLAGS   += -Werror
  195.  
  196. ### Assembly Flags ###
  197.  
  198. ASFLAGS     := $(INCLUDES) $(DEPENDFLAGS) -D__ASSEMBLY__
  199.  
  200. ### C Flags ###
  201. CFLAGS      := $(INCLUDES) $(DEPENDFLAGS) $(BASEFLAGS) $(WARNFLAGS)
  202. CFLAGS      += -std=c11
  203.  
  204. ### C++ Flags ###
  205. CXXFLAGS    := $(INCLUDES) $(DEPENDFLAGS) $(BASEFLAGS) $(WARNFLAGS)
  206. CXXFLAGS    += -std=c++14
  207.  
  208. ###
  209. # Rules
  210. ###
  211.  
  212. # Rule to make everything.
  213. all: $(TARGET) $(LIST)
  214.  
  215. # Rule to remake everything. Does not include clean.
  216. rebuild: all
  217.  
  218.  
  219. # Rule to make the listing file.
  220. $(LIST) : $(BUILD)output.elf $(OUTPUT)
  221.         $(ARMGNU)-objdump$(SUFFIX) -d $(BUILD)output.elf > $(LIST)
  222.  
  223. # Rule to make the image file.
  224. $(TARGET) : $(BUILD)output.elf $(OUTPUT)
  225.         $(ARMGNU)-objcopy$(SUFFIX) $(BUILD)output.elf -O binary $(TARGET)
  226.  
  227. # Rule to make the elf file.
  228. $(BUILD)output.elf : $(OBJECTS) $(LINKER) $(BUILD) $(OUTPUT)
  229.         $(ARMGNU)-ld$(SUFFIX) --no-undefined $(OBJECTS) -Map $(MAP) -o $(BUILD)output.elf -T $(LINKER)
  230.  
  231. # Rule to make the assembler object files.
  232. $(BUILD)%.o: $(SOURCE)%.s $(BUILD)
  233.         $(ARMGNU)-as$(SUFFIX) -I $(SOURCE) $< -o $@
  234.  
  235. # C.
  236. $(BUILD)%.o: $(SOURCE)%.c $(BUILD)
  237.         $(ARMGNU)-gcc$(SUFFIX) $(CFLAGS) -c $< -o $@  $(CASM_LIST)
  238.  
  239. # CPP.
  240. $(BUILD)%.o: $(SOURCE)%.cpp $(BUILD)
  241.         $(ARMGNU)-g++$(SUFFIX) $(CXXFLAGS) -c $< -o $@  $(CASM_LIST)
  242.  
  243. $(BUILD):
  244.         mkdir -p $(BUILD)
  245.  
  246. $(OUTPUT):
  247.         mkdir -p $(OUTPUT)
  248.  
  249. # Rule to clean files.
  250. clean :
  251.         -rm -f $(BUILD)*.o
  252.         -rm -f $(BUILD)*.d
  253.         -rm -f $(BUILD)*.lst
  254.         -rm -f $(BUILD)output.elf
  255.         -rm -f $(TARGET)
  256.         -rm -f $(LIST)
  257.         -rm -f $(MAP)
  258.         -rmdir $(BUILD)
  259.         -rmdir $(OUTPUT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement