Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
825 views
in Technique[技术] by (71.8m points)

makefile removing uname command

I want to just run make in windows cmd. Goal is just that i can run make in default windows CMD without that i need run make inside MSYSY or CYGWIN.

When i run make command inside windows cmd it shows message: 'uname' is not recognized as an internal or external command, operable program or batch file. process_begin: CreateProcess(NULL, uname -m, ...) failed.

   ####################################################################
# Makefile
#
# OS variable must either be 'posix' or 'win'. E.g. 'make OS=posix'.
# Error is thrown if OS variable is not equal with any of these.
#
####################################################################

.SUFFIXES:              # ignore builtin rules
.PHONY: all debug release clean export

####################################################################
# Definitions                                                      #
####################################################################

# uniq is a function which removes duplicate elements from a list
uniq = $(strip $(if $1,$(firstword $1) 
       $(call uniq,$(filter-out $(firstword $1),$1))))

PROJECTNAME = projectoutput
CONFIG ?= default
SDK_DIR = ../../../..
OBJ_DIR = obj
EXE_DIR = exe
LST_DIR = lst
EXPORT_DIR = export

RTL_DIR = $(SDK_DIR)/util


####################################################################
# Definitions of toolchain.                                        #
# You might need to do changes to match your system setup          #
####################################################################

RMDIRS     := rm -rf
RMFILES    := rm -rf
ALLFILES   := /*.*
NULLDEVICE := /dev/null
SHELLNAMES := $(ComSpec)$(COMSPEC)
UNAME      := $(shell uname | tr '[:upper:]' '[:lower:]')
DEVICE     := x64
ifneq ($(filter arm%, $(shell uname -m)),)
DEVICE     := cortexa
endif

ifeq (export,$(findstring export, $(MAKECMDGOALS)))
  # Set the default OS for exporting if not specified externally
  ifeq (,$(filter $(OS),posix win))
    OS:=posix
  endif
else
  # Try autodetecting the environment: Windows
  ifneq ($(SHELLNAMES),)
    QUOTE :="
    ifeq (,$(filter $(OS),posix win))
      OS:=win
    endif
    ifneq ($(COMSPEC),)
      ifeq ($(findstring cygdrive,$(shell set)),)
        # We were not on a cygwin platform
        NULLDEVICE := NUL
      endif
    else
      # Assume we are making on a Windows platform
      # This is a convenient place to override TOOLDIR, DO NOT add trailing
      # whitespace chars, they do matter !
      SHELL      := $(SHELLNAMES)
      RMDIRS     := rd /s /q
      RMFILES    := del /s /q
      ALLFILES   := *.*
      NULLDEVICE := NUL
    endif
  # Other than Windows
  else
    ifeq (,$(filter $(OS),posix win))
      OS:=posix
    endif
  endif
endif

# Create directories and do a clean which is compatible with parallell make
$(shell mkdir $(OBJ_DIR)>$(NULLDEVICE) 2>&1)
$(shell mkdir $(EXE_DIR)>$(NULLDEVICE) 2>&1)
$(shell mkdir $(LST_DIR)>$(NULLDEVICE) 2>&1)
ifeq (clean,$(findstring clean, $(MAKECMDGOALS)))
  ifneq ($(filter $(MAKECMDGOALS),all debug release),)
    $(shell $(RMFILES) $(OBJ_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
    $(shell $(RMFILES) $(EXE_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
    $(shell $(RMFILES) $(LST_DIR)$(ALLFILES)>$(NULLDEVICE) 2>&1)
  endif
endif

ifeq ($(OS),posix)
CC = gcc
LD = ld
AR = ar
else
CC = x86_64-w64-mingw32-gcc
LD = x86_64-w64-mingw32-ld
AR = x86_64-w64-mingw32-ar
endif


####################################################################
# Flags                                                            #
####################################################################

INCLUDEPATHS += . 
$(SDK_DIR)/app/common_host/uart 
$(SDK_DIR)/app/common_host/tcp 
$(SDK_DIR)/app/common_host/system 
$(SDK_DIR)/app/common_host/app_assert 
$(SDK_DIR)/app/common_host/app_signal 
$(SDK_DIR)/app/common_host/log 
$(SDK_DIR)/app/common_host/log/config 



INCFLAGS = $(addprefix -I, $(INCLUDEPATHS))



# -MMD : Don't generate dependencies on system header files.
# -MP  : Add phony targets, useful when a h-file is removed from a project.
# -MF  : Specify a file to write the dependencies to.
DEPFLAGS = 
-MMD 
-MP 
-MF $(@:.o=.d)

# Add -Wa,-ahld=$(LST_DIR)/$(@F:.o=.lst) to CFLAGS to produce assembly list files
override CFLAGS += 
-fno-short-enums 
-Wall 
-c 
-fmessage-length=0 
-std=c99 
$(DEPFLAGS)

# Linux platform: if _DEFAULT_SOURCE is defined, the default is to have _POSIX_SOURCE set to one
# and _POSIX_C_SOURCE set to 200809L, as well as enabling miscellaneous functions from BSD and SVID.
# See usr/include/fetures.h for more information.
# 
# _BSD_SOURCE (deprecated since glibc 2.20)
# Defining this macro with any value causes header files to expose BSD-derived definitions.
# In glibc versions up to and including 2.18, defining this macro also causes BSD definitions to be
# preferred in some situations where standards conflict, unless one or more of _SVID_SOURCE,
# _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE, _XOPEN_SOURCE_EXTENDED, or _GNU_SOURCE is defined,
# in which case BSD definitions are disfavored. Since glibc 2.19, _BSD_SOURCE no longer causes BSD
# definitions to be preferred in case of conflicts. Since glibc 2.20, this macro is deprecated. 
# It now has the same effect as defining _DEFAULT_SOURCE, but generates a compile-time warning
# (unless _DEFAULT_SOURCE is also defined). Use _DEFAULT_SOURCE instead.
# To allow code that requires _BSD_SOURCE in glibc 2.19 and earlier and _DEFAULT_SOURCE in glibc
# 2.20 and later to compile without warnings, define both _BSD_SOURCE and _DEFAULT_SOURCE.
#
# OSX platform: _DEFAULT_SOURCE is not used, instead _DARWIN_C_SOURCE is defined by default.
ifeq ($(OS),posix)
override CFLAGS += 
-D_DEFAULT_SOURCE 
-D_BSD_SOURCE
endif

# NOTE: The -Wl,--gc-sections flag may interfere with debugging using gdb.
ifeq ($(OS),posix)
override LDFLAGS += 
-L$(RTL_DIR)/lib/$(UNAME)_$(DEVICE)/gcc/release 
-lstdc++ 
-lpthread 
-lm
else
override LDFLAGS += 
-static 
-lstdc++ 
-lpthread 
-lWs2_32
endif


####################################################################
# Files                                                            #
####################################################################

C_SRC +=  
$(SDK_DIR)/app/common_host/system/system.c 

$(SDK_DIR)/app/common_host/app_signal/app_signal_$(OS).c 
app.c 
loc.c 
conn.c 
main.c




# this file should be the last added
C_SRC += 
$(SDK_DIR)/app/common/uart/uart_$(OS).c 




# Project resources
INC_FILES = $(foreach dir,$(INCLUDEPATHS),$(wildcard $(dir)/*.h))
PROJ_FILES = $(C_SRC) $(INC_FILES) $(RTL_DIR)/lib makefile
DST_DIR = $(EXPORT_DIR)/app/$(PROJECTNAME)/
DST_FILES := $(addprefix $(DST_DIR), $(PROJ_FILES))


####################################################################
# Rules                                                            #
####################################################################

C_FILES = $(notdir $(C_SRC) )
#make list of source paths, uniq removes duplicate paths
C_PATHS = $(call uniq, $(dir $(C_SRC) ) )

C_OBJS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.o))
C_DEPS = $(addprefix $(OBJ_DIR)/, $(C_FILES:.c=.d))
OBJS = $(C_OBJS)

vpath %.c $(C_PATHS)

# Default build is debug build
all:      debug

debug:    CFLAGS += -O0 -g3
debug:    $(EXE_DIR)/$(PROJECTNAME)

release:  $(EXE_DIR)/$(PROJECTNAME)


# Create objects from C SRC files
$(OBJ_DIR)/%.o: %.c
    @echo "Building file: $<"
    $(CC) $(CFLAGS) $(INCFLAGS) -c -o $@ $<

# Link
$(EXE_DIR)/$(PROJECTNAME): $(OBJS) 
    @echo "Linking target: $@"
    $(CC) $^ $(LDFLAGS) -o $@



clean:
ifeq ($(filter $(MAKECMDGOALS),all debug release),)
    $(RMDIRS) $(OBJ_DIR) $(LST_DIR) $(EXE_DIR) $(EXPORT_DIR)
endif

# Collect project files for exporting
$(DST_FILES) : $(addprefix $(DST_DIR), %) : %
    @mkdir -p $(dir $@) && cp -pRv $< $@

export: $(DST_FILES)
    @echo "Exporting done."

# include auto-generated dependency files (explicit rules)
ifneq (clean,$(findstring clean, $(MAKECMDGOALS)))
-include $(C_DEPS)
endif
question from:https://stackoverflow.com/questions/65924174/makefile-removing-uname-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Look here:

UNAME      := $(shell uname | tr '[:upper:]' '[:lower:]')

You run $(shell uname ...). That starts a shell and runs the command given. If you run make so that it uses cmd.exe as its shell without msys or Cygwin, then it's as if you typed uname | tr '[:upper:]' '[:lower:]' at your cmd.exe prompt, which obviously will fail as you've seen.

If you want to avoid msys or Cygwin then you have to fix ALL of your makefile to not use any POSIX commands, including here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...