[PATCH] Makefile: re-use Git's Makefile where possible
John Keeping
john at keeping.me.uk
Tue Mar 5 22:02:55 CET 2013
On Tue, Mar 05, 2013 at 03:39:34PM -0500, Jamie Couture wrote:
> On Tue, Mar 05, 2013 at 08:12:54PM +0000, John Keeping wrote:
> > diff --git a/cgit.mk b/cgit.mk
> > new file mode 100644
> > index 0000000..9226d94
> > --- /dev/null
> > +++ b/cgit.mk
> > @@ -0,0 +1,72 @@
> > +# This Makefile is run in the "git" directory in order to re-use Git's
> > +# build variables and operating system detection. Hence all files in
> > +# CGit's directory must be prefixed with "../".
> > +include Makefile
> > +
> > +CGIT_PREFIX = ../
> > +
> > +# The CGIT_* variables are inherited when this file is called from the
> > +# main Makefile - they are defined there.
> > +
> > +$(CGIT_PREFIX)VERSION: force-version
> > + @cd $(CGIT_PREFIX) && ./gen-version.sh "$(CGIT_VERSION)"
> > +-include $(CGIT_PREFIX)VERSION
> > +.PHONY: force-version
> > +
> > +# CGIT_CFLAGS is a separate variable so that we can track it separately
> > +# and avoid rebuilding all of Git when these variables change.
> > +CGIT_CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
> > +CGIT_CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
> > +CGIT_CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
> > +CGIT_CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
> > +
> > +ifdef NO_C99_FORMAT
> > + CFLAGS += -DNO_C99_FORMAT
> > +endif
> > +
> > +CGIT_OBJS += $(CGIT_PREFIX)cgit.o
> > +CGIT_OBJS += $(CGIT_PREFIX)cache.o
> > +CGIT_OBJS += $(CGIT_PREFIX)cmd.o
> > +CGIT_OBJS += $(CGIT_PREFIX)configfile.o
> > +CGIT_OBJS += $(CGIT_PREFIX)html.o
> > +CGIT_OBJS += $(CGIT_PREFIX)parsing.o
> > +CGIT_OBJS += $(CGIT_PREFIX)scan-tree.o
> > +CGIT_OBJS += $(CGIT_PREFIX)shared.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-atom.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-blob.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-clone.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-commit.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-diff.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-log.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-patch.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-plain.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-refs.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-repolist.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-shared.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-snapshot.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-ssdiff.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-stats.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-summary.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-tag.o
> > +CGIT_OBJS += $(CGIT_PREFIX)ui-tree.o
> > +CGIT_OBJS += $(CGIT_PREFIX)vector.o
> > +
> can we do a patsubst instead? Something like:
>
> OBJECTS =
> OBJECTS += cgit.o
> .... and so on
>
> CGIT_OBJS = $(OBJECTS:$(CGIT_PREFIX)%=%)
>
> _or_
>
> CGIT_OBJS = $(patsubst %,$(CGIT_PREFIX)%,$(OBJECTS))
I don't think this should be OBJECTS since that's already used in Git's
Makefile. I'd rather do something like:
CGIT_OBJ_NAMES =
CGIT_OBJ_NAMES += cgit.o
...
CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES))
> > +ifeq ($(wildcard $(CGIT_PREFIX).depend),)
> > +missing_dep_dirs += $(CGIT_PREFIX).depend
> > +endif
> > +
> > +$(CGIT_PREFIX).depend:
> > + @mkdir -p $@
> > +
> > +$(CGIT_PREFIX)CGIT-CFLAGS: FORCE
> > + @FLAGS='$(subst ','\'',$(CGIT_CFLAGS))'; \
> > + if test x"$$FLAGS" != x"`cat ../CGIT-CFLAGS 2>/dev/null`" ; then \
> > + echo 1>&2 " * new CGit build flags"; \
> > + echo "$$FLAGS" >$(CGIT_PREFIX)CGIT-CFLAGS; \
> > + fi
> > +
> > +$(CGIT_OBJS): %.o: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS $(missing_dep_dirs)
> > + $(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $<
> > +
> > +$(CGIT_PREFIX)cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS)
> > + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
> > --
> > 1.8.2.rc1.339.g93ec2c9
More information about the CGit
mailing list