├── .gitignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── linux_driver ├── Makefile └── hello │ ├── Makefile │ ├── come.c │ └── on.c ├── log-again.txt ├── log.txt ├── mult_dir_project ├── bar │ ├── Makefile │ ├── bar.c │ ├── crc.cpp │ └── foo.c ├── foo │ ├── Makefile │ ├── foobar.cpp │ └── not-foo.cpp ├── include │ ├── backtrace.h │ ├── bar.h │ ├── crc.h │ └── foo.h ├── main │ ├── Makefile │ ├── config.mk │ ├── main.cpp │ ├── mkconfig │ └── rules.mk └── readme.txt ├── mult_dir_project_new ├── Makefile ├── bar │ └── bar.cpp ├── crc │ └── crc.cpp ├── debug.c ├── debug.h ├── foo │ └── foo.c ├── hello │ ├── Makefile │ └── hello.c ├── inc │ ├── bar.h │ ├── crc.h │ ├── foo.h │ └── hello.h ├── main.cpp └── readme.txt ├── mult_dir_project_new1 ├── Makefile ├── bar │ └── bar.cpp ├── crc │ └── crc.cpp ├── debug.c ├── debug.h ├── foo │ └── foo.c ├── generate_version.sh ├── hello │ └── hello.c ├── inc │ ├── bar.h │ ├── crc.h │ ├── foo.h │ └── hello.h ├── main.cpp └── readme.txt ├── mult_dir_project_new2 ├── Makefile ├── bar │ ├── bar.cpp │ └── bar.h ├── crc │ ├── crc.cpp │ └── crc.h ├── debug.c ├── debug.h ├── foo │ ├── foo.c │ └── foo.h ├── hello │ ├── hello.c │ └── hello.h ├── main.cpp └── readme.txt ├── one_dir_project ├── Makefile ├── bar.cpp ├── bar.h ├── crc.cpp ├── crc.h ├── debug.c ├── debug.h ├── foo.c ├── foo.h └── main.cpp └── stm32_project ├── Makefile └── Makefile_my /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.d 4 | *.ko 5 | *.obj 6 | *.elf 7 | 8 | # Libraries 9 | *.lib 10 | *.a 11 | 12 | # Shared objects (inc. Windows DLLs) 13 | *.dll 14 | *.so 15 | *.so.* 16 | *.dylib 17 | 18 | # Executables 19 | *.exe 20 | *.out 21 | *.app 22 | *.i*86 23 | *.x86_64 24 | *.hex 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | git: 2 | quiet: true 3 | 4 | language: c 5 | 6 | install: 7 | echo "install sth here" 8 | before_script: 9 | echo "before script" 10 | script: 11 | - make -C one_dir_project/ 12 | - make -C mult_dir_project_new1/ 13 | 14 | after_script: 15 | echo "after script" 16 | 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # (C) Copyleft 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2 | # Late Lee(li@latelee.org) from http://www.latelee.org 3 | # 4 | # A simple Makefile for *ONE* project(c or/and cpp file) in *ONE* or *MORE* directory 5 | # 6 | # note: 7 | # you can put head file(s) in 'include' directory, so it looks 8 | # a little neat. 9 | # 10 | # usage: 11 | # $ make 12 | # $ make V=1 # verbose ouput 13 | # $ make CROSS_COMPILE=arm-arago-linux-gnueabi- # cross compile for ARM, etc. 14 | # $ make debug=y # debug 15 | # 16 | # log 17 | # 2013-05-14 sth about debug... 18 | # 2016-02-29 sth for c/c++ multi diretory 19 | # 2017-04-17 -s for .a/.so if no debug 20 | # 2017-05-05 Add V for verbose ouput 21 | ############################################################################### 22 | 23 | # !!!=== cross compile... 24 | CROSS_COMPILE ?= 25 | 26 | MKDIR_P ?= mkdir -p 27 | 28 | CC = $(CROSS_COMPILE)gcc 29 | CXX = $(CROSS_COMPILE)g++ 30 | AR = $(CROSS_COMPILE)ar 31 | 32 | # !!!=== 33 | # in case all .c/.cpp need g++, specify CC=CXX... 34 | # CC = $(CXX) 35 | 36 | ARFLAGS = -cr 37 | RM = -rm -rf 38 | MAKE = make 39 | 40 | # !!!=== 41 | # target executable file or .a or .so 42 | target = a.out 43 | 44 | # !!!=== 45 | # compile flags 46 | CFLAGS += -Wall -Wfatal-errors -MMD 47 | 48 | # !!!=== pkg-config here 49 | #CFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 50 | #LDFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 51 | 52 | #**************************************************************************** 53 | # debug can be set to y to include debugging info, or n otherwise 54 | debug = y 55 | 56 | #**************************************************************************** 57 | 58 | ifeq ($(debug), y) 59 | CFLAGS += -ggdb -rdynamic 60 | else 61 | CFLAGS += -O2 -s 62 | endif 63 | 64 | # !!!=== 65 | # Macros define here 66 | DEFS += -DJIMKENT 67 | 68 | # !!! compile flags define here... 69 | CFLAGS += $(DEFS) 70 | # !!! c++ flags 71 | CXXFLAGS = $(CFLAGS) 72 | # !!! library here... 73 | LIBS += 74 | # !!! gcc/g++ link flags here 75 | LDFLAGS += $(LIBS) -lpthread -lrt 76 | 77 | # !!!=== 78 | # include head file directory here 79 | INC = ./ ./inc 80 | # or try this 81 | #INC := $(shell find $(INC) -type d) 82 | 83 | # !!!=== 84 | # build directory 85 | BUILD_DIR ?= #./build/ 86 | 87 | # !!!=== 88 | # source file(s), including ALL c file(s) or cpp file(s) 89 | # just need the directory. 90 | SRC_DIRS = . 91 | # or try this 92 | #SRC_DIRS = . ../outbox 93 | 94 | # !!!=== 95 | # gcc/g++ compile flags 96 | CFLAGS += $(INCDIRS) 97 | CXXFLAGS += -std=c++11 98 | 99 | # dynamic library build flags 100 | DYNC_FLAGS += -fpic -shared 101 | 102 | # include directory(s) 103 | INCDIRS := $(addprefix -I, $(INC)) 104 | 105 | # source file(s) 106 | SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name '*.cpp' -or -name '*.c') 107 | # or try this 108 | #SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c') 109 | 110 | OBJS = $(patsubst %.c,$(BUILD_DIR)%.o, $(patsubst %.cpp,$(BUILD_DIR)%.o, $(SRCS))) 111 | 112 | # depend files(.d) 113 | DEPS := $(OBJS:.o=.d) 114 | 115 | ifeq ($(V),1) 116 | Q= 117 | NQ=true 118 | else 119 | Q=@ 120 | NQ=echo 121 | endif 122 | 123 | ############################################################################### 124 | 125 | all: $(BUILD_DIR)$(target) 126 | 127 | $(BUILD_DIR)$(target): $(OBJS) 128 | 129 | ifeq ($(suffix $(target)), .so) 130 | @$(NQ) "Generating dynamic lib file..." $(notdir $(target)) 131 | $(Q)$(CXX) $^ $(LDFLAGS) $(DYNC_FLAGS) -o $(target) 132 | else ifeq ($(suffix $(target)), .a) 133 | @$(NQ) "Generating static lib file..." $(notdir $(target)) 134 | $(Q)$(AR) $(ARFLAGS) -o $(target) $^ 135 | else 136 | @$(NQ) "Generating executable file..." $(notdir $(target)) 137 | $(Q)$(CXX) $^ $(LDFLAGS) -o $(target) 138 | endif 139 | 140 | # make all .c or .cpp 141 | $(BUILD_DIR)%.o: %.c 142 | @$(MKDIR_P) $(dir $@) 143 | @$(NQ) "Compiling: " $(addsuffix .c, $(basename $(notdir $@))) 144 | $(Q)$(CC) $(CFLAGS) -c $< -o $@ 145 | 146 | $(BUILD_DIR)%.o: %.cpp 147 | @$(MKDIR_P) $(dir $@) 148 | @$(NQ) "Compiling: " $(addsuffix .cpp, $(basename $(notdir $@))) 149 | $(Q)$(CXX) $(CXXFLAGS) -c $< -o $@ 150 | 151 | clean: 152 | @$(NQ) "Cleaning..." 153 | $(Q)$(RM) $(OBJS) $(target) $(DEPS) 154 | # delete build directory if needed 155 | ifneq ($(BUILD_DIR),) 156 | $(Q)$(RM) $(BUILD_DIR) 157 | endif 158 | # use 'grep -v soapC.o' to skip the file 159 | @find . -iname '*.o' -o -iname '*.bak' -o -iname '*.d' | xargs rm -f 160 | 161 | .PHONY: all clean 162 | 163 | -include $(DEPS) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/README.md -------------------------------------------------------------------------------- /linux_driver/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################# 2 | # (C) Copyleft 2010 2011 2013 2015 2016 2017 2018 3 | # by Late Lee from www.latelee.org 4 | # 5 | # A simple Makefile for linux driver 6 | # 7 | # make CROSS_COMPILE=arm-linux- 8 | # usage: 9 | # $ make 10 | # $ make V=1 # verbose ouput 11 | # $ make CROSS_COMPILE=arm-linux- # cross compile for ARM, etc. 12 | # $ make debug=y # debug 13 | ################################################################# 14 | 15 | CLEAN_BEGIN=@echo "Cleaning up ..." 16 | CLEAN_END=@echo "[Done.]" 17 | 18 | MAKE_BEGIN=@echo "Compiling ..." 19 | MAKE_DONE=" [Job done!]"; 20 | MAKE_ERR=" [Oops!Error occurred]"; 21 | ### nothing end 22 | 23 | # !!!=== for cross compile 24 | CROSS_COMPILE = arm-linux- 25 | 26 | CC := $(CROSS_COMPILE)gcc 27 | LD := $(CROSS_COMPILE)ld 28 | 29 | 30 | # !!!=== for debug 31 | #DEBUG = y 32 | 33 | ifeq ($(DEBUG), y) 34 | DEBFLAGS = -O -g 35 | else 36 | DEBFLAGS = -O1 37 | endif 38 | 39 | # CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR) 40 | 41 | # !!!=== module name here 42 | MODULE = GotoHell 43 | 44 | SRC = $(wildcard *.c *.cpp) 45 | OBJ = $(patsubst %.c,%.o, $(patsubst %.cpp,%.o, $(SRC))) 46 | 47 | ifeq ($(V),1) 48 | Q= 49 | NQ=true 50 | else 51 | Q= 52 | NQ=echo 53 | endif 54 | 55 | # obj-m = module 56 | # obj-y = into kernel 57 | # foo.o -> foo.ko 58 | ifneq ($(KERNELRELEASE), ) 59 | obj-m := $(MODULE).o 60 | 61 | # !!!=== your obj file(s) here 62 | $(MODULE)-objs := come.o on.o 63 | 64 | else 65 | # !!!=== change to your linux kernel path 66 | #KERNELDIR ?= /lib/modules/$(shell uname -r)/build 67 | KERNELDIR ?= /home/latelee/linux_ebook/linux 68 | PWD := $(shell pwd) 69 | 70 | 71 | all: 72 | $(MAKE_BEGIN) 73 | @echo 74 | @if \ 75 | $(MAKE) -C $(KERNELDIR) M=$(PWD) modules;\ 76 | then echo $(MAKE_DONE)\ 77 | else \ 78 | echo $(MAKE_ERR)\ 79 | exit 1; \ 80 | fi 81 | endif 82 | 83 | clean: 84 | $(CLEAN_BEGIN) 85 | rm -rf *.cmd *.o *.ko *.mod.c *.symvers *.order *.markers \ 86 | .tmp_versions .*.cmd *~ 87 | $(CLEAN_END) 88 | 89 | install: 90 | @echo " Note:" 91 | @echo "To install or not install,that is a question." 92 | 93 | modules: 94 | @echo "Do not need to do this." 95 | 96 | modules_install: 97 | @echo "Do not need to do this." 98 | love: 99 | @echo "To make or not to make, that is also a question." 100 | 101 | .PHONY:all clean install love modules modules_install 102 | -------------------------------------------------------------------------------- /linux_driver/hello/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################# 2 | # (C) Copyleft 2010 2011 2013 2015 2016 2017 2018 3 | # by Late Lee from www.latelee.org 4 | # 5 | # A simple Makefile for linux driver 6 | # 7 | # make CROSS_COMPILE=arm-linux- 8 | # usage: 9 | # $ make 10 | # $ make V=1 # verbose ouput 11 | # $ make CROSS_COMPILE=arm-linux- # cross compile for ARM, etc. 12 | # $ make debug=y # debug 13 | ################################################################# 14 | 15 | CLEAN_BEGIN=@echo "Cleaning up ..." 16 | CLEAN_END=@echo "[Done.]" 17 | 18 | MAKE_BEGIN=@echo "Compiling ..." 19 | MAKE_DONE=" [Job done!]"; 20 | MAKE_ERR=" [Oops!Error occurred]"; 21 | ### nothing end 22 | 23 | # !!!=== for cross compile 24 | CROSS_COMPILE = arm-linux- 25 | 26 | CC := $(CROSS_COMPILE)gcc 27 | LD := $(CROSS_COMPILE)ld 28 | 29 | 30 | # !!!=== for debug 31 | #DEBUG = y 32 | 33 | ifeq ($(DEBUG), y) 34 | DEBFLAGS = -O -g 35 | else 36 | DEBFLAGS = -O1 37 | endif 38 | 39 | # CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR) 40 | 41 | # !!!=== module name here 42 | MODULE = GotoHell 43 | 44 | SRC = $(wildcard *.c *.cpp) 45 | OBJ = $(patsubst %.c,%.o, $(patsubst %.cpp,%.o, $(SRC))) 46 | 47 | ifeq ($(V),1) 48 | Q= 49 | NQ=true 50 | else 51 | Q= 52 | NQ=echo 53 | endif 54 | 55 | # obj-m = module 56 | # obj-y = into kernel 57 | # foo.o -> foo.ko 58 | ifneq ($(KERNELRELEASE), ) 59 | obj-m := $(MODULE).o 60 | 61 | # !!!=== your obj file(s) here 62 | $(MODULE)-objs := come.o on.o 63 | 64 | else 65 | # !!!=== change to your linux kernel path 66 | #KERNELDIR ?= /lib/modules/$(shell uname -r)/build 67 | KERNELDIR ?= /home/latelee/linux_ebook/linux 68 | PWD := $(shell pwd) 69 | 70 | 71 | all: 72 | $(MAKE_BEGIN) 73 | @echo 74 | @if \ 75 | $(MAKE) -C $(KERNELDIR) M=$(PWD) modules;\ 76 | then echo $(MAKE_DONE)\ 77 | else \ 78 | echo $(MAKE_ERR)\ 79 | exit 1; \ 80 | fi 81 | endif 82 | 83 | clean: 84 | $(CLEAN_BEGIN) 85 | rm -rf *.cmd *.o *.ko *.mod.c *.symvers *.order *.markers \ 86 | .tmp_versions .*.cmd *~ 87 | $(CLEAN_END) 88 | 89 | install: 90 | @echo " Note:" 91 | @echo "To install or not install,that is a question." 92 | 93 | modules: 94 | @echo "Do not need to do this." 95 | 96 | modules_install: 97 | @echo "Do not need to do this." 98 | love: 99 | @echo "To make or not to make, that is also a question." 100 | 101 | .PHONY:all clean install love modules modules_install 102 | -------------------------------------------------------------------------------- /linux_driver/hello/come.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | //#include 4 | //#include 5 | #include 6 | 7 | static int __init hello_init(void) 8 | { 9 | printk(KERN_WARNING "Hello world!\n"); 10 | return 0; 11 | } 12 | 13 | module_init(hello_init); 14 | -------------------------------------------------------------------------------- /linux_driver/hello/on.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | //#include 4 | //#include 5 | #include 6 | 7 | #if 0 8 | static int __init hello_init(void) 9 | { 10 | printk(KERN_WARNING "Hello world!\n"); 11 | return 0; 12 | } 13 | #endif 14 | 15 | static void __exit hello_exit(void) 16 | { 17 | /* KERN_ALERT: display on console */ 18 | printk(KERN_ALERT "Goodbye world!\n"); 19 | } 20 | 21 | //module_init(hello_init); 22 | module_exit(hello_exit); 23 | 24 | MODULE_LICENSE("GPL"); 25 | -------------------------------------------------------------------------------- /log-again.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/log-again.txt -------------------------------------------------------------------------------- /log.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/log.txt -------------------------------------------------------------------------------- /mult_dir_project/bar/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # (C) Copyleft 2011 3 | # Late Lee from http://www.latelee.org 4 | # 5 | # A simple Makefile for lib(libxxx.a) 6 | # You just need to change library name and source file(s) 7 | # 8 | 9 | include $(TOPDIR)/config.mk 10 | 11 | # static library name 12 | LIB = $(obj)libbar.a 13 | 14 | # source file(s), including c file(s) cpp file(s) 15 | # you can also use $(wildcard *.c) or *.c, etc. 16 | SRC_C := bar.c foo.c 17 | SRC_CPP := crc.cpp 18 | 19 | # object file(s) 20 | OBJ_C := $(addprefix $(obj),$(patsubst %.c,%.o,$(SRC_C))) 21 | OBJ_CPP := $(addprefix $(obj),$(patsubst %.cpp,%.o,$(SRC_CPP))) 22 | 23 | all: $(obj).depend $(LIB) 24 | 25 | $(LIB): $(OBJ_C) $(OBJ_CPP) 26 | @echo "Generating static library: " $(notdir $@) 27 | @$(AR) $(ARFLAGS) $@ $^ 28 | 29 | clean: 30 | @echo "Cleaning..." 31 | @$(RM) $(LIB) $(OBJ_C) $(OBJ_CPP) *.bak *~ $(obj).depend *.o 32 | 33 | .PHONY: all clean 34 | 35 | ######################################################################### 36 | 37 | include $(TOPDIR)/rules.mk 38 | 39 | sinclude $(obj).depend 40 | 41 | ######################################################################### 42 | -------------------------------------------------------------------------------- /mult_dir_project/bar/bar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void bar(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_bar(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | foo(200); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project/bar/crc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project/bar/crc.cpp -------------------------------------------------------------------------------- /mult_dir_project/bar/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void foo(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_foo(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | bar(100); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project/foo/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # (C) Copyleft 2011 3 | # Late Lee from http://www.latelee.org 4 | # 5 | # A simple Makefile for lib(libxxx.a) 6 | # You just need to change library name and source file(s) 7 | # 8 | 9 | include $(TOPDIR)/config.mk 10 | 11 | # here you can set your own flags 12 | CFLAGS += -D_A_ 13 | 14 | # static library name 15 | LIB = $(obj)libfoo.a 16 | 17 | # source file(s), including c file(s) cpp file(s) 18 | # you can also use $(wildcard *.c), etc. 19 | SRC_C := 20 | SRC_CPP := foobar.cpp 21 | 22 | # object file(s) 23 | OBJ_C := $(addprefix $(obj),$(patsubst %.c,%.o,$(SRC_C))) 24 | OBJ_CPP := $(addprefix $(obj),$(patsubst %.cpp,%.o,$(SRC_CPP))) 25 | 26 | all: $(obj).depend $(LIB) 27 | 28 | $(LIB): $(OBJ_C) $(OBJ_CPP) 29 | @echo "Generating static library: " $(notdir $@) 30 | @$(AR) $(ARFLAGS) $@ $^ 31 | 32 | clean: 33 | @echo "Cleaning..." 34 | @$(RM) $(OBJ_C) $(OBJ_CPP) $(LIB) *.bak *~ *.d *.o $(obj).depend 35 | 36 | .PHONY: all clean 37 | 38 | ######################################################################### 39 | 40 | include $(TOPDIR)/rules.mk 41 | 42 | sinclude $(obj).depend 43 | 44 | ######################################################################### 45 | -------------------------------------------------------------------------------- /mult_dir_project/foo/foobar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // test of macro in Makefile 6 | #if !defined (_A_) && !defined (_B_) 7 | #error "define _A_ or _B_!!" 8 | #endif 9 | 10 | void foo(int i) 11 | { 12 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 13 | } 14 | 15 | int hello_foo(void) 16 | { 17 | printf("in func: %s()\n", __func__); 18 | bar(100); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /mult_dir_project/foo/not-foo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void foo(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_foo(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | bar(100); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project/include/backtrace.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file backtrace.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | 11 | #ifndef _BACKTRACE_H 12 | #define _BACKTRACE_H 13 | 14 | /* Even complicated programs rather seldom have a nesting 15 | * level of more than, say, 50 and with 200 possible entries 16 | * probably all programs should be covered. -- from glibc manual 17 | */ 18 | /* here, we let it be 30 */ 19 | #define NEST 30 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | void print_trace(int sig); 26 | void print_trace_fd(int sig); 27 | void print_trace_file(int sig); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* _BACKTRACE_H */ -------------------------------------------------------------------------------- /mult_dir_project/include/bar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bar.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | #ifndef BAR_H_ 11 | #define BAR_H_ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | void bar(int i); 18 | int hello_bar(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /mult_dir_project/include/crc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC_H 2 | #define CRC_H 3 | 4 | typedef unsigned long u32; 5 | typedef unsigned char u8; 6 | typedef unsigned short u16; 7 | typedef unsigned long uLong; 8 | typedef char Byte; 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | u32 crc32(const u8 *buf, u32 len); 15 | u32 crc32_1(u32 crc, const u8 *buf, u32 len); 16 | u16 crc16(const u8 *buf, u32 len); 17 | u16 crc16_1(const u8 *buf, u32 len); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* CRC_H */ -------------------------------------------------------------------------------- /mult_dir_project/include/foo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file foo.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | 11 | #ifndef FOO_H_ 12 | #define FOO_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | void foo(int i); 19 | int hello_foo(void); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /mult_dir_project/main/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # (C) Copyleft 2011 3 | # Late Lee from http://www.latelee.org 4 | # 5 | # A simple Makefile for multi-directory 6 | # Most idea comes from U-boot project 7 | # 8 | 9 | # object file directory, eg 10 | # $ make O =../build 11 | # BUILD_DIR = ../build 12 | # NOTE!!! do not add "/" at the end! 13 | BUILD_DIR := ../build 14 | 15 | # binary file director 16 | BIN_DIR := ../bin 17 | 18 | OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR)) 19 | SRCTREE := $(CURDIR) 20 | TOPDIR := $(SRCTREE) 21 | LNDIR := $(OBJTREE) 22 | export TOPDIR SRCTREE OBJTREE 23 | 24 | include $(TOPDIR)/config.mk 25 | 26 | ############################################################################### 27 | # libs 28 | _LIBS := ../bar/libbar.a ../foo/libfoo.a 29 | 30 | LIBS := $(addprefix $(obj),$(_LIBS)) 31 | 32 | LDFLAGS = $(addprefix $(obj),$(subst ../,,$(_LIBS))) 33 | 34 | # main.c in this directory, can be empty 35 | MAIN_DIR := main/ 36 | 37 | # source file(s), including c file(s) cpp file(s) 38 | # you can also use $(wildcard *.c), etc. 39 | SRC_C := $(wildcard *.c) 40 | SRC_CPP := $(wildcard *.cpp) 41 | 42 | # object file(s) 43 | OBJ_C := $(addprefix $(obj)$(MAIN_DIR),$(patsubst %.c,%.o,$(SRC_C))) 44 | OBJ_CPP := $(addprefix $(obj)$(MAIN_DIR),$(patsubst %.cpp,%.o,$(SRC_CPP))) 45 | 46 | # mkdir MAIN_DIR 47 | ifneq ($(MAIN_DIR),) 48 | $(shell mkdir -p $(addprefix $(obj),$(MAIN_DIR))) 49 | endif 50 | 51 | ifneq ($(BIN_DIR),) 52 | $(shell mkdir -p $(BIN_DIR)) 53 | endif 54 | 55 | # executable file 56 | target = $(BIN_DIR)/a.out 57 | 58 | ############################################################################### 59 | 60 | all: config $(target) 61 | 62 | config: 63 | @echo "Generating... hello.h" 64 | @$(MKCONFIG) 65 | 66 | $(target): $(LIBS) exe 67 | 68 | # make all .c or .cpp 69 | $(obj)$(MAIN_DIR)%.o: %.c 70 | @echo "Compling: " $(addsuffix .c, $(basename $(notdir $@))) 71 | $(CC) $(CFLAGS) -c $< -o $@ 72 | 73 | $(obj)$(MAIN_DIR)%.o: %.cpp 74 | @echo "Compling: " $(addsuffix .cpp, $(basename $(notdir $@))) 75 | $(CXX) $(CFLAGS) -c $< -o $@ 76 | 77 | exe: $(OBJ_CPP) $(OBJ_C) 78 | @echo "Generating executable file..." $(notdir $(target)) 79 | $(CXX) $(CFLAGS) $^ -o $(target) $(LDFLAGS) 80 | 81 | $(LIBS): 82 | $(MAKE) -C $(dir $(subst $(obj),,$@)) 83 | 84 | depend: 85 | $(MAKE) -C ../bar/ _depend 86 | 87 | clean: 88 | @echo "cleaning..." 89 | @$(RM) $(target) 90 | @$(RM) hello.h 91 | @find $(OBJTREE) $(BIN_DIR) -type f \ 92 | \( -name 'core' -o -name '*.bak' -o -name '*~' \ 93 | -o -name '*.o' -o -name '*.a' -o -name '*.exe' -o -name '.depend' \) -print \ 94 | | xargs rm -f 95 | distclean: 96 | @echo "distcleaning..." 97 | @$(RM) $(target) 98 | @$(RM) hello.h 99 | @find $(OBJTREE) $(BIN_DIR) -type f \ 100 | \( -name 'core' -o -name '*.bak' -o -name '*~' \ 101 | -o -name '*.o' -o -name '*.a' -o -name '*.exe' -o -name '.depend' \) -print \ 102 | | xargs rm -f 103 | @$(RM) $(obj) $(BUILD_DIR) 104 | @$(RM) $(BIN_DIR) 105 | 106 | .PHONY: all clean distclean $(LIBS) exe 107 | -------------------------------------------------------------------------------- /mult_dir_project/main/config.mk: -------------------------------------------------------------------------------- 1 | # 2 | # (C) Copyleft 2011 3 | # Late Lee from http://www.latelee.org 4 | # 5 | # A simple file to specify compier and macros and flags 6 | # and ways to compile .c & .cpp 7 | # 8 | 9 | # cross compile... 10 | CROSS_COMPILE = 11 | 12 | CC = $(CROSS_COMPILE)gcc 13 | CXX = $(CROSS_COMPILE)g++ 14 | AR = $(CROSS_COMPILE)ar 15 | 16 | ARFLAGS = cr 17 | RM = -rm -rf 18 | MAKE = make 19 | 20 | CFLAGS = -Wall -Wfatal-errors 21 | DEBUG = y 22 | 23 | ifeq ($(DEBUG), y) 24 | CFLAGS += -g 25 | DEBREL = Debug 26 | else 27 | CFLAGS += -O2 -s 28 | DEBREL = Release 29 | endif 30 | 31 | DEFS = 32 | 33 | CFLAGS += $(DEFS) 34 | 35 | LDFLAGS = $(LIBS) 36 | 37 | INCDIRS = ../include/ 38 | 39 | CFLAGS += -I$(INCDIRS) 40 | 41 | ############################################################################### 42 | 43 | ifneq ($(OBJTREE),$(SRCTREE)) 44 | ifeq ($(CURDIR),$(SRCTREE)) 45 | dir := 46 | else 47 | dir := $(subst $(SRCTREE)/,,$(CURDIR)) 48 | endif 49 | 50 | obj := $(if $(dir),$(OBJTREE)/$(notdir $(dir))/,$(OBJTREE)/) 51 | src := $(if $(dir),$(SRCTREE)/$(notdir $(dir))/,$(SRCTREE)/) 52 | 53 | $(shell mkdir -p $(obj)) 54 | else 55 | obj := 56 | src := 57 | endif 58 | 59 | suffix = $(notdir $(CURDIR)) 60 | export suffix 61 | 62 | # test of shell script 63 | MKCONFIG := $(SRCTREE)/mkconfig 64 | export MKCONFIG 65 | 66 | # export to other Makefile 67 | export CC 68 | export CFLAGS 69 | export INCDIRS 70 | export AR 71 | export ARFLAGS 72 | export RM 73 | 74 | ############################################################################### 75 | 76 | # make all .c or .cpp 77 | $(obj)%.o: %.c 78 | @echo "Compling: " $(addsuffix .c, $(basename $(notdir $@))) 79 | $(CC) $(CFLAGS) -c $< -o $@ 80 | 81 | $(obj)%.o: %.cpp 82 | @echo "Compling: " $(addsuffix .cpp, $(basename $(notdir $@))) 83 | $(CXX) $(CFLAGS) -c $< -o $@ 84 | -------------------------------------------------------------------------------- /mult_dir_project/main/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include "hello.h" 9 | 10 | static void nogood(void) 11 | { 12 | printf("no good %s.\n", "nogood"); 13 | } 14 | 15 | int main(void) 16 | { 17 | printf("hello from %s() %d.\n", __func__, HELLO); 18 | hello_foo(); 19 | hello_bar(); 20 | //print_trace(33); 21 | nogood(); 22 | ///////////////////////// 23 | int crc = 0; 24 | const char* buf = "voice from hell."; 25 | crc = crc32((unsigned char *)buf, strlen(buf)); 26 | printf("crc: 0x%x\n", crc); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /mult_dir_project/main/mkconfig: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "#ifndef A_HELLO_H " > hello.h 4 | echo "#define A_HELLO_H " >> hello.h 5 | echo "#define HELLO 0 " >> hello.h 6 | echo "#endif " >> hello.h -------------------------------------------------------------------------------- /mult_dir_project/main/rules.mk: -------------------------------------------------------------------------------- 1 | # 2 | # (C) Copyleft 2011 3 | # Late Lee from http://www.latelee.org 4 | # 5 | # A simple way to generate depend file(.depend) for .c & .cpp, 6 | # so you change the head file, it will recompile the 7 | # file(s) which include the head file. 8 | # 9 | 10 | _depend: $(obj).depend 11 | 12 | $(obj).depend: $(TOPDIR)/config.mk $(SRC_C) $(SRC_CPP) 13 | @rm -f $@ 14 | @for f in $(SRC_C); do \ 15 | g=`basename $$f | sed -e 's/\(.*\)\.\w/\1.o/'`; \ 16 | $(CC) -MM $(CFLAGS) -E -MQ $(_obj)$$g $$f >> $@ ; \ 17 | done 18 | @for f in $(SRC_CPP); do \ 19 | g=`basename $$f | sed -e 's/\(.*\)\...\w/\1.o/'`; \ 20 | $(CC) -MM $(CFLAGS) -E -MQ $(_obj)$$g $$f >> $@ ; \ 21 | done 22 | -------------------------------------------------------------------------------- /mult_dir_project/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project/readme.txt -------------------------------------------------------------------------------- /mult_dir_project_new/Makefile: -------------------------------------------------------------------------------- 1 | # (C) Copyleft 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2 | # Late Lee(li@latelee.org) from http://www.latelee.org 3 | # 4 | # A simple Makefile for *ONE* project(c or/and cpp file) in *ONE* or *MORE* directory 5 | # 6 | # note: 7 | # you can put head file(s) in 'include' directory, so it looks 8 | # a little neat. 9 | # 10 | # usage: 11 | # $ make 12 | # $ make V=1 # verbose ouput 13 | # $ make CROSS_COMPILE=arm-arago-linux-gnueabi- # cross compile for ARM, etc. 14 | # $ make debug=y # debug 15 | # $ make SRC_DIR1=foo SRC_DIR2=bar SRC_DIR3=crc 16 | # 17 | # log 18 | # 2013-05-14 sth about debug... 19 | # 2016-02-29 sth for c/c++ multi diretory 20 | # 2017-04-17 -s for .a/.so if no debug 21 | # 2017-05-05 Add V for verbose ouput 22 | ############################################################################### 23 | 24 | # !!!=== cross compile... 25 | CROSS_COMPILE ?= 26 | 27 | CC = $(CROSS_COMPILE)gcc 28 | CXX = $(CROSS_COMPILE)g++ 29 | AR = $(CROSS_COMPILE)ar 30 | 31 | ARFLAGS = -cr 32 | RM = -rm -rf 33 | MAKE = make 34 | 35 | CFLAGS = 36 | LDFLAGS = 37 | DEFS = 38 | LIBS = 39 | 40 | # !!!=== 41 | # target executable file or .a or .so 42 | target = a.out 43 | 44 | # !!!=== 45 | # compile flags 46 | CFLAGS += -Wall -Wfatal-errors 47 | 48 | # !!!=== pkg-config here 49 | #CFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 50 | #LDFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 51 | 52 | #**************************************************************************** 53 | # debug can be set to y to include debugging info, or n otherwise 54 | debug = y 55 | 56 | #**************************************************************************** 57 | 58 | ifeq ($(debug), y) 59 | CFLAGS += -ggdb -rdynamic 60 | else 61 | CFLAGS += -O2 -s 62 | endif 63 | 64 | # !!!=== 65 | DEFS += -DJIMKENT 66 | 67 | CFLAGS += $(DEFS) 68 | CXXFLAGS = $(CFLAGS) 69 | 70 | LIBS += ./hello/libhello.a 71 | 72 | LDFLAGS += $(LIBS) 73 | 74 | # !!!=== 75 | INC = ./ ./inc 76 | 77 | INCDIRS := $(addprefix -I, $(INC)) 78 | 79 | # !!!=== 80 | CFLAGS += $(INCDIRS) 81 | CXXFLAGS += -std=c++11 82 | 83 | # !!!=== 84 | LDFLAGS += -lpthread -lrt 85 | 86 | DYNC_FLAGS += -fpic -shared 87 | 88 | # !!!=== 89 | # source file(s), including c file(s) or cpp file(s) 90 | SRC_DIRS = . foo crc bar 91 | 92 | SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name '*.cpp' -or -name '*.c') 93 | 94 | OBJS = $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(SRCS))) 95 | 96 | # !!!=== 97 | # in case all .c/.cpp need g++... 98 | # CC = $(CXX) 99 | 100 | ifeq ($(V),1) 101 | Q= 102 | NQ=true 103 | else 104 | Q=@ 105 | NQ=echo 106 | endif 107 | 108 | ############################################################################### 109 | 110 | all: $(target) 111 | 112 | $(target): $(OBJS) 113 | 114 | ifeq ($(suffix $(target)), .so) 115 | @$(NQ) "Generating dynamic lib file..." $(notdir $(target)) 116 | $(Q)$(CXX) $^ $(LDFLAGS) $(DYNC_FLAGS) -o $(target) 117 | else ifeq ($(suffix $(target)), .a) 118 | @$(NQ) "Generating static lib file..." $(notdir $(target)) 119 | $(Q)$(AR) $(ARFLAGS) -o $(target) $^ 120 | else 121 | @$(NQ) "Generating executable file..." $(notdir $(target)) 122 | $(Q)$(CXX) $^ $(LDFLAGS) -o $(target) 123 | endif 124 | 125 | # make all .c or .cpp 126 | %.o: %.c 127 | @$(NQ) "Compiling: " $(addsuffix .c, $(basename $(notdir $@))) 128 | $(Q)$(CC) $(CFLAGS) -c $< -o $@ 129 | 130 | %.o: %.cpp 131 | @$(NQ) "Compiling: " $(addsuffix .cpp, $(basename $(notdir $@))) 132 | $(Q)$(CXX) $(CXXFLAGS) -c $< -o $@ 133 | 134 | clean: 135 | @$(NQ) "Cleaning..." 136 | $(Q)$(RM) $(target) $(OBJS) 137 | 138 | # use 'grep -v soapC.o' to skip the file 139 | @find . -iname '*.o' -o -iname '*.bak' -o -iname '*.d' | xargs rm -f 140 | 141 | .PHONY: all clean 142 | -------------------------------------------------------------------------------- /mult_dir_project_new/bar/bar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void bar(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_bar(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | foo(200); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project_new/crc/crc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new/crc/crc.cpp -------------------------------------------------------------------------------- /mult_dir_project_new/debug.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new/debug.c -------------------------------------------------------------------------------- /mult_dir_project_new/debug.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new/debug.h -------------------------------------------------------------------------------- /mult_dir_project_new/foo/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void foo(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_foo(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | bar(100); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project_new/hello/Makefile: -------------------------------------------------------------------------------- 1 | # (C) Copyleft 2011 2012 2013 2014 2015 2016 2017 2018 2 | # Late Lee(li@latelee.org) from http://www.latelee.org 3 | # 4 | # A simple Makefile for *ONE* project(c or/and cpp file) in *ONE* or *MORE* directory 5 | # 6 | # note: 7 | # you can put head file(s) in 'include' directory, so it looks 8 | # a little neat. 9 | # 10 | # usage: 11 | # $ make 12 | # $ make V=1 # verbose ouput 13 | # $ make CROSS_COMPILE=arm-arago-linux-gnueabi- # cross compile for ARM, etc. 14 | # $ make debug=y # debug 15 | # $ make SRC_DIR1=foo SRC_DIR2=bar SRC_DIR3=crc 16 | # 17 | # log 18 | # 2013-05-14 sth about debug... 19 | # 2016-02-29 sth for c/c++ multi diretory 20 | # 2017-04-17 -s for .a/.so if no debug 21 | # 2017-05-05 Add V for verbose ouput 22 | ############################################################################### 23 | 24 | # !!!=== cross compile... 25 | CROSS_COMPILE ?= 26 | 27 | CC = $(CROSS_COMPILE)gcc 28 | CXX = $(CROSS_COMPILE)g++ 29 | AR = $(CROSS_COMPILE)ar 30 | 31 | ARFLAGS = -cr 32 | RM = -rm -rf 33 | MAKE = make 34 | 35 | CFLAGS = 36 | LDFLAGS = 37 | DEFS = 38 | LIBS = 39 | 40 | # !!!=== 41 | # target executable file or .a or .so 42 | target = libhello.a 43 | 44 | # !!!=== 45 | # compile flags 46 | CFLAGS += -Wall -Wfatal-errors 47 | 48 | # !!!=== pkg-config here 49 | #CFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 50 | #LDFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 51 | 52 | #**************************************************************************** 53 | # debug can be set to y to include debugging info, or n otherwise 54 | debug = y 55 | 56 | #**************************************************************************** 57 | 58 | ifeq ($(debug), y) 59 | CFLAGS += -ggdb -rdynamic 60 | else 61 | CFLAGS += -O2 -s 62 | endif 63 | 64 | # !!!=== 65 | DEFS += -DJIMKENT 66 | 67 | CFLAGS += $(DEFS) 68 | CXXFLAGS = $(CFLAGS) 69 | 70 | LIBS += 71 | 72 | LDFLAGS += $(LIBS) 73 | 74 | # !!!=== 75 | INC = ./ ../inc 76 | 77 | INCDIRS := $(addprefix -I, $(INC)) 78 | 79 | # !!!=== 80 | CFLAGS += $(INCDIRS) 81 | CXXFLAGS += -std=c++11 82 | 83 | # !!!=== 84 | LDFLAGS += -lpthread -lrt 85 | 86 | DYNC_FLAGS += -fpic -shared 87 | 88 | # !!!=== 89 | # source file(s), including c file(s) or cpp file(s) 90 | SRC_DIRS = . 91 | 92 | SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name '*.cpp' -or -name '*.c') 93 | 94 | OBJS = $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(SRCS))) 95 | 96 | 97 | # !!!=== 98 | # in case all .c/.cpp need g++... 99 | # CC = $(CXX) 100 | 101 | ifeq ($(V),1) 102 | Q= 103 | NQ=true 104 | else 105 | Q=@ 106 | NQ=echo 107 | endif 108 | 109 | ############################################################################### 110 | 111 | all: $(target) 112 | 113 | $(target): $(OBJS) 114 | 115 | ifeq ($(suffix $(target)), .so) 116 | @$(NQ) "Generating dynamic lib file..." $(notdir $(target)) 117 | $(Q)$(CXX) $^ $(LDFLAGS) $(DYNC_FLAGS) -o $(target) 118 | else ifeq ($(suffix $(target)), .a) 119 | @$(NQ) "Generating static lib file..." $(notdir $(target)) 120 | $(Q)$(AR) $(ARFLAGS) -o $(target) $^ 121 | else 122 | @$(NQ) "Generating executable file..." $(notdir $(target)) 123 | $(Q)$(CXX) $^ $(LDFLAGS) -o $(target) 124 | endif 125 | 126 | # make all .c or .cpp 127 | %.o: %.c 128 | @$(NQ) "Compiling: " $(addsuffix .c, $(basename $(notdir $@))) 129 | $(Q)$(CC) $(CFLAGS) -c $< -o $@ 130 | 131 | %.o: %.cpp 132 | @$(NQ) "Compiling: " $(addsuffix .cpp, $(basename $(notdir $@))) 133 | $(Q)$(CXX) $(CXXFLAGS) -c $< -o $@ 134 | 135 | clean: 136 | @$(NQ) "Cleaning..." 137 | $(Q)$(RM) $(target) $(OBJS) 138 | 139 | # use 'grep -v soapC.o' to skip the file 140 | @find . -iname '*.o' -o -iname '*.bak' -o -iname '*.d' | xargs rm -f 141 | 142 | .PHONY: all clean 143 | -------------------------------------------------------------------------------- /mult_dir_project_new/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | static void _hello(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%s\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | _hello(100); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project_new/inc/bar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bar.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | #ifndef BAR_H_ 11 | #define BAR_H_ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | void bar(int i); 18 | int hello_bar(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /mult_dir_project_new/inc/crc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC_H 2 | #define CRC_H 3 | 4 | typedef unsigned long u32; 5 | typedef unsigned char u8; 6 | typedef unsigned short u16; 7 | typedef unsigned long uLong; 8 | typedef char Byte; 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | u32 crc32(const u8 *buf, u32 len); 15 | u32 crc32_1(u32 crc, const u8 *buf, u32 len); 16 | u16 crc16(const u8 *buf, u32 len); 17 | u16 crc16_1(const u8 *buf, u32 len); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* CRC_H */ -------------------------------------------------------------------------------- /mult_dir_project_new/inc/foo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file foo.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | 11 | #ifndef FOO_H_ 12 | #define FOO_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | void foo(int i); 19 | int hello_foo(void); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /mult_dir_project_new/inc/hello.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hello.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | 11 | #ifndef HELLO_H_ 12 | #define HELLO_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | int hello(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /mult_dir_project_new/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "hello.h" 7 | #include "debug.h" 8 | 9 | #include 10 | static void c11_test() 11 | { 12 | std::string foo = "good"; 13 | for (auto it = foo.begin(); it < foo.end(); it++) 14 | { 15 | printf("%s\n", *it); 16 | } 17 | } 18 | 19 | static void nogood(void) 20 | { 21 | printf("no good %s.\n", "nogood"); 22 | } 23 | 24 | int main(void) 25 | { 26 | printf("hello from %s().\n", __func__); 27 | 28 | hello(); 29 | 30 | hello_foo(); 31 | hello_bar(); 32 | nogood(); 33 | ///////////////////////// 34 | int crc = 0; 35 | const char* buf = "voice from hell...."; 36 | crc = crc32((unsigned char *)buf, strlen(buf)); 37 | printf("crc: 0x%x\n", crc); 38 | dump(buf, strlen(buf)); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /mult_dir_project_new/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new/readme.txt -------------------------------------------------------------------------------- /mult_dir_project_new1/Makefile: -------------------------------------------------------------------------------- 1 | # (C) Copyleft 2011 2012 2013 2014 2015 2016 2017 2018 2 | # Late Lee(li@latelee.org) from http://www.latelee.org 3 | # 4 | # A simple Makefile for *ONE* project(c or/and cpp file) in *ONE* or *MORE* directory 5 | # 6 | # note: 7 | # you can put head file(s) in 'include' directory, so it looks 8 | # a little neat. 9 | # 10 | # usage: 11 | # $ make 12 | # $ make V=1 # verbose ouput 13 | # $ make CROSS_COMPILE=arm-arago-linux-gnueabi- # cross compile for ARM, etc. 14 | # $ make debug=y # debug 15 | # 16 | # log 17 | # 2013-05-14 sth about debug... 18 | # 2016-02-29 sth for c/c++ multi diretory 19 | # 2017-04-17 -s for .a/.so if no debug 20 | # 2017-05-05 Add V for verbose ouput 21 | ############################################################################### 22 | 23 | # !!!=== version information 24 | VER_MAJOR ?= 0 25 | VER_MINOR ?= 1 26 | # !!!=== version head file 27 | VER_FILE ?= inc/version.h 28 | 29 | # !!!=== release or not (R=1 means release) 30 | R ?= 0 31 | 32 | # !!!=== 33 | # version script 34 | VER_SCRIPT ?= ./generate_version.sh 35 | 36 | # !!!=== cross compile... 37 | CROSS_COMPILE ?= 38 | 39 | MKDIR_P ?= mkdir -p 40 | 41 | CC = $(CROSS_COMPILE)gcc 42 | CXX = $(CROSS_COMPILE)g++ 43 | AR = $(CROSS_COMPILE)ar 44 | 45 | # !!!=== 46 | # in case all .c/.cpp need g++... 47 | # CC = $(CXX) 48 | 49 | ARFLAGS = -cr 50 | RM = -rm -rf 51 | MAKE = make 52 | 53 | CFLAGS = 54 | LDFLAGS = 55 | DEFS = 56 | LIBS = 57 | 58 | # !!!=== 59 | # target executable file or .a or .so 60 | target = a.out 61 | 62 | # !!!=== 63 | # compile flags 64 | CFLAGS += -Wall -Wfatal-errors -MMD 65 | 66 | # !!!=== pkg-config here 67 | #CFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 68 | #LDFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 69 | 70 | #**************************************************************************** 71 | # debug can be set to y to include debugging info, or n otherwise 72 | debug = y 73 | 74 | #**************************************************************************** 75 | 76 | ifeq ($(debug), y) 77 | CFLAGS += -ggdb -rdynamic 78 | else 79 | CFLAGS += -O2 -s 80 | endif 81 | 82 | # !!!=== 83 | # Macros define here 84 | DEFS += -DJIMKENT 85 | 86 | CFLAGS += $(DEFS) 87 | CXXFLAGS = $(CFLAGS) 88 | 89 | LIBS += 90 | 91 | LDFLAGS += $(LIBS) 92 | 93 | # !!!=== 94 | # include head file directory here 95 | INC = ./include ./inc 96 | # or try this 97 | #INC := $(shell find $(INC) -type d) 98 | 99 | # !!!=== 100 | # build directory 101 | BUILD_DIR ?= #./build/ 102 | 103 | # !!!=== 104 | # source file(s), including ALL c file(s) or cpp file(s) 105 | # just need the directory. 106 | SRC_DIRS = . foo bar crc hello 107 | # or try this 108 | #SRC_DIRS = ./ 109 | #SRC_DIRS += ../outbox 110 | 111 | # !!!=== 112 | # gcc/g++ compile flags 113 | CFLAGS += $(INCDIRS) 114 | CXXFLAGS += -std=c++11 115 | 116 | # !!!=== 117 | # gcc/g++ link flags 118 | LDFLAGS += -lpthread -lrt 119 | 120 | DYNC_FLAGS += -fpic -shared 121 | 122 | INCDIRS := $(addprefix -I, $(INC)) 123 | 124 | SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name '*.cpp' -or -name '*.c' | grep -v main.cpp) 125 | #SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c') 126 | 127 | OBJS = $(patsubst %.c,$(BUILD_DIR)%.o, $(patsubst %.cpp,$(BUILD_DIR)%.o, $(SRCS))) 128 | 129 | DEPS := $(OBJS:.o=.d) 130 | 131 | ifeq ($(V),1) 132 | Q= 133 | NQ=true 134 | else 135 | Q=@ 136 | NQ=echo 137 | endif 138 | 139 | ############################################################################### 140 | 141 | # internal lib name, just ignore it 142 | libtarget=libfoobar.a 143 | 144 | all: $(VER_FILE) $(BUILD_DIR)$(target) 145 | 146 | $(VER_FILE): 147 | @echo "building version..." 148 | @chmod +x $(VER_SCRIPT); sh $(VER_SCRIPT) $(VER_FILE) $(VER_MAJOR) $(VER_MINOR) $(R) 149 | 150 | # generate target, we need main.o here 151 | $(BUILD_DIR)$(target): $(BUILD_DIR)$(libtarget) main.o 152 | @$(NQ) "Generating executable file..." $(notdir $(target)) 153 | $(Q)$(CXX) $(CXXFLAGS) $^ -o $(target) $(BUILD_DIR)$(libtarget) $(LDFLAGS) 154 | @rm -rf $(BUILD_DIR)$(libtarget) 155 | 156 | $(BUILD_DIR)$(libtarget): $(OBJS) 157 | ifeq ($(suffix $(libtarget)), .so) 158 | @$(NQ) "Generating dynamic lib file..." $(notdir $(libtarget)) 159 | $(Q)$(CXX) $^ $(LDFLAGS) $(DYNC_FLAGS) -o $(libtarget) 160 | else ifeq ($(suffix $(libtarget)), .a) 161 | @$(NQ) "Generating static lib file..." $(notdir $(libtarget)) 162 | $(Q)$(AR) $(ARFLAGS) -o $(libtarget) $^ 163 | else 164 | @$(NQ) "Generating executable file..." $(notdir $(libtarget)) 165 | $(Q)$(CXX) $(LDFLAGS) $^ -o $(libtarget) 166 | endif 167 | 168 | # make all .c or .cpp 169 | $(BUILD_DIR)%.o: %.c 170 | @$(MKDIR_P) $(dir $@) 171 | @$(NQ) "Compiling: " $(addsuffix .c, $(basename $(notdir $@))) 172 | $(Q)$(CC) $(CFLAGS) -c $< -o $@ 173 | 174 | $(BUILD_DIR)%.o: %.cpp 175 | @$(MKDIR_P) $(dir $@) 176 | @$(NQ) "Compiling: " $(addsuffix .cpp, $(basename $(notdir $@))) 177 | $(Q)$(CXX) $(CXXFLAGS) -c $< -o $@ 178 | 179 | clean: 180 | @$(NQ) "Cleaning..." 181 | $(Q)$(RM) $(OBJS) $(target) $(DEPS) 182 | # delete build directory if needed 183 | ifneq ($(BUILD_DIR),) 184 | $(Q)$(RM) $(BUILD_DIR) 185 | endif 186 | # use 'grep -v soapC.o' to skip the file 187 | @find . -iname '*.o' -o -iname '*.bak' -o -iname '*.d' | xargs rm -f 188 | 189 | .PHONY: all clean 190 | 191 | -include $(DEPS) -------------------------------------------------------------------------------- /mult_dir_project_new1/bar/bar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void bar(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_bar(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | foo(200); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project_new1/crc/crc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new1/crc/crc.cpp -------------------------------------------------------------------------------- /mult_dir_project_new1/debug.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new1/debug.c -------------------------------------------------------------------------------- /mult_dir_project_new1/debug.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new1/debug.h -------------------------------------------------------------------------------- /mult_dir_project_new1/foo/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void foo(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_foo(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | bar(100); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project_new1/generate_version.sh: -------------------------------------------------------------------------------- 1 | # file name: generate_version.sh 2 | # copyleft by Late Lee 2013~2018 3 | #!/bin/sh 4 | 5 | if [ $# != 4 ] 6 | then 7 | FILENAME=version.h 8 | MAJ_VER=0 9 | MIN_VER=0 10 | RELEASE=0 11 | else 12 | FILENAME=$1 # 头文件名称 13 | MAJ_VER=$2 # 主版本号 14 | MIN_VER=$3 # 次版本号 15 | RELEASE=$4 # 是否发布版本(决定了生成的版本号内容) 16 | fi 17 | 18 | VER_FILE=$FILENAME 19 | 20 | #编译时间 21 | GEN_DATE=`date +"build: %Y-%m-%d %k:%M:%S"` 22 | 23 | # 读取Git版本号 24 | TESTGIT=`git rev-list HEAD` 25 | if [ "$TESTGIT" != "" ] 26 | then 27 | GITLOCALVER=`git rev-list HEAD --count` 28 | #echo "Git Local version:" $GITLOCALVER 29 | GIT_VER=$GITLOCALVER 30 | GIT_VER1="$(git rev-list HEAD -n 1 | cut -c 1-8)" 31 | GIT_VERSION=$GIT_VER1 32 | VB_HASGITVER=1 33 | else 34 | echo "There is no Git version control." 35 | VB_HASGITVER=0 36 | exit 37 | fi 38 | 39 | #生成版本信息文件 40 | if [ $VB_HASGITVER = 0 ] 41 | then 42 | echo "There isn't any version control." 43 | else 44 | echo "#ifndef _VERSION_H_" > $VER_FILE 45 | echo "#define _VERSION_H_" >> $VER_FILE 46 | echo "" >> $VER_FILE 47 | 48 | if [ $VB_HASGITVER = 1 ] 49 | then 50 | BUILD_VER="[$GIT_VERSION $GEN_DATE]" 51 | echo "#define VER_MAJOR $MAJ_VER" >> $VER_FILE 52 | echo "#define VER_MINOR $MIN_VER" >> $VER_FILE 53 | echo "#define VER_BUILD $GIT_VER" >> $VER_FILE 54 | if [ $RELEASE = 1 ] 55 | then 56 | echo "#define VERSION_STRING \"v$MAJ_VER.$MIN_VER.$GIT_VER\"" >> $VER_FILE 57 | else 58 | echo "#define VER_BTIME \"$BUILD_VER\"" >> $VER_FILE 59 | echo "#define VERSION_STRING \"v$MAJ_VER.$MIN_VER.$GIT_VER $BUILD_VER\"" >> $VER_FILE 60 | fi 61 | fi 62 | 63 | echo "" >> $VER_FILE 64 | echo "#endif" >> $VER_FILE 65 | fi 66 | 67 | echo "Generate " "v$MAJ_VER.$MIN_VER.$GIT_VER $BUILD_VER" 68 | echo "to file:" $VER_FILE -------------------------------------------------------------------------------- /mult_dir_project_new1/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | static void _hello(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%s\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | _hello(100); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project_new1/inc/bar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bar.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | #ifndef BAR_H_ 11 | #define BAR_H_ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | void bar(int i); 18 | int hello_bar(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /mult_dir_project_new1/inc/crc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC_H 2 | #define CRC_H 3 | 4 | typedef unsigned long u32; 5 | typedef unsigned char u8; 6 | typedef unsigned short u16; 7 | typedef unsigned long uLong; 8 | typedef char Byte; 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | u32 crc32(const u8 *buf, u32 len); 15 | u32 crc32_1(u32 crc, const u8 *buf, u32 len); 16 | u16 crc16(const u8 *buf, u32 len); 17 | u16 crc16_1(const u8 *buf, u32 len); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* CRC_H */ -------------------------------------------------------------------------------- /mult_dir_project_new1/inc/foo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file foo.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | 11 | #ifndef FOO_H_ 12 | #define FOO_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | void foo(int i); 19 | int hello_foo(void); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /mult_dir_project_new1/inc/hello.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hello.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | 11 | #ifndef HELLO_H_ 12 | #define HELLO_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | int hello(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /mult_dir_project_new1/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "hello.h" 7 | #include "debug.h" 8 | 9 | #include "version.h" 10 | 11 | static void nogood(void) 12 | { 13 | printf("no good %s.\n", "nogood"); 14 | } 15 | 16 | int main(void) 17 | { 18 | printf("hello from %s() %s.\n", __func__, VERSION_STRING); 19 | 20 | hello(); 21 | 22 | hello_foo(); 23 | hello_bar(); 24 | nogood(); 25 | ///////////////////////// 26 | int crc = 0; 27 | const char* buf = "voice from hell...."; 28 | crc = crc32((unsigned char *)buf, strlen(buf)); 29 | printf("crc: 0x%x\n", crc); 30 | dump(buf, strlen(buf)); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /mult_dir_project_new1/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new1/readme.txt -------------------------------------------------------------------------------- /mult_dir_project_new2/Makefile: -------------------------------------------------------------------------------- 1 | # (C) Copyleft 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2 | # Late Lee(li@latelee.org) from http://www.latelee.org 3 | # 4 | # A simple Makefile for *ONE* project(c or/and cpp file) in *ONE* or *MORE* directory 5 | # 6 | # note: 7 | # you can put head file(s) in 'include' directory, so it looks 8 | # a little neat. 9 | # 10 | # usage: 11 | # $ make 12 | # $ make V=1 # verbose ouput 13 | # $ make CROSS_COMPILE=arm-arago-linux-gnueabi- # cross compile for ARM, etc. 14 | # $ make debug=y # debug 15 | # 16 | # log 17 | # 2013-05-14 sth about debug... 18 | # 2016-02-29 sth for c/c++ multi diretory 19 | # 2017-04-17 -s for .a/.so if no debug 20 | # 2017-05-05 Add V for verbose ouput 21 | ############################################################################### 22 | 23 | # !!!=== cross compile... 24 | CROSS_COMPILE ?= 25 | 26 | MKDIR_P ?= mkdir -p 27 | 28 | CC = $(CROSS_COMPILE)gcc 29 | CXX = $(CROSS_COMPILE)g++ 30 | AR = $(CROSS_COMPILE)ar 31 | 32 | # !!!=== 33 | # in case all .c/.cpp need g++, specify CC=CXX... 34 | # CC = $(CXX) 35 | 36 | ARFLAGS = -cr 37 | RM = -rm -rf 38 | MAKE = make 39 | 40 | # !!!=== 41 | # target executable file or .a or .so 42 | target = a.out 43 | 44 | # !!!=== 45 | # compile flags 46 | CFLAGS += -Wall -Wfatal-errors -MMD 47 | 48 | # !!!=== pkg-config here 49 | #CFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 50 | #LDFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 51 | 52 | #**************************************************************************** 53 | # debug can be set to y to include debugging info, or n otherwise 54 | debug = y 55 | 56 | #**************************************************************************** 57 | 58 | ifeq ($(debug), y) 59 | CFLAGS += -ggdb -rdynamic 60 | else 61 | CFLAGS += -O2 -s 62 | endif 63 | 64 | # !!!=== 65 | # Macros define here 66 | DEFS += -DJIMKENT 67 | 68 | # !!! compile flags define here... 69 | CFLAGS += $(DEFS) 70 | # !!! c++ flags 71 | CXXFLAGS = $(CFLAGS) 72 | # !!! library here... 73 | LIBS += 74 | # !!! gcc/g++ link flags here 75 | LDFLAGS += $(LIBS) -lpthread -lrt 76 | 77 | # !!!=== 78 | # include head file directory here 79 | INC = ./ ./inc 80 | # or try this 81 | INC += $(shell find $(SRCS) -type d) 82 | 83 | # !!!=== 84 | # build directory 85 | BUILD_DIR ?= #./build/ 86 | 87 | # !!!=== 88 | # source file(s), including ALL c file(s) or cpp file(s) 89 | # just need the directory. 90 | SRC_DIRS = . 91 | # or try this 92 | #SRC_DIRS = . ../outbox 93 | 94 | # !!!=== 95 | # gcc/g++ compile flags 96 | CFLAGS += $(INCDIRS) 97 | CXXFLAGS += -std=c++11 98 | 99 | # dynamic library build flags 100 | DYNC_FLAGS += -fpic -shared 101 | 102 | # include directory(s) 103 | INCDIRS := $(addprefix -I, $(INC)) 104 | 105 | # source file(s) 106 | SRCS := $(shell find $(SRC_DIRS) -maxdepth 2 -name '*.cpp' -or -name '*.c') 107 | # or try this 108 | #SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c') 109 | 110 | OBJS = $(patsubst %.c,$(BUILD_DIR)%.o, $(patsubst %.cpp,$(BUILD_DIR)%.o, $(SRCS))) 111 | 112 | # depend files(.d) 113 | DEPS := $(OBJS:.o=.d) 114 | 115 | ifeq ($(V),1) 116 | Q= 117 | NQ=true 118 | else 119 | Q=@ 120 | NQ=echo 121 | endif 122 | 123 | ############################################################################### 124 | 125 | all: $(BUILD_DIR)$(target) 126 | 127 | $(BUILD_DIR)$(target): $(OBJS) 128 | 129 | ifeq ($(suffix $(target)), .so) 130 | @$(NQ) "Generating dynamic lib file..." $(notdir $(target)) 131 | $(Q)$(CXX) $^ $(LDFLAGS) $(DYNC_FLAGS) -o $(target) 132 | else ifeq ($(suffix $(target)), .a) 133 | @$(NQ) "Generating static lib file..." $(notdir $(target)) 134 | $(Q)$(AR) $(ARFLAGS) -o $(target) $^ 135 | else 136 | @$(NQ) "Generating executable file..." $(notdir $(target)) 137 | $(Q)$(CXX) $^ $(LDFLAGS) -o $(target) 138 | endif 139 | 140 | # make all .c or .cpp 141 | $(BUILD_DIR)%.o: %.c 142 | @$(MKDIR_P) $(dir $@) 143 | @$(NQ) "Compiling: " $(addsuffix .c, $(basename $(notdir $@))) 144 | $(Q)$(CC) $(CFLAGS) -c $< -o $@ 145 | 146 | $(BUILD_DIR)%.o: %.cpp 147 | @$(MKDIR_P) $(dir $@) 148 | @$(NQ) "Compiling: " $(addsuffix .cpp, $(basename $(notdir $@))) 149 | $(Q)$(CXX) $(CXXFLAGS) -c $< -o $@ 150 | 151 | clean: 152 | @$(NQ) "Cleaning..." 153 | $(Q)$(RM) $(OBJS) $(target) $(DEPS) 154 | # delete build directory if needed 155 | ifneq ($(BUILD_DIR),) 156 | $(Q)$(RM) $(BUILD_DIR) 157 | endif 158 | # use 'grep -v soapC.o' to skip the file 159 | @find . -iname '*.o' -o -iname '*.bak' -o -iname '*.d' | xargs rm -f 160 | 161 | .PHONY: all clean 162 | 163 | -include $(DEPS) 164 | -------------------------------------------------------------------------------- /mult_dir_project_new2/bar/bar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void bar(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_bar(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | foo(200); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project_new2/bar/bar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bar.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | #ifndef BAR_H_ 11 | #define BAR_H_ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | void bar(int i); 18 | int hello_bar(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /mult_dir_project_new2/crc/crc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new2/crc/crc.cpp -------------------------------------------------------------------------------- /mult_dir_project_new2/crc/crc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC_H 2 | #define CRC_H 3 | 4 | typedef unsigned long u32; 5 | typedef unsigned char u8; 6 | typedef unsigned short u16; 7 | typedef unsigned long uLong; 8 | typedef char Byte; 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | u32 crc32(const u8 *buf, u32 len); 15 | u32 crc32_1(u32 crc, const u8 *buf, u32 len); 16 | u16 crc16(const u8 *buf, u32 len); 17 | u16 crc16_1(const u8 *buf, u32 len); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* CRC_H */ -------------------------------------------------------------------------------- /mult_dir_project_new2/debug.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new2/debug.c -------------------------------------------------------------------------------- /mult_dir_project_new2/debug.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new2/debug.h -------------------------------------------------------------------------------- /mult_dir_project_new2/foo/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void foo(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_foo(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | bar(100); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project_new2/foo/foo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file foo.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | 11 | #ifndef FOO_H_ 12 | #define FOO_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | void foo(int i); 19 | int hello_foo(void); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /mult_dir_project_new2/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | static void _hello(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%s\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | _hello(100); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /mult_dir_project_new2/hello/hello.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hello.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | 11 | #ifndef HELLO_H_ 12 | #define HELLO_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | int hello(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /mult_dir_project_new2/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "hello.h" 8 | #include "debug.h" 9 | 10 | #include 11 | static void c11_test() 12 | { 13 | std::string foo = "good"; 14 | for (auto it = foo.begin(); it < foo.end(); it++) 15 | { 16 | printf("%s\n", *it); 17 | } 18 | } 19 | 20 | static void nogood(void) 21 | { 22 | printf("no good %s.\n", "nogood"); 23 | } 24 | 25 | int main(void) 26 | { 27 | printf("hello from %s().\n", __func__); 28 | 29 | hello(); 30 | 31 | hello_foo(); 32 | hello_bar(); 33 | nogood(); 34 | ///////////////////////// 35 | int crc = 0; 36 | const char* buf = "voice from hell...."; 37 | crc = crc32((unsigned char *)buf, strlen(buf)); 38 | printf("crc: 0x%x\n", crc); 39 | dump(buf, strlen(buf)); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /mult_dir_project_new2/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/mult_dir_project_new2/readme.txt -------------------------------------------------------------------------------- /one_dir_project/Makefile: -------------------------------------------------------------------------------- 1 | # (C) Copyleft 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2 | # Late Lee(li@latelee.org) from http://www.latelee.org 3 | # 4 | # A simple Makefile for *ONE* project(c or/and cpp file) in *ONE* or *MORE* directory 5 | # 6 | # note: 7 | # you can put head file(s) in 'include' directory, so it looks 8 | # a little neat. 9 | # 10 | # usage: 11 | # $ make 12 | # $ make V=1 # verbose ouput 13 | # $ make CROSS_COMPILE=arm-arago-linux-gnueabi- # cross compile for ARM, etc. 14 | # $ make debug=y # debug 15 | # 16 | # log 17 | # 2013-05-14 sth about debug... 18 | # 2016-02-29 sth for c/c++ multi diretory 19 | # 2017-04-17 -s for .a/.so if no debug 20 | # 2017-05-05 Add V for verbose ouput 21 | ############################################################################### 22 | 23 | # !!!=== cross compile... 24 | CROSS_COMPILE ?= 25 | 26 | MKDIR_P ?= mkdir -p 27 | 28 | CC = $(CROSS_COMPILE)gcc 29 | CXX = $(CROSS_COMPILE)g++ 30 | AR = $(CROSS_COMPILE)ar 31 | 32 | # !!!=== 33 | # in case all .c/.cpp need g++, specify CC=CXX... 34 | # CC = $(CXX) 35 | 36 | ARFLAGS = -cr 37 | RM = -rm -rf 38 | MAKE = make 39 | 40 | # !!!=== 41 | # target executable file or .a or .so 42 | target = a.out 43 | 44 | # !!!=== 45 | # compile flags 46 | CFLAGS += -Wall -Wfatal-errors -MMD 47 | 48 | # !!!=== pkg-config here 49 | #CFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 50 | #LDFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 51 | 52 | #**************************************************************************** 53 | # debug can be set to y to include debugging info, or n otherwise 54 | debug = y 55 | 56 | #**************************************************************************** 57 | 58 | ifeq ($(debug), y) 59 | CFLAGS += -ggdb -rdynamic 60 | else 61 | CFLAGS += -O2 -s 62 | endif 63 | 64 | # !!!=== 65 | # Macros define here 66 | DEFS += -DJIMKENT 67 | 68 | # !!! compile flags define here... 69 | CFLAGS += $(DEFS) 70 | # !!! c++ flags 71 | CXXFLAGS = $(CFLAGS) 72 | # !!! library here... 73 | LIBS += 74 | # !!! gcc/g++ link flags here 75 | LDFLAGS += $(LIBS) -lpthread -lrt 76 | 77 | # !!!=== 78 | # include head file directory here 79 | INC = ./ ./inc 80 | # or try this 81 | #INC := $(shell find $(INC) -type d) 82 | 83 | # !!!=== 84 | # build directory 85 | BUILD_DIR ?= #./build/ 86 | 87 | # !!!=== 88 | # source file(s), including ALL c file(s) or cpp file(s) 89 | # just need the directory. 90 | SRC_DIRS = . 91 | # or try this 92 | #SRC_DIRS = . ../outbox 93 | 94 | # !!!=== 95 | # gcc/g++ compile flags 96 | CFLAGS += $(INCDIRS) 97 | CXXFLAGS += -std=c++11 98 | 99 | # dynamic library build flags 100 | DYNC_FLAGS += -fpic -shared 101 | 102 | # include directory(s) 103 | INCDIRS := $(addprefix -I, $(INC)) 104 | 105 | # source file(s) 106 | SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name '*.cpp' -or -name '*.c') 107 | # or try this 108 | #SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c') 109 | 110 | OBJS = $(patsubst %.c,$(BUILD_DIR)%.o, $(patsubst %.cpp,$(BUILD_DIR)%.o, $(SRCS))) 111 | 112 | # depend files(.d) 113 | DEPS := $(OBJS:.o=.d) 114 | 115 | ifeq ($(V),1) 116 | Q= 117 | NQ=true 118 | else 119 | Q=@ 120 | NQ=echo 121 | endif 122 | 123 | ############################################################################### 124 | 125 | all: $(BUILD_DIR)$(target) 126 | 127 | $(BUILD_DIR)$(target): $(OBJS) 128 | 129 | ifeq ($(suffix $(target)), .so) 130 | @$(NQ) "Generating dynamic lib file..." $(notdir $(target)) 131 | $(Q)$(CXX) $^ $(LDFLAGS) $(DYNC_FLAGS) -o $(target) 132 | else ifeq ($(suffix $(target)), .a) 133 | @$(NQ) "Generating static lib file..." $(notdir $(target)) 134 | $(Q)$(AR) $(ARFLAGS) -o $(target) $^ 135 | else 136 | @$(NQ) "Generating executable file..." $(notdir $(target)) 137 | $(Q)$(CXX) $^ $(LDFLAGS) -o $(target) 138 | endif 139 | 140 | # make all .c or .cpp 141 | $(BUILD_DIR)%.o: %.c 142 | @$(MKDIR_P) $(dir $@) 143 | @$(NQ) "Compiling: " $(addsuffix .c, $(basename $(notdir $@))) 144 | $(Q)$(CC) $(CFLAGS) -c $< -o $@ 145 | 146 | $(BUILD_DIR)%.o: %.cpp 147 | @$(MKDIR_P) $(dir $@) 148 | @$(NQ) "Compiling: " $(addsuffix .cpp, $(basename $(notdir $@))) 149 | $(Q)$(CXX) $(CXXFLAGS) -c $< -o $@ 150 | 151 | clean: 152 | @$(NQ) "Cleaning..." 153 | $(Q)$(RM) $(OBJS) $(target) $(DEPS) 154 | # delete build directory if needed 155 | ifneq ($(BUILD_DIR),) 156 | $(Q)$(RM) $(BUILD_DIR) 157 | endif 158 | # use 'grep -v soapC.o' to skip the file 159 | @find . -iname '*.o' -o -iname '*.bak' -o -iname '*.d' | xargs rm -f 160 | 161 | .PHONY: all clean 162 | 163 | -include $(DEPS) -------------------------------------------------------------------------------- /one_dir_project/bar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void bar(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_bar(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | foo(200); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /one_dir_project/bar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bar.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | #ifndef BAR_H_ 11 | #define BAR_H_ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | void bar(int i); 18 | int hello_bar(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /one_dir_project/crc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/one_dir_project/crc.cpp -------------------------------------------------------------------------------- /one_dir_project/crc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC_H 2 | #define CRC_H 3 | 4 | typedef unsigned long u32; 5 | typedef unsigned char u8; 6 | typedef unsigned short u16; 7 | typedef unsigned long uLong; 8 | typedef char Byte; 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | u32 crc32(const u8 *buf, u32 len); 15 | u32 crc32_1(u32 crc, const u8 *buf, u32 len); 16 | u16 crc16(const u8 *buf, u32 len); 17 | u16 crc16_1(const u8 *buf, u32 len); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* CRC_H */ -------------------------------------------------------------------------------- /one_dir_project/debug.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/one_dir_project/debug.c -------------------------------------------------------------------------------- /one_dir_project/debug.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latelee/Makefile_templet/6453191dbf48dc7b33dcca423f9237e9deaa9dae/one_dir_project/debug.h -------------------------------------------------------------------------------- /one_dir_project/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void foo(int i) 6 | { 7 | printf("hell from %s() in file: %s, num:%d\n", __func__, __FILE__, i); 8 | } 9 | 10 | int hello_foo(void) 11 | { 12 | printf("in func: %s()\n", __func__); 13 | bar(100); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /one_dir_project/foo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file foo.h 3 | * @author Late Lee 4 | * @date Thu Apr 7 2011 5 | * 6 | * @brief none 7 | * 8 | * 9 | */ 10 | 11 | #ifndef FOO_H_ 12 | #define FOO_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | void foo(int i); 19 | int hello_foo(void); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /one_dir_project/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "debug.h" 7 | 8 | static void nogood(void) 9 | { 10 | printf("no good %s.\n", "nogood"); 11 | } 12 | 13 | int main(void) 14 | { 15 | printf("hello from %s().\n", __func__); 16 | hello_foo(); 17 | hello_bar(); 18 | nogood(); 19 | ///////////////////////// 20 | int crc = 0; 21 | const char* buf = "voice from hell...."; 22 | crc = crc32((unsigned char *)buf, strlen(buf)); 23 | printf("crc: 0x%x\n", crc); 24 | dump(buf, strlen(buf)); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /stm32_project/Makefile: -------------------------------------------------------------------------------- 1 | # STM32F103 Makefile模板 2 | # 参考来源: 3 | # https://github.com/andytt/stm32_template 4 | # https://github.com/latelee/Makefile_templet 5 | # 使用: 6 | # make #默认编译:调试版本,不输出详细编译过程 7 | # make debug=n # release版本,不输出详细编译过程 8 | # make V=1 # 调试版本,输出详细编译过程 9 | # make debug=n V=1 # release版本,输出详细编译过程 10 | # 11 | # 为加快编译,make可加“-j”选项。 12 | # 可能需要修改的地方使用“!!!===”标示出来 13 | # log: 14 | # 2018.12.10: 首版完成 15 | ################################################ 16 | 17 | #!!!=== 交叉编译器 18 | CROSS_COMPILE = arm-none-eabi- 19 | CC = $(CROSS_COMPILE)gcc 20 | AS = $(CROSS_COMPILE)gcc -x assembler-with-cpp 21 | CP = $(CROSS_COMPILE)objcopy 22 | AR = $(CROSS_COMPILE)ar 23 | SZ = $(CROSS_COMPILE)size 24 | HEX = $(CP) -O ihex 25 | BIN = $(CP) -O binary -S 26 | 27 | MKDIR_P ?= mkdir -p 28 | 29 | #!!!=== 目标文件名,注:下面会生成$(target).hex等文件 30 | target = target 31 | 32 | #!!!=== 是否调试版本,如是,设置为y,反之,为n 33 | debug = y 34 | 35 | #!!!=== 编译目录 36 | BUILD_DIR = build 37 | 38 | #!!!=== 头文件目录,需要一个一个列出目录名称 39 | INC = CORE FWLIB/inc HARDWARE SYSTEM USER 40 | INCDIRS := $(addprefix -I, $(INC)) 41 | 42 | ###################################### 43 | # C源码文件 44 | #注:find会递归查找项目目录所有.c文件,如c文件不必要,则要删除,否则可能会编译出错 45 | C_SOURCES = $(shell find ./ -name '*.c') 46 | 47 | #!!!=== 启动汇编文件 48 | ASM_SOURCES = startup_stm32f103xb.s 49 | # TODO:其它目录在此列出 50 | 51 | # float-abi 如不支持,则不填写 52 | FLOAT-ABI = 53 | FPU = 54 | 55 | # 目标芯片特有编译指令 56 | MCU = -mcpu=cortex-m3 -mthumb $(FPU) $(FLOAT-ABI) 57 | 58 | # c编译标志 59 | CFLAGS = $(MCU) $(DEFS) $(INCDIRS) -Wall -Wfatal-errors -MMD -fdata-sections -ffunction-sections 60 | ASFLAGS = $(CFLAGS) $(AS_DEFS) 61 | 62 | # debug或release版本选择 63 | ifeq ($(debug), y) 64 | CFLAGS += -g -gdwarf-2 65 | else 66 | CFLAGS += -O2 -s # 或者-Og 67 | endif 68 | 69 | # AS宏定义 70 | AS_DEFS = 71 | 72 | #!!!=== C宏定义 73 | DEFS_STR += STM32F103X_MD USE_STDPERIPH_DRIVER 74 | DEFS := $(addprefix -D, $(DEFS_STR)) 75 | 76 | #!!!=== 链接脚本文件 77 | LDSCRIPT = STM32F103R8Tx_FLASH.ld 78 | 79 | #!!!=== 静态库名称 80 | LIBS = -lc -lm -lnosys 81 | # 其它库目录 82 | LIBDIR = 83 | # 链接标志 84 | LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) \ 85 | -Wl,-Map=$(BUILD_DIR)/$(target).map,--cref -Wl,--gc-sections 86 | 87 | ifeq ($(V),1) 88 | Q= 89 | NQ=true 90 | else 91 | Q=@ 92 | NQ=echo 93 | endif 94 | 95 | # default action: build all 96 | all: $(BUILD_DIR)/$(target).elf $(BUILD_DIR)/$(target).hex $(BUILD_DIR)/$(target).bin 97 | 98 | ####################################### 99 | ## 目标文件规则(由.c .s产生.o的规则) 100 | OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) 101 | vpath %.c $(sort $(dir $(C_SOURCES))) 102 | OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) 103 | vpath %.s $(sort $(dir $(ASM_SOURCES))) 104 | 105 | DEPS := $(OBJECTS:.o=.d) 106 | 107 | # 编译.c .s文件 108 | $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 109 | @$(NQ) "Compiling: " $(basename $(notdir $@)).c 110 | $(Q)$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ 111 | 112 | $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) 113 | @$(NQ) "Compiling: " $(basename $(notdir $@)).s 114 | $(Q)$(AS) -c $(CFLAGS) $< -o $@ 115 | 116 | # 生成elf hex bin文件 117 | $(BUILD_DIR)/$(target).elf: $(OBJECTS) Makefile 118 | @$(NQ) "Generating elf file..." $(notdir $@) 119 | $(Q)$(CC) $(OBJECTS) $(LDFLAGS) -o $@ 120 | $(SZ) $@ 121 | 122 | $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) 123 | @$(NQ) "Generating hex file..." $(notdir $@) 124 | $(Q)$(HEX) $< $@ 125 | $(Q)mv $@ . 126 | 127 | $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) 128 | @$(NQ) "Generating bin file..." $(notdir $@) 129 | $(Q)$(BIN) $< $@ 130 | $(Q)mv $@ . 131 | 132 | $(BUILD_DIR): 133 | mkdir $@ 134 | 135 | ## 清理文件 136 | clean: 137 | -rm -fR .dep $(BUILD_DIR) 138 | @find . -iname '*.o' -o -iname '*.bak' -o -iname '*.d' | xargs rm -f 139 | 140 | ## 烧录命令 141 | flash: 142 | st-flash write $(BUILD_DIR)/$(target).bin 0x8000000 143 | ## 擦除命令 144 | erase: 145 | st-flash erase 146 | 147 | .PHONY: all clean flash erase 148 | 149 | ## 依赖文件 150 | -include $(DEPS) 151 | -------------------------------------------------------------------------------- /stm32_project/Makefile_my: -------------------------------------------------------------------------------- 1 | # (C) Copyleft 2011 2012 2013 2014 2015 2016 2017 2018 2 | # Late Lee(li@latelee.org) from http://www.latelee.org 3 | # 4 | # A simple Makefile for *ONE* project(c or/and cpp file) in *ONE* or *MORE* directory 5 | # 6 | # note: 7 | # you can put head file(s) in 'include' directory, so it looks 8 | # a little neat. 9 | # 10 | # usage: 11 | # $ make 12 | # $ make V=1 # verbose ouput 13 | # $ make CROSS_COMPILE=arm-arago-linux-gnueabi- # cross compile for ARM, etc. 14 | # $ make debug=y # debug 15 | # 16 | # log 17 | # 2013-05-14 sth about debug... 18 | # 2016-02-29 sth for c/c++ multi diretory 19 | # 2017-04-17 -s for .a/.so if no debug 20 | # 2017-05-05 Add V for verbose ouput 21 | ############################################################################### 22 | 23 | # !!!=== cross compile... 24 | CROSS_COMPILE ?= arm-none-eabi- 25 | 26 | MKDIR_P ?= mkdir -p 27 | 28 | CC = $(CROSS_COMPILE)gcc 29 | CXX = $(CROSS_COMPILE)gcc 30 | AR = $(CROSS_COMPILE)ar 31 | AS = $(CROSS_COMPILE)gcc -x assembler-with-cpp 32 | CP = $(CROSS_COMPILE)objcopy 33 | SZ = $(CROSS_COMPILE)size 34 | HEX = $(CP) -O ihex 35 | BIN = $(CP) -O binary -S 36 | 37 | # !!!=== 38 | # in case all .c/.cpp need g++... 39 | # CC = $(CXX) 40 | 41 | ARFLAGS = -cr 42 | RM = -rm -rf 43 | MAKE = make 44 | 45 | MCU = -mcpu=cortex-m3 -mthumb $(FPU) $(FLOAT-ABI) 46 | CFLAGS = $(MCU) -Wall -fdata-sections -ffunction-sections 47 | ASFLAGS = $(CFLAGS) 48 | LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(target).map,--cref -Wl,--gc-sections 49 | DEFS = 50 | LIBS = -lc -lm -lnosys 51 | 52 | # link script 53 | LDSCRIPT = STM32F103R8Tx_FLASH.ld 54 | 55 | # !!!=== 56 | # target executable file or .a or .so 57 | target = out 58 | 59 | # !!!=== 60 | # compile flags 61 | CFLAGS += -Wall -Wfatal-errors -MMD 62 | 63 | # !!!=== pkg-config here 64 | #CFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 65 | #LDFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib) 66 | 67 | #**************************************************************************** 68 | # debug can be set to y to include debugging info, or n otherwise 69 | debug = y 70 | 71 | #**************************************************************************** 72 | 73 | ifeq ($(debug), y) 74 | CFLAGS += -g -gdwarf-2 75 | else 76 | CFLAGS += -O2 -s 77 | endif 78 | 79 | # !!!=== 80 | # Macros define here 81 | DEFS_STR += STM32F103X_MD USE_STDPERIPH_DRIVER 82 | DEFS := $(addprefix -D, $(DEFS_STR)) 83 | CFLAGS += $(DEFS) 84 | CXXFLAGS = $(CFLAGS) 85 | 86 | LIBS += 87 | 88 | LDFLAGS += $(LIBS) 89 | 90 | # !!!=== 91 | # include head file directory here 92 | INC = CORE FWLIB/inc HARDWARE SYSTEM USER 93 | # or try this 94 | #INC := $(shell find $(INC) -type d) 95 | 96 | # !!!=== 97 | # build directory 98 | BUILD_DIR ?= #./build/ 99 | 100 | # !!!=== 101 | # source file(s), including ALL c file(s) or cpp file(s) 102 | # just need the directory. 103 | SRC_DIRS = CORE FWLIB/src HARDWARE SYSTEM USER 104 | # or try this 105 | #SRC_DIRS = ./ 106 | #SRC_DIRS += ../outbox 107 | 108 | # !!!=== 109 | # gcc/g++ compile flags 110 | CFLAGS += $(INCDIRS) 111 | CXXFLAGS += 112 | 113 | # !!!=== 114 | # gcc/g++ link flags 115 | LDFLAGS += #-lpthread -lrt 116 | 117 | DYNC_FLAGS += #-fpic -shared 118 | 119 | INCDIRS := $(addprefix -I, $(INC)) 120 | 121 | #SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name '*.cpp' -or -name '*.c' | grep -v main.cpp) 122 | SRCS := $(shell find ./ -name '*.s' -or -name '*.c' | grep -v main.c) 123 | 124 | OBJS = $(patsubst %.c,$(BUILD_DIR)%.o, $(patsubst %.s,$(BUILD_DIR)%.o, $(SRCS))) 125 | 126 | DEPS := $(OBJS:.o=.d) 127 | 128 | ifeq ($(V),1) 129 | Q= 130 | NQ=true 131 | else 132 | Q=@ 133 | NQ=echo 134 | endif 135 | 136 | ############################################################################### 137 | 138 | # internal lib name, just ignore it 139 | libtarget=libfoobar.a 140 | 141 | all: $(BUILD_DIR)$(target).elf 142 | 143 | # generate target, we need main.o here 144 | $(BUILD_DIR)$(target): $(BUILD_DIR)$(libtarget) USER/main.o 145 | 146 | @$(NQ) "Generating executable file..." $(notdir $(target)) 147 | $(Q)$(CXX) $(CXXFLAGS) $^ -o $(BUILD_DIR)$(target) $(BUILD_DIR)$(libtarget) $(LDFLAGS) 148 | $(SZ) $@ 149 | @rm -rf $(BUILD_DIR)$(libtarget) 150 | 151 | $(BUILD_DIR)$(libtarget): $(OBJS) 152 | ifeq ($(suffix $(libtarget)), .so) 153 | @$(NQ) "Generating dynamic lib file..." $(notdir $(libtarget)) 154 | $(Q)$(CXX) $(CXXFLAGS) $^ -o $(libtarget) $(LDFLAGS) $(DYNC_FLAGS) 155 | else ifeq ($(suffix $(libtarget)), .a) 156 | @$(NQ) "Generating static lib file..." $(notdir $(libtarget)) 157 | $(Q)$(AR) $(ARFLAGS) -o $(libtarget) $^ 158 | else 159 | @$(NQ) "Generating executable file..." $(notdir $(libtarget)) 160 | $(Q)$(CXX) $(CXXFLAGS) $^ -o $(libtarget) $(LDFLAGS) 161 | endif 162 | 163 | 164 | # make all .c or .s 165 | $(BUILD_DIR)%.o: %.s 166 | @$(MKDIR_P) $(dir $@) 167 | @$(NQ) "Compiling: " $(basename $(notdir $@)).s 168 | $(Q)$(AS) $(CFLAGS) -c $< -o $@ 169 | 170 | $(BUILD_DIR)%.o: %.c 171 | @$(MKDIR_P) $(dir $@) 172 | @$(NQ) "Compiling: " $(basename $(notdir $@)).c 173 | $(Q)$(CC) $(CFLAGS) -c $< -o $@ 174 | 175 | clean: 176 | @$(NQ) "Cleaning..." 177 | $(Q)$(RM) $(OBJS) $(target) $(DEPS) 178 | # delete build directory if needed 179 | ifneq ($(BUILD_DIR),) 180 | $(Q)$(RM) $(BUILD_DIR) 181 | endif 182 | # use 'grep -v soapC.o' to skip the file 183 | @find . -iname '*.o' -o -iname '*.bak' -o -iname '*.d' | xargs rm -f 184 | 185 | .PHONY: all clean 186 | 187 | -include $(DEPS) --------------------------------------------------------------------------------