如何正确识别构建平台?

时间:2022-09-11 16:35:22

I want to know a parameter which is an indicator of the current OS. If am supporting Windows and Linux, how can I get a system parameter which differentiates the OS types. This for an OS independent makefile which runs both in Windows and Linux by checking the parameter in an 'if'.

我想知道一个参数,它是当前操作系统的指标。如果支持Windows和Linux,我如何获得区分操作系统类型的系统参数。这适用于OS独立的makefile,它通过检查'if'中的参数在Windows和Linux中运行。

2 个解决方案

#1


In the past I've checked the value of the environment variable OS. This is set on Windows. For other platforms I've explicitly set it in the environment. This then lets you push platform specific settings into makefiles called ...

在过去,我检查了环境变量OS的值。这是在Windows上设置的。对于其他平台,我已在环境中明确设置它。然后,您可以将特定于平台的设置推送到名为的makefile中......

makefile.Windows_NT
makefile.Linux
makefile.HPUX

In my main makefile I then just do

在我的主要makefile中,我就是这么做的

SUPPORTED_PLATFORMS=Windows_NT AIX AIX32 Solaris8 Linux HPUX Solaris_64

ifeq (,$(findstring $(OS),$(SUPPORTED_PLATFORMS)))

all %:
        @echo The OS environment variable is set to [$(OS)].
        @echo Please set the OS environment variable to one of the following:
        @echo $(SUPPORTED_PLATFORMS)

else


include makefile.$(OS)


all:
        @$(TCLSH) makefile.tcl
        @$(MAKE) -f makefile.gen


clean:
        @$(TCLSH) makefile.tcl
        @$(MAKE) -f makefile.gen clean
        @$(RM) makefile.gen

etags:
        @$(RM) TAGS
        @etags *.cpp *.h TAGS
        @$(MAKE) -C Core etags
        @$(MAKE) -C Components etags
        @$(MAKE) -C Repository etags

tags: ctags

ctags:
        @ctags *.h
        @$(MAKE) -C Core ctags
        @$(MAKE) -C Components ctags
        @$(MAKE) -C Repository ctags

lint:
        @$(TCLSH) makefile.tcl
        @$(MAKE) -f makefile.gen lint

depends:
        @$(TCLSH) makefile.tcl
        @$(MAKE) -f makefile.gen depends

endif

This all works because I can pull in the platform specific settings via makefile.$(OS)

这一切都有效,因为我可以通过makefile引入特定于平台的设置。$(OS)

That's the sum total of my main makefile and it compiles for seven different platforms. You could make the detection cleverer but that would reduce comprehensability.

这是我的主要makefile的总和,它编译七个不同的平台。你可以使检测更聪明,但这会降低可理解性。

In each makefile.WHATEVER I provide definitions of things like

在每个makefile.WHATEVER我提供的事情的定义

#*******************************************************************************
#
#   Platform specific tools
#
CC              = CL
RM              = rm
LINK            = LINK
ETAGS           = c:\emacs\bin\etags
TCLSH           = tclsh83

#*******************************************************************************
#
#   Platform specific CC definitions
#
INCLUDE := $(SYS_INCDIR);$(INCLUDE);$(SOURCE_ROOT_DIR)/SivTech/cpp;$(ORACLE_INCDIR);$(DB2_INCDIR);$(ODBC_INCDIR);$(MYSQL_INCDIR);$(TCL_INCDIR);$(XML_INCDIR);$(XSLT_INCDIR);$(JNI_INCLUDE);$(ACE_INCDIR);$(TAO_INCDIR);$(TAO_SERVICES_INC);$(CPPUNIT_INCDIR);$(ICU_INCDIR);$(SAP_INCDIR);$(QAS_INCDIR);$(INFA_INCDIR);$(MELISSADATA_INCDIR);$(ADDRESSDOCTOR_INCDIR)

CC_DEFS := $(CC_DEFS) -DOS_WIN_95 -D_WIN32_WINNT=0x400 -D_MBCS -DWIN32_LEAN_AND_MEAN -DWIN32 -DWIN32_EXTRA_LEAN $(CC_DEFINES)

CC_FLAGS_CMN    := /c /nologo /G7  /EHsc /W3  $(CC_FLAGS$) $(CC_DEFS) $(MYFLAGS)
CC_FLAGS_DBG    := $(CC_FLAGS_CMN) /Gi /MDd /Od /Zi /RTCu /RTCs /GZ

Obviously this is quite a C/C++ focus makefile but it proves that you can abstract away all of the platform specifics.

