Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Automated GNU Makefile

A simple automated GNU Makefile to build and link c/c++/asm projects. All the variables that need to be tweaked are located at the begining:
PROGNAME: the name of the executable to be built
CC: the C compiler
CPP: the C++ compiler
ASM: the assambler
LD: the linker

This searches for all *.c, *.cpp and *.s files and compiles them into objects. It then links all the files into a single executable.

The strip rule is used to strip all unwanted symbols from the resulting executable. This usually results in a significant (think 40%) size optimisation.

   1  
   2  $(VERBOSE).SILENT:
   3  
   4  PROGNAME = prog
   5  
   6  CC = gcc
   7  CC += -c
   8  CPP = g++
   9  CPP += -c
  10  ASM = nasm
  11  ASM += -f elf -d ELF_TYPE
  12  LD = g++
  13  
  14  OBJFILES = $(patsubst %.c,%.o,$(wildcard *.c))
  15  OBJFILES += $(patsubst %.s,%.o,$(wildcard *.s))
  16  OBJFILES += $(patsubst %.cpp,%.o,$(wildcard *.cpp))
  17  
  18  all: $(PROGNAME)
  19  
  20  clean:
  21  	@echo "Cleaning object files"
  22  	@echo "    rm -f     *.o"
  23  	rm -f *.o
  24  	@echo "Cleaning backups"
  25  	@echo "    rm -f     *~"
  26  	rm -f *~
  27  	@echo "Removing programme"
  28  	@echo "    rm -f     "$(PROGNAME)
  29  	rm -f $(PROGNAME)
  30  
  31  %.o: %.s
  32  	@echo "Assambling "$@
  33  	@echo "    ASM       "$<
  34  	$(ASM) $<
  35  
  36  %.o: %.c
  37  	@echo "Compiling "$@
  38  	@echo "    CC        "$<
  39  	$(CC) $<
  40  
  41  %.o: %.cpp
  42  	@echo "Compiling "$@
  43  	@echo "    CPP       "$<
  44  	$(CPP) $<
  45  
  46  $(PROGNAME): $(OBJFILES)
  47  	@echo "Linking "$@
  48  	@echo "    LD        -o "$(PROGNAME)"        "$(OBJFILES)
  49  	$(LD) -o $(PROGNAME) $(OBJFILES)
  50  
  51  strip: $(PROGNAME)
  52  	@echo "Stripping "$(PROGNAME)
  53  	echo -n "Size of "$(PROGNAME)" before strip is "
  54  	ls -sh $(PROGNAME) | cut -d' ' -f1
  55  	@echo "    strip     "$(PROGNAME)
  56  	strip $(PROGNAME)
  57  	echo -n "Size of "$(PROGNAME)" after strip is "
  58  	ls -sh $(PROGNAME) | cut -d' ' -f1
  59  
  60  nothing:
  61  	@echo "Nothing to do; quitting  :("
  62  	@echo "HINT: Try make all"
  63  


Init rails project script

