Skip to content

Commit 3baa61c

Browse files
committed
Merge pull request #610 from Golmote/prism-makefile
Add support for Makefile
2 parents 3ede718 + 12219d2 commit 3baa61c

File tree

4 files changed

+302
-0
lines changed

4 files changed

+302
-0
lines changed

components.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ var components = {
202202
"title": "LOLCODE",
203203
"owner": "Golmote"
204204
},
205+
"makefile": {
206+
"title": "Makefile",
207+
"owner": "Golmote"
208+
},
205209
"markdown": {
206210
"title": "Markdown",
207211
"require": "markup",

components/prism-makefile.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Prism.languages.makefile = {
2+
'comment': {
3+
pattern: /(^|[^\\])#(?:\\[\s\S]|.)*/,
4+
lookbehind: true
5+
},
6+
'string': /(["'])(?:\\[\s\S]|(?!\1)[^\\\r\n])*\1/,
7+
8+
// Built-in target names
9+
'builtin': /\.[A-Z][^:#=\s]+(?=\s*:(?!=))/,
10+
11+
// Targets
12+
'symbol': {
13+
pattern: /^[^:=\r\n]+(?=\s*:(?!=))/m,
14+
inside: {
15+
'variable': /\$+(?:[^(){}:#=\s]+|(?=[({]))/
16+
}
17+
},
18+
'variable': /\$+(?:[^(){}:#=\s]+|\([@*%<^+?][DF]\)|(?=[({]))/,
19+
20+
'keyword': [
21+
// Directives
22+
/\b(?:define|else|endef|endif|export|ifn?def|ifn?eq|-?include|override|private|sinclude|undefine|unexport|vpath)\b/,
23+
// Functions
24+
{
25+
pattern: /(\()(?:addsuffix|abspath|and|basename|call|dir|error|eval|file|filter(?:-out)?|findstring|firstword|flavor|foreach|guile|if|info|join|lastword|load|notdir|or|origin|patsubst|realpath|shell|sort|strip|subst|suffix|value|warning|wildcard|word(?:s|list)?)(?=[ \t])/,
26+
lookbehind: true
27+
}
28+
],
29+
'operator': /(?:::|[?:+!])?=|[|@]/,
30+
'punctuation': /[:;(){}]/
31+
};

components/prism-makefile.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-makefile.html

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
<h1>Makefile</h1>
2+
<p>To use this language, use the class "language-makefile".</p>
3+
4+
<h2>Comments</h2>
5+
<pre><code># This is a comment
6+
include foo # This is another comment</code></pre>
7+
8+
<h2>Targets</h2>
9+
<pre><code>kbd.o command.o files.o : command.h
10+
display.o insert.o search.o files.o : buffer.h
11+
12+
.PHONY: clean
13+
clean:
14+
rm *.o temp</code></pre>
15+
16+
<h2>Variables</h2>
17+
<pre><code>objects = main.o kbd.o command.o display.o \
18+
insert.o search.o files.o utils.o
19+
20+
edit : $(objects)
21+
cc -o edit $(objects)
22+
23+
$(objects) : defs.h
24+
25+
%oo: $$< $$^ $$+ $$*
26+
27+
foo : bar/lose
28+
cd $(@D) && gobble $(@F) > ../$@</code></pre>
29+
30+
<h2>Strings</h2>
31+
<pre><code>STR = 'A string!'
32+
33+
HELLO = 'hello \
34+
world'
35+
36+
HELLO2 = "hello \
37+
world"</code></pre>
38+
39+
<h2>Directives</h2>
40+
<pre><code>include foo *.mk $(bar)
41+
42+
vpath %.c foo
43+
44+
override define two-lines =
45+
foo
46+
$(bar)
47+
endef
48+
49+
ifeq ($(CC),gcc)
50+
libs=$(libs_for_gcc)
51+
else
52+
libs=$(normal_libs)
53+
endif</code></pre>
54+
55+
<h2>Functions</h2>
56+
<pre><code>whoami := $(shell whoami)
57+
host-type := $(shell arch)
58+
59+
y = $(subst 1,2,$(x))
60+
61+
dirs := a b c d
62+
files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))
63+
64+
reverse = $(2) $(1)
65+
foo = $(call reverse,a,b)
66+
67+
$(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))</code></pre>
68+
69+
<h2>Complete example</h2>
70+
<pre><code>#!/usr/bin/make -f
71+
# Generated automatically from Makefile.in by configure.
72+
# Un*x Makefile for GNU tar program.
73+
# Copyright (C) 1991 Free Software Foundation, Inc.
74+
75+
# This program is free software; you can redistribute
76+
# it and/or modify it under the terms of the GNU
77+
# General Public License …
78+
79+
80+
81+
SHELL = /bin/sh
82+
83+
#### Start of system configuration section. ####
84+
85+
srcdir = .
86+
87+
# If you use gcc, you should either run the
88+
# fixincludes script that comes with it or else use
89+
# gcc with the -traditional option. Otherwise ioctl
90+
# calls will be compiled incorrectly on some systems.
91+
CC = gcc -O
92+
YACC = bison -y
93+
INSTALL = /usr/local/bin/install -c
94+
INSTALLDATA = /usr/local/bin/install -c -m 644
95+
96+
# Things you might add to DEFS:
97+
# -DSTDC_HEADERS If you have ANSI C headers and
98+
# libraries.
99+
# -DPOSIX If you have POSIX.1 headers and
100+
# libraries.
101+
# -DBSD42 If you have sys/dir.h (unless
102+
# you use -DPOSIX), sys/file.h,
103+
# and st_blocks in `struct stat'.
104+
# -DUSG If you have System V/ANSI C
105+
# string and memory functions
106+
# and headers, sys/sysmacros.h,
107+
# fcntl.h, getcwd, no valloc,
108+
# and ndir.h (unless
109+
# you use -DDIRENT).
110+
# -DNO_MEMORY_H If USG or STDC_HEADERS but do not
111+
# include memory.h.
112+
# -DDIRENT If USG and you have dirent.h
113+
# instead of ndir.h.
114+
# -DSIGTYPE=int If your signal handlers
115+
# return int, not void.
116+
# -DNO_MTIO If you lack sys/mtio.h
117+
# (magtape ioctls).
118+
# -DNO_REMOTE If you do not have a remote shell
119+
# or rexec.
120+
# -DUSE_REXEC To use rexec for remote tape
121+
# operations instead of
122+
# forking rsh or remsh.
123+
# -DVPRINTF_MISSING If you lack vprintf function
124+
# (but have _doprnt).
125+
# -DDOPRNT_MISSING If you lack _doprnt function.
126+
# Also need to define
127+
# -DVPRINTF_MISSING.
128+
# -DFTIME_MISSING If you lack ftime system call.
129+
# -DSTRSTR_MISSING If you lack strstr function.
130+
# -DVALLOC_MISSING If you lack valloc function.
131+
# -DMKDIR_MISSING If you lack mkdir and
132+
# rmdir system calls.
133+
# -DRENAME_MISSING If you lack rename system call.
134+
# -DFTRUNCATE_MISSING If you lack ftruncate
135+
# system call.
136+
# -DV7 On Version 7 Unix (not
137+
# tested in a long time).
138+
# -DEMUL_OPEN3 If you lack a 3-argument version
139+
# of open, and want to emulate it
140+
# with system calls you do have.
141+
# -DNO_OPEN3 If you lack the 3-argument open
142+
# and want to disable the tar -k
143+
# option instead of emulating open.
144+
# -DXENIX If you have sys/inode.h
145+
# and need it 94 to be included.
146+
147+
DEFS = -DSIGTYPE=int -DDIRENT -DSTRSTR_MISSING \
148+
-DVPRINTF_MISSING -DBSD42
149+
# Set this to rtapelib.o unless you defined NO_REMOTE,
150+
# in which case make it empty.
151+
RTAPELIB = rtapelib.o
152+
LIBS =
153+
DEF_AR_FILE = /dev/rmt8
154+
DEFBLOCKING = 20
155+
156+
CDEBUG = -g
157+
CFLAGS = $(CDEBUG) -I. -I$(srcdir) $(DEFS) \
158+
-DDEF_AR_FILE=\"$(DEF_AR_FILE)\" \
159+
-DDEFBLOCKING=$(DEFBLOCKING)
160+
LDFLAGS = -g
161+
162+
prefix = /usr/local
163+
# Prefix for each installed program,
164+
# normally empty or `g'.
165+
binprefix =
166+
167+
# The directory to install tar in.
168+
bindir = $(prefix)/bin
169+
170+
# The directory to install the info files in.
171+
infodir = $(prefix)/info
172+
173+
#### End of system configuration section. ####
174+
175+
SRCS_C = tar.c create.c extract.c buffer.c \
176+
getoldopt.c update.c gnu.c mangle.c \
177+
version.c list.c names.c diffarch.c \
178+
port.c wildmat.c getopt.c getopt1.c \
179+
regex.c
180+
SRCS_Y = getdate.y
181+
SRCS = $(SRCS_C) $(SRCS_Y)
182+
OBJS = $(SRCS_C:.c=.o) $(SRCS_Y:.y=.o) $(RTAPELIB)
183+
184+
AUX = README COPYING ChangeLog Makefile.in \
185+
makefile.pc configure configure.in \
186+
tar.texinfo tar.info* texinfo.tex \
187+
tar.h port.h open3.h getopt.h regex.h \
188+
rmt.h rmt.c rtapelib.c alloca.c \
189+
msd_dir.h msd_dir.c tcexparg.c \
190+
level-0 level-1 backup-specs testpad.c
191+
192+
.PHONY: all
193+
all: tar rmt tar.info
194+
195+
tar: $(OBJS)
196+
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
197+
198+
rmt: rmt.c
199+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ rmt.c
200+
201+
tar.info: tar.texinfo
202+
makeinfo tar.texinfo
203+
204+
.PHONY: install
205+
install: all
206+
$(INSTALL) tar $(bindir)/$(binprefix)tar
207+
-test ! -f rmt || $(INSTALL) rmt /etc/rmt
208+
$(INSTALLDATA) $(srcdir)/tar.info* $(infodir)
209+
210+
$(OBJS): tar.h port.h testpad.h
211+
regex.o buffer.o tar.o: regex.h
212+
# getdate.y has 8 shift/reduce conflicts.
213+
214+
testpad.h: testpad
215+
./testpad
216+
217+
testpad: testpad.o
218+
$(CC) -o $@ testpad.o
219+
220+
TAGS: $(SRCS)
221+
etags $(SRCS)
222+
223+
.PHONY: clean
224+
clean:
225+
rm -f *.o tar rmt testpad testpad.h core
226+
227+
.PHONY: distclean
228+
distclean: clean
229+
rm -f TAGS Makefile config.status
230+
231+
.PHONY: realclean
232+
realclean: distclean
233+
rm -f tar.info*
234+
235+
.PHONY: shar
236+
shar: $(SRCS) $(AUX)
237+
shar $(SRCS) $(AUX) | compress \
238+
> tar-`sed -e '/version_string/!d' \
239+
-e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
240+
-e q
241+
version.c`.shar.Z
242+
243+
.PHONY: dist
244+
dist: $(SRCS) $(AUX)
245+
echo tar-`sed \
246+
-e '/version_string/!d' \
247+
-e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
248+
-e q
249+
version.c` > .fname
250+
-rm -rf `cat .fname`
251+
mkdir `cat .fname`
252+
ln $(SRCS) $(AUX) `cat .fname`
253+
tar chZf `cat .fname`.tar.Z `cat .fname`
254+
-rm -rf `cat .fname` .fname
255+
256+
tar.zoo: $(SRCS) $(AUX)
257+
-rm -rf tmp.dir
258+
-mkdir tmp.dir
259+
-rm tar.zoo
260+
for X in $(SRCS) $(AUX) ; do \
261+
echo $$X ; \
262+
sed 's/$$/^M/' $$X \
263+
> tmp.dir/$$X ; done
264+
cd tmp.dir ; zoo aM ../tar.zoo *
265+
-rm -rf tmp.dir
266+
</code></pre>

0 commit comments

Comments
 (0)