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/>
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
= \
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 \
43 TEMPLATE_BIN-KMK_CLEAN
= $(TEMPLATE_BIN-KMK_DEPS
)
44 TEMPLATE_BIN-KMK_DEPS.solaris
= \
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 \
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
66 TEMPLATE_BIN-KMK_CFLAGS
= $(TEMPLATE_BIN_CFLAGS
) -include $(kmk_PATH
)/electric.h
-DELECTRIC_HEAP
=1
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
79 kmkmissing_SOURCES
= \
82 kmkbuiltin
/setmode.c \
83 kmkbuiltin
/strmode.c \
84 kmkbuiltin
/kbuild_version.c \
85 kmkbuiltin
/kbuild_protection.c \
90 kmkmissing_SOURCES.darwin
= \
95 kmkmissing_SOURCES.dragonfly
= \
99 kmkmissing_SOURCES.freebsd
= \
103 kmkmissing_SOURCES.linux
+= \
106 kmkmissing_SOURCES.solaris
= \
107 kmkbuiltin
/strlcpy.c \
108 kmkbuiltin
/solfakes.c \
112 kmkmissing_SOURCES.win
+= \
113 kmkbuiltin
/strlcpy.c \
114 kmkbuiltin
/mscfakes.c \
119 w32
/subproc
/sub_proc.c \
120 w32
/subproc
/w32err.c \
121 w32
/compat
/dirent.c \
129 kmk_TEMPLATE
= BIN-KMK
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 \
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 \
155 CONFIG_WITH_ABSPATHEX \
156 CONFIG_WITH_COMPARE \
161 CONFIG_WITH_SET_CONDITIONALS \
162 CONFIG_WITH_IF_CONDITIONALS \
164 CONFIG_WITH_FILE_SIZE \
167 CONFIG_WITH_EVALPLUS \
168 CONFIG_WITH_MINIMAL_STATS \
169 CONFIG_WITH_COMMANDS_FUNC \
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
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
)
231 kmkbuiltin
/append.c \
235 kmkbuiltin
/cmp_util.c \
237 kmkbuiltin
/cp_utils.c \
240 kmkbuiltin
/install.c \
241 kmkbuiltin
/kDepIDB.c \
242 kmkbuiltin
/md5sum.c \
246 kmkbuiltin
/printf.c \
252 ## @todo kmkbuiltin/redirect.c
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.
284 kmk_append_TEMPLATE
= BIN-KMK
285 kmk_append_DEFS
= kmk_builtin_append
=main
287 kmk_append_SOURCES
= \
290 kmk_cat_TEMPLATE
= BIN-KMK
291 kmk_cat_DEFS
= kmk_builtin_cat
=main
295 kmk_chmod_TEMPLATE
= BIN-KMK
296 kmk_chmod_DEFS
= kmk_builtin_chmod
=main
297 kmk_chmod_SOURCES
= \
300 kmk_cmp_TEMPLATE
= BIN-KMK
301 kmk_cmp_DEFS
= kmk_builtin_cmp
=main
304 kmkbuiltin
/cmp_util.c
306 kmk_cp_TEMPLATE
= BIN-KMK
307 kmk_cp_DEFS
= kmk_builtin_cp
=main
310 kmkbuiltin
/cp_utils.c \
311 kmkbuiltin
/cmp_util.c
313 kmk_echo_TEMPLATE
= BIN-KMK
314 kmk_echo_DEFS
= kmk_builtin_echo
=main
318 kmk_expr_TEMPLATE
= BIN-KMK
319 kmk_expr_DEFS
= kmk_builtin_expr
=main
323 kmk_install_TEMPLATE
= BIN-KMK
324 kmk_install_DEFS
= kmk_builtin_install
=main
325 kmk_install_SOURCES
= \
328 kmk_ln_TEMPLATE
= BIN-KMK
329 kmk_ln_DEFS
= kmk_builtin_ln
=main
333 kmk_mkdir_TEMPLATE
= BIN-KMK
334 kmk_mkdir_DEFS
= kmk_builtin_mkdir
=main
335 kmk_mkdir_SOURCES
= \
338 kmk_md5sum_TEMPLATE
= BIN-KMK
339 kmk_md5sum_DEFS
= kmk_builtin_md5sum
=main
340 kmk_md5sum_SOURCES
= \
342 kmk_md5sum_LIBS
= $(LIB_KUTIL
)
344 kmk_mv_TEMPLATE
= BIN-KMK
345 kmk_mv_DEFS
= kmk_builtin_mv
=main
349 kmk_printf_TEMPLATE
= BIN-KMK
350 kmk_printf_DEFS
= kmk_builtin_printf
=main
351 kmk_printf_SOURCES
= \
354 kmk_rm_TEMPLATE
= BIN-KMK
355 kmk_rm_DEFS
= kmk_builtin_rm
=main
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
= \
369 kmk_sleep_TEMPLATE
= BIN-KMK
370 kmk_sleep_DEFS
= kmk_builtin_sleep
=main
371 kmk_sleep_SOURCES
= \
374 kmk_test_TEMPLATE
= BIN-KMK
375 kmk_test_DEFS
= kmk_builtin_test
=main
379 kDepIDB_TEMPLATE
= BIN-KMK
380 kDepIDB_DEFS
= kmk_builtin_kDepIDB
=main
382 kDepIDB_LIBS
= $(LIB_KDEP
)
388 # kmk_gmake - almost plain GNU Make.
390 PROGRAMS
+= kmk_gmake
392 kmk_gmake_TEMPLATE
= BIN-KMK
396 CONFIG_WITH_TOUPPER_TOLOWER \
399 kmk_gmake_SOURCES
= \
425 # kmk_fmake - Faster GNU Make.
427 ifeq ($(USER
),bird
) # for experimental purposes only.
428 PROGRAMS
+= kmk_fgmake
431 kmk_fgmake_TEMPLATE
= BIN-KMK
435 CONFIG_WITH_TOUPPER_TOLOWER \
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
444 # CONFIG_WITH_PRINT_STATS_SWITCH \
445 # CONFIG_WITH_EXTENDED_NOTPARALLEL \
447 kmk_fgmake_SOURCES
= \
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 $@
)
486 # Some missing headers.
488 $(PATH_kmk
)/fts.h
: $(kmk_PATH
)/kmkbuiltin
/ftsfake.h |
$(call DIRDEP
,$(PATH_kmk
))
491 $(PATH_kmk
)/unistd.h
: |
$(call DIRDEP
,$(PATH_kmk
))
494 $(PATH_kmk
)/sysexits.h
: |
$(call DIRDEP
,$(PATH_kmk
))
497 $(PATH_kmk
)/inttypes.h
: |
$(call DIRDEP
,$(PATH_kmk
))
500 $(PATH_kmk
)/paths.h
: |
$(call DIRDEP
,$(PATH_kmk
))
503 $(PATH_kmk
)/pwd.h
: |
$(call DIRDEP
,$(PATH_kmk
))
506 $(PATH_kmk
)/grp.h
: |
$(call DIRDEP
,$(PATH_kmk
))
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
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).
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 \
544 test_shell_double_quoting2
:
545 $(ECHO_EXT
) "foo foo foo" |
$(SED_EXT
) -e \
551 # when using batch mode shell, the newline got escaped twice and spoiling everything.
553 $(ECHO_EXT
) "foo foo foo" |
$(SED_EXT
) -e \
560 $(MAKE
) -f
$(kmk_PATH
)/testcase-stack.kmk
563 $(MAKE
) -f
$(kmk_PATH
)/testcase-math.kmk
566 $(MAKE
) -f
$(kmk_PATH
)/testcase-if1of.kmk
569 $(MAKE
) -f
$(kmk_PATH
)/testcase-local.kmk
572 $(MAKE
) -f
$(kmk_PATH
)/testcase-includedep.kmk
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
; \
584 if
test $${RC} -ne
2; then \
585 echo
"$@: FAILED - exit code $${RC} instead of 2."; \
588 echo
"$@: SUCCESS"; \
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