显然这是一个相当C / C ++焦点的makefile,但它证明你可以抽象出所有平台细节。

Chris

#2


You may be interested in checking out: Pre-defined C/C++ Compiler Macros. It's a goldmine.

您可能有兴趣查看:预定义的C / C ++编译器宏。这是一个金矿。

#1


In the past I've checked the value of the environment variable OS. This is set on Windows. For other platforms I've explicitly set it in the environment. This then lets you push platform specific settings into makefiles called ...

在过去,我检查了环境变量OS的值。这是在Windows上设置的。对于其他平台,我已在环境中明确设置它。然后,您可以将特定于平台的设置推送到名为的makefile中......

makefile.Windows_NT
makefile.Linux
makefile.HPUX

In my main makefile I then just do

在我的主要makefile中,我就是这么做的

SUPPORTED_PLATFORMS=Windows_NT AIX AIX32 Solaris8 Linux HPUX Solaris_64

ifeq (,$(findstring $(OS),$(SUPPORTED_PLATFORMS)))

all %:
        @echo The OS environment variable is set to [$(OS)].
        @echo Please set the OS environment variable to one of the following:
        @echo $(SUPPORTED_PLATFORMS)

else


include makefile.$(OS)


all:
        @$(TCLSH) makefile.tcl
        @$(MAKE) -f makefile.gen


clean:
        @$(TCLSH) makefile.tcl
        @$(MAKE) -f makefile.gen clean
        @$(RM) makefile.gen

etags:
        @$(RM) TAGS
        @etags *.cpp *.h TAGS
        @$(MAKE) -C Core etags
        @$(MAKE) -C Components etags
        @$(MAKE) -C Repository etags

tags: ctags

ctags:
        @ctags *.h
        @$(MAKE) -C Core ctags
        @$(MAKE) -C Components ctags
        @$(MAKE) -C Repository ctags

lint:
        @$(TCLSH) makefile.tcl
        @$(MAKE) -f makefile.gen lint

depends:
        @$(TCLSH) makefile.tcl
        @$(MAKE) -f makefile.gen depends

endif

This all works because I can pull in the platform specific settings via makefile.$(OS)

这一切都有效,因为我可以通过makefile引入特定于平台的设置。$(OS)

That's the sum total of my main makefile and it compiles for seven different platforms. You could make the detection cleverer but that would reduce comprehensability.

这是我的主要makefile的总和,它编译七个不同的平台。你可以使检测更聪明,但这会降低可理解性。

In each makefile.WHATEVER I provide definitions of things like

在每个makefile.WHATEVER我提供的事情的定义

#*******************************************************************************
#
#   Platform specific tools
#
CC              = CL
RM              = rm
LINK            = LINK
ETAGS           = c:\emacs\bin\etags
TCLSH           = tclsh83

#*******************************************************************************
#
#   Platform specific CC definitions
#
INCLUDE := $(SYS_INCDIR);$(INCLUDE);$(SOURCE_ROOT_DIR)/SivTech/cpp;$(ORACLE_INCDIR);$(DB2_INCDIR);$(ODBC_INCDIR);$(MYSQL_INCDIR);$(TCL_INCDIR);$(XML_INCDIR);$(XSLT_INCDIR);$(JNI_INCLUDE);$(ACE_INCDIR);$(TAO_INCDIR);$(TAO_SERVICES_INC);$(CPPUNIT_INCDIR);$(ICU_INCDIR);$(SAP_INCDIR);$(QAS_INCDIR);$(INFA_INCDIR);$(MELISSADATA_INCDIR);$(ADDRESSDOCTOR_INCDIR)

CC_DEFS := $(CC_DEFS) -DOS_WIN_95 -D_WIN32_WINNT=0x400 -D_MBCS -DWIN32_LEAN_AND_MEAN -DWIN32 -DWIN32_EXTRA_LEAN $(CC_DEFINES)

CC_FLAGS_CMN    := /c /nologo /G7  /EHsc /W3  $(CC_FLAGS$) $(CC_DEFS) $(MYFLAGS)
CC_FLAGS_DBG    := $(CC_FLAGS_CMN) /Gi /MDd /Od /Zi /RTCu /RTCs /GZ

Obviously this is quite a C/C++ focus makefile but it proves that you can abstract away all of the platform specifics.

显然这是一个相当C / C ++焦点的makefile,但它证明你可以抽象出所有平台细节。

Chris

#2


You may be interested in checking out: Pre-defined C/C++ Compiler Macros. It's a goldmine.

您可能有兴趣查看:预定义的C / C ++编译器宏。这是一个金矿。