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 # `CGIRLS_TESTOBJS´ lists the additional object files used for the testing programs.
37 CGIRLS_OBJS
:= $(patsubst %.c
,%.o
,$(shell find
'$(CGIRLSDIR)' '(' -path
'$(CGIRLSDIR)' -o
-prune
')' -a
-type f
-a
-name
'*.c' -a
'!' -name
'cgirls-test-*.c'))
38 CGIRLS_TESTOBJS
:= $(patsubst %.c
,%.o
,$(shell find
'$(CGIRLSDIR)' '(' -path
'$(CGIRLSDIR)' -o
-prune
')' -a
-type f
-a
-name
'cgirls-test-*.c'))
39 CGIRLS_TESTS
:= $(patsubst %.o
,%,$(CGIRLS_TESTOBJS
))
41 # `CGIRLS_ALLOBJS´ contains both `CGIRLS_OBJS´ and `CGIRLS_TESTOBJS´.
42 CGIRLS_ALLOBJS
= $(CGIRLS_OBJS
) $(CGIRLS_TESTOBJS
)
44 # Only `cgirls.c´ references CGIRLS_VERSION so we only rebuild its objects when the version changes.
45 CGIRLS_VERSION_OBJS
:= $(CGIRLSDIR
)/cgirls.o
46 $(CGIRLS_VERSION_OBJS
) : $(CGIRLSDIR
)/.VERSION
47 $(CGIRLS_VERSION_OBJS
) : EXTRA_CPPFLAGS
= \
48 -DCGIRLS_VERSION
='"$(CGIRLS_VERSION)"'
50 # Git handles dependencies using `:=´, so they have already been computed by this point.
51 # We have to manage the dependency files for `CGIRLS_OBJS´ ourselves.
52 cgirls_dep_files
:= $(foreach f
,$(CGIRLS_ALLOBJS
),$(dir $f).depend
/$(notdir $f).d
)
53 cgirls_dep_dirs
:= $(addsuffix .depend
,$(sort $(dir $(CGIRLS_ALLOBJS
))))
54 ifeq ($(COMPUTE_HEADER_DEPENDENCIES
),yes
)
57 missing_dep_dirs
+= $(filter-out $(wildcard $(cgirls_dep_dirs
)),$(cgirls_dep_dirs
))
59 ifdef USE_COMPUTED_HEADER_DEPENDENCIES
60 cgirls_dep_files_present
:= $(wildcard $(cgirls_dep_files
))
61 ifneq ($(cgirls_dep_files_present
),)
62 include $(cgirls_dep_files_present
)
65 $(CGIRLS_ALLOBJS
) : $(CGIRLS_H_SOURCES
) $(LIB_H
) $(GENERATED_H
)
68 # At this point, all the variables have been defined.
69 # Include custom modifications, if defined.
70 -include $(CGIRLSDIR
)/make
/config.mak
72 # This saves the value of `CGIRLS_CFLAGS´ to force a rebuild of `CGIRLS_OBJS´ if the flags should change.
73 $(CGIRLSDIR
)/.CGIRLS-CFLAGS
: FORCE
74 @FLAGS
='$(subst ','"'"',$(CGIRLS_CFLAGS))'; \
75 if test x"$$FLAGS" != x"$$(cat
$(CGIRLSDIR
)/.CGIRLS-CFLAGS
2>/dev
/null
)" ; then \
76 echo 1>&2 " * new CGit build flags
"; \
77 echo "$$FLAGS" >$(CGIRLSDIR)/.CGIRLS-CFLAGS; \
80 # 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´.
81 $(CGIRLS_ALLOBJS) : $(CGIRLSDIR)/%.o : $(CGIRLSDIR)/%.c GIT-CFLAGS $(CGIRLSDIR)/.CGIRLS-CFLAGS $(missing_dep_dirs)
82 $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(ALL_CGIRLS_CFLAGS) $(EXTRA_CPPFLAGS) $<
83 $(CGIRLSDIR)/cgirls : $(CGIRLS_OBJS) GIT-LDFLAGS $(GITLIBS)
84 $(QUIET_LINK)$(CC) $(ALL_CGIRLS_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
85 $(CGIRLS_TESTS) : $(CGIRLSDIR)/% : $(CGIRLSDIR)/%.o $(filter-out $(CGIRLSDIR)/cgirls.o,$(CGIRLS_OBJS)) GIT-LDFLAGS $(GITLIBS)
86 $(QUIET_LINK)$(CC) $(ALL_CGIRLS_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
87 cgirls-tests : $(CGIRLS_TESTS) ;