Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

create_c_project with tap harness

by QuillMeantTen (Friar)
on Sep 11, 2015 at 10:34 UTC ( [id://1141657]=CUFP: print w/replies, xml ) Need Help??

Greetings fellow monks,
Too sick to be able to crawl to my classes I sat at my workbench and started hammering away at my latest obsession After devouring calcote fine autotools book I finally got it to work as I wanted it to (the obsession, not the book).
Alas as many of you may know trial and error is a bitch especially if your mind is deprived from his usual clarity by the wicked veils of sickness.

Pretty sure that by the end of my exhaustion induced nap with my cat I would have completely forgotten how I did it (and thanks to said veils I have not versionned correctly each trial) I set up to write the following script :

Given a path to your newly created c project folder and one to your c-tap-harness folder it will create a new project with the set of files needed by autotools.
Fellow monks that dabble in the Deep and Dark arts of C programming I give you those tools so you can use them or discard them as you see fit.

As always I am eager for ways to get better at perling so if you spot errors or ways to improve that script I am all electronic ears and shall follow up on your suggestions

Yours, still relatively coherent,

and now : create_c_project.pl:
Update: thanks for the good idea about filepath, I have updated the code and got rid of a silly bug related to the placement of AUTOMAKE_INIT and such things inside configure.ac

Yet Another update : fixed some issues and made the resulting project folder easier to work with (mainly by sprinkling it with symlinks and moving object files around)

And now the last update, I got everything working so make dist really distribute everything important

And the last update, promised, this time the template makefile works for distclean type commands

#!/usr/bin/perl use strict; use warnings; use Cwd; use File::Path qw(make_path remove_tree); if($#ARGV < 1 || $ARGV[0] =~ /(?:-h)|(?:--help)/){ print "this script requires two arguments :\n a path for the newly created c project\n a path to your c-tap-harness folder\n\n\n"; die; } my $folder = $ARGV[0]; my $ctap_folder_path = $ARGV[1]; my $starting_folder=getcwd(); mkdir $folder; chdir $folder; mkdir "tests"; `cp $ctap_folder_path/tests/runtests.c tests/`; `cp -r $ctap_folder_path/tests/tap tests/`; `touch NEWS README AUTHORS ChangeLog`; make_path('src/c','src/h','obj/src','obj/tests','bin','doc'); my $makefile_am = <<'END'; EXTRA_DIST=src doc tests obj AM_CFLAGS=-I$(abs_top_srcdir)/src/h AUTOMAKE_OPTIONS=subdir-objects check_PROGRAMS = tests/runtests #tests/exemple_test #executable file name of each test must be added to tests/TESTS #this setup allows you to use make distcheck as well as make distclean + and #related commands tests_runtests_CPPFLAGS = -DSOURCE='"$(abs_top_srcdir)/tests"' \ -DBUILD='"$(abs_top_builddir)/tests"' check_LIBRARIES = tests/tap/libtap.a tests_tap_libtap_a_CPPFLAGS = -I$(abs_top_srcdir)/tests tests_tap_libtap_a_SOURCES = tests/tap/basic.c tests/tap/basic.h tests +/tap/macros.h check-local:$(check_PROGRAMS) cd tests && ./runtests -l $(abs_top_srcdir)/tests/TESTS tests/runtests$(EXEEXT):tests/runtests.c gcc $^ -o tests/runtests #tests must be added this way: # # #tests/exemple_tests$(EXEEXT):$(abs_top_srcdir)/obj/tests/exemple_test +s.o #obj/src/exemple_test.o\ # obj/src/basic.o # gcc -o tests/exemple_tests $^ #$(abs_top_srcdir)/obj/tests/exemple_tests.o: tests/exemple_tests.c # gcc -c $^ -o $(abs_top_srcdir)/obj/tests/exemple_tests.o $(AM_CFL +AGS) # #normal files: # #obj/src/main.o:src/c/main.c # gcc -c $^ -o obj/src/main.o END open my $fh, '>','Makefile.am'; print $fh $makefile_am; close $fh; `autoscan`; open $fh,'<','configure.scan'; open my $ac,'>','configure.ac'; while(<$fh>){ my $line = $_; if($line =~ /\AAC_INIT/gxms){ $line =~ s/FULL-PACKAGE-NAME/$folder/; $line =~ s/VERSION/0.1/; $line =~ s/BUG-REPORT-ADDRESS/changeMeAtBugReportEmail/; print $ac $line; print $ac "AM_INIT_AUTOMAKE\nAC_PROG_RANLIB\n", } else{ print $ac $line; } } close $fh; close $ac; chdir 'tests'; `mv runtests.c ../src/tests/`; chdir 'tap'; my @file = glob "*.c"; foreach my $file (@file){ `gcc -c $file`; } chdir '../..'; `touch tests/TESTS`; unlink 'configure.scan'; `autoreconf -i`;

Replies are listed 'Best First'.
Re: create_c_project with tap harness
by RichardK (Parson) on Sep 11, 2015 at 11:39 UTC

    You could use File::Path to create the directories so you don't have to shell out.

    use File::Path qw(make_path remove_tree); make_path('foo/bar/baz', '/zug/zwang');

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://1141657]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-16 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found