From http://vinsol.com/2007/02/08/ruby-script-for-creating-new-rails-project-and-initial-svn-import-with-ignoringremoving-logother-files

   1  
   2  require 'fileutils'
   3  
   4  puts  "########################################"
   5  puts  "This script creates a new rails project and do the initial svn import with ignoring/deleting files from subversion"
   6  puts  "Please send your feedback to Akhil Bansal<bansalakhil30.10@gmail.com>"
   7  puts  "I have tested this script and it works great on my system."
   8  puts  ""
   9  puts  ""
  10  puts  "                    ###### ATTENTION #######"
  11  puts  ""
  12  puts  ""
  13  puts  "Use this script at your own risk, if your computer explodes its not my fault :-) "
  14  puts  "#######################################"
  15  
  16  puts  "Enter svn username: "
  17  username = gets.strip
  18  puts  "Enter the svn url: "
  19  svn_url =gets.strip
  20  
  21  puts  "Enter Rails Application Path:(eg: /home/akhil/ror): "
  22  app_path = gets.strip
  23  puts  "Enter Application Name: "
  24  app_name = gets.strip
  25  
  26  puts  "######################################"
  27  
  28  
  29  puts  "Please verify the following variables: "
  30  puts  "Svn Username: #{username}"
  31  puts  "Svn URL: #{svn_url}"
  32  puts  "Application Path: #{app_path}"
  33  puts  "Application name: #{app_name}"
  34  
  35  puts  "Proceed (y/n)"
  36  proceed = gets
  37  proceed = proceed.strip.upcase
  38  if proceed == 'N' 
  39      puts  "Terminating..."
  40      exit 0
  41  elsif proceed == 'Y' 
  42      if system("rails -v")
  43        s="/"
  44      elsif   system("rails.cmd -v")
  45        s="\\"
  46      else
  47          puts "Cannot find rails. Terminating..."
  48          exit 0
  49      end    
  50      app_root=app_path+s+ app_name
  51      
  52      puts  "Generating rails project: (#{app_root})"
  53      if system("rails #{app_root}")
  54        s="/"
  55      elsif   system("rails.cmd #{app_root}")
  56        s="\\"
  57      else
  58          puts "Cannot create rails project. Terminating..."
  59          exit 0
  60      end    
  61      
  62      puts  "SVNinitial import: "
  63      system("svn import #{app_root} #{svn_url} -m \"Initial Import\" --username #{username}")
  64     
  65      FileUtils.remove_dir(app_root, true)
  66     
  67      puts  "Checking out from svn: "
  68  
  69      system("svn checkout #{svn_url} #{app_root}")
  70      FileUtils.cd(app_root, :verbose => true)
  71      
  72      puts  "Removing all log files from SVN"
  73      system("svn remove log"+s+"*")
  74      puts  "commiting..."
  75      system("svn commit -m \"removing all log files from subversion \" ")
  76      puts  "Ignoring all log files under log dir"
  77      system("svn propset svn:ignore \"*.log\" log"+s)
  78      puts  "Updating and commiting..."
  79      system("svn update log"+s)
  80      system("svn commit -m \"Ignoring all files in "+s+"log"+s+" ending in .log \" ")
  81      puts  "Removing tmp directory from SVN"
  82      system("svn remove tmp"+s)
  83      puts  "commiting..."
  84      system("svn commit -m \"removing the temp directory from subversion \" ")
  85      puts  "Ignoring tmp dir"
  86      system("svn propset svn:ignore \"*\" tmp"+s)
  87      puts  "Updating and commiting again...."
  88  
  89      system("svn update tmp"+s)
  90      system("svn commit -m \"Ignore the whole tmp"+s+" directory, might not work on subdirectories? \" ")
  91      puts  "Moving database.yml to database.example"
  92      system("svn move config"+s+"database.yml config"+s+"database.example")
  93      puts  "commiting..."
  94      system("svn commit -m \"Moving database.yml to database.example to provide a template for anyone who checks out the code \" ")
  95      puts  "Ignoring database.yml , updating and commiting..."
  96      system("svn propset svn:ignore 'database.yml' config"+s)
  97      system("svn update config"+s)
  98      system("svn commit -m \"Ignoring database.yml\" ")
  99      puts  "Finished."
 100  
 101  else
 102      puts  "Unknown Input. Terminating..."
 103  	exit 0
 104  end

transform normal projet to rails project in radrails

// in radrails when you import a project from subversion
// it is a normal project

// in the menu I found no way to transform it
// but so it worked for me:

// 1. edit the .project file and copy the natueres block

   1  
   2  	<natures>
   3  		<nature>org.radrails.rails.ui.railsnature</nature>
   4  		<nature>org.rubypeople.rdt.core.rubynature</nature>
   5  	</natures>


// 2. copy the buildSpec block too
// (I'm not sure if this is necessary, I did both and it worked)

   1  
   2  	<buildSpec>
   3  		<buildCommand>
   4  			<name>org.rubypeople.rdt.core.rubybuilder</name>
   5  			<arguments>
   6  			</arguments>
   7  		</buildCommand>
   8  	</buildSpec>


// 3. restart radrails and
// 4. add a webrick-server to the project
// and you are done
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS