############################################################################### # CLAM System default rules and targets for C++ compilation. # This file composite macros and rules for creating compilation objects # (such as library archives, object files, executable programs, and others). # This file should be included in the user's Makefile after the variables # have been initialized appropriately for the particular project being # compiled. The user's own targets should be placed after the include # directive that specifies this file. ############################################################################### # This section manipulates variable values to prepare them for their use # in the standard CLAM support. # Modify the output directory for executable files if we're building a # test project. ifeq "$(TYPE)" "test" EXECUTABLE_DIR = $(TARGETS_STORE)/tests/$(PROJECT) ifneq "$(CONSOLE_MODE)" "" COMPILER_FLAGS += -target:exe else COMPILER_FLAGS += -target:winexe endif endif ifeq "$(TYPE)" "application" ifneq "$(CONSOLE_MODE)" "" COMPILER_FLAGS += -target:exe else COMPILER_FLAGS += -target:winexe endif endif ifeq "$(TYPE)" "library" COMPILER_FLAGS += -target:library endif # prep the actual source variable so that certain file names are translated. ACTUAL_RESX = $(RESX:%.resx=%.resources) ifeq "$(OP_SYSTEM)" "WIN32" ifneq "$(OMIT_VERSIONS)" "" # remove version rc files if we're not dealing with versions. ACTUAL_RESOURCE = $(RESOURCE:%.rc=) else ACTUAL_RESOURCE = $(RESOURCE:%.rc=%.res) endif else # replace this when supporting resource files on unix. ACTUAL_RESOURCE = $(RESOURCE:%.rc=) endif # patch the sources so that subdirs work. ACTUAL_SOURCE = $(SOURCE:%.cs=$(CURRENT_DIR)/%.cs) # visual studio settings. ifeq "$(COMPILER)" "VISUAL_CPP" # processes the def file for linkage, if one has been specified. ifneq "$(DEF_FILE)" "" LOAD_FLAG_PREFIX += -def:$(DEF_FILE) endif # these are loaded after any special debugging libs. ifneq "$(VCPP_USE_BASE)" "" # the first set will be included in almost any old program. we include # winmm for multimedia in the base support since we make heavy use of the # more accurate uptime function. # LOAD_FLAG_PREFIX += advapi32.lib kernel32.lib version.lib winmm.lib endif #is advapi32 really part of the base required stuff? will it work on #win98? how about win95? ifneq "$(VCPP_USE_GUI)" "" LOAD_FLAG_PREFIX += comdlg32.lib gdi32.lib user32.lib winspool.lib endif ifneq "$(VCPP_USE_OLE)" "" LOAD_FLAG_PREFIX += ole32.lib oleaut32.lib uuid.lib VCPP_USE_RPC = t endif ifneq "$(VCPP_USE_RPC)" "" LOAD_FLAG_PREFIX += rpcndr.lib rpcns4.lib rpcrt4.lib VCPP_USE_SOCK = t endif ifneq "$(VCPP_USE_SOCK)" "" LOAD_FLAG_PREFIX += netapi32.lib ws2_32.lib endif endif # Updates the search path for the compiler and local libraries. BASE_HEADER_PATH = $(CODEBASE_HEADERS) $(LOCAL_HEADERS) $(HOOPLE_HEADERS) $(SEARCH_DIRS) HEADER_SEARCH_PATH += $(BASE_HEADER_PATH) $(COMPILER_HEADER_DIR) LIBRARY_SEARCH_PATH += $(LOCAL_LIBRARIES) $(HOOPLE_LIBRARIES) \ $(STATIC_LIBRARY_DIR) $(COMPILER_LIBRARY_DIR) $(SEARCH_DIRS) # Adds some directories that must be searched onto the search path for # header files, such as the compiler's own special header file directory. COMPILER_FLAGS += $(DEFINITIONS:%=-D:%) $(UNDEFINITIONS:%=-U%) #$(HEADER_SEARCH_PATH:%=-I%) # The load flags are updated by looking for code libraries in the directories # to search and by adding all of the code libraries that are used. LOAD_FLAG_PREFIX += $(LIBRARY_SEARCH_PATH:%=$(LIBRARY_PATH_FLAG)%) LOAD_FLAG_PREFIX += $(LIBS_USED:%=$(LIBRARY_NAME_FLAG)%) # prepare for mfc style DLLs. currently we plan on all dlls we create being # based on MFC. this is an unfortunate requirement for using the mfc debug # support for allocations; if regular new and DEBUG_NEW get mixed together, # crashes used to result. supposedly these are gone now at least. ifneq "$(USE_MFC)" "" # set the flag that says we are doing mfc extension dlls. DEFINITIONS += _AFXDLL # add in the mfc directories. COMPILER_HEADER_DIR += $(COMPILER_ROOT_DIR)/mfc/include COMPILER_LIBRARY_DIR += $(COMPILER_ROOT_DIR)/mfc/lib endif ifeq "$(OMIT_VERSIONS)" "" ifneq "$(VERSION_RC_ROOT)" "" VERSION_TARGET = $(VERSION_RC_ROOT)_version.rc endif endif # Make sure that the directory for objects exists. ACTUAL_FIRST_TARGETS = check_requirements $(VERSION_TARGET) $(FIRST_TARGETS) pre_compilation # Adds the primary targets to the list of products to create. ACTUAL_TARGETS1 = $(TARGETS:%.exe=$(EXECUTABLE_DIR)/%.exe) ACTUAL_TARGETS2 = $(ACTUAL_TARGETS1:%.dll=$(DYNAMIC_LIBRARY_DIR)/%.dynlibrary) ACTUAL_TARGETS3 = $(ACTUAL_TARGETS2:%.so=$(DYNAMIC_LIBRARY_DIR)/%.so) ACTUAL_TARGETS4 = $(ACTUAL_TARGETS3:%.lib=$(STATIC_LIBRARY_DIR)/%.library) ACTUAL_TARGETS = $(ACTUAL_TARGETS4:%.elf=$(EXECUTABLE_DIR)/%.elf) # Adds the last few targets for CLAM to do. ACTUAL_LAST_TARGETS = post_compilation $(LAST_TARGETS) ############################################################################ # This section defines the rules used to generate various objects from their # source files. ############################################################################ # resource compiler for c#. %.resources: %.resx @echo Creating resource file [$@]. $(RC) $< $@ # $(CATCHER)$(RC) $< $@ ############################################################################ # resource compiler for standard resource files. ifeq "$(OP_SYSTEM)" "WIN32" %.res: %.rc @echo Creating resource file [$@]. ifeq "$(NO_COMPILE)" "" $(CATCHER)$(STANDARD_RC) -r $(DEFINITIONS:%=-D%) $(HEADER_SEARCH_PATH:%=-i%) -fo $@ $< endif endif ############################################################################ # creates dynamic libraries. # we whack any existing LIB file, since we want to use changes in that file # as a clue for when we should rescan the dependencies. we'd be fine if # visual c++ didn't keep an existing LIB if it doesn't change (even when the # DLL does). $(DYNAMIC_LIBRARY_DIR)/%.dynlibrary: $(LOCAL_LIBS_USED:%=$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(ACTUAL_RESX) $(ACTUAL_SOURCE) $(ACTUAL_RESOURCE) $(HIDER)echo Creating dynamic library [$@]. @echo $@ >$(DIRTY_FILE) $(HIDER)rm -f $(@:%.dll=%.lib) $(CATCHER)$(CC) $(COMPILER_FLAGS) $(EXE_FLAGS) $(LOAD_FLAG_PREFIX) $(LOCAL_LIBS_USED:%=$(LIBRARY_NAME_FLAG)$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(LOAD_FLAG_SUFFIX) $(LINKER_OUTPUT_FLAG)$@ $(ACTUAL_SOURCE) $(ACTUAL_RESX:%=-res:%) $(ACTUAL_RESOURCE:%=-win32res:%) ifneq "$(VCPP_VISTA_ICON)" "" $(HIDER)ReplaceVistaIcon "$@" "$(VCPP_VISTA_ICON)" endif $(HIDER)mv $@ $(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)$*$(LIB_ENDING) ifneq "$(CREATE_TLB)" "" $(CATCHER)$(TLBEXPORT) $(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)$*$(LIB_ENDING) -out:$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)$*.tlb endif $(HIDER)echo nil >$@ #$(LINKER_OUTPUT_FLAG)$@ -dll $(LOAD_FLAG_PREFIX) $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(LOCAL_LIBS_USED:%=$(LIBRARY_NAME_FLAG)$(LIB_PREFIX)%$(LIB_ENDING)) $(LOAD_FLAG_SUFFIX) ############################################################################ # creates "exe" executables using all of the appropriate objects. $(EXECUTABLE_DIR)/%.exe: $(LOCAL_LIBS_USED:%=$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(ACTUAL_RESX) $(ACTUAL_SOURCE) $(ACTUAL_RESOURCE) $(HIDER)echo Building program [$@]. @echo $@ >$(DIRTY_FILE) $(CATCHER)$(CC) $(COMPILER_FLAGS) $(EXE_FLAGS) $(LOAD_FLAG_PREFIX) $(LOCAL_LIBS_USED:%=$(LIBRARY_NAME_FLAG)$(DYNAMIC_LIBRARY_DIR)/$(LIB_PREFIX)%$(LIB_ENDING)) $(LOAD_FLAG_SUFFIX) $(LINKER_OUTPUT_FLAG)$@ $(ACTUAL_SOURCE) $(ACTUAL_RESX:%=-res:%) $(ACTUAL_RESOURCE:%=-win32res:%) ifneq "$(VCPP_VISTA_ICON)" "" $(HIDER)ReplaceVistaIcon "$@" "$(VCPP_VISTA_ICON)" endif ############################################################################ # handles creating version resource files if this project has a version.ini. ifeq "$(OMIT_VERSIONS)" "" ifneq "$(VERSION_RC_ROOT)" "" # only redo the version resource if it or version.ini is out of date. %_version.rc: version.ini $(PARAMETER_FILE) $(CATCHER)$(CLAM_BINARIES)/version_stamper$(EXE_END) . $(PARAMETER_FILE) endif endif ############################################################################ # Now the active part of the make process... # Adds the main CLAM system in to get some work done. This should be placed # after the module's rules are defined and before the module's targets are # defined. include rules.def # preserves intermediate files from being deleted. ##.PRECIOUS: %.resources # zaps things when they could not be created correctly. .DELETE_ON_ERROR: ############################################################################ # examines the required variables and complains if they're missing. check_requirements: $(HIDESH) -c 'if [ -z "$(PROJECT)" ]; then echo the PROJECT variable is not defined!; . $(CLAM_SCRIPTS)/exit_make.sh; fi' $(HIDESH) -c 'if [ -z "$(TYPE)" ]; then echo the TYPE variable is not defined!; . $(CLAM_SCRIPTS)/exit_make.sh; fi' ############################################################################ # calls the script for preparing output directories and such. pre_compilation: $(HIDESH)$(CLAM_SCRIPTS)/csharp/preconditions.sh ############################################################################ # calls the script for copying the final products to the library directory. # we don't bother reporting errors from touch since there will sometimes # not be any objects in the final directory. post_compilation: $(HIDESH)$(CLAM_SCRIPTS)/csharp/postconditions.sh ############################################################################ # if REBUILD is defined, then we cause all objects to be recompiled. .PHONY: force_rebuild force_rebuild: ifneq "$(REBUILD)" "" # the target below needs the blank rule that it has for this to work. $(FIRST_TARGETS) $(ACTUAL_OBJECTS:%=$(OBJECT_DIR)/%) $(ACTUAL_TARGETS) $(LAST_TARGETS): force_rebuild endif ############################################################################