© Copyright 2005 Peri Hankey - documentation license Gnu FDL - code license Gnu GPL - validate HTML
SourceForge.net Logo a makefile in wiki format
 # Language Machine: makefile for examples of the language machine in action
 # (C) Copyright Peri Hankey 2005 - mpah@users.sourceforge.net - license Gnu GPL
 # this file comes with absolutely no warranty

home what is this about?

This is a demonstration of how a very small ruleset can be used to generate makefiles from source text in a subset of the mediawiki text format. The advantage of doing this is that the same format can be used to generate HTML pages. Also, for anyone who prefers using text editor settings that replace TAB by spaces, the makefile format is awkward, and the make system itself somewhat harsh and unhelpful.

home sources

home configuration

Local configuration - paths to the D compiler etc - is held in an include file.

 include ../config/config.mak

The following should possibly be in the config file:

 LM     = $(LMPREFIX)/bin/lm
 LMN2M  = lmn2m
 LMN2D  = lmn2d
 LMN2C  = lmn2c
 LMN2DD = lmn2D
 LMN2CC = lmn2C
 WIKI2HTML = ./makesite.lm

This is a list of files to be maintained when this Makefile is being used to maintain a website:

 HTMLFILES=  mediawiki.html
 HTMLFILES+= sitehtml.html
 HTMLFILES+= wiki2make.html
 HTMLFILES+= testmakefile.html

home targets

 all: wiki2make.lm testmakefile.mak makesite.lm $(HTMLFILES)
 clean:
         rm -f *.html
         rm -f *.lm *.out *.lmr *.o *~  
         rm -f *.tcc *.tCc *.gcc *.gCc *.gdc *.gDc 
 makesite.lm: mediawiki.lmn sitehtml.lmn
         $(LMN2M) $+ -o $@ -s $(LM); 
         chmod +x $@

home rules to generate makefiles

 # rule to create .mak from .wiki - makefile with mediawiki annotation
 %.mak: %.wiki
         ./wiki2make.lm $+ -o $*.mak
 # fake dependency rule to force conversion to .mak
 %.2mak: %.wiki
         ./wiki2make.lm $+ -o $*.mak

home rules to generate html pages

 # rule to create .html from .lmn - metalanguage source with mediawiki annotation
 %.html : %.lmn
         $(WIKI2HTML) $+ -o $*.html 
 # fake dependency rule to force conversion .html from .lmn
 %.2html : %.lmn
         $(WIKI2HTML) $+ -o $*.html 
 # rule to create .html from .wiki - mediawiki text files
 %.html : %.wiki
         $(WIKI2HTML) $+ -o $*.html 
 # fake dependency rule to force conversion to .html from .wiki
 %.2html : %.wiki
         $(WIKI2HTML) $+ -o $*.html 

home rules to compile D sources

 # make object file from d source
 %.o : %.d
         $(GDC) $(DFLAGS) -c -o $@ $< 
 %.so : %.d
         $(GDC) $(DFLAGS) -c -shared -fPIC -o $@ $<

home rules to compile rulesets

 # compile rules to lm loader format
 %.lmr : %.lmn
         $(LMN2M) -o $@ $+
 # make shebang script from rules: extensions have to be registered with lm engine
 %.lm :  %.lmn
         $(LMN2M) -o $@ -s $(LM) $+
         chmod +x $@
 # make D wrapper for lmn rules: extensions are functions with C linkdage
 %.2d : %.lmn
         $(LMN2D) -o  $*.d $<
 # compile lmn rules to D code:  extensions are functions with C linkdage
 %.2D : %.lmn
         $(LMN2DD) -o $*.d $<
 # make C wrapper for lmn rules: extensions are functions with C linkdage
 %.2c : %.lmn
         $(LMN2C) -o  $*.c $<
 # compile lmn rules to C code:  extensions are functions with C linkdage
 %.2C : %.lmn
         $(LMN2CC) -o $*.c $<
 # compile and link lmn rules as C code with no extensions using gcc
 %.gcc : %.lmn
         $(LMN2C)  -o $*.c -c $<
         gcc -o $@  $*.c -ldl $(LMLIB)/liblm -Wl,-rpath,$(LMLIB)/ -L$(GDCPREFIX)/lib/ -lgphobos -lm -lpthread -lc
 %.gCc : %.lmn
         $(LMN2CC) -o $*.c -c $<
         gcc -o $@  $*.c -ldl $(LMLIB)/liblm -Wl,-rpath,$(LMLIB)/ -L$(GDCPREFIX)/lib/ -lgphobos -lm -lpthread -lc
 # compile and link lmn rules as D code with no extensions using gdc
 %.gdc : %.lmn
         $(LMN2D)  -o $*.d -d $<
         $(GDC) -o $@ $(DFLAGS) $*.d -ldl $(LMLIB)/liblm -Wl,-rpath,$(LMLIB)/ 
 %.gDc : %.lmn
         $(LMN2DD) -o $*.d -d $<
         $(GDC) -o $@ $(DFLAGS) $*.d -ldl $(LMLIB)/liblm -Wl,-rpath,$(LMLIB)/ 
home