make
utility (such as GNU make or BSD make),
a Bourne shell and the commands test
, echo
and sed
.
Security, ease of testing and debuggability has always been a consideration in the design of BSDBuild.
-
BSDBuild
configure
scripts are simpler than autoconf scripts. They do not use shell functions or complicated tricks in general. They use a minimal number of commands (mainlytest
,echo
andsed
). -
BSDBuild
configure
scripts may be easily regenerated by runningmkconfigure
. In a ports/packages setting, maintainers only need to reviewconfigure.in
and use BSDBuild to regenerate (or diff against)configure
as part of the packaging process. -
The
config.log
generated by BSDBuildconfigure
scripts contains a copy of all of the tests performed. Each test can be manually replayed by copy/pasting the relevantconfig.log
fragment to the shell. -
With BSDBuild's make libraries, the
make install
target is guaranteed to only perform basic file installations (e.g., runninginstall
). It will never trigger any type of compilation or last-minute generation process. By design,make install
never impliesmake all
.
The language of a source file in a
${SRCS}
lists is determined by its
file extension.
Refer to the current build.prog.mk and build.lib.mk manual
pages for the complete list.
--host
to any BSDBuild ./configure
script and
it will arrange for cross-compilation to the given target.
BSDBuild also provides special support for the
cc65
compiler to 65(C)02 based platforms
and emscripten
for compiling to WebAssembly.
The following should allow you to compile a "Hello world" program in C.
First, create a directory for the project and use the mkify prog
command
to create a copy of the files required by the build.prog.mk
module:
$ mkdir hello $ cd hello $ mkify prog Installing in mk: ... Installing scripts: ...
mkify
should create a subdirectory mk
and an empty Makefile
.
Open up the Makefile
in an editor and add the directives:
TOP=. PROG= hello SRCS= hello.c include ${TOP}/mk/build.prog.mk
A minimal hello.c
might look like:
#include <stdio.h> int main(int argc, char *argv[]) { printf("Hello, world!\n"); return (0); }
Now you can run make depend
for the first time to generate dependencies:
$ touch .depend $ make depend
Finally, compile the program with make
:
$ make cc -O2 -pipe -o hello.o -c hello.c $ ./hello Hello, world!
Next, you might want to add a configure
script. Create a file
called configure.in
with the following:
# Example BSDBuild configure script. # ex:syn=bsdbuild package("hello") version("1.0") register("--some-option", "An example option") register("--enable-warnings", "Enable compiler warnings") require(cc) check_header(stdio.h) if [ "${enable_warnings}" = "yes" ]; then c_option(-Wall) c_option(-Werror) c_option(-Wmissing-prototypes) fi # Write definitions to a config/ directory? c_incdir_config(config) # Write definitions to a single config.h file? #c_include_config(config.h)
To compile to a POSIX-style configure
script, use the
mkconfigure command:
$ cat configure.in | mkconfigure > configure $ chmod 755 configure
You can create a standard build.lib.mk
makefile and use relative path
names in ${SRCS}
, for example:
TOP= . LIB= mylib SRCS= source1.c \ subdir1/source2.c \ subdir2/source3.c include ${TOP}/Makefile.config include ${TOP}/mk/build.lib.mk
Yes, by including only build.subdir.mk
, and setting the targets
explicitely:
TOP= . SUBDIR= dir1 \ dir2 all: all-subdir install: install-subdir deinstall: deinstall-subdir clean: clean-subdir cleandir: cleandir-subdir depend: depend-subdir include ${TOP}/mk/build.subdir.mk
Yes, you can set ${GMONOUT}
to the desired output filename and then
invoke:
$ make ${GMONOUT}
To ignore files generated by make depend
and configure
:
Makefile.config config.log config.status .depend # If configure uses c_incdir_config(): config/ # If configure uses c_include_config(): config.h # If configure uses config_script(): myprogram-config # If configure uses pkgconfig_mod(): myprogram.pc *.so *.so.* *.dll *.exe *.o *.obj *.res *.lib *.a *.la *.lo *.dSYM *.lnk *.err *.exp *.map *.orig *~ *.swp *.tmp *.rej