1 # SPDX-FileCopyrightText: 2013 John Keeping <john@keeping.me.uk>
2 # SPDX-FileCopyrightText: 2025 Lady <https://www.ladys.computer/about/#lady>
3 # SPDX-License-Identifier: GPL-2.0-only
7 # This make·file is heavily based on the one used by `cgit´ (<https://git.zx2c4.com/cgit/tree/cgit.mk>) as of commit a5e4ad2d8b9c6bcfc7029894d3a3837166996b35.
8 # (Later additions to this file have mostly not been significant.)
9 # It is very important that C·Girls be built using the same settings as Git (since they are statically linked), and this is managed by simply including Gits make·file at the beginning of this one.
11 # A consequence of this is that this make·file ⹐must⹑ be run from Gits source code directory (i·e with `make -C $(GITDIR)´).
12 # The variable `CGIRLSDIR´ is used to point back to the directory containing the C·Girls code.
14 cgirls
: $(CGIRLSDIR
)/cgirls
18 # The `gen-version.sh´ script updates the `VERSION´ file when·ever the version changes.
19 # This file is then included to set `CGIRLS_VERSION´.
20 $(CGIRLSDIR
)/VERSION
: VERSIONFORCE
21 @cd
'$(CGIRLSDIR)' && $(SHELL_PATH_SQ
) sh
/gen-version.sh VERSION
24 -include $(CGIRLSBUILDDIR
)/VERSION
26 # `CGIRLS_CFLAGS´ is a separate variable so that it can be tracked separately, to avoid rebuilding all of Git when these variables change.
27 # `ALL_CGIRLS_CFLAGS´ is the same as `ALL_CFLAGS´ plus `CGIRLS_CFLAGS´, except that it changes the C standard target to be `c2x´.
29 ALL_CGIRLS_CFLAGS
= -std
=c2x
$(filter-out -std
=%,$(ALL_CFLAGS
)) $(CGIRLS_CFLAGS
)
31 # All of the C·Girls header sources are given as prerequisites for all C·Girls objects if `USE_COMPUTED_HEADER_DEPENDENCIES´ is false.
32 CGIRLS_SOURCE_FILES
:= $(shell cd
'$(CGIRLSDIR)' && $(SOURCES_CMD
))
33 CGIRLS_H_SOURCES
= $(filter %.h
,$(CGIRLS_SOURCE_FILES
))
35 # `CGIRLS_OBJS´ lists the object files which this make·file is expected to create.
36 # These are listed one per line to make merges easier.
37 # `CGIRLSBUILDDIR´ is added as a prefix at the end.
39 CGIRLS_OBJS
+= cgirls.o
40 CGIRLS_OBJS
:= $(addprefix $(CGIRLSDIR
)/,$(CGIRLS_OBJS
))
42 # Only `cgirls.c´ references CGIRLS_VERSION so we only rebuild its objects when the version changes.
43 CGIRLS_VERSION_OBJS
:= $(CGIRLSDIR
)/cgirls.o
44 $(CGIRLS_VERSION_OBJS
) : $(CGIRLSDIR
)/VERSION
45 $(CGIRLS_VERSION_OBJS
) : EXTRA_CPPFLAGS
= \
46 -DCGIRLS_VERSION
='"$(CGIRLS_VERSION)"'
48 # Git handles dependencies using `:=´, so they have already been computed by this point.
49 # We have to manage the dependency files for `CGIRLS_OBJS´ ourselves.
50 cgirls_dep_files
:= $(foreach f
,$(CGIRLS_OBJS
),$(dir $f).depend
/$(notdir $f).d
)
51 cgirls_dep_dirs
:= $(addsuffix .depend
,$(sort $(dir $(CGIRLS_OBJS
))))
52 ifeq ($(COMPUTE_HEADER_DEPENDENCIES
),yes
)
55 missing_dep_dirs
+= $(filter-out $(wildcard $(cgirls_dep_dirs
)),$(cgirls_dep_dirs
))
57 ifdef USE_COMPUTED_HEADER_DEPENDENCIES
58 cgirls_dep_files_present
:= $(wildcard $(cgirls_dep_files
))
59 ifneq ($(cgirls_dep_files_present
),)
60 include $(cgirls_dep_files_present
)
63 $(CGIRLS_OBJS
) : $(CGIRLS_H_SOURCES
) $(LIB_H
) $(GENERATED_H
)
66 # This saves the value of `CGIRLS_CFLAGS´ to force a rebuild of `CGIRLS_OBJS´ if the flags should change.
67 $(CGIRLSDIR
)/CGIRLS-CFLAGS
: FORCE
68 @FLAGS
='$(subst ','"'"',$(CGIRLS_CFLAGS))'; \
69 if test x"$$FLAGS" != x"$$(cat
$(CGIRLSDIR
)/CGIRLS-CFLAGS
2>/dev
/null
)" ; then \
70 echo 1>&2 " * new CGit build flags
"; \
71 echo "$$FLAGS" >$(CGIRLSDIR)/CGIRLS-CFLAGS; \
74 # Objects are built and linked the same as with Git, except depending on the additional `CGIRLS-CFLAGS´ file and using `ALL_CGIRLS_CFLAGS´ in place of `ALL_CFLAGS´.
75 $(CGIRLS_OBJS) : $(CGIRLSDIR)/%.o : $(CGIRLSDIR)/%.c GIT-CFLAGS $(CGIRLSDIR)/CGIRLS-CFLAGS $(missing_dep_dirs)
76 $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(ALL_CGIRLS_CFLAGS) $(EXTRA_CPPFLAGS) $<
77 $(CGIRLSDIR)/cgirls : $(CGIRLS_OBJS) GIT-LDFLAGS $(GITLIBS)
78 $(QUIET_LINK)$(CC) $(ALL_CGIRLS_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(sort $(LIBS))