Use includes for makefile consistency. Added make depend rule for BSDmakefile.
[xonotic/gmqcc.git] / Makefile
1 include include.mk
2
3 UNAME  ?= $(shell uname)
4 CYGWIN  = $(findstring CYGWIN,  $(UNAME))
5 MINGW   = $(findstring MINGW32, $(UNAME))
6
7 CFLAGS  += -Wall -Wextra -Werror -fno-strict-aliasing $(OPTIONAL)
8 ifneq ($(shell git describe --always 2>/dev/null),)
9     CFLAGS += -DGMQCC_GITINFO="\"$(shell git describe --always)\""
10 endif
11 #turn on tons of warnings if clang is present
12 # but also turn off the STUPID ONES
13 ifeq ($(CC), clang)
14         CFLAGS +=                              \
15             -Weverything                       \
16             -Wno-padded                        \
17             -Wno-format-nonliteral             \
18             -Wno-disabled-macro-expansion      \
19             -Wno-conversion                    \
20             -Wno-missing-prototypes            \
21             -Wno-float-equal                   \
22             -Wno-unknown-warning-option        \
23             -Wstrict-prototypes
24 else
25         #Tiny C Compiler doesn't know what -pedantic-errors is
26         # and instead of ignoring .. just errors.
27         ifneq ($(CC), tcc)
28                 CFLAGS += -pedantic-errors
29         else
30                 CFLAGS += -Wno-pointer-sign -fno-common
31         endif
32         
33         #-Wstrict-prototypes is not valid in g++
34         ifneq ($(CC), g++)
35                 CFLAGS += -Wstrict-prototypes
36         endif
37 endif
38
39 #we have duplicate object files when dealing with creating a simple list
40 #for dependinces. To combat this we use some clever recrusive-make to
41 #filter the list and remove duplicates which we use for make depend
42 RMDUP = $(if $1,$(firstword $1) $(call RMDUP,$(filter-out $(firstword $1),$1)))
43 DEPS := $(call RMDUP, $(OBJ_P) $(OBJ_T) $(OBJ_C) $(OBJ_X))
44
45 ifneq ("$(CYGWIN)", "")
46         #nullify the common variables that
47         #most *nix systems have (for windows)
48         PREFIX   :=
49         BINDIR   :=
50         DATADIR  :=
51         MANDIR   :=
52         QCVM      = qcvm.exe
53         GMQCC     = gmqcc.exe
54         TESTSUITE = testsuite.exe
55         PAK       = gmqpak.exe
56 else
57 ifneq ("$(MINGW)", "")
58         #nullify the common variables that
59         #most *nix systems have (for windows)
60         PREFIX   :=
61         BINDIR   :=
62         DATADIR  :=
63         MANDIR   :=
64         QCVM      = qcvm.exe
65         GMQCC     = gmqcc.exe
66         TESTSUITE = testsuite.exe
67         PAK       = gmqpak.exe
68 else
69         QCVM      = qcvm
70         GMQCC     = gmqcc
71         TESTSUITE = testsuite
72         PAK       = gmqpak
73 endif
74 endif
75
76 #standard rules
77 %.o: %.c
78         $(CC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS)
79
80 exec-standalone.o: exec.c
81         $(CC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS) -DQCVM_EXECUTOR=1
82
83 $(QCVM): $(OBJ_X)
84         $(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
85
86 $(GMQCC): $(OBJ_C) $(OBJ_D)
87         $(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
88
89 $(TESTSUITE): $(OBJ_T)
90         $(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
91
92 $(PAK): $(OBJ_P)
93         $(CC) -o $@ $^ $(LDFLAGS)
94
95 all: $(GMQCC) $(QCVM) $(TESTSUITE) $(PAK)
96
97 check: all
98         @ ./$(TESTSUITE)
99 test: all
100         @ ./$(TESTSUITE)
101
102 clean:
103         rm -f *.o $(GMQCC) $(QCVM) $(TESTSUITE) $(PAK) *.dat gource.mp4 *.exe
104
105 splint:
106         @  splint $(SPLINTFLAGS) *.c *.h
107
108 gource:
109         @ gource $(GOURCEFLAGS)
110
111 gource-record:
112         @ gource $(GOURCEFLAGS) -o - | ffmpeg $(FFMPEGFLAGS) gource.mp4
113
114 depend:
115         @ makedepend -Y -w 65536 2> /dev/null $(subst .o,.c,$(DEPS))
116
117 #install rules
118 install: install-gmqcc install-qcvm install-gmqpak install-doc
119 install-gmqcc: $(GMQCC)
120         install -d -m755               $(DESTDIR)$(BINDIR)
121         install    -m755  $(GMQCC)     $(DESTDIR)$(BINDIR)/$(GMQCC)
122 install-qcvm: $(QCVM)
123         install -d -m755               $(DESTDIR)$(BINDIR)
124         install    -m755  $(QCVM)      $(DESTDIR)$(BINDIR)/$(QCVM)
125 install-gmqpak: $(PAK)
126         install -d -m755               $(DESTDIR)$(BINDIR)
127         install    -m755  $(PAK)       $(DESTDIR)$(BINDIR)/$(PAK)
128 install-doc:
129         install -d -m755               $(DESTDIR)$(MANDIR)/man1
130         install    -m644  doc/gmqcc.1  $(DESTDIR)$(MANDIR)/man1/
131         install    -m644  doc/qcvm.1   $(DESTDIR)$(MANDIR)/man1/
132         install    -m644  doc/gmqpak.1 $(DESTDIR)$(MANDIR)/man1/
133
134 # DO NOT DELETE