From 3bbbb7a9b1eec9b835e26e1b4a4a7886476ba584 Mon Sep 17 00:00:00 2001 From: impressionyang Date: Wed, 21 Aug 2024 11:07:49 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E2=9C=A8=20first=20add=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ Makefile | 83 ++++++++++++++++++++++++++++++ main.c | 9 ++++ test_funcs/README.md | 0 test_funcs/test_funcs.h | 47 +++++++++++++++++ test_funcs/test_hello_word/hello.c | 7 +++ 6 files changed, 149 insertions(+) create mode 100644 Makefile create mode 100644 main.c create mode 100644 test_funcs/README.md create mode 100644 test_funcs/test_funcs.h create mode 100644 test_funcs/test_hello_word/hello.c diff --git a/.gitignore b/.gitignore index acf5dd9..6368606 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,6 @@ dkms.conf *.out *.app + +.vscode/ +build/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ddac678 --- /dev/null +++ b/Makefile @@ -0,0 +1,83 @@ +# lazy build C project Makefiles by impressionyang +# user config values +CC="/usr/bin/gcc" +# CC="E:\\impressionyang\\scoop\\apps\\mingw\\12.2.0\\bin\\gcc.exe" +PROJECT=test +BUILD_DIR=build + +# check operating system type +ifeq ($(OS), Windows_NT) + OS_TYPE := WINDOWS + SHELL := cmd +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + OS_TYPE := LINUX + endif + ifeq ($(UNAME_S),Darwin) + OS_TYPE := OSX + endif +endif + +$(info OS type = $(OS_TYPE)) + +# patern config +FILES_PATH := ./ +SRC_FILES_SUFFIX := %.c +HDR_FILES_SUFFIX := %.h + +# add build flags +CFLAGS += -fdiagnostics-color=always -g +CFLAGS += -lm + +# define func to remove_same_str for debug: $(info get seen ${seen}) +define remove_same_str = + $(eval seen :=) + $(foreach _,$1,$(if $(filter $_,${seen}),,$(if $_, $(eval seen += $_)))) + ${seen} +endef + +# find recursive all files +rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2)) + +# get source file and header file +FIND_ALL_FILES := $(foreach files_path,$(FILES_PATH), $(call rwildcard,$(files_path),*.*) ) +SOURCES := $(filter $(SRC_FILES_SUFFIX),$(FIND_ALL_FILES)) +SOURCES := $(SOURCES:$(LOCAL_PATH)/%=%) +HEADERS := $(filter $(HDR_FILES_SUFFIX),$(FIND_ALL_FILES)) +HEADERS := $(HEADERS:$(LOCAL_PATH)/%=%) + +# fillter out all include path +FIND_ALL_FILES_DIR := $(dir $(foreach files_path,$(FILES_PATH), $(call rwildcard,$(files_path),*/) ) ) +GET_INC_DIRS := $(call remove_same_str,$(FIND_ALL_FILES_DIR)) +INC_DIRS := +INC_DIRS += $(foreach v, $(GET_INC_DIRS), $(if $(filter %/,$v) , $(eval INC_DIRS+=$v), )) +INC_DIRS := $(subst ./, -I./, $(INC_DIRS)) +INC_DIRS := $(wordlist 1, $(words $(INC_DIRS)), $(INC_DIRS)) + +# debug print info, no need to be change +# $(info "INC_DIRS") +# $(info $(INC_DIRS)) +# $(info "HEADERS") +# $(info $(HEADERS)) +# $(info "SOURCES") +# $(info $(SOURCES)) + +# compile job +all : + mkdir -p $(BUILD_DIR) + $(CC) $(CFLAGS) $(SOURCES) $(HEADERS) $(INC_DIRS) -o $(BUILD_DIR)/$(PROJECT) + +# virtual clean job +.PHONY : clean +clean: +ifeq ($(OS_TYPE), WINDOWS) + del $(PROJECT).exe +endif +ifeq ($(OS_TYPE), LINUX) + rm $(PROJECT) +endif +ifeq ($(OS_TYPE), OSX) + rm $(PROJECT) +endif + diff --git a/main.c b/main.c new file mode 100644 index 0000000..c3a1df3 --- /dev/null +++ b/main.c @@ -0,0 +1,9 @@ +#include "test_funcs.h" +#include + +int main(int argc, char const *argv[]) +{ + printf("start c test\r\n"); + hello(); + return 0; +} diff --git a/test_funcs/README.md b/test_funcs/README.md new file mode 100644 index 0000000..e69de29 diff --git a/test_funcs/test_funcs.h b/test_funcs/test_funcs.h new file mode 100644 index 0000000..f230d94 --- /dev/null +++ b/test_funcs/test_funcs.h @@ -0,0 +1,47 @@ +/** + * @file test_funcs.h + * @author Alvin Young (impressionyang@outlook.com) + * @brief + * @version 0.1 + * @date 2024-08-21 + * + * _ _ + * (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _ + * / / ' \/ _ \/ __/ -_|_-<(_- + * Date Version Author Description + * 2024-08-21 v1.0 Alvin Young 首次创建 + * + * + */ +/* Define to prevent recursive inclusion -------------------------------------*/ + +#ifndef __TEST_FUNCS_H__ +#define __TEST_FUNCS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +/* define --------------------------------------------------------------------*/ +/* typedef -------------------------------------------------------------------*/ +/* variables -----------------------------------------------------------------*/ +/* Private function(only *.c) -----------------------------------------------*/ +/* Exported functions --------------------------------------------------------*/ + +void hello(); + +#ifdef __cplusplus +} +#endif +#endif //__TEST_FUNCS_H__ + +/* + * EOF + */ \ No newline at end of file diff --git a/test_funcs/test_hello_word/hello.c b/test_funcs/test_hello_word/hello.c new file mode 100644 index 0000000..285dbb2 --- /dev/null +++ b/test_funcs/test_hello_word/hello.c @@ -0,0 +1,7 @@ +#include +#include "test_funcs.h" + +void hello() +{ + printf("Hello World!\r\n"); +} \ No newline at end of file