📄 inc.makefile
字号:
################################################################# Copyright (c) 2001 Sigma Designs Inc. All rights reserved. ## Author : Julien Soulier ## Date : 06-19-2001 ## ## This is the base makefile for all realmagic projects ## ################################################################################################### Project specific variables ## ################################ifndef DEPEND_FILE DEPEND_FILE = Makefile.dendififndef MAKEFILE_NAME MAKEFILE_NAME = Makefileendif ifndef LOCAL_MAKEFILE LOCAL_MAKEFILE = $(MAKEFILE_NAME)endififndef CCOMPILER CCOMPILER := gccendififndef CXXCOMPILER CXXCOMPILER := g++endifCC := $(CROSS)$(CCOMPILER)CXX := $(CROSS)$(CXXCOMPILER)LD := $(CROSS)$(LD)OBJCPY := $(CROSS)objcopyifndef LINKER LINKER = $(CC) # must be = and not :=else LINKER := $(CROSS)$(LINKER)endifLOCALDIR = $(shell pwd)ifndef RMPREFIX export RMPREFIX := $(LOCALDIR)/..endifAPIDIR := $(RMPREFIX)/externalapiLIBDIR := $(RMPREFIX)/lib DISTDIR := $(RMPREFIX)/dist MAKEARGS = -f $(MAKEFILE_NAME) ## the -f option is not passed through MAKEFLAGSCXXFLAGS = $(CFLAGS)CFLAGS += $(RMCFLAGS) -I. -D_REENTRANT ########################### Compilation options ###########################ifeq ($(findstring leakchecker, $(COMPILKIND)), leakchecker)EXEFLAGS += `glib-config --libs glib`CFLAGS += -DUSE_LEAK_CHECKER=1endififeq ($(findstring withthreads, $(COMPILKIND)), withthreads)CFLAGS += -DWITH_THREADS=1LDFLAGS += -lpthread endififeq ($(findstring withdl, $(COMPILKIND)), withdl)EXEFLAGS += -ldl -rdynamicendififeq ($(findstring kernel, $(COMPILKIND)), kernel) ## kernel compilationifndef MUM_KIMUM_KI=-I/usr/src/linux-$(shell uname -r)/include -I/usr/src/linux-2.4/includeendififndef KERNELSTYLEKERNELSTYLE= \ -D__KERNEL__ -DMODULE \ -fomit-frame-pointer \ -fno-strict-aliasing \ -fno-common \ -pipe \ -mpreferred-stack-boundary=2endifCFLAGS+= \ $(KERNELSTYLE) \ -Wno-import \ -Wunused \ -Wimplicit \ -Wmain \ -Wreturn-type \ -Wswitch \ -Wtrigraphs \ -Wchar-subscripts \ -Wuninitialized -O \ -Wparentheses \ -Wpointer-arith \ -Wcast-align \ -fcheck-new \ $(MUM_KI)else ## user compilation## Switch to release/debug compilation ### The macro to do this is called ``_DEBUG'' to fit how Windows does. Sorry.ifeq ($(findstring release, $(COMPILKIND)), release) CFLAGS += -U_DEBUG -O2else CFLAGS += -D_DEBUG=1 -O0ifeq "$(CCOMPILER)" "gcc" CFLAGS += -gdwarf-2else CFLAGS += -gendifendif ## Switch for fascist warnings.ifndef DISABLE_WARNINGSCFLAGS+=-Wall \ -Wchar-subscripts \ -Wmissing-declarations \ -Wmissing-prototypes \ -Wnested-externs \ -Wsign-compare \ -fcheck-new \ -fwritable-strings \ -Wuninitialized -O \ -Werror endif### if libc heades are neededifndef USE_STD_LIB CFLAGS += -nostdincendifendif # kernel/user switch########################################################### select compilation according to COMPILKIND variable ###########################################################TARGET_TYPE := $(strip $(TARGET_TYPE))ifeq "$(TARGET_TYPE)" "LIBRARY"ifeq ($(findstring static, $(COMPILKIND)), static)TARGET_TYPE := OBJECT_LIBRARYelseTARGET_TYPE := SHARED_LIBRARYendifendififeq ($(findstring static, $(COMPILKIND)), static)STATIC_LINKS_WITH += $(LINKS_WITH)LDFLAGS += -staticelseifeq ($(findstring implicit, $(COMPILKIND)), implicit)IMPLICIT_LINKS_WITH := $(LINKS_WITH)elseDEPENDS_ON += $(LINKS_WITH)endifendif###################################################### Describes the rule to make each type of target ######################################################OBJECT_LIBRARY = $(LD) -r $^ -o $@SHARED_LIBRARY = $(LINKER) -shared $^ $(LDFLAGS) -o $@EXECUTABLE = $(LINKER) $^ $(LDFLAGS) $(EXEFLAGS) -o $@DEPEND_COMMAND = gcc $(CFLAGS) -MM -E $(SRC) $(MAIN_SRC)BINARY_FILE = $(OBJCPY) -O binary $< $@define MICROCODE $(SPASM) $^ -o $@ $(SPBIN) -h $@endef##################################### Describes ugly shell commands #####################################COPY_FILE_LIST = sed 's/^.*://' | sed 's/\\$$//' | tr ' ' '\n' | sed '/^$$/d' | \ sed '/^\//d' | \ sed 's/^\([^/]\)/$(subst /,\/,$(LOCALDIR))\/\1/' | \ sed '{ : rm_dotdot s/[^/]*\/..\/// ; t rm_dotdot }' | sort -u | \ xargs cp -f --parents --target-directory=$(1)REDUCE_DIR_TREE = cd $(1) ; x=1 ; while [ $$x -eq 1 ] ; \ do x=0 ; [ `ls -1 | wc -l` -eq 1 -a -d `ls -1 | head -n 1` ] && \ y=`ls -1` && mv $$y/* . && rmdir $$y && x=1 ; \ done ; exit 0########################################################### Compute the local object files and the dependencies ## #########################################################SRC := $(strip $(SRC))MAIN_SRC := $(strip $(MAIN_SRC))OBJ := $(addsuffix .o, $(basename $(SRC)))MAIN_OBJ := $(addsuffix .o, $(basename $(MAIN_SRC)))EXE := $(basename $(MAIN_SRC))SUBDIR := $(dir $(STATIC_LINKS_WITH) $(IMPLICIT_LINKS_WITH) $(DEPENDS_ON))ifneq ($(findstring clean, $(MAKECMDGOALS)) ,clean) # if target is not clean ifneq "$(SRC) $(MAIN_SRC)" " " # if SRC or MAIN_SRC are not void DEPEND := $(shell cat $(DEPEND_FILE)) # take the dependencies in DEPEND_FILE DEPEND := $(subst \, ,$(DEPEND)) # remove the back-slash DEPEND := $(subst :, , $(DEPEND)) # remove the : DEPEND := $(filter-out %.o, $(DEPEND)) # remove the .o file names DEPEND := $(SRC) $(MAIN_SRC) $(DEPEND) # add SRC and MAIN_SRC in case not present before DEPEND := $(sort $(DEPEND)) # remove doublons endifendififeq "$(TARGET_TYPE)" "OBJFILE"TARGET := $(OBJ)endififeq "$(TARGET_TYPE)" "EXECUTABLE"TARGET := $(EXE)endif################################################################### put here the targets you want to be updated anytime you ask ###################################################################.PHONY: cleanall clean dist localdist reduce_dist api $(SUBDIR) all local prebuild postbuild copy_shared############################### rule to make the target ###############################all: prebuild $(SUBDIR) $(TARGET) postbuildlocal: prebuild $(TARGET) postbuildifeq "$(TARGET_TYPE)" "SHARED_LIBRARY"copy_shared: $(TARGET) $(SUBDIR) [ -d $(LIBDIR) ] && cp -f $(TARGET) $(LIBDIR)elsecopy_shared: $(SUBDIR)endififeq "$(TARGET_TYPE)" "OBJECT_LIBRARY"$(TARGET): $(OBJ) $(STATIC_LINKS_WITH) $(EXTERNAL_STATIC_LINKS_WITH) $(OBJECT_LIBRARY)endififeq "$(TARGET_TYPE)" "SHARED_LIBRARY"$(TARGET): $(OBJ) $(STATIC_LINKS_WITH) $(EXTERNAL_STATIC_LINKS_WITH) $(IMPLICIT_LINKS_WITH) $(SHARED_LIBRARY)endififeq "$(TARGET_TYPE)" "EXECUTABLE"$(TARGET): %: %.o $(OBJ) $(STATIC_LINKS_WITH) $(EXTERNAL_STATIC_LINKS_WITH) $(IMPLICIT_LINKS_WITH) $(EXECUTABLE)endififeq "$(TARGET_TYPE)" "MICROCODE"$(TARGET): $(SRC) $(MICROCODE)endififeq "$(TARGET_TYPE)" "BINARY_FILE"$(TARGET): $(EXE) $(BINARY_FILE)$(EXE): %: %.o $(OBJ) $(STATIC_LINKS_WITH) $(EXTERNAL_STATIC_LINKS_WITH) $(IMPLICIT_LINKS_WITH) $(EXECUTABLE)endif$(STATIC_LINKS_WITH): $(@D)$(IMPLICIT_LINKS_WITH): $(@D)$(DEPENDS_ON): $(@D)$(SUBDIR): $(MAKE) $(MAKEARGS) -C $@ $(MAKECMDGOALS)$(SRC):$(MAIN_SRC):########################################################## rules to execute a prebuild or a postbuild command ##########################################################prebuild:ifneq "$(PREBUILD)" "" @echo "------START PREBUILD STEP-------" $(PREBUILD) @echo "------FINISH PREBUILD STEP------"endifpostbuild:ifneq "$(POSTBUILD)" "" @echo "------START POSTBUILD STEP-------" $(POSTBUILD) @echo "------FINISH POSTBUILD STEP------"endif######################################################## include and compute if necessary the DEPEND_FILE ########################################################$(DEPEND_FILE): $(DEPEND) $(LOCAL_MAKEFILE)ifneq "$(TARGET_TYPE)" "MICROCODE"ifneq "$(SRC) $(MAIN_SRC)" " " $(DEPEND_COMMAND) | sed 's/:/: $(LOCAL_MAKEFILE)/' > $@endifendififneq ($(findstring clean, $(MAKECMDGOALS)) ,clean)-include $(DEPEND_FILE)endif######################################################## copy all the needed files to compile the project ########################################################dist: localdist $(SUBDIR)localdist: @[ -d $(DISTDIR) ] && \ echo $(EXTRA_DIST_FILES) | cat - $(DEPEND_FILE) | $(call COPY_FILE_LIST,$(DISTDIR)) reduce_dist: @$(call REDUCE_DIR_TREE,$(DISTDIR))api: @[ -d $(APIDIR) ] && \ $(DEPEND_COMMAND) | $(call COPY_FILE_LIST,$(APIDIR)) @$(call REDUCE_DIR_TREE,$(APIDIR))################################ how to clean the project ################################cleanall: clean $(SUBDIR)clean: $(RM) $(OBJ) $(MAIN_OBJ) $(TARGET) $(DEPEND_FILE) *~ core.*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -