LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-25-2010, 09:44 PM   #1
Mitchell314
LQ Newbie
 
Registered: Mar 2010
Distribution: Ubuntu
Posts: 8

Rep: Reputation: 0
Question Making a project distribution folder


(Newb question alert)

I'm trying to make my first c project (a simple tic tac toe console game), and I am wondering how to make a final product (copy all source code files to a distribution folder upon compilation). Should I use a bash script or should I use a makefile to make the distribution folder? I'm not terrible familiar with either; I have a basic makefile to make an executable, and that's about all I know of make.

And if I do use a bash script, how do I copy over source code files? I tried cp ./*.c and cp ./*.h, but I think the script read it literally as moving a file named ./*.c (and ./*.h), and couldn't find it.

My makefile is pretty much this:
Code:
objectFiles = main.o io.o board.o game.o

ttt : $(objectFiles)
	cc -o ttt $(objectFiles)

Last edited by Mitchell314; 06-26-2010 at 02:23 PM. Reason: Added "solved" prefix thingy
 
Old 06-26-2010, 01:24 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
I wrote a script to do that exact thing, I like to keep things simple rather than use a full IDE ... rename to .sh

cheers

start_code_project.txt
 
Old 06-26-2010, 08:55 AM   #3
Mitchell314
LQ Newbie
 
Registered: Mar 2010
Distribution: Ubuntu
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks for the script. Though, I already have an existing project with code, except the folder is cluttered with object files and editor backups. So I'm trying to copy all *.h and *.c files to a clean subdirectory (/distr), then zip it upon compiling. Though I don't know how to copy files just based on having a .c or .h. I can do it in the terminal no problem, cp ./*.c ./distr and cp ./*.h ./distr, but that same code wouldn't work in the script.

So pretty much, how do I copy source files in a shell script?


So far this is what I have (and it doesn't work):
Code:
#!/bin/bash

# Remove old source-distribution directory
if [ -e ./distr ]; then
   rm -r ./distr
fi

# Make a clean source-distribution directory
mkdir ./distr

# Move source code to distribution directory
cFiles=ls "./*.c"
for i in $cFiles; do
        cp $i ./distr
done

hFiles=ls "./*.h"
for i in $hFiles; do
        cp $i ./distr
done

ETA: Found out how to do that. Had to feed ls output to grep. Ye gads I'm horrible with shell scripting.

Code:
!/bin/bash

# Distribution folder name
distrFolder="./distr"

# Source code file extension expression (for grep)
extension="\.[ch]$"


# Remove old source-distribution directory
if [ -e "$distrFolder" ]; then
   rm -r "$distrFolder"
fi

# Make a clean source-distribution directory
mkdir "./$distrFolder"

# Get source code files from current directory
srcFiles=$(ls | grep "$extension")

# Move source code files to distribution directory
for file in $srcFiles; do
    cp "./$file" "$distrFolder"
done

Last edited by Mitchell314; 06-26-2010 at 02:21 PM. Reason: Solved
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
which linux distribution for embedded project jvoyce Slackware 4 09-29-2005 04:14 PM
Making a new distribution CyberTron Linux - Distributions 2 04-13-2005 10:03 AM
Which LINUX distribution i should prefer for my Project report ?? Aquarian Linux - Distributions 5 11-05-2003 06:01 AM
Which LINUX distribution i should prefer for my Project report ?? Aquarian Debian 3 11-04-2003 10:24 AM
Making a distribution dadelcas Linux - General 2 03-17-2003 02:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration