How can I correctly define my build platform?

I want to know a parameter that is an indicator of the current OS. If I support Windows and Linux, how can I get a system parameter that distinguishes OS types. This is for an OS-independent makefile that works on both Windows and Linux, checking the parameter in "if".

+3
source share
2 answers

In the past, I checked the value of the OS environment variable. This installs on Windows. For other platforms, I explicitly set it in the environment. This allows you to configure specific platform settings in makefiles called ...

makefile.Windows_NT
makefile.Linux
makefile.HPUX

In my main make file, then I just do

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

, makefile. $(OS)

makefile . , .

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

, C/++, , .

+3

: C/++. .

0

Source: https://habr.com/ru/post/1709207/


All Articles