var scope reduction
[trinity.git] / Makefile
blob4a00485a6634c61f0bdf0fe124e243d9fb686c0f
1 VERSION=1.4pre
3 INSTALL_PREFIX ?= $(DESTDIR)
4 INSTALL_PREFIX ?= $(HOME)
6 ifeq ($(CC),"")
7 CC := gcc
8 endif
9 CC := $(CROSS_COMPILE)$(CC)
10 LD := $(CROSS_COMPILE)$(LD)
12 CFLAGS += -Wall -W -g -O2 -I. -Iinclude/ -Wimplicit -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D__linux__
13 ifneq ($(SYSROOT),)
14 CFLAGS += --sysroot=$(SYSROOT)
15 endif
16 #CFLAGS += $(shell if $(CC) -m32 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-m32"; fi)
17 CFLAGS += -Wdeclaration-after-statement
18 CFLAGS += -Wformat=2
19 CFLAGS += -Winit-self
20 CFLAGS += -Wlogical-op
21 CFLAGS += -Wnested-externs
22 CFLAGS += -Wpacked
23 CFLAGS += -Wshadow
24 CFLAGS += -Wstrict-aliasing=3
25 CFLAGS += -Wswitch-enum
26 CFLAGS += -Wundef
27 CFLAGS += -Wwrite-strings
28 CFLAGS += -Wno-format-nonliteral
29 CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
31 # Only enabled during development, and on gcc 4.8+
32 CPP_MAJOR := $(shell $(CPP) -dumpversion 2>&1 | cut -d'.' -f1)
33 CPP_MINOR := $(shell $(CPP) -dumpversion 2>&1 | cut -d'.' -f2)
34 DEVEL := $(shell grep VERSION Makefile | head -n1 | grep pre | wc -l)
35 CFLAGS += $(shell if [ $(CPP_MAJOR) -eq 4 -a $(CPP_MINOR) -ge 8 -a $(DEVEL) -eq 1 ] ; then echo "-Werror"; else echo ""; fi)
37 V = @
38 Q = $(V:1=)
39 QUIET_CC = $(Q:@=@echo ' CC '$@;)
42 all: trinity
44 test:
45 @if [ ! -f config.h ]; then echo "\e[1;31mRun configure.sh first.\e[0m" ; exit; fi
48 MACHINE = $(shell $(CC) -dumpmachine)
49 SYSCALLS_ARCH = $(shell case "$(MACHINE)" in \
50 (sh*) echo syscalls/sh/*.c ;; \
51 (ia64*) echo syscalls/ia64/*.c ;; \
52 esac)
54 HEADERS = $(patsubst %.h,%.h,$(wildcard *.h)) $(patsubst %.h,%.h,$(wildcard syscalls/*.h)) $(patsubst %.h,%.h,$(wildcard ioctls/*.h))
56 SRCS = $(wildcard *.c) \
57 $(wildcard children/*.c) \
58 $(wildcard ioctls/*.c) \
59 $(wildcard net/*.c) \
60 $(wildcard syscalls/*.c) \
61 $(SYSCALLS_ARCH)
63 OBJS = $(sort $(patsubst %.c,%.o,$(wildcard *.c))) \
64 $(sort $(patsubst %.c,%.o,$(wildcard children/*.c))) \
65 $(sort $(patsubst %.c,%.o,$(wildcard ioctls/*.c))) \
66 $(sort $(patsubst %.c,%.o,$(wildcard net/*.c))) \
67 $(sort $(patsubst %.c,%.o,$(wildcard syscalls/*.c))) \
68 $(sort $(patsubst %.c,%.o,$(SYSCALLS_ARCH)))
70 DEPDIR= .deps
72 -include $(SRCS:%.c=$(DEPDIR)/%.d)
74 trinity: test $(OBJS) $(HEADERS)
75 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o trinity $(OBJS)
76 @mkdir -p tmp
78 df = $(DEPDIR)/$(*D)/$(*F)
80 %.o : %.c
81 $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -c $<
82 @mkdir -p $(DEPDIR)/$(*D)
83 @gcc -MM $(CFLAGS) $*.c > $(df).d
84 @mv -f $(df).d $(df).d.tmp
85 @sed -e 's|.*:|$*.o:|' <$(df).d.tmp > $(df).d
86 @sed -e 's/.*://' -e 's/\\$$//' < $(df).d.tmp | fmt -1 | \
87 sed -e 's/^ *//' -e 's/$$/:/' >> $(df).d
88 @rm -f $(df).d.tmp
90 clean:
91 @rm -f $(OBJS)
92 @rm -f core.*
93 @rm -f trinity
94 @rm -f tags
95 @rm -rf $(DEPDIR)/*
97 devel:
98 @perl -p -i -e 's/DEVEL=0/DEVEL=1/' configure.sh
99 git commit Makefile configure.sh -m "Enable -Werror & devel mode"
101 release:
102 @perl -p -i -e 's/DEVEL=1/DEVEL=0/' configure.sh
103 git commit Makefile configure.sh -m "Disable -Werror & devel mode"
105 tag:
106 git tag -a $(VERSION) -m "$(VERSION) release."
108 tarball:
109 git repack -a -d
110 git prune-packed
111 git archive --format=tar.gz --prefix=trinity-$(VERSION)/ HEAD > trinity-$(VERSION).tgz
113 install: trinity
114 install -d -m 755 $(INSTALL_PREFIX)/bin
115 install trinity $(INSTALL_PREFIX)/bin
117 tags: $(SRCS)
118 @ctags -R --exclude=tmp
120 mirror:
121 @git push --mirror git@github.com:kernelslacker/trinity.git
123 scan:
124 @scan-build --use-analyzer=/usr/bin/clang make
126 coverity:
127 rm -rf cov-int trinity-coverity.tgz
128 cov-build --dir cov-int make
129 tar czvf trinity-coverity.tgz cov-int