Skip to content

Commit a59fc61

Browse files
author
Reini Urban
committed
more make and dist: .o vs o, all potion libs, ...
rearrange order along p2 fix deps by using the proper .o .opic suffices unify LINK targets to help windows add ranlib for darwin add LTO gold -O4 workaround for test/api/potion-test rewrote sloc: in clean dir cleanup clean target add test.c testcase for a commonly failing target dist all lib/potion* files
1 parent 8c79aa5 commit a59fc61

File tree

2 files changed

+79
-60
lines changed

2 files changed

+79
-60
lines changed

Makefile

Lines changed: 75 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# posix (linux, bsd, osx, solaris) + mingw with gcc/clang only
22
.SUFFIXES: .y .c .i .o .opic .textile .html
3-
.PHONY: all pn static usage config clean doc rebuild test bench tarball dist release install grammar
3+
.PHONY: all pn static usage config clean doc rebuild test bench tarball dist release install grammar \
4+
doxygen website testable
45
.NOTPARALLEL: test
56

67
SRC = core/asm.c core/ast.c core/compile.c core/contrib.c core/file.c core/gc.c core/internal.c core/lick.c core/load.c core/mt19937ar.c core/number.c core/objmodel.c core/primitive.c core/string.c core/syntax.c core/table.c core/vm.c
78
PLIBS = readline buffile aio
8-
GREGCFLAGS = -O3 -DNDEBUG
99

1010
# bootstrap config.inc with make -f config.mak
1111
include config.inc
@@ -49,15 +49,16 @@ LIBUV = lib/libuv${DLL}
4949
endif
5050
EXTLIBDEPS = ${LIBUV}
5151
DYNLIBS = $(foreach m,${PLIBS},lib/potion/$m${LOADEXT})
52-
DOC = doc/start.textile doc/glossary.textile
53-
DOCHTML = ${DOC:.textile=.html}
54-
OBJS = .o
52+
OBJS = o
5553
ifneq (${FPIC},)
5654
OBJS += ${OPIC}
5755
endif
56+
DOC = doc/start.textile doc/glossary.textile
57+
DOCHTML = ${DOC:.textile=.html}
5858

59+
GREGCFLAGS = -O3 -DNDEBUG
5960
CAT = /bin/cat
60-
ECHO = /bin/echo
61+
ECHO ?= /bin/echo
6162
MV = /bin/mv
6263
SED = sed
6364
EXPR = expr
@@ -87,7 +88,7 @@ usage:
8788
@${ECHO} " "
8889
@${ECHO} " ~ using potion ~"
8990
@${ECHO} " "
90-
@${ECHO} " Running a script."
91+
@${ECHO} " Running a script or code."
9192
@${ECHO} " "
9293
@${ECHO} " $$ bin/potion example/fib.pn"
9394
@${ECHO} " $$ bin/potion -e \"code\""
@@ -157,39 +158,39 @@ core/potion.${OPIC}: core/potion.c core/potion.h core/config.h core/internal.h \
157158
@${ECHO} CC $@ -O0
158159
@${CC} -c ${CFLAGS} -O0 ${FPIC} ${INCS} -o $@ $<
159160
endif
160-
core/vm.o core/vm.opic: core/vm-dis.c core/config.h
161161

162162
core/potion.h: core/config.h
163163
core/table.h: core/potion.h core/internal.h core/khash.h
164-
# for c in core/*.c; do gcc -MM -D_GNU_SOURCE -Icore $c; done |perl -lpe's/^(.+)o:/\$(foreach o,\${OBJS},core\/$1\${o} ):/'
165-
$(foreach o,${OBJS},core/asm${o} ): core/asm.c core/potion.h core/config.h core/internal.h \
164+
# for c in core/*.c; do gcc -MM -D_GNU_SOURCE -Icore $c; done |perl -lpe's/^(.+)o:/\$(foreach o,\${OBJS},core\/$1.\${o} ):/'
165+
$(foreach o,${OBJS},core/asm.${o} ): core/asm.c core/potion.h core/config.h core/internal.h \
166166
core/opcodes.h core/asm.h
167-
$(foreach o,${OBJS},core/ast${o} ): core/ast.c core/potion.h core/config.h core/internal.h core/ast.h
168-
$(foreach o,${OBJS},core/compile${o} ): core/compile.c core/potion.h core/config.h core/internal.h \
167+
$(foreach o,${OBJS},core/ast.${o} ): core/ast.c core/potion.h core/config.h core/internal.h core/ast.h
168+
$(foreach o,${OBJS},core/compile.${o} ): core/compile.c core/potion.h core/config.h core/internal.h \
169169
core/ast.h core/opcodes.h core/asm.h
170-
$(foreach o,${OBJS},core/contrib${o} ): core/contrib.c core/config.h
171-
$(foreach o,${OBJS},core/file${o} ): core/file.c core/potion.h core/config.h core/internal.h \
170+
$(foreach o,${OBJS},core/contrib.${o} ): core/contrib.c core/config.h
171+
$(foreach o,${OBJS},core/file.${o} ): core/file.c core/potion.h core/config.h core/internal.h \
172172
core/table.h core/khash.h
173-
$(foreach o,${OBJS},core/gc${o} ): core/gc.c core/potion.h core/config.h core/internal.h core/gc.h \
173+
$(foreach o,${OBJS},core/gc.${o} ): core/gc.c core/potion.h core/config.h core/internal.h core/gc.h \
174174
core/khash.h core/table.h
175-
$(foreach o,${OBJS},core/internal${o} ): core/internal.c core/potion.h core/config.h core/internal.h \
175+
$(foreach o,${OBJS},core/internal.${o} ): core/internal.c core/potion.h core/config.h core/internal.h \
176176
core/table.h core/khash.h core/gc.h
177-
$(foreach o,${OBJS},core/lick${o} ): core/lick.c core/potion.h core/config.h core/internal.h
178-
$(foreach o,${OBJS},core/load${o} ): core/load.c core/potion.h core/config.h core/internal.h \
177+
$(foreach o,${OBJS},core/lick.${o} ): core/lick.c core/potion.h core/config.h core/internal.h
178+
$(foreach o,${OBJS},core/load.${o} ): core/load.c core/potion.h core/config.h core/internal.h \
179179
core/table.h core/khash.h
180-
$(foreach o,${OBJS},core/mt19937ar${o} ): core/mt19937ar.c core/potion.h core/config.h
181-
$(foreach o,${OBJS},core/number${o} ): core/number.c core/potion.h core/config.h core/internal.h
182-
$(foreach o,${OBJS},core/objmodel${o} ): core/objmodel.c core/potion.h core/config.h core/internal.h \
180+
$(foreach o,${OBJS},core/mt19937ar.${o} ): core/mt19937ar.c core/potion.h core/config.h
181+
$(foreach o,${OBJS},core/number.${o} ): core/number.c core/potion.h core/config.h core/internal.h
182+
$(foreach o,${OBJS},core/objmodel.${o} ): core/objmodel.c core/potion.h core/config.h core/internal.h \
183183
core/khash.h core/table.h core/asm.h
184-
$(foreach o,${OBJS},core/primitive${o} ): core/primitive.c core/potion.h core/config.h core/internal.h
185-
$(foreach o,${OBJS},core/string${o} ): core/string.c core/potion.h core/config.h core/internal.h \
184+
$(foreach o,${OBJS},core/primitive.${o} ): core/primitive.c core/potion.h core/config.h core/internal.h
185+
$(foreach o,${OBJS},core/string.${o} ): core/string.c core/potion.h core/config.h core/internal.h \
186186
core/khash.h core/table.h
187-
$(foreach o,${OBJS},core/table${o} ): core/table.c core/potion.h core/config.h core/internal.h \
187+
$(foreach o,${OBJS},core/table.${o} ): core/table.c core/potion.h core/config.h core/internal.h \
188188
core/khash.h core/table.h
189-
$(foreach o,${OBJS},core/vm${o} ): core/vm.c core/potion.h core/config.h core/internal.h \
189+
$(foreach o,${OBJS},core/vm.${o} ): core/vm.c core/potion.h core/config.h core/internal.h \
190190
core/opcodes.h core/asm.h core/khash.h core/table.h core/vm-dis.c
191-
$(foreach o,${OBJS},core/vm-ppc${o} ): core/vm-ppc.c core/config.h core/potion.h core/internal.h core/opcodes.h
192-
$(foreach o,${OBJS},core/vm-x86${o} ): core/vm-x86.c core/potion.h core/config.h core/internal.h \
191+
$(foreach o,${OBJS},core/vm-ppc.${o} ): core/vm-ppc.c core/potion.h core/config.h core/internal.h \
192+
core/opcodes.h core/asm.h
193+
$(foreach o,${OBJS},core/vm-x86.${o} ): core/vm-x86.c core/potion.h core/config.h core/internal.h \
193194
core/opcodes.h core/asm.h core/khash.h core/table.h
194195

