*: Updated copyright to 2009 and normalized name & email.
[kbuild-mirror.git] / src / kmk / Makefile.kmk
blob94b4bf5e7aa5fe9d47e46e7d4ca82694060b0312
1 # $Id$
2 ## @file
3 # Sub-makefile for kmk / GNU Make.
7 # Copyright (c) 2004-2009 knut st. osmundsen <bird-kBuild-spamix@anduin.net>
9 # This file is part of kBuild.
11 # kBuild is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # kBuild is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with kBuild. If not, see <http://www.gnu.org/licenses/>
26 SUB_DEPTH = ../..
27 include $(KBUILD_PATH)/subheader.kmk
31 # Template for kmk and the kmk_* binaries in this makefile.
33 TEMPLATE_BIN-KMK = Template for src/gmake binaries
34 TEMPLATE_BIN-KMK_EXTENDS = BIN
35 TEMPLATE_BIN-KMK_DEFS = \
36 HAVE_CONFIG_H \
37 $(TEMPLATE_BIN_DEFS) \
38 KBUILD_SVN_REV=$(KBUILD_SVN_REV) \
39 KBUILD_TYPE=\"$(KBUILD_TYPE)\"
40 TEMPLATE_BIN-KMK_DEPS = \
41 $(PATH_kmk)/config.h \
42 $(PATH_kmk)/fts.h
43 TEMPLATE_BIN-KMK_CLEAN = $(TEMPLATE_BIN-KMK_DEPS)
44 TEMPLATE_BIN-KMK_DEPS.solaris = \
45 $(PATH_kmk)/paths.h
46 TEMPLATE_BIN-KMK_CLEAN.solaris = $(TEMPLATE_BIN-KMK_DEPS.solaris)
47 TEMPLATE_BIN-KMK_DEPS.win = \
48 $(PATH_kmk)/sysexits.h \
49 $(PATH_kmk)/unistd.h \
50 $(PATH_kmk)/paths.h \
51 $(PATH_kmk)/grp.h \
52 $(PATH_kmk)/pwd.h \
53 $(PATH_kmk)/inttypes.h
54 TEMPLATE_BIN-KMK_CFLAGS.win.amd64 = $(TEMPLATE_BIN_CFLAGS.win.amd64) -wd4244 -wd4267
55 TEMPLATE_BIN-KMK_CLEAN.win = $(TEMPLATE_BIN-KMK_DEPS.win)
56 TEMPLATE_BIN-KMK_INCS = $(PATH_kmk) . $(TEMPLATE_BIN_INCS)
57 TEMPLATE_BIN-KMK_INCS.darwin = glob
58 TEMPLATE_BIN-KMK_INCS.dragonfly = glob
59 TEMPLATE_BIN-KMK_INCS.freebsd = glob
60 TEMPLATE_BIN-KMK_INCS.solaris = glob
61 TEMPLATE_BIN-KMK_LIBS = $(TEMPLATE_BIN_LIBS) $(TARGET_kmkmissing) $(LIB_KUTIL)
62 ifdef ELECTRIC_HEAP # for electric heap (see electric.c) - windows only.
63 ifeq ($(KBUILD_TARGET),win)
64 TEMPLATE_BIN-KMK_CFLAGS = $(TEMPLATE_BIN_CFLAGS) /FI$(kmk_PATH)/electric.h -DELECTRIC_HEAP=1
65 else
66 TEMPLATE_BIN-KMK_CFLAGS = $(TEMPLATE_BIN_CFLAGS) -include $(kmk_PATH)/electric.h -DELECTRIC_HEAP=1
67 endif
68 endif
72 # A library containing the missing features needed by kmk and the
73 # kmk_* binaries. Saves a bit of work later on.
75 LIBRARIES += kmkmissing
76 kmkmissing_TEMPLATE = BIN-KMK
77 kmkmissing_DEFS = KMK
78 kmkmissing_NOINST = 1
79 kmkmissing_SOURCES = \
80 kmkbuiltin/err.c \
81 kmkbuiltin/fts.c \
82 kmkbuiltin/setmode.c \
83 kmkbuiltin/strmode.c \
84 kmkbuiltin/kbuild_version.c \
85 kmkbuiltin/kbuild_protection.c \
86 getopt.c \
87 getopt1.c \
88 electric.c
90 kmkmissing_SOURCES.darwin = \
91 kmkbuiltin/darwin.c \
92 glob/glob.c \
93 glob/fnmatch.c
95 kmkmissing_SOURCES.dragonfly = \
96 glob/glob.c \
97 glob/fnmatch.c
99 kmkmissing_SOURCES.freebsd = \
100 glob/glob.c \
101 glob/fnmatch.c
103 kmkmissing_SOURCES.linux += \
104 kmkbuiltin/strlcpy.c
106 kmkmissing_SOURCES.solaris = \
107 kmkbuiltin/strlcpy.c \
108 kmkbuiltin/solfakes.c \
109 glob/glob.c \
110 glob/fnmatch.c
112 kmkmissing_SOURCES.win += \
113 kmkbuiltin/strlcpy.c \
114 kmkbuiltin/mscfakes.c \
115 glob/glob.c \
116 glob/fnmatch.c \
117 getloadavg.c \
118 w32/subproc/misc.c \
119 w32/subproc/sub_proc.c \
120 w32/subproc/w32err.c \
121 w32/compat/dirent.c \
122 w32/pathstuff.c
125 # kmk
127 PROGRAMS += kmk
129 kmk_TEMPLATE = BIN-KMK
131 kmk_DEFS = \
132 NO_ARCHIVES \
133 EXPERIMENTAL \
134 CONFIG_WITH_TOUPPER_TOLOWER \
135 CONFIG_WITH_DEFINED \
136 CONFIG_WITH_EXPLICIT_MULTITARGET \
137 CONFIG_WITH_DOT_MUST_MAKE \
138 CONFIG_WITH_PREPEND_ASSIGNMENT \
139 CONFIG_WITH_LOCAL_VARIABLES \
140 CONFIG_WITH_2ND_TARGET_EXPANSION \
141 CONFIG_WITH_ALLOC_CACHES \
142 CONFIG_WITH_STRCACHE2 \
144 KMK \
145 KMK_HELPERS \
146 CONFIG_NO_DEFAULT_SUFFIXES \
147 CONFIG_NO_DEFAULT_PATTERN_RULES \
148 CONFIG_NO_DEFAULT_TERMINAL_RULES \
149 CONFIG_NO_DEFAULT_SUFFIX_RULES \
150 CONFIG_NO_DEFAULT_VARIABLES \
151 CONFIG_WITH_EXTENDED_NOTPARALLEL \
152 CONFIG_WITH_INCLUDEDEP \
153 CONFIG_WITH_VALUE_LENGTH \
154 CONFIG_WITH_RSORT \
155 CONFIG_WITH_ABSPATHEX \
156 CONFIG_WITH_COMPARE \
157 CONFIG_WITH_STACK \
158 CONFIG_WITH_MATH \
159 CONFIG_WITH_XARGS \
160 CONFIG_WITH_NANOTS \
161 CONFIG_WITH_SET_CONDITIONALS \
162 CONFIG_WITH_IF_CONDITIONALS \
163 CONFIG_WITH_DATE \
164 CONFIG_WITH_FILE_SIZE \
165 CONFIG_WITH_WHICH \
166 CONFIG_WITH_PRINTF \
167 CONFIG_WITH_EVALPLUS \
168 CONFIG_WITH_MINIMAL_STATS \
169 CONFIG_WITH_COMMANDS_FUNC \
170 CONFIG_WITH_PRINTF \
171 CONFIG_WITH_STRING_FUNCTIONS \
172 CONFIG_WITH_LOOP_FUNCTIONS \
173 CONFIG_WITH_ROOT_FUNC \
174 CONFIG_PRETTY_COMMAND_PRINTING \
175 CONFIG_WITH_PRINT_STATS_SWITCH \
176 CONFIG_WITH_PRINT_TIME_SWITCH \
177 CONFIG_WITH_RDONLY_VARIABLE_VALUE \
178 CONFIG_WITH_LAZY_DEPS_VARS \
179 CONFIG_WITH_MEMORY_OPTIMIZATIONS \
181 KBUILD_HOST=\"$(KBUILD_TARGET)\" \
182 KBUILD_HOST_ARCH=\"$(KBUILD_TARGET_ARCH)\" \
183 KBUILD_HOST_CPU=\"$(KBUILD_TARGET_CPU)\"
184 kmk_DEFS.x86 = CONFIG_WITH_OPTIMIZATION_HACKS
185 kmk_DEFS.amd64 = CONFIG_WITH_OPTIMIZATION_HACKS
186 kmk_DEFS.win = CONFIG_NEW_WIN32_CTRL_EVENT CONFIG_WITH_FAST_IS_SPACE
187 kmk_DEFS.debug = CONFIG_WITH_MAKE_STATS
189 kmk_SOURCES = \
190 main.c \
191 kbuild.c \
192 read.c \
193 expreval.c \
194 incdep.c \
195 hash.c \
196 strcache.c \
197 strcache2.c \
198 variable.c \
199 ar.c \
200 arscan.c \
201 commands.c \
202 default.c \
203 dir.c \
204 expand.c \
205 file.c \
206 function.c \
207 implicit.c \
208 job.c \
209 misc.c \
210 alloccache.c \
211 remake.c \
212 rule.c \
213 signame.c \
214 version.c \
215 vpath.c \
216 remote-stub.c
218 #kmk_LIBS.solaris = malloc
219 #kmk_DEFS.solaris += HAVE_MALLINFO
221 kmk_LIBS.freebsd.amd64 = pthread
222 kmk_DEFS.freebsd.x86 = CONFIG_WITHOUT_THREADS
225 # kmkbuiltin commands
227 kmk_DEFS += CONFIG_WITH_KMK_BUILTIN
228 kmk_LIBS += $(LIB_KUTIL) $(LIB_KDEP)
229 kmk_SOURCES += \
230 kmkbuiltin.c \
231 kmkbuiltin/append.c \
232 kmkbuiltin/cat.c \
233 kmkbuiltin/chmod.c \
234 kmkbuiltin/cmp.c \
235 kmkbuiltin/cmp_util.c \
236 kmkbuiltin/cp.c \
237 kmkbuiltin/cp_utils.c \
238 kmkbuiltin/echo.c \
239 kmkbuiltin/expr.c \
240 kmkbuiltin/install.c \
241 kmkbuiltin/kDepIDB.c \
242 kmkbuiltin/md5sum.c \
243 kmkbuiltin/mkdir.c \
244 kmkbuiltin/mv.c \
245 kmkbuiltin/ln.c \
246 kmkbuiltin/printf.c \
247 kmkbuiltin/rm.c \
248 kmkbuiltin/rmdir.c \
249 kmkbuiltin/sleep.c \
250 kmkbuiltin/test.c \
252 ## @todo kmkbuiltin/redirect.c
254 ## Some profiling
255 #kmk_SOURCES += kbuildprf.c
256 #kmk_DEFS += open=prf_open read=prf_read lseek=prf_lseek close=prf_close
257 ##kmk_DEFS += KMK_PRF=1
258 ##kmkmissing_DEFS += KMK_PRF=1
261 # Standalone kmkbuiltin commands.
263 PROGRAMS += \
264 kmk_append \
265 kmk_cat \
266 kmk_chmod \
267 kmk_cp \
268 kmk_cmp \
269 kmk_echo \
270 kmk_expr \
271 kmk_md5sum \
272 kmk_mkdir \
273 kmk_mv \
274 kmk_install \
275 kmk_ln \
276 kmk_printf \
277 kmk_redirect \
278 kmk_rm \
279 kmk_rmdir \
280 kmk_sleep \
281 kmk_test \
282 kDepIDB \
284 kmk_append_TEMPLATE = BIN-KMK
285 kmk_append_DEFS = kmk_builtin_append=main
286 kmk_append_INCS = .
287 kmk_append_SOURCES = \
288 kmkbuiltin/append.c
290 kmk_cat_TEMPLATE = BIN-KMK
291 kmk_cat_DEFS = kmk_builtin_cat=main
292 kmk_cat_SOURCES = \
293 kmkbuiltin/cat.c
295 kmk_chmod_TEMPLATE = BIN-KMK
296 kmk_chmod_DEFS = kmk_builtin_chmod=main
297 kmk_chmod_SOURCES = \
298 kmkbuiltin/chmod.c
300 kmk_cmp_TEMPLATE = BIN-KMK
301 kmk_cmp_DEFS = kmk_builtin_cmp=main
302 kmk_cmp_SOURCES = \
303 kmkbuiltin/cmp.c \
304 kmkbuiltin/cmp_util.c
306 kmk_cp_TEMPLATE = BIN-KMK
307 kmk_cp_DEFS = kmk_builtin_cp=main
308 kmk_cp_SOURCES = \
309 kmkbuiltin/cp.c \
310 kmkbuiltin/cp_utils.c \
311 kmkbuiltin/cmp_util.c
313 kmk_echo_TEMPLATE = BIN-KMK
314 kmk_echo_DEFS = kmk_builtin_echo=main
315 kmk_echo_SOURCES = \
316 kmkbuiltin/echo.c
318 kmk_expr_TEMPLATE = BIN-KMK
319 kmk_expr_DEFS = kmk_builtin_expr=main
320 kmk_expr_SOURCES = \
321 kmkbuiltin/expr.c
323 kmk_install_TEMPLATE = BIN-KMK
324 kmk_install_DEFS = kmk_builtin_install=main
325 kmk_install_SOURCES = \
326 kmkbuiltin/install.c
328 kmk_ln_TEMPLATE = BIN-KMK
329 kmk_ln_DEFS = kmk_builtin_ln=main
330 kmk_ln_SOURCES = \
331 kmkbuiltin/ln.c
333 kmk_mkdir_TEMPLATE = BIN-KMK
334 kmk_mkdir_DEFS = kmk_builtin_mkdir=main
335 kmk_mkdir_SOURCES = \
336 kmkbuiltin/mkdir.c
338 kmk_md5sum_TEMPLATE = BIN-KMK
339 kmk_md5sum_DEFS = kmk_builtin_md5sum=main
340 kmk_md5sum_SOURCES = \
341 kmkbuiltin/md5sum.c
342 kmk_md5sum_LIBS = $(LIB_KUTIL)
344 kmk_mv_TEMPLATE = BIN-KMK
345 kmk_mv_DEFS = kmk_builtin_mv=main
346 kmk_mv_SOURCES = \
347 kmkbuiltin/mv.c
349 kmk_printf_TEMPLATE = BIN-KMK
350 kmk_printf_DEFS = kmk_builtin_printf=main
351 kmk_printf_SOURCES = \
352 kmkbuiltin/printf.c
354 kmk_rm_TEMPLATE = BIN-KMK
355 kmk_rm_DEFS = kmk_builtin_rm=main
356 kmk_rm_SOURCES = \
357 kmkbuiltin/rm.c
359 kmk_redirect_TEMPLATE = BIN-KMK
360 kmk_redirect_DEFS = kmk_builtin_redirect=main
361 kmk_redirect_SOURCES = \
362 kmkbuiltin/redirect.c
364 kmk_rmdir_TEMPLATE = BIN-KMK
365 kmk_rmdir_DEFS = kmk_builtin_rmdir=main
366 kmk_rmdir_SOURCES = \
367 kmkbuiltin/rmdir.c
369 kmk_sleep_TEMPLATE = BIN-KMK
370 kmk_sleep_DEFS = kmk_builtin_sleep=main
371 kmk_sleep_SOURCES = \
372 kmkbuiltin/sleep.c
374 kmk_test_TEMPLATE = BIN-KMK
375 kmk_test_DEFS = kmk_builtin_test=main
376 kmk_test_SOURCES = \
377 kmkbuiltin/test.c
379 kDepIDB_TEMPLATE = BIN-KMK
380 kDepIDB_DEFS = kmk_builtin_kDepIDB=main
381 kDepIDB_INCS = .
382 kDepIDB_LIBS = $(LIB_KDEP)
383 kDepIDB_SOURCES = \
384 kmkbuiltin/kDepIDB.c
388 # kmk_gmake - almost plain GNU Make.
390 PROGRAMS += kmk_gmake
392 kmk_gmake_TEMPLATE = BIN-KMK
393 kmk_gmake_DEFS = \
394 HAVE_CONFIG_H \
395 NO_ARCHIVES \
396 CONFIG_WITH_TOUPPER_TOLOWER \
397 EXPERIMENTAL
399 kmk_gmake_SOURCES = \
400 main.c \
401 read.c \
402 hash.c \
403 strcache.c \
404 variable.c \
405 ar.c \
406 arscan.c \
407 commands.c \
408 default.c \
409 dir.c \
410 expand.c \
411 file.c \
412 function.c \
413 implicit.c \
414 job.c \
415 misc.c \
416 remake.c \
417 rule.c \
418 signame.c \
419 version.c \
420 vpath.c \
421 remote-stub.c
425 # kmk_fmake - Faster GNU Make.
427 ifeq ($(USER),bird) # for experimental purposes only.
428 PROGRAMS += kmk_fgmake
429 endif
431 kmk_fgmake_TEMPLATE = BIN-KMK
432 kmk_fgmake_DEFS = \
433 HAVE_CONFIG_H \
434 NO_ARCHIVES \
435 CONFIG_WITH_TOUPPER_TOLOWER \
436 EXPERIMENTAL \
438 CONFIG_WITH_ALLOC_CACHES \
439 CONFIG_WITH_LAZY_DEPS_VARS \
440 CONFIG_WITH_STRCACHE2 \
441 CONFIG_WITH_VALUE_LENGTH \
442 CONFIG_WITH_RDONLY_VARIABLE_VALUE
443 # TODO ?
444 # CONFIG_WITH_PRINT_STATS_SWITCH \
445 # CONFIG_WITH_EXTENDED_NOTPARALLEL \
447 kmk_fgmake_SOURCES = \
448 main.c \
449 read.c \
450 hash.c \
451 strcache.c \
452 strcache2.c \
453 variable.c \
454 ar.c \
455 arscan.c \
456 commands.c \
457 default.c \
458 dir.c \
459 expand.c \
460 file.c \
461 function.c \
462 implicit.c \
463 job.c \
464 misc.c \
465 alloccache.c \
466 remake.c \
467 rule.c \
468 signame.c \
469 version.c \
470 vpath.c \
471 remote-stub.c
474 include $(FILE_KBUILD_SUB_FOOTER)
478 # Use checked in config.h instead of running ./Configure for it.
480 kmk_config.h.$(KBUILD_TARGET) := $(kmk_PATH)/config.h.$(KBUILD_TARGET)
481 $(PATH_kmk)/config.h: $(kmk_config.h.$(KBUILD_TARGET))
482 $(MKDIR) -p $(dir $@)
483 $(CP) $^ $@
486 # Some missing headers.
488 $(PATH_kmk)/fts.h: $(kmk_PATH)/kmkbuiltin/ftsfake.h | $(call DIRDEP,$(PATH_kmk))
489 $(CP) $^ $@
491 $(PATH_kmk)/unistd.h: | $(call DIRDEP,$(PATH_kmk))
492 $(ECHO_EXT) > $@
494 $(PATH_kmk)/sysexits.h: | $(call DIRDEP,$(PATH_kmk))
495 $(ECHO_EXT) > $@
497 $(PATH_kmk)/inttypes.h: | $(call DIRDEP,$(PATH_kmk))
498 $(ECHO_EXT) > $@
500 $(PATH_kmk)/paths.h: | $(call DIRDEP,$(PATH_kmk))
501 $(ECHO_EXT) > $@
503 $(PATH_kmk)/pwd.h: | $(call DIRDEP,$(PATH_kmk))
504 $(ECHO_EXT) > $@
506 $(PATH_kmk)/grp.h: | $(call DIRDEP,$(PATH_kmk))
507 $(ECHO_EXT) > $@
511 # Some tests.
513 parallel: parallel_1 parallel_2 parallel_3 parallel_4 parallel_5
514 parallel_1 parallel_2 parallel_3 parallel_4 parallel_5:
515 echo $@_start ; sleep 1; echo $@_done
517 my_test:
518 echo "1"
519 echo "2"
520 echo "3"
521 echo "4"
525 # Shell execution tests.
527 test_shell: test_shell_quoting test_shell_double_quoting test_shell_newline
529 # shell double and single quoting check (was busted on windows in 3.81).
530 test_shell_quoting:
531 $(ECHO_EXT) "double quoted sTrInG"
532 $(ECHO_EXT) "double quoted sTrInG" | $(SED_EXT) -e "s/sTrInG/string/g"
533 $(ECHO_EXT) 'single quoted sTrInG' | $(SED_EXT) -e 's/sTrInG/string/g'
534 $(ECHO) "This string should not be printed with double quotes."
535 $(ECHO) 'This string should not be printed with single quotes.'
536 ( echo " #define PWD \"`pwd`\""; )
538 test_shell_double_quoting:
539 $(ECHO_EXT) "foo foo foo" | $(SED_EXT) -e \
540 "s/foo/$@/" -e \
541 "s/foo/works/" \
542 -e "s/foo/\!/"
544 test_shell_double_quoting2:
545 $(ECHO_EXT) "foo foo foo" | $(SED_EXT) -e \
546 "s/foo/$@/" -e \
547 "s/foo/works/" \
549 "s/foo/\!/"
551 # when using batch mode shell, the newline got escaped twice and spoiling everything.
552 test_shell_newline:
553 $(ECHO_EXT) "foo foo foo" | $(SED_EXT) -e \
554 's/foo/$@/' -e \
555 's/foo/works/' \
556 -e 's/foo/\!/'
559 test_stack:
560 $(MAKE) -f $(kmk_PATH)/testcase-stack.kmk
562 test_math:
563 $(MAKE) -f $(kmk_PATH)/testcase-math.kmk
565 test_if1of:
566 $(MAKE) -f $(kmk_PATH)/testcase-if1of.kmk
568 test_local:
569 $(MAKE) -f $(kmk_PATH)/testcase-local.kmk
571 test_includedep:
572 $(MAKE) -f $(kmk_PATH)/testcase-includedep.kmk
574 test_2ndtargetexp:
575 $(MAKE) -f $(kmk_PATH)/testcase-2ndtargetexp.kmk
577 test_30_continued_on_failure_worker:
578 this_executable_does_not_exist.exe
579 echo "We shouldn't see this..."
581 test_30_continued_on_failure:
582 $(MAKE) -f $(MAKEFILE) test_30_continued_on_failure_worker; \
583 RC=$$?; \
584 if test $${RC} -ne 2; then \
585 echo "$@: FAILED - exit code $${RC} instead of 2."; \
586 exit 1; \
587 else \
588 echo "$@: SUCCESS"; \
591 test_lazy_deps_vars:
592 $(MAKE) -C $(kmk_PATH) -f testcase-lazy-deps-vars.kmk
595 test_all: test_math test_stack test_shell test_if1of test_local test_includedep test_2ndtargetexp test_30_continued_on_failure test_lazy_deps_vars