Anselm R Garbe dixit: >Are you willing to accept a Makefile/config.mk approach for mksh? This […] >My current approach for all sta.li userland tools is creating a custom >Makefile/config.mk, simply because the existing Build.sh, autoconf or >whatever approach sucks.
(jump to tl;dr at the end of the mail if needed) I agree that they all suck. I know exactly why and where mksh’s Build.sh sucks, but it’s the lesser evil for me (as upstream) considering mksh’s target “market” (including really ancient and really weird OSes). The problem at hand is: upstream definitely needs the automatic discovery of flags method because no downstream (not even distro vendors) usually know exactly what to put in there. One thing you *can* do with mksh, and which I regularily do for MirBSD and Android, and which laffer1 regularily does for MidnightBSD, is to have Build.sh generate you a Makefrag.inc that contains the results from all the tests. You can then either include that from a Makefile or (which is what we currently do) move the definitions into the regular Makefile/Android.mk. The CPPFLAGS you end up with are dependent on the OS, OS version and mksh version, so you’d have to run this step once when you import a newer mksh version. But it’s pretty decently automated, so it’s not that hard. As an example, running this tg@hugh:~/build $ mksh /usr/src/bin/mksh/Build.sh -M on MirBSD, after exporting CC and CFLAGS, yields: ------------------------------------------------------------------>8 # Makefile fragment for building mksh R47 2013/07/26 PROG= mksh MAN= mksh.1 SRCS= lalloc.c eval.c exec.c expr.c funcs.c histrap.c jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c edit.c strlcpy.c SRCS_FP= /usr/src/bin/mksh/lalloc.c /usr/src/bin/mksh/eval.c /usr/src/bin/mksh/exec.c /usr/src/bin/mksh/expr.c /usr/src/bin/mksh/funcs.c /usr/src/bin/mksh/histrap.c /usr/src/bin/mksh/jobs.c /usr/src/bin/mksh/lex.c /usr/src/bin/mksh/main.c /usr/src/bin/mksh/misc.c /usr/src/bin/mksh/shf.c /usr/src/bin/mksh/syn.c /usr/src/bin/mksh/tree.c /usr/src/bin/mksh/var.c /usr/src/bin/mksh/edit.c /usr/src/bin/mksh/strlcpy.c OBJS_BP= lalloc.o eval.o exec.o expr.o funcs.o histrap.o jobs.o lex.o main.o misc.o shf.o syn.o tree.o var.o edit.o strlcpy.o INDSRCS= emacsfn.h sh.h sh_flags.h var_spec.h NONSRCS_INST= dot.mkshrc $(MAN) NONSRCS_NOINST= Build.sh Makefile Rebuild.sh check.pl check.t test.sh CC= mgcc CFLAGS= -O2 -pipe -std=gnu99 -Os -fweb -frename-registers -Wformat -Wstrict-aliasing -Wbounded -fwrapv -fno-align-functions -fno-align-labels -falign-loops=4 -falign-jumps=4 -march=i486 -mpush-args -mpreferred-stack-boundary=2 -momit-leaf-frame-pointer -fhonour-copts -Wno-deprecated-declarations -fno-asynchronous-unwind-tables -fno-strict-aliasing -fstack-protector-all -Wall -fwrapv CPPFLAGS= -I. -I'/usr/src/bin/mksh' -DMKSH_BUILDSH -DHAVE_ATTRIBUTE_BOUNDED=1 -DHAVE_ATTRIBUTE_FORMAT=1 -DHAVE_ATTRIBUTE_NORETURN=1 -DHAVE_ATTRIBUTE_UNUSED=1 -DHAVE_ATTRIBUTE_USED=1 -DHAVE_SYS_TIME_H=1 -DHAVE_TIME_H=1 -DHAVE_BOTH_TIME_H=1 -DHAVE_SYS_BSDTYPES_H=0 -DHAVE_SYS_FILE_H=1 -DHAVE_SYS_MKDEV_H=0 -DHAVE_SYS_MMAN_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_SYS_RESOURCE_H=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SYS_SYSMACROS_H=0 -DHAVE_BSTRING_H=0 -DHAVE_GRP_H=1 -DHAVE_LIBGEN_H=1 -DHAVE_LIBUTIL_H=0 -DHAVE_PATHS_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_TERMIOS_H=1 -DHAVE_ULIMIT_H=0 -DHAVE_VALUES_H=0 -DHAVE_CAN_INTTYPES=1 -DHAVE_CAN_UCBINTS=1 -DHAVE_CAN_INT8TYPE=1 -DHAVE_CAN_UCBINT8=1 -DHAVE_RLIM_T=1 -DHAVE_SIG_T=1 -DHAVE_SYS_ERRLIST=1 -DHAVE_SYS_SIGNAME=1 -DHAVE_SYS_SIGLIST=1 -DHAVE_FLOCK=1 -DHAVE_LOCK_FCNTL=1 -DHAVE_GETRUSAGE=1 -DHAVE_GETTIMEOFDAY=1 -DHAVE_KILLPG=1 -DHAVE_MEMMOVE=1 -DHAVE_MKNOD=0 -DHAVE_MMAP=1 -DHAVE_NICE=1 -DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=1 -DHAVE_LANGINFO_CODESET=1 -DHAVE_SELECT=1 -DHAVE_SETRESUGID=1 -DHAVE_SETGROUPS=1 -DHAVE_STRERROR=0 -DHAVE_STRSIGNAL=0 -DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 -DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 -DHAVE_PERSISTENT_HISTORY=1 -DMKSH_BUILD_R=471 LDFLAGS= LIBS= # not BSD make only: #VPATH= /usr/src/bin/mksh #all: $(PROG) #$(PROG): $(OBJS_BP) # $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS_BP) $(LIBS) #$(OBJS_BP): $(SRCS_FP) $(NONSRCS) #.c.o: # $(CC) $(CFLAGS) $(CPPFLAGS) -c $< # for all make variants: #REGRESS_FLAGS= -f #regress: # ./test.sh $(REGRESS_FLAGS) check_categories= shell:legacy-no int:32 # for BSD make only: #.PATH: /usr/src/bin/mksh #.include <bsd.prog.mk> ------------------------------------------------------------------>8 The only important line of this is the CPPFLAGS= one. You’ll need from and including -DMKSH_BUILDSH up to and including -DMKSH_BUILD_R={someversionnumber}. As long as it’s one operating system, such as just sta.li, the defines should stay the same – currently even across varying CPU architectures. As I use #if HAVE_FOO, defining the “unset” ones to 0 explicitly is really recommended. Oh, a test.sh file is also generated… but all it does is calculate check_categories (also in the Makefrag.inc) then run this: perl $srcdir/check.pl -s $srcdir/check.t -p $objdir/mksh \ -v -C ${check_categories// /,} You’d want to run this at least once. tl;dr: mksh/Build.sh supports generating a Makefrag.inc already. You can just ${vcs} add then ${vcs} commit the generated file whenever you import a new mksh version, as it should stay the same for sta.li across CPUs even. You can then use regular (even parallel) make to build the actual executables. Examples: https://raw.github.com/rofl0r/sabotage/e3c832e9892dbc97795db980eb3a4bb3202e1856/pkg/mksh ‣ automatic running of Build.sh -M during preparation, then parallel building with stock make https://android.googlesource.com/platform/external/mksh/+/f8c396c4d446a038358106a301b329607a04633d/Android.mk ‣ committing of generated file, globally parallel make build (the file is pregenerated with the correct cross-compiler in CC, correct CFLAGS, etc. since it’s system-dependent) Hope that’s okay for you, //mirabilos -- Sometimes they [people] care too much: pretty printers [and syntax highligh- ting, d.A.] mechanically produce pretty output that accentuates irrelevant detail in the program, which is as sensible as putting all the prepositions in English text in bold font. -- Rob Pike in "Notes on Programming in C"