195196
%.i: %.c core/config.h
@@ -237,27 +238,29 @@ ${GREG}: tools/greg.c tools/compile.c tools/tree.c
237238

238239
bin/potion${EXE}: ${PIC_OBJ_POTION} lib/libpotion${DLL}
239240
@${ECHO} LINK $@
240-
@${CC} ${CFLAGS} ${PIC_OBJ_POTION} -o $@ ${RPATH} \
241-
-Llib -lpotion ${LIBPTH} ${LIBS}
242-
@if [ "${DEBUG}" != "1" ]; then \
243-
${ECHO} STRIP $@; \
244-
${STRIP} $@; \
245-
fi
241+
@${CC} ${CFLAGS} ${LDFLAGS} ${PIC_OBJ_POTION} -o $@ ${LIBPTH} ${RPATH} -lpotion ${LIBS}
242+
@if [ "${DEBUG}" != "1" ]; then ${ECHO} STRIP $@; ${STRIP} $@; fi
246243

247244
bin/potion-s${EXE}: core/potion.o lib/libpotion.a lib/libuv.a
248245
@${ECHO} LINK $@
249-
@${CC} ${CFLAGS} core/potion.o -o $@ lib/libpotion.a lib/libuv.a ${LIBPTH} ${LIBS}
246+
@${CC} ${CFLAGS} ${LDFLAGS} core/potion.o -o $@ lib/libpotion.a lib/libuv.a ${LIBPTH} ${LIBS}
247+
248+
lib/potion/readline.o:
249+
@${ECHO} CC $@
250+
@${MAKE} -s -C lib/readline static
250251

251252
lib/libpotion.a: ${OBJ} core/config.h core/potion.h
252253
@${ECHO} AR $@
253254
@if [ -e $@ ]; then rm -f $@; fi
254255
@${AR} rcs $@ core/*.o > /dev/null
256+
@${ECHO} RANLIB $@
257+
@-${RANLIB} $@
255258

256259
lib/libpotion${DLL}: ${PIC_OBJ} core/config.h core/potion.h
257260
@${ECHO} LD $@
258261
@if [ -e $@ ]; then rm -f $@; fi
259262
@${CC} ${DEBUGFLAGS} -o $@ ${LDDLLFLAGS} ${RPATH} \
260-
${PIC_OBJ} -Llib ${LIBPTH} ${LIBS} > /dev/null
263+
${PIC_OBJ} ${LIBPTH} ${LIBS} > /dev/null
261264
@if [ x${DLL} = x.dll ]; then cp $@ bin/; fi
262265

263266
# 3rdparty EXTLIBS statically linked
@@ -312,10 +315,12 @@ lib/potion/readline${LOADEXT}: core/config.h core/potion.h \
312315
@cp lib/readline/readline${LOADEXT} $@
313316

314317
lib/potion/buffile${LOADEXT}: core/config.h core/potion.h \
315-
lib/buffile.${OPIC} lib/buffile.c
318+
lib/buffile.${OPIC} lib/buffile.c lib/libpotion${DLL}
316319
@${ECHO} LD $@
320+
@if [ -f lib/libpotion.a ]; then mv lib/libpotion.a lib/libpotion.a.tmp; fi
317321
@${CC} $(DEBUGFLAGS) -o $@ ${LDDLLFLAGS} \
318322
lib/buffile.${OPIC} ${LIBPTH} -lpotion ${LIBS} > /dev/null
323+
@if [ -f lib/libpotion.a.tmp ]; then mv lib/libpotion.a.tmp lib/libpotion.a; fi
319324

320325
ifeq ($(HAVE_LIBUV),1)
321326
AIO_DEPS =
@@ -324,12 +329,14 @@ AIO_DEPS = ${LIBUV}
324329
endif
325330

326331
lib/potion/aio${LOADEXT}: core/config.h core/potion.h \
327-
lib/aio.c $(AIO_DEPS)
332+
lib/aio.c $(AIO_DEPS) lib/libpotion${DLL}
328333
@${ECHO} CC lib/aio.${OPIC}
329334
@${CC} -c ${FPIC} ${CFLAGS} ${INCS} -o lib/aio.${OPIC} lib/aio.c > /dev/null
330335
@${ECHO} LD $@
336+
@if [ -f lib/libpotion.a ]; then mv lib/libpotion.a lib/libpotion.a.tmp; fi
331337
@${CC} $(DEBUGFLAGS) -o $@ $(subst libpotion,aio,${LDDLLFLAGS}) ${RPATH} \
332338
lib/aio.${OPIC} ${LIBPTH} -lpotion -luv ${LIBS} > /dev/null
339+
@if [ -f lib/libpotion.a.tmp ]; then mv lib/libpotion.a.tmp lib/libpotion.a; fi
333340

334341
bench: test/api/gc-bench${EXE} bin/potion${EXE}
335342
@${ECHO}; \
@@ -392,17 +399,19 @@ test: pn libs test/api/potion-test${EXE} test/api/gc-test${EXE}
392399

393400
testable : bin/potion${EXE} libs test/api/potion-test${EXE} test/api/gc-test${EXE} test/api/gc-bench${EXE}
394401

402+
# for LTO gold -O4
395403
test/api/potion-test${EXE}: ${OBJ_TEST} lib/libpotion.a
396404
@${ECHO} LINK $@
397-
@${CC} ${CFLAGS} ${OBJ_TEST} -o $@ lib/libpotion.a ${LIBS}
405+
@if ${CC} ${CFLAGS} ${LDFLAGS} ${OBJ_TEST} -o $@ lib/libpotion.a ${LIBS}; then true; else \
406+
${CC} ${CFLAGS} ${LDFLAGS} ${OBJ_TEST} -o $@ ${OBJ} ${OBJ_SYN} ${LIBS}; fi
398407

399408
test/api/gc-test${EXE}: ${OBJ_GC_TEST} lib/libpotion.a
400409
@${ECHO} LINK $@
401-
@${CC} ${CFLAGS} ${OBJ_GC_TEST} -o $@ lib/libpotion.a ${LIBS}
410+
@${CC} ${CFLAGS} ${LDFLAGS} ${OBJ_GC_TEST} -o $@ lib/libpotion.a ${LIBS}
402411

403412
test/api/gc-bench${EXE}: ${OBJ_GC_BENCH} lib/libpotion.a
404413
@${ECHO} LINK $@
405-
@${CC} ${CFLAGS} ${OBJ_GC_BENCH} -o $@ lib/libpotion.a ${LIBS}
414+
@${CC} ${CFLAGS} ${LDFLAGS} ${OBJ_GC_BENCH} -o $@ lib/libpotion.a ${LIBS}
406415

407416
examples: pn
408417
for e in example/*.pn; do echo $$e; time bin/potion $$e; done
@@ -417,7 +426,7 @@ dist: bins libs $(AIO_DEPS) static docall ${GREG}
417426
install: dist
418427
+${MAKE} -f dist.mak $@ PREFIX="${PREFIX}"
419428

420-
tarball: dist
429+
tarball:
421430
+${MAKE} -f dist.mak $@ PREFIX="${PREFIX}"
422431

423432
release: dist
@@ -441,7 +450,7 @@ doc: ${DOCHTML} doc/html/files.html
441450
docall: doc GTAGS
442451

443452
doxygen: doc/html/files.html
444-
@${ECHO} DOXYGEN -f core
453+
@${ECHO} DOXYGEN -f core lib
445454
@perl -pe's/^ //;s/^~ /## ~ /;' README > README.md
446455
@doc/footer.sh > doc/footer.inc
447456
mv core/syntax.c core/syntax-c.tmp
@@ -458,7 +467,7 @@ doc/html/files.html: core/*.c core/*.h doc/Doxyfile doc/footer.sh Makefile
458467
mv core/syntax-c.tmp core/syntax.c
459468
@rm README.md
460469

461-
# perl11.org only. needs: doxygen redcloth global
470+
# perl11.org admins only. requires: doxygen redcloth global
462471
website:
463472
test -d ${WEBSITE} || exit
464473
@${MAKE} doxygen
@@ -476,36 +485,45 @@ GTAGS: ${SRC} core/*.h
476485

477486
TAGS: ${SRC} core/*.h
478487
@rm -f TAGS
479-
/usr/bin/find \( -name \*.c -o -name \*.h \) -exec etags -a --language=c \{\} \;
488+
/usr/bin/find core lib \( -name \*.c -o -name \*.h \) -exec etags -a --language=c \{\} \;
480489

481490
sloc: clean
482-
-@rm core/syntax.c
483-
@sloccount core lib
491+
@rm -rf dist
492+
@git checkout-index --prefix=dist/ -a
493+
@cd dist && \
494+
rm tools/greg.c && \
495+
sloccount core lib && \
496+
cd .. && \
497+
rm -rf dist
484498

485499
todo:
486-
@grep -rInso 'TODO: \(.\+\)' core tools
500+
@grep -rInso 'TODO: \(.\+\)' core tools lib
487501

488502
clean:
489503
@${ECHO} cleaning
490504
@rm -f core/*.o core/*.opic core/*.i test/api/*.o
491-
@rm -f tools/*.o tools/*~ doc/*~ example/*~ tools/config.c
505+
@rm -f bin/* lib/libpotion.* lib/potion/*${DLL} lib/*/*${LOADEXT} lib/*/*.o
492506
@rm -f ${DOCHTML} README.md doc/footer.inc
493-
@rm -f core/config.h core/version.h
494-
@rm -f bin/potion${EXE} bin/potion-s${EXE} lib/libpotion.* \
507+
@rm -f bin/potion${EXE} bin/potion-s${EXE} \
495508
test/api/potion-test${EXE} test/api/gc-test${EXE} test/api/gc-bench${EXE}
496-
@rm -f lib/potion/*${LOADEXT} lib/readline/readline${LOADEXT}
497-
@rm -f lib/lib*$(DLL) lib/lib*.a
498509
@rm -f tools/*.o core/config.h core/version.h
499-
@rm -f tools/*~ doc/*~ example/*~ tools/config.c
500-
@rm -rf doc/html doc/latex doc/ref
510+
@rm -f tools/*~ doc/*~ example/*~ core/*~ config.inc~ tools/config.c
511+
@rm -rf doc/latex
501512

513+
# also config.inc and files needed for cross-compilation
502514
realclean: clean
503515
@rm -f config.inc ${GREG} ${GREGCROSS} core/syntax.c
504516
@rm -f GPATH GTAGS GRTAGS
505-
@rm -rf doc/ref
517+
@rm -rf doc/ref doc/html
518+
@rm -rf lib/*${DLL} lib/*${LOADEXT}
506519
@${MAKE} -s clean -C 3rd/libuv
507520
@if test -f 3rd/libuv/Makefile.am; then rm 3rd/libuv/Makefile; fi
508521
@find . -name \*.gcov -delete
509522

510-
.PHONY: all config clean doc docall rebuild check test bench tarball dist \
511-
release install grammar doxygen website
523+
test.c: bin/potion${EXE}
524+
f=test/classes/creature.pn && \
525+
look=`${CAT} $$f | ${SED} "/\#=>/!d; s/.*\#=> //"` && \
526+
for=`bin/potion -I -B $$f | ${SED} "s/\n$$//"` && \
527+
if [ "$$look" != "$$for" ]; then \
528+
${ECHO} "$$f: expected <$$look>, but got <$$for>"; \
529+
fi

dist.mak

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ install: bin-dist
3131

3232
bin-dist: ${BINDIST}
3333

34-
pkg/${PKGBIN}.tar.gz: core/config.h core/version.h core/syntax.c bin/potion${EXE} \
34+
pkg/${PKGBIN}.tar.gz: core/config.h core/version.h bin/potion${EXE} \
3535
lib/libpotion${DLL} lib/potion/readline${LOADEXT}
3636
rm -rf dist
3737
mkdir -p dist dist/bin dist/include/potion dist/lib/potion \
3838
dist/share/potion/doc dist/share/potion/example
3939
cp bin/potion${EXE} dist/bin/
4040
cp lib/libpotion${DLL} dist/lib/
41-
cp lib/potion/*${LOADEXT} dist/lib/potion/
41+
cp -r lib/potion/ dist/lib/potion/
4242
if [ ${WIN32} = 1 ]; then mv dist/lib/*.dll dist/bin/; fi
4343
cp core/potion.h dist/include/potion/
4444
cp core/config.h dist/include/potion/
@@ -72,7 +72,8 @@ pkg/${PKGBIN}.zip: core/config.h core/version.h core/syntax.c bin/potion${EXE} \
7272
(cd dist && zip ../pkg/${PKGBIN}.zip -rm * && cd ..)
7373
rm -rf dist
7474

75-
pkg/${PKGBIN}-devel.tar.gz: ${GREG} bin/potion-s${EXE} lib/libpotion.a GTAGS
75+
pkg/${PKGBIN}-devel.tar.gz: ${GREG} bin/potion-s${EXE} lib/libpotion.a
76+
+${MAKE} doxygen GTAGS
7677
rm -rf dist
7778
mkdir -p dist dist/bin dist/include/potion dist/lib/potion \
7879
dist/share/potion/doc/ref dist/share/potion/test

0 commit comments

Comments
 (0)