From b5d4ff64a9011f378524912262535f8f61bc58bc Mon Sep 17 00:00:00 2001 From: impressionyang <31137790+impressionyang@users.noreply.github.com> Date: Sat, 27 Jan 2024 15:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=93=8D=E4=BD=9C=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=92=8C=E6=A3=80=E6=B5=8B=E5=92=8C=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E5=A4=84=E7=90=86=20=E6=B7=BB=E5=8A=A0=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=B7=AF=E5=BE=84=E6=97=B6call=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=9A=84=E6=8D=A2=E8=A1=8C=E9=97=AE=E9=A2=98=E5=AF=BC?= =?UTF-8?q?=E8=87=B4Linux=E4=B8=8B=E7=BC=96=E8=AF=91=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加操作系统和检测和区分处理 添加去除重复路径时call增加的换行问题导致Linux下编译异常 --- Makefile | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 9744346..fe12c5f 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,34 @@ # lazy build C project Makefiles by impressionyang # user config values -CC="E:\\impressionyang\\scoop\\apps\\mingw\\12.2.0\\bin\\gcc.exe" +CC="/usr/bin/gcc" +# CC="E:\\impressionyang\\scoop\\apps\\mingw\\12.2.0\\bin\\gcc.exe" PROJECT=test +# 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 -# define func to remove_same_str +# define func to remove_same_str for debug: $(info get seen ${seen}) define remove_same_str = $(eval seen :=) - $(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_))) + $(foreach _,$1,$(if $(filter $_,${seen}),,$(if $_, $(eval seen += $_)))) ${seen} endef @@ -27,7 +44,9 @@ HEADERS := $(HEADERS:$(LOCAL_PATH)/%=%) # fillter out all include path FIND_ALL_FILES_DIR := $(dir $(foreach files_path,$(FILES_PATH), $(call rwildcard,$(files_path),*/) ) ) -INC_DIRS := $(call remove_same_str,$(FIND_ALL_FILES_DIR)) +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)) @@ -46,5 +65,13 @@ all : # virtual clean job .PHONY : clean clean: - $(warning "remove some files but it may not exist because the OS different") - rm $(PROJECT).exe $(PROJECT) +ifeq ($(OS_TYPE), WINDOWS) + del $(PROJECT).exe +endif +ifeq ($(OS_TYPE), LINUX) + rm $(PROJECT) +endif +ifeq ($(OS_TYPE), OSX) + rm $(PROJECT) +endif +