Skip to content

Instantly share code, notes, and snippets.

@cr1901
cr1901 / genmake.m4
Last active July 3, 2022 21:21
m4 (simple) Makefile generator
dnl http://mbreen.com/m4.html#toc19
define(`LQ',`changequote(<,>)`dnl'
changequote`'')dnl
define(`RQ',`changequote(<,>)dnl`
'changequote`'')dnl
define(`for',`ifelse($#,0,``$0'',`ifelse(eval($2<=$3),1,
`pushdef(`$1',$2)$4`'popdef(`$1')$0(`$1',incr($2),$3,`$4')')')')dnl
define(`foreach',`ifelse(eval($#>2),1,
`pushdef(`$1',`$3')$2`'popdef(`$1')dnl
`'ifelse(eval($#>3),1,`$0(`$1',`$2',shift(shift(shift($@))))')')')dnl
@cr1901
cr1901 / ddtemplate.m4
Created June 16, 2014 06:20
ddrescue command generator
define(`LQ',`changequote(<,>)`dnl'
changequote`'')dnl
define(`RQ',`changequote(<,>)dnl`
'changequote`'')dnl
# m4 -DSRCDRV=$1 -DDESTDIR=$2 -DIMGNAME=$3 -DLOGNAME=$4 ddtemplate > $2/rescue.sh;
if [ -e curr_phase_`'DESTDIR ]; then
CURR_PHASE=`'LQ()`'cat curr_phase_`'DESTDIR`'`'LQ()`'
else
CURR_PHASE=1
@cr1901
cr1901 / build.m4
Last active August 29, 2015 14:03
NetBSD ./build.sh generator for separate builds
#!/bin/sh
define(`_CONTAINER_NAME', `ARCH'`-'`TARGET')dnl
define(`_CAPITALIZE', `translit($1, a-z, A-Z)')dnl
define(`_NETBSD_XSRC', ifdef(`BUILD_X', ` -x -X ../xsrc'))dnl
define(`_TOOLS_SUB', ifdef(`TOOLS_SUBDIR', TOOLS_SUBDIR, _CONTAINER_NAME))dnl
NETBSD_SRC=NETBSD_SRC_DIR
MAKECONF=MAKECONF_DIR/mk.conf._CONTAINER_NAME
@cr1901
cr1901 / scope.c
Created July 31, 2014 23:46
Variable Scope Fun
#include <stdio.h>
#include <stdlib.h>
/* Topics to review:
definition vs declaration
scope vs storage duration
storage classes- auto, static, extern, register
internal vs external linkage */
static int my_static = 1; /* This is a definition. This current file and THIS
@cr1901
cr1901 / gmacros.asm
Last active August 29, 2015 14:12
NASM Macros for Bare Metal/DOS x86 (8086-80386 PM)
[list -]
%ifndef GLOBAL_MACROS_ASM
%define GLOBAL_MACROS_ASM
;Macros to create a stack frame
%macro prolog 0.nolist
%ifidni CPU_TARGET, 8086
push bp
mov bp, sp
%else
@cr1901
cr1901 / Makefile
Last active July 1, 2018 14:43
NetBSD Raspberry Pi I2C IOCTL Sample
CFLAGS=
CPPFLAGS=
LDFLAGS=
LIBS=
LIBPATH=
RM=rm
RMFLAGS=-f
INSTALL=install
@cr1901
cr1901 / Makefile
Created February 4, 2015 13:00
NASM Map Unix Sections to DOS Segments
.SUFFIXES : .asm .obj
AS=nasm
ASPPFLAGS=-DAPI=MSDOS_API -DCPU_TARGET=8086
ASFLAGS=-fobj
LINK=wcl
LINKFLAGS=-zq -bcl=dos -fm
RM=rm
RMFLAGS=-rf
@cr1901
cr1901 / rust-errors-symbols-missing.txt
Created February 8, 2015 11:52
Errors: Rust build with nonstandard paths
warning: removing previous 'librustc_llvm-*.so' libraries: i686-unknown-linux-gn
u/stage1/lib/librustc_llvm-4e7c5e5c.so
cp i686-unknown-linux-gnu/stage0/lib/rustlib/i686-unknown-linux-gnu/lib/stamp.ru
stc_llvm i686-unknown-linux-gnu/stage1/lib/stamp.rustc_llvm
cp -R i686-unknown-linux-gnu/stage0/lib/rustlib/i686-unknown-linux-gnu/lib/libru
stc_llvm-*.so i686-unknown-linux-gnu/stage1/lib
info: now are following matches for librustc_llvm-*.so libraries:
i686-unknown-linux-gnu/stage1/lib/librustc_llvm-4e7c5e5c.so
MATCHES=""; if [ -n "$MATCHES" ] ; then echo "warning: removing previous" \'libr
ustc_back-*.so\' "libraries:" $MATCHES; rm $MATCHES ; fi
@cr1901
cr1901 / config.log
Created February 8, 2015 12:06
Rust internal LLVM config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by LLVM configure 3.6.0, which was
generated by GNU Autoconf 2.60. Invocation command line was
$ /home/william/Projects/rust/src/llvm/configure --enable-targets=x86,x86_64,arm,aarch64,mips,powerpc --enable-optimized --enable-assertions --disable-docs --enable-bindings=none --disable-terminfo --disable-zlib --disable-libffi --build=i686-unknown-linux-gnu --host=i686-unknown-linux-gnu --target=i686-unknown-linux-gnu --with-python=/usr/bin/python2.7
## --------- ##
## Platform. ##
@cr1901
cr1901 / llvm_boostrap.sh
Created February 8, 2015 14:21
Compile LLVM/Rust on Ubuntu 12.04 using non-standard paths.
#!/bin/sh
BOOTSTRAP_ROOT=/home/william/Projects
#TEMP_TOOLS=$BOOTSTRAP_ROOT/llvm-temp-tools
TEMP_TOOLS=$BOOTSTRAP_ROOT/llvm-toolchain
LLVM_TOOLCHAIN=$BOOTSTRAP_ROOT/llvm-toolchain
FETCH=wget #Try BSD FTP if wget doesn't exist.
NUM_JOBS=4
#export PATH=$TEMP_TOOLS/bin:$PATH
export LD_LIBRARY_PATH=$TEMP_TOOLS/lib:$LD_LIBRARY_PATH