Merge pull request #183 from kernigh/kernigh-include
[ack.git] / Makefile
1 # ======================================================================= #
2 #                          ACK CONFIGURATION                              #
3 #                      (Edit this before building)                        #
4 # ======================================================================= #
5
6 # What platform to build for by default?
7
8 DEFAULT_PLATFORM = pc86
9
10 # Where should the ACK put its temporary files?
11
12 ACK_TEMP_DIR = /tmp
13
14 # Where is the ACK going to be installed, eventually? If you don't want to
15 # install it and just want to run the ACK from the build directory
16 # (/tmp/ack-build/staging, by default), leave this as $(INSDIR).
17
18 PREFIX = /usr/local
19 #PREFIX = $(INSDIR)
20
21 # Where do you want to put the object files used when building?
22
23 BUILDDIR = $(ACK_TEMP_DIR)/ack-build
24
25 # What build flags do you want to use for native code?
26
27 CFLAGS = -g -Wno-return-type
28 LDFLAGS = 
29
30 # Various commands.
31
32 AR = ar
33 CC = gcc
34
35 # Which build system to use; use 'ninja' or 'make' (in lower case). Leave
36 # blank to autodetect.
37
38 BUILDSYSTEM =
39
40 # Build flags for ninja.
41
42 NINJAFLAGS =
43
44 # Build flags for make.
45
46 MAKEFLAGS = 
47
48 # ======================================================================= #
49 #                         END OF CONFIGURATION                            #
50 # ======================================================================= #
51
52 # You shouldn't need to change anything below this point unless you are
53 # actually developing ACK.
54
55 OBJDIR = $(abspath $(BUILDDIR)/obj)
56 BINDIR = $(abspath $(BUILDDIR)/bin)
57 LIBDIR = $(abspath $(BUILDDIR)/lib)
58 INCDIR = $(abspath $(BUILDDIR)/include)
59 INSDIR = $(abspath $(BUILDDIR)/staging)
60
61 PLATIND = $(INSDIR)/share/ack
62 PLATDEP = $(INSDIR)/lib/ack
63
64 .NOTPARALLEL:
65
66 ifeq ($(BUILDSYSTEM),)
67   ifneq ($(shell which ninja),)
68 BUILDSYSTEM = ninja
69   else
70 BUILDSYSTEM = make
71   endif
72 endif
73
74 build-file = $(BUILDDIR)/build.$(BUILDSYSTEM)
75 lua-files = $(shell find . -name 'build*.lua')
76 our-lua = $(BUILDDIR)/lua
77
78 # GNU make sets MAKECMDGOALS to the list of targets from the command
79 # line.  We look for targets with '+' and forward them to BUILDSYSTEM.
80 # This handles commands like
81 #     $ make util/opt+pkg util/ego+pkg
82
83 all-goals = +ack +tests
84 plus-goals := $(patsubst all,$(all-goals),$(or $(MAKECMDGOALS),all))
85 plus-goals := $(foreach g,$(plus-goals),$(if $(findstring +,$(g)),$(g),))
86
87 # @true silences extra message, "make: Nothing to be done..."
88
89 all: build-plus-goals
90         @true
91
92 ifneq ($(plus-goals),)
93 $(plus-goals): build-plus-goals
94         @true
95 endif
96
97 build-plus-goals: $(build-file)
98 ifeq ($(BUILDSYSTEM),ninja)
99         @ninja $(NINJAFLAGS) -f $(build-file) $(plus-goals)
100 else ifeq ($(BUILDSYSTEM),make)
101 # GNU make passes MAKEFLAGS in environment.
102         @$(MAKE) -f $(build-file) $(plus-goals)
103 else
104 $(error unknown BUILDSYSTEM = $(BUILDSYSTEM))
105 endif
106
107 $(build-file): first/ackbuilder.lua Makefile $(lua-files) $(our-lua)
108         @mkdir -p $(BUILDDIR)
109         @$(our-lua) first/ackbuilder.lua \
110                 first/build.lua build.lua \
111                 --$(BUILDSYSTEM) \
112                 LUA=$(our-lua) \
113                 DEFAULT_PLATFORM=$(DEFAULT_PLATFORM) \
114                 OBJDIR=$(OBJDIR) \
115                 BINDIR=$(BINDIR) \
116                 LIBDIR=$(LIBDIR) \
117                 INCDIR=$(INCDIR) \
118                 INSDIR=$(INSDIR) \
119                 PLATIND=$(PLATIND) \
120                 PLATDEP=$(PLATDEP) \
121                 PREFIX=$(PREFIX) \
122                 AR=$(AR) \
123                 CC=$(CC) \
124                 CFLAGS="$(CFLAGS)" \
125                 > $(build-file)
126
127 install:
128         mkdir -p $(PREFIX)
129         tar cf - -C $(INSDIR) . | tar xvf - -C $(PREFIX)
130
131 clean:
132         rm -rf $(BUILDDIR)
133
134 uname := $(shell uname)
135 ifeq (Linux,$(uname))
136 # Turn on LUA_USE_POSIX so that Lua is not compiled with the dangerous
137 # tmpnam(.) function.  But, do not use LUA_USE_LINUX here, since that will
138 # also turn on LUA_USE_READLINE, and I do not want to force everyone to
139 # install libreadline-dev.  -- tkchia
140 $(our-lua): CFLAGS += -DLUA_USE_POSIX -DLUA_USE_DLOPEN
141 $(our-lua): LDFLAGS += -ldl
142 else
143 ifeq (Darwin,$(uname))
144 $(our-lua): CFLAGS += -DLUA_USE_MACOSX
145 endif
146 endif
147
148 $(our-lua): first/lua-5.1/*.c first/lua-5.1/*.h
149         @echo Bootstrapping build
150         @mkdir -p $(BUILDDIR)
151         @$(CC) $(CFLAGS) -o $(our-lua) -O first/lua-5.1/*.c $(LDFLAGS) -lm