makefile.all.inc

来自「minix操作系统最新版本(3.1.1)的源代码」· INC 代码 · 共 167 行

INC
167
字号
#######Top Makefile to build the Minix libraries for ack and gnu###needed in makefile that includes this file:###libraries to build without .a:#LIBRARIES=liba libb libc###object files per library:#liba_OBJECTS=filea2.o filea2.o#libb_OBJECTS=fileb.o#libc_OBJECTS=filec.o###if it has subdirectories#SUBDIRS=subdir1 subdir2####The main Makefile has to specify the ack and gnu base object directories:#ACKBASE=/path/to/ack-obj#GNUBASE=/path/to/gnu-obj##or relative in this way: #ACKBASE=$(CURDIR)/ack-obj#GNUBASE=$(CURDIR)/gnu-obj###All these variables have to be set before including this Makefile####To customize dependencies for targets you can do the following#$(call ADDDEPENDENCIES,filea2.o fileb.o,header1.h header2.h)###And to customize MAKE variables for targets use the same construct this way#$(call ADDDEPENDENCIES,filea2.o fileb.o,CFLAGS+=-D_EXTRA_DEFINES -g)###Only one variable can be set per call to ADDDEPENDENCIES###Object files that must end up in the top level object directory must be in##then variabel named TOPLEVEL_OBJECTSifndef ACKBASE$(error ACKBASE not set)endififndef GNUBASE$(error GNUBASE not set)endif.PHONY: all all:: $(addsuffix .a, \	$(addprefix $(ACKBASE)/,$(LIBRARIES)) \	$(addprefix $(GNUBASE)/,$(LIBRARIES))) \	$(addprefix $(ACKBASE)/,$(TOPLEVEL_OBJECTS)) \	$(addprefix $(GNUBASE)/,$(TOPLEVEL_OBJECTS)) \	subdirs.PHONY: cleanclean:: subdirs	rm -f $(ACKBASE)/$(OBJDIR)/* $(GNUBASE)/$(OBJDIR)/*.PHONY: installinstall::#Start objectsdefine TOPLEVEL_template$$(addprefix $$(ACKBASE)/,$(1)): $$(addprefix $$(ACKBASE)/$$(OBJDIR)/,$(1))	cp $$? $$@$$(addprefix $$(GNUBASE)/,$(1)): $$(addprefix $$(GNUBASE)/$$(OBJDIR)/,$(1))	cp $$? $$@endef$(foreach obj,$(TOPLEVEL_OBJECTS),$(eval $(call TOPLEVEL_template,$(obj))))#Library stuffdefine LIBRARY_template$$(ACKBASE)/$(1).a: $$(addprefix $$(ACKBASE)/$$(OBJDIR)/,$$($(1)_OBJECTS))	$$(AR) cr $$@ $$?$$(GNUBASE)/$(1).a: $$(addprefix $$(GNUBASE)/$$(OBJDIR)/,$$($(1)_OBJECTS))	$$(AR) cr $$@ $$?	ranlib $$@endef$(foreach lib,$(LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))#subdirectories.PHONY: subdirs $(SUBDIRS)subdirs: $(SUBDIRS)$(SUBDIRS):	if [ ! -d $(ACKBASE)/$(OBJDIR)/$@ ]; \	then \		mkdir $(ACKBASE)/$(OBJDIR)/$@; \	fi	if [ ! -d $(GNUBASE)/$(OBJDIR)/$@ ]; \	then \		mkdir $(GNUBASE)/$(OBJDIR)/$@; \	fi	ACKBASE=$(ACKBASE) GNUBASE=$(GNUBASE) OBJDIR=$(OBJDIR)/$@ $(MAKE) -C $@ $(MAKECMDGOALS)#	$(call compiledir-ack,$@)#	$(call compiledir-gnu,$@)#ack vs gnudefine compiledir_ack	if [ ! -d $(ack_OBJDIR)/$(OBJDIR)/$(1) ] \	then \		mkdir $(ack_OBJDIR)/$(OBJDIR)/$(1) \	fi	cd $(1) && OBJDIR=$(OBJDIR)/$(1) AR=ar AS='cc -c' CC=cc RANLIB= ASMEXT=s gmake $@ $(MAKECMDGOALS)endefdefine compiledir_gnu	if [ ! -d $(gnu_OBJDIR)/$(OBJDIR)/$(1) ] \	then \		mkdir $(gnu_OBJDIR)/$(OBJDIR)/$(1) \	fi	cd $(1) && OBJDIR=$(OBJDIR)/$(1) AR=gar AS=gas CC=gcc RANLIB=ranlib ASMEXT=gs gmake $@ $(MAKECMDGOALS)endef#Build commands#$(GNUBASE)/$(OBJDIR)/%: AR=gar AS=gas CC=gcc RANLIB=ranlib ASMEXT=gs ASMPREFIX=$(GNUBASE)/$(OBJDIR)#$(ACKBASE)/$(OBJDIR)/%: AR=ar AS='cc -c' CC=cc RANLIB= ASMEXT=s#$(1)/$$(OBJDIR)/%.o: $(3)define COMPILE_template$(1)/%: AR=$(3)$(1)/%: AS=$(4)$(1)/%: CC=$(5)$(1)/$$(OBJDIR)/%.o: %.$(2)	$$(COMPILE.s) -o $$@ $$<$(1)/$$(OBJDIR)/%.o: %.c	$$(COMPILE.c) -o $$@ $$<endef#ASMPREFIX?#$(1)/$$(OBJDIR)/%.o: $(2)%.$(3)#	$$(COMPILE.s) -o $$@ $$<#$(eval $(call COMPILE_template,$$(ACKBASE),,s,ar,cc -c,cc))#$(eval $(call COMPILE_template,$$(GNUBASE),$$(GNUBASE)/$$(OBJDIR)/,gs,gar,gas,gcc))#$(GNUBASE)/$(OBJDIR)/%.gs: %.s#$(GNUBASE)/$(OBJDIR)/%.o: $(GNUBASE)/$(OBJDIR)/%.gs#	$(COMPILE.s) -o $@ $<#$(GNUBASE)/$(OBJDIR)/%.o: %.c#	$(COMPILE.c) -o $@ $<$(eval $(call COMPILE_template,$$(ACKBASE),s,ar,cc -c,cc))$(eval $(call COMPILE_template,$$(GNUBASE),gs,gar,gas,gcc))%.gs: %.s	@echo converting $< to gnu assembler format...	@-gcc $(CFLAGS) -E -x assembler-with-cpp -I. $< | asmconv -mi386 ack gnu > $@#DEPENDENCIESdefine DEPENDENCIES_template$$(ACKBASE)/$$(OBJDIR)/$(1): $(2)$$(GNUBASE)/$$(OBJDIR)/$(1): $(2)endefdefine ADDDEPENDENCIES$(foreach target,$(1),$(eval $(call DEPENDENCIES_template,$(target),$(2))))endef#this could also be automated by adding an extra template that uses the names of object files as variable name

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?