From 926337a7f848287b70452e6873765e97a74a5c4d Mon Sep 17 00:00:00 2001 From: ketmar Date: Fri, 28 Sep 2012 04:10:00 +0300 Subject: [PATCH] better separate 'main' targets --- TODO | 2 + defaults/Jambase | 2 +- defaults/Jambase.clean | 30 ++++++++ defaults/Jambase.main | 64 ++++++++++++++++ defaults/Jambase.object | 14 +++- defaults/link/{c => }/Jambase.link.c | 0 defaults/link/{cpp => }/Jambase.link.cpp | 5 ++ defaults/link/Jambase.link.libs | 33 +++++++++ defaults/link/cpp/Jambase.link.lib.cpp | 3 - defaults/link/cpp/Jambase.link.libso.cpp | 0 defaults/main/Jambase.main.c | 61 +++------------ defaults/main/Jambase.main.cpp | 86 +++------------------- .../c/Jambase.link.lib.c => main/Jambase.main.lib} | 2 +- .../Jambase.main.libso} | 0 defaults/main/Jambase.main.objc | 7 +- doc/ChangeLog | 9 +++ 16 files changed, 184 insertions(+), 134 deletions(-) rename defaults/link/{c => }/Jambase.link.c (100%) rename defaults/link/{cpp => }/Jambase.link.cpp (85%) delete mode 100644 defaults/link/cpp/Jambase.link.lib.cpp delete mode 100644 defaults/link/cpp/Jambase.link.libso.cpp rewrite defaults/main/Jambase.main.c (87%) rewrite defaults/main/Jambase.main.cpp (91%) rename defaults/{link/c/Jambase.link.lib.c => main/Jambase.main.lib} (98%) rename defaults/{link/c/Jambase.link.libso.c => main/Jambase.main.libso} (100%) diff --git a/TODO b/TODO index 94a7b9e..3a888cb 100644 --- a/TODO +++ b/TODO @@ -3,3 +3,5 @@ [.] replace regexp library with new one (from Tcl?) [.] glob: allow ']' and '-' escaping inside ranges [.] InstallConfig target with 'cfgname.new' if old one exists + + [.] separate make target always relinks .exe; why? diff --git a/defaults/Jambase b/defaults/Jambase index c0cbdcf..8693b19 100644 --- a/defaults/Jambase +++ b/defaults/Jambase @@ -106,7 +106,7 @@ # ObjectC++Flags source : flags ; add compiler flags for object # ObjectObjCFlags source : flags ; add compiler flags for object # ObjectHdrs source : dirs ; add include directories for object -# Objects sources ; compile sources +# Objects sources targets exename ; compile sources # RmTemps target : sources ; remove temp sources after target made # Setuid images ; mark executables Setuid # SoftLink target : source ; make symlink from source to target diff --git a/defaults/Jambase.clean b/defaults/Jambase.clean index 3eb2d34..5f620ce 100644 --- a/defaults/Jambase.clean +++ b/defaults/Jambase.clean @@ -16,3 +16,33 @@ rule RmTemps { actions quietly updated piecemeal together RmTemps { $(RM) $(>) } + + +# convert 'target clean' to 'target_clean' +rule --normalize-cleans-- { + local _t _pt _nt ; + _pt = ; # prev target + _nt = ; # new JAM_TARGETS + for _t in $(JAM_TARGETS) { + if $(_t) = "clean" { + if $(_pt) { + # have previous target + _nt += $(_pt)_clean ; + } else { + _nt += $(_t) ; + } + _pt = ; + continue; + } + if $(_pt) { _nt += $(_pt) ; } + _pt = $(_t) ; + } + if $(_pt) { _nt += $(_pt) ; } + #Echo "new targets:" $(_nt) ; + JAM_TARGETS = $(_nt) ; +} + + +if "clean" in $(JAM_TARGETS) { + --normalize-cleans-- ; +} diff --git a/defaults/Jambase.main b/defaults/Jambase.main index 3552dda..de5bc44 100644 --- a/defaults/Jambase.main +++ b/defaults/Jambase.main @@ -1,3 +1,67 @@ +# $(1): image +# $(2): target list +# returns "_" for 'selftarget' +rule --MainNormalizeTargets-- { + local _ctt = $(2) ; + if ! $(_ctt) { _ctt = exe ; } + else if $(_ctt) = $(1) { _ctt = "_" ; } + return $(_ctt) ; +} + + +# /--MainFromObjects-- image : objects : targets : linkrule ; +# +# Links _objects_ into _image_. Dependency of exe. +# @MainFromObjects provides a default suffix for _image_ +# +rule --MainFromObjects-- { + local _s _t _ctt _f ; + local _ctt = $(3) ; + + # Add grist to file names + # Add suffix to exe + _s = [ FGristFiles $(>) ] ; + _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ; + # so 'jam foo' works when it's really foo.exe + if $(_t) != $(<) { + Depends $(<) : $(_t) ; + NotFile $(<) ; + } + + #Echo "MainFromObjects: _t:" "$(_t)" "_ctt:" "$(_ctt)" ; + + # make compiled sources a dependency of target + if $(_ctt) != "_" { + for _f in $(_ctt) { + #Echo "separate target:" "$(_f)" ; + Depends $(_f) : $(_t) ; + Clean $(_f)_clean : $(_t) ; + Depends $(_f)_clean : clean ; + } + } else { + Echo "separate target:" "$(_t)" ; + Clean $(_t)_clean : $(_t) ; + Depends $(_t)_clean : clean ; + } + #Depends exe : $(_t) ; + Depends $(_t) : $(_s) ; + #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ; + MakeLocate $(_t) : $(LOCATE_BIN) ; + Clean clean : $(_t) ; + + # special case for stupid Borland C++, which always generates a + # .tds file for executables, even when no debug information is needed + # + #if $(JAM_TOOLSET) = BORLANDC { + # MakeLocate $(_t:S=.tds) : $(LOCATE_TARGET) ; + # Clean clean : $(_t:S=.tds) ; + #} + + $(4) $(_t) : $(_s) ; +} + . main/Jambase.main.c . main/Jambase.main.cpp . main/Jambase.main.objc +. main/Jambase.main.lib +. main/Jambase.main.libso diff --git a/defaults/Jambase.object b/defaults/Jambase.object index bf854cb..3b4b19e 100644 --- a/defaults/Jambase.object +++ b/defaults/Jambase.object @@ -144,18 +144,26 @@ rule ObjectHdrs { } -# /Objects sources ; +# /Objects sources : targets : exename ; # # this rule is used to compile one or more sources into object files. # do not call it directly, it is used by the Main and Library rules # automatically # rule Objects { - local _i ; + local _i _f _t ; + if ! $(2) || $(2) = "obj" { _t = obj ; } else { _t = $(3)_obj ; } for _i in [ FGristFiles $(<) ] { + #Echo "Objects:" "$(_i)" "-->" "$(_i:S=$(SUFOBJ))"; + #Echo " $(_t)" ":" "$(_i:S=$(SUFOBJ))" ; Object $(_i:S=$(SUFOBJ)) : $(_i) ; - Depends obj : $(_i:S=$(SUFOBJ)) ; + Depends $(_t) : $(_i:S=$(SUFOBJ)) ; + } + + if $(_t) != "obj" { + #Echo "$(3)" "depends of" "$(_t)" ; + Depends $(3) : $(_t) ; } } diff --git a/defaults/link/c/Jambase.link.c b/defaults/link/Jambase.link.c similarity index 100% rename from defaults/link/c/Jambase.link.c rename to defaults/link/Jambase.link.c diff --git a/defaults/link/cpp/Jambase.link.cpp b/defaults/link/Jambase.link.cpp similarity index 85% rename from defaults/link/cpp/Jambase.link.cpp rename to defaults/link/Jambase.link.cpp index 7293b6b..b6845f5 100644 --- a/defaults/link/cpp/Jambase.link.cpp +++ b/defaults/link/Jambase.link.cpp @@ -36,3 +36,8 @@ rule C++LinkFlagsOn { actions C++Link bind NEEDLIBS { $(C++LINK) $(LINKFLAGS.all) $(C++LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS.all) $(C++LINKLIBS) } + + +### actions updated together piecemeal C++LinkUnixLibrary bind NEEDLIBS { +### $(C++LINK) $(C++LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(C++LINKLIBS) +### } diff --git a/defaults/link/Jambase.link.libs b/defaults/link/Jambase.link.libs index 0157dc6..3cda6e2 100644 --- a/defaults/link/Jambase.link.libs +++ b/defaults/link/Jambase.link.libs @@ -36,3 +36,36 @@ rule LinkSharedLibraries { Depends $(_t) : $(>:S=$(_ext)) ; NEEDLIBS on $(_t) += $(>:S=$(_ext)) ; } + + +# Since building shared libraries is so different depending on the +# compiler being used, I've broken this task into compiler-specific +# ones +# +rule SharedLink-LCC { + Echo "Sorry, but generating DLLs with LCC is not supported. That's" ; + Echo "because the 'lcclnk' tool that comes with this compiler is" ; + Echo "unreliable and doesn't work as expected." ; + Exit ; + + # the 'lcclnk' tool is absolutely broken: + # - its -o flag doesn't work when there is a LIBRARY statement + # in the .def file. + # + # - it uses the LIBRARY name in the .def file to determine + # the name of the dll and its import library, and always + # places them in the current directory !! + # + # - if there is no LIBRARY statement, the -o flag is only + # used to determine where the DLL is placed, the import + # library will always be placed in the current directory !! + # + + # clean the .exp file too, don't know how to get rid of it + Clean clean : $(4:S=.exp) ; +} + + +actions updated together piecemeal LinkUnixLibrary bind NEEDLIBS { + $(LINK) $(LINKFLAGS.all) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(LINKLIBS.all) $(LINKLIBS) +} diff --git a/defaults/link/cpp/Jambase.link.lib.cpp b/defaults/link/cpp/Jambase.link.lib.cpp deleted file mode 100644 index 74ccf64..0000000 --- a/defaults/link/cpp/Jambase.link.lib.cpp +++ /dev/null @@ -1,3 +0,0 @@ -### actions updated together piecemeal C++LinkUnixLibrary bind NEEDLIBS { -### $(C++LINK) $(C++LINKFLAGS) -o $(<) $(UNDEFS) $(>) $(NEEDLIBS) $(C++LINKLIBS) -### } diff --git a/defaults/link/cpp/Jambase.link.libso.cpp b/defaults/link/cpp/Jambase.link.libso.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/defaults/main/Jambase.main.c b/defaults/main/Jambase.main.c dissimilarity index 87% index 1308712..298bff4 100644 --- a/defaults/main/Jambase.main.c +++ b/defaults/main/Jambase.main.c @@ -1,49 +1,12 @@ -# /Main image : sources ; -# -# Compiles _sources_ and links them into _image_. Calls @Objects and -# @MainFromObjects. -# -# _image_ may be supplied without suffix. -# -rule Main { - MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ; - Objects $(>) ; -} - - -# /MainFromObjects image : objects ; -# -# Links _objects_ into _image_. Dependency of exe. -# @MainFromObjects provides a default suffix for _image_ -# -rule MainFromObjects { - local _s _t ; - - # Add grist to file names - # Add suffix to exe - _s = [ FGristFiles $(>) ] ; - _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ; - # so 'jam foo' works when it's really foo.exe - - if $(_t) != $(<) { - Depends $(<) : $(_t) ; - NotFile $(<) ; - } - - # make compiled sources a dependency of target - Depends exe : $(_t) ; - Depends $(_t) : $(_s) ; - #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ; - MakeLocate $(_t) : $(LOCATE_BIN) ; - Clean clean : $(_t) ; - - # special case for stupid Borland C++, which always generates a - # .tds file for executables, even when no debug information is needed - # - #if $(JAM_TOOLSET) = BORLANDC { - # MakeLocate $(_t:S=.tds) : $(LOCATE_TARGET) ; - # Clean clean : $(_t:S=.tds) ; - #} - - Link $(_t) : $(_s) ; -} +# /Main image : sources [ : targets ] ; +# +# Compiles _sources_ and links them into _image_. Calls @Objects and +# @MainFromObjects. +# +# _image_ may be supplied without suffix. +# +rule Main { + local _tgts = [ --MainNormalizeTargets-- $(1) : $(3) ] ; + --MainFromObjects-- $(<) : $(>:S=$(SUFOBJ)) : $(_tgts) : Link ; + Objects $(>) : $(3) : $(1) ; +} diff --git a/defaults/main/Jambase.main.cpp b/defaults/main/Jambase.main.cpp dissimilarity index 91% index 860df08..1378c71 100644 --- a/defaults/main/Jambase.main.cpp +++ b/defaults/main/Jambase.main.cpp @@ -1,74 +1,12 @@ -# /C++Main image : sources ; -# -# Compiles _sources_ and links them into _image_. Calls @Objects and -# @C++MainFromObjects. -# -# _image_ may be supplied without suffix. -# -rule C++Main { - C++MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ; - Objects $(>) ; -} - - -# /C++MainFromObjects image : objects ; -# -# Links _objects_ into _image_. Dependency of exe. -# @MainFromObjects provides a default suffix for _image_ -# -rule C++MainFromObjects { - local _s _t ; - - # Add grist to file names - # Add suffix to exe - _s = [ FGristFiles $(>) ] ; - _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ; - # so 'jam foo' works when it's really foo.exe - - if $(_t) != $(<) { - Depends $(<) : $(_t) ; - NotFile $(<) ; - } - - # make compiled sources a dependency of target - Depends exe : $(_t) ; - Depends $(_t) : $(_s) ; - #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ; - MakeLocate $(_t) : $(LOCATE_BIN) ; - Clean clean : $(_t) ; - - # special case for stupid Borland C++, which always generates a - # .tds file for executables, even when no debug information is needed - # - #if $(JAM_TOOLSET) = BORLANDC { - # MakeLocate $(_t:S=.tds) : $(LOCATE_TARGET) ; - # Clean clean : $(_t:S=.tds) ; - #} - - C++Link $(_t) : $(_s) ; ###k8:FIXME -} - - -rule ObjC-MainFromObjects { - local _s _t ; - - # Add grist to file names - # Add suffix to exe - _s = [ FGristFiles $(>) ] ; - _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ; - # so 'jam foo' works when it's really foo.exe - - if $(_t) != $(<) { - Depends $(<) : $(_t) ; - NotFile $(<) ; - } - - # make compiled sources a dependency of target - Depends exe : $(_t) ; - Depends $(_t) : $(_s) ; - #k8:MakeLocate $(_t) : $(LOCATE_TARGET) ; - MakeLocate $(_t) : $(LOCATE_BIN) ; - Clean clean : $(_t) ; - - ObjC-Link $(_t) : $(_s) ; ###k8:FIXME -} +# /C++Main image : sources [ : targets ] ; +# +# Compiles _sources_ and links them into _image_. Calls @Objects and +# @C++MainFromObjects. +# +# _image_ may be supplied without suffix. +# +rule C++Main { + local _tgts = [ --MainNormalizeTargets-- $(1) : $(3) ] ; + --MainFromObjects-- $(<) : $(>:S=$(SUFOBJ)) : $(_tgts) : C++Link ; + Objects $(>) : $(3) : $(1) ; +} diff --git a/defaults/link/c/Jambase.link.lib.c b/defaults/main/Jambase.main.lib similarity index 98% rename from defaults/link/c/Jambase.link.lib.c rename to defaults/main/Jambase.main.lib index 6bb84e7..60067d1 100644 --- a/defaults/link/c/Jambase.link.lib.c +++ b/defaults/main/Jambase.main.lib @@ -8,7 +8,7 @@ # rule Library { LibraryFromObjects $(<) : $(>:S=$(SUFOBJ)) ; - Objects $(>) ; + Objects $(>) : : $(1) ; } diff --git a/defaults/link/c/Jambase.link.libso.c b/defaults/main/Jambase.main.libso similarity index 100% rename from defaults/link/c/Jambase.link.libso.c rename to defaults/main/Jambase.main.libso diff --git a/defaults/main/Jambase.main.objc b/defaults/main/Jambase.main.objc index cadd74d..339cf21 100644 --- a/defaults/main/Jambase.main.objc +++ b/defaults/main/Jambase.main.objc @@ -1,4 +1,4 @@ -# /ObjC-Main image : sources ; +# /ObjC-Main image : sources [ : targets ] ; # # Compiles _sources_ and links them into _image_. Calls @Objects and # @ObjC-MainFromObjects. @@ -6,6 +6,7 @@ # _image_ may be supplied without suffix. # rule ObjC-Main { - ObjC-MainFromObjects $(<) : $(>:S=$(SUFOBJ)) ; - Objects $(>) ; + local _tgts = [ --MainNormalizeTargets-- $(1) : $(3) ] ; + --MainFromObjects-- $(<) : $(>:S=$(SUFOBJ)) : $(_tgts) : ObjC-Link ; + Objects $(>) : $(3) : $(1) ; } diff --git a/doc/ChangeLog b/doc/ChangeLog index d5cf135..18068f0 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -244,3 +244,12 @@ [+] you can set K8JAM-JOBS variable to force number of jobs [+] use DBG=1 to suppress NDEBUG define for non-debug profiles + + [+] easy independent targets in *Main: + specify independent target name as 3rd arg to *Main: + Main alsatest : alsatest.c : alsatest ; # or Main alsatest : alsatest.c : _ ; + Main zytest : zytest.c : test tests ; + to cleanup, do: + jam alsatest_clean + or + jam alsatest clean -- 2.11.4.GIT