github.com/aretext/aretext@v1.3.0/syntax/languages/testdata/makefile/Makefile (about) 1 # Below text is taken from https://github.com/theicfire/makefiletutorial, 2 # which uses the MIT license: 3 # 4 # The MIT License (MIT) 5 # 6 # Copyright (c) 2014 Vinit Kumar 7 # 8 # Permission is hereby granted, free of charge, to any person obtaining a copy 9 # of this software and associated documentation files (the "Software"), to deal 10 # in the Software without restriction, including without limitation the rights 11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 # copies of the Software, and to permit persons to whom the Software is 13 # furnished to do so, subject to the following conditions: 14 # 15 # The above copyright notice and this permission notice shall be included in all 16 # copies or substantial portions of the Software. 17 # 18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 # SOFTWARE. 25 26 # Thanks to Job Vranish (https://spin.atomicobject.com/2016/08/26/makefile-c-projects/) 27 TARGET_EXEC := final_program 28 29 BUILD_DIR := ./build 30 SRC_DIRS := ./src 31 32 # Find all the C and C++ files we want to compile 33 # Note the single quotes around the * expressions. The shell will incorrectly expand these otherwise, but we want to send the * directly to the find command. 34 SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s') 35 36 # Prepends BUILD_DIR and appends .o to every src file 37 # As an example, ./your_dir/hello.cpp turns into ./build/./your_dir/hello.cpp.o 38 OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) 39 40 # String substitution (suffix version without %). 41 # As an example, ./build/hello.cpp.o turns into ./build/hello.cpp.d 42 DEPS := $(OBJS:.o=.d) 43 44 # Every folder in ./src will need to be passed to GCC so that it can find header files 45 INC_DIRS := $(shell find $(SRC_DIRS) -type d) 46 # Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag 47 INC_FLAGS := $(addprefix -I,$(INC_DIRS)) 48 49 # The -MMD and -MP flags together generate Makefiles for us! 50 # These files will have .d instead of .o as the output. 51 CPPFLAGS := $(INC_FLAGS) -MMD -MP 52 53 # The final build step. 54 $(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) 55 $(CXX) $(OBJS) -o $@ $(LDFLAGS) 56 57 # Build step for C source 58 $(BUILD_DIR)/%.c.o: %.c 59 mkdir -p $(dir $@) 60 $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 61 62 # Build step for C++ source 63 $(BUILD_DIR)/%.cpp.o: %.cpp 64 mkdir -p $(dir $@) 65 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ 66 67 68 .PHONY: clean 69 clean: 70 rm -r $(BUILD_DIR) 71 72 # Include the .d makefiles. The - at the front suppresses the errors of missing 73 # Makefiles. Initially, all the .d files will be missing, and we don't want those 74 # errors to show up. 75 -include $(DEPS)