.if defined(USE_CC) CC = $(USE_CC) .else CC != ( ( wgcc --version ) > /dev/null 2>&1 && echo wgcc ) || echo gcc .endif .if defined(CC_ADD) CC += $(CC_ADD) .endif CPPFLAGS = $(CPPFLAGS_ADD) CFLAGS = $(CPPFLAGS) $(CFLAGS_ADD) LOCALROOT ?= /local VERSION ?= $(.CURDIR:T) INSTBINDIR ?= $(LOCALROOT)/.bin/$(VERSION) INSTHDRDIR ?= $(LOCALROOT)/.include/$(VERSION) INSTLIBDIR ?= $(LOCALROOT)/.lib/$(VERSION) INSTMANDIR ?= $(LOCALROOT)/.man/$(VERSION) DEPENDFILES ?= *.c .if defined(BUILDBINS) && !empty(BUILDBINS) && !defined(INSTALLBIN) INSTALLBIN = $(BUILDBINS) .endif .if defined(BUILDLIBS) && !empty(BUILDLIBS) && !defined(INSTALLLIB) INSTALLLIB = $(BUILDLIBS) .endif CLEANFILES_ := $(CLEANFILES) $(OBJALL) .if defined(BUILDBINS) && !empty(BUILDBINS) .for x in $(BUILDBINS) .if !defined(OBJ_$(x)) OBJ_$(x) = $(x).o .endif .if defined(OVERRIDE_LIBS_$(x)) $(x): $(OBJ_$(x)) $(OBJALL) $(CC) $(LDFLAGS_$(x)) -o $(.TARGET) $(OBJ_$(x)) $(OBJALL) $(OVERRIDE_LIBS_$(x)) $(TRACE) .else $(x): $(OBJ_$(x)) $(OBJALL) $(CC) $(LDFLAGS_$(x)) -o $(.TARGET) $(OBJ_$(x)) $(OBJALL) $(LIBS_$(x)) $(LIBS) $(TRACE) .endif CLEANFILES_ += $(x) $(OBJ_$(x)) .endfor .endif .if defined(BUILDLIBS) && !empty(BUILDLIBS) BUILDLIBBASE := .for x in $(BUILDLIBS) .if empty(BUILDLIBBASE:M^$(x:R)$) BUILDLIBBASE := $(BUILDLIBBASE) $(x:R) CLEANFILES_ += $(OBJ_$(x:R)) .endif BUILDLIBTMP := $(x:N*.a) .if empty(BUILDLIBTMP) $(x): $(OBJ_$(x:R)) rm -f $(.TARGET) ar rv $(.TARGET) $(OBJ_$(x:R)) ranlib $(.TARGET) CLEANFILES_ += $(x) .endif .endfor .endif .PHONY: install .PHONY: install_dirs .PHONY: install_files install:: install_dirs .WAIT install_files install_dirs:: .for d in BIN HDR LIB .PHONY: install_dirs_$(d) .if exists($(INST$(d)DIR)) INST$(d)DEP = install_dirs_$(d):: .else INST$(d)DEP = $(INST$(d)DIR) install_dirs_$(d):: $(INST$(d)DIR) .if !target($(INST$(d)DIR)) $(INST$(d)DIR): mkdir -p $(.TARGET) .endif .endif .endfor .for x in $(INSTALLBIN) install_files:: $(x:C;^;$(INSTBINDIR)/;) install_dirs:: install_dirs_BIN $(x:C;^;$(INSTBINDIR)/;): $(x) $(INSTBINDEP) install -c $(INSTFLAGS_$(x)) $(x) $(.TARGET) .endfor .for x in $(INSTALLHDR) install_files:: $(x:C;^;$(INSTHDRDIR)/;) install_dirs:: install_dirs_HDR $(x:C;^;$(INSTHDRDIR)/;): $(x) $(INSTHDRDEP) cp $(x) $(.TARGET) .endfor .for x in $(INSTALLLIB) install_files:: $(x:C;^;$(INSTLIBDIR)/;) install_dirs:: install_dirs_LIB INSTLIBTMP := $(x:N*.a) $(x:C;^;$(INSTLIBDIR)/;): $(x) $(INSTLIBDEP) cp $(x) $(.TARGET) .if empty(INSTLIBTMP) ranlib $(.TARGET) .endif .endfor .PHONY: install_dirs_MAN .for x in $(INSTALLMAN) install_files:: $(x:C;^(.*)\.([0-9].*)$;$(INSTMANDIR)/cat\2/\1.0;) install_dirs:: install_dirs_MAN $(x:C;^(.*)\.([0-9].*)$;$(INSTMANDIR)/cat\2/\1.0;): \ $(x:C;^.*\.([0-9].*)$;$(INSTMANDIR)/cat\1;) \ $(x:C;\.([0-9].*)$;.cat\1;) cp $(x:C;\.([0-9].*)$;.cat\1;) $(.TARGET) CLEANFILES_ += $(x:C;\.([0-9].*)$;.cat\1;) .if !exists($(x:C;^.*\.([0-9].*)$;$(INSTMANDIR)/cat\1;)) && \ !target($(x:C;^.*\.([0-9].*)$;$(INSTMANDIR)/cat\1;)) install_dirs_MAN:: $(x:C;^.*\.([0-9].*)$;$(INSTMANDIR)/cat\1;) $(x:C;^.*\.([0-9].*)$;$(INSTMANDIR)/cat\1;): mkdir -p $(.TARGET) .endif .if !target($(x:C;\.([0-9].*)$;.cat\1;)) $(x:C;\.([0-9].*)$;.cat\1;): $(x) nroff -mandoc $(.ALLSRC) > $(.TARGET) || (rm -f $(.TARGET); false) .endif .endfor install_dirs_MAN:: .for d in BIN HDR LIB .if defined(INST$(d)LINKS) && !empty(INST$(d)LINKS) INSTLINKSTMP1 := INSTLINKSTMP2 := .for x in $(INST$(d)LINKS) .if empty(INSTLINKSTMP1) INSTLINKSTMP1 := $(x) .else INSTLINKSTMP2 := $(INSTLINKSTMP2) $(x)$(INSTLINKSTMP1) INSTLINKSTMP1 := .endif .endfor .for x in $(INSTLINKSTMP2) install_files:: $(x:C;^.*;$(INST$(d)DIR)/;) $(x:C;^.*;$(INST$(d)DIR)/;): $(x:C;^;$(INST$(d)DIR)/;:C;.*$;;) rm -f $(.TARGET) && ln $(.ALLSRC) $(.TARGET) .endfor .endif .endfor .if defined(INSTMANLINKS) && !empty(INSTMANLINKS) INSTLINKSTMP1 := INSTLINKSTMP2 := .for x in $(INSTMANLINKS) .if empty(INSTLINKSTMP1) INSTLINKSTMP1 := $(x) .else INSTLINKSTMP2 := $(INSTLINKSTMP2) $(x)$(INSTLINKSTMP1) INSTLINKSTMP1 := .endif .endfor .for x in $(INSTLINKSTMP2) install_files:: $(x:C;^.*(.*)\.([0-9].*)$;$(INSTMANDIR)/cat\2/\1.0;) $(x:C;^.*(.*)\.([0-9].*)$;$(INSTMANDIR)/cat\2/\1.0;): \ $(x:C;^(.*)\.([0-9].*).*$;$(INSTMANDIR)/cat\2/\1.0;) rm -f $(.TARGET) && ln $(.ALLSRC) $(.TARGET) .endfor .endif .if !target(.MAIN) .MAIN: $(BUILDBINS) .endif REMOVEDIRS := .for x in BIN HDR LIB MAN .if exists($(INST$(x)DIR)) REMOVEDIRS := $(REMOVEDIRS) $(INST$(x)DIR) .endif .endfor .c.o: .if defined(USE_LCS_CVT) && !empty(USE_LCS_CVT) $(CC_$@:U$(CC)) $(CFLAGS) $(CFLAGS_$<) $(CFLAGS_$@) -E $< -o _.i && lcs-cvt _.i && $(CC_$@:U$(CC)) $(CFLAGS) $(CFLAGS_$<) $(CFLAGS_$@) -c _.i -o $@ && rm _.i .else $(CC_$@:U$(CC)) $(CFLAGS) $(CFLAGS_$<) $(CFLAGS_$@) -c $< -o $@ .endif .PHONY: remove remove:: .if !empty(REMOVEDIRS) rm -rf $(REMOVEDIRS) .endif .PHONY: depend depend: $(PREDEPEND) mkdep -- $(CFLAGS) $(DEPENDFILES) CLEANFILES_ += .depend .PHONY: predepend predepend: $(PREDEPEND) .PHONY: clean clean:: rm -f $(CLEANFILES_)