Sponsored Content
Top Forums Shell Programming and Scripting Question in creating targets in makefile Post 302843976 by Anand Venkatesa on Friday 16th of August 2013 02:09:51 AM
Old 08-16-2013
Question Question about creating targets in makefile

Hi,

I have a question related to makefile. I'm new to makefile and I'm in the process of writing a makefile for my RBT build. I have multiple source files and when I compile them I will get multiple object files (one object file for each source file). I'm having problem in creating a target for each object file with out hardcoding the object file names. I read the list of source file names from another make file. Assume the variable SRC_NAMES contains list of source file names (say test1.c test2.c test3.c). Now I want to create target for each objects for it (say test1.obj test2.obj test3.obj). Currently I have written some thing like below,

Code:
 
#############################################
OBJS_LIST := $(foreach file,$(SRC_NAMES),$(notdir ${file}))
OBJS_LIST := $(DSP_COMMON_OBJ_LIST:.c=.obj)
 
all: final.exe
 
final.exe: $(OBJS_LIST)
   create exe here
 
$(OBJS_LIST): $(SRC_NAMES)
    compile and generate object file for each source files here.
 
#############################################

This is not working. Since OBJS_LIST contains many object names, compilation action is repeated for many times for the target $(OBJS_LIST). My question is how to split the obj target into multiple targets without hard-coding the target obj names?

Thanks,
Anand

Last edited by Anand Venkatesa; 08-16-2013 at 03:46 AM.. Reason: Trivial Change in Title
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Creating new system Makefile template

I am attempting to set-up a Makefile to use for a new system on a Sun Unix machine. I am new to creating Makefiles. I am trying to start simply by compiling a program. I am getting the following error message but an uncertain what 'Error Code 1' is. Is there a web site with Error Codes... (1 Reply)
Discussion started by: CaptainRo
1 Replies

2. UNIX for Dummies Questions & Answers

Makefile question

I'm trying to do string replacement with a Makefile and this is my scenario: Inside file "fileA", I have "#include<text>" statements and I want to replace it with the text inside a file called "params". I wish to perform this task using Makefiles. I've tried using m4 but that only works if... (1 Reply)
Discussion started by: hc29
1 Replies

3. Programming

Tough makefile question

At my company, we build some stuff using a makefile. While the makefile script is running, a developer may check in a newer version of a source file. The problem is, when we next run the make command, the target file isn't rebuilt, because the date of the target is after the dependency. Any... (1 Reply)
Discussion started by: mbbeaubi
1 Replies

4. UNIX for Dummies Questions & Answers

makefile Q about targets $@

Hi All I need to parse the target something like: ifeq '$@' 'first' echo 1 $@ endif ifeq '$@' 'second' echo 2 $@ endif The thing is to be able compare the target string to any string and then do the commands Thanks a lot ziv (0 Replies)
Discussion started by: zivsegal
0 Replies

5. Shell Programming and Scripting

Makefile question

Hi all, I've a makefile which has this line: @touch $@ I know $@ is for representing the target. But I don't know what's the @ preceding the touch. Can anyone help me? Thanks in advance. (4 Replies)
Discussion started by: mjdousti
4 Replies

6. UNIX for Dummies Questions & Answers

makefile Question

Hello, I'm trying to use the make command with a makefile I've made for an assignment. The professor supplied the code and I've copied it into a new file. I made sure to place the tabs in the correct spaces, however when I try to execute it in UNIX I get: "make: Fatal error in reader:... (5 Replies)
Discussion started by: Shinra1003
5 Replies

7. AIX

makefile question

Hi all, In a makefile I would like to grab the first line of a given parameter file using ‘head' and assign it to a variable, how do I do this? I've got a simple makefile but it does not work? #! /bin/ksh ... .sqc.c: db2prep $*.sqc bindfile if ] DB2_PARM=`/usr/bin/head -1 $*.prm`; fi... (2 Replies)
Discussion started by: apersak
2 Replies

8. UNIX for Advanced & Expert Users

Help in creating a makefile

Hi, I wanted to know whether there is any way to specify in a makefile how to compile sources from a directory directly by giving the directory path name instead of mentioning each and every source file name. Regards, Anil (1 Reply)
Discussion started by: anil_lami
1 Replies

9. UNIX for Advanced & Expert Users

makefile head-scratcher: multiple targets in one go

Hi! I've got a build process where scripts create multiple targets from their sources. But here I'm running into a conceptual problem of GNU make: If one has multiple targets in a dependency, make applies the rules once for every target that is out of sync - which is correct for normal... (3 Replies)
Discussion started by: treczoks
3 Replies

10. Programming

Problem creating a makefile

hello, I'm trying to create a makefile to run multiple c files. I am able to run one c file only with the code I have when I tried to run 2 or more c files I'm not able. here is my code # $Source: /home/hectormasencio/make/Makefile,v $ # $Date: 2012/11/27 11:35:30 $ CC= gcc OBJS= temp.o... (3 Replies)
Discussion started by: Hector M.
3 Replies
CRUNCHGEN(1)						    BSD General Commands Manual 					      CRUNCHGEN(1)

NAME
crunchgen -- generates build environment for a crunched binary SYNOPSIS
crunchgen [-fOoq] [-c c-file-name] [-D src-root] [-d build-options] [-e exec-file-name] [-L lib-dir] [-m makefile-name] [-v var-spec] conf-file DESCRIPTION
A crunched binary is a program made up of many other programs linked together into a single executable. The crunched binary main() function determines which component program to run by the contents of argv[0]. The main reason to crunch programs together is for fitting as many programs as possible onto an installation or system recovery floppy. crunchgen reads in the specifications in conf-file for a crunched binary, and generates a Makefile and accompanying top-level C source file that when built create the crunched executable file from the component programs. For each component program, crunchgen can optionally attempt to determine the object (.o) files that make up the program from its source directory Makefile. This information is cached between runs. crunchgen uses the companion program crunchide to eliminate link-time conflicts between the component programs by hiding all unneces- sary symbols. After crunchgen is run, the crunched binary can be built by running ``make -f <conf-name>.mk''. The component programs' object files must already be built. An ``objs'' target, included in the output makefile, will run make in each component program's source dir to build the object files for the user. This is not done automatically since in release engineering circumstances it is generally not desirable to be modifying objects in other directories. The options are as follows: -c c-file-name Set output C file name to c-file-name. The default name is ``<confname>.c''. -D src-root Assume that relative source directory specifications begin with src-root. -d build-options Set the DBG variable in the generated makefile to build-options. The default flags are -Os. -e exec-file-name Set crunched binary executable file name to exec-file-name. The default name is ``<conf-name>''. -f Flush cache. Forces the recalculation of cached parameters. -L lib-dir Try to obtain libraries from lib-dir. -m makefile-name Set output Makefile name to makefile-name. The default name is ``<conf-name>.mk''. -O Force crunchgen to parse the program's Makefile in determine the list of .o files. Without this option crunchgen expects the pro- gram's Makefile to have a program.ro target that links all the program objects into a single relocatable. -o Use existing object files. Rather than rebuilding object files via reach-over makefiles, instead search for and use existing object files. -q Quiet operation. Status messages are suppressed. -v varspec Append a variable specification to the on-the fly generated Makefile. CRUNCHGEN CONFIGURATION FILE COMMANDS
crunchgen reads specifications from the conf-file that describe the components of the crunched binary. In its simplest use, the component program names are merely listed along with the top-level source directories in which their sources can be found. crunchgen then calculates (via the source makefiles) and caches the list of object files and their locations. For more specialized situations, the user can specify by hand all the parameters that crunchgen needs. The conf-file commands are as follows: srcdirs dirname ... A list of source trees in which the source directories of the component programs can be found. These dirs are searched using the BSD ``<source-dir>/<progname>/'' convention. Multiple srcdirs lines can be specified. The directories are searched in the order they are given. progs progname ... A list of programs that make up the crunched binary. Multiple progs lines can be specified. libs libspec ... A list of library specifications to be included in the crunched binary link. Multiple libs lines can be specified. ln progname linkname Causes the crunched binary to invoke progname whenever linkname appears in argv[0]. This allows programs that change their behavior when run under different names to operate correctly. To handle specialized situations, such as when the source is not available or not built via a conventional Makefile, the following special commands can be used to set crunchgen parameters for a component program. special progname keepsymbols symbols ... Don't hide the specified symbols for progname. Normally all externally visible symbols for a program is hidden to avoid interfer- ence. Multiple keepsymbols lines can be specified for given progname. special progname srcdir pathname Set the source directory for progname. This is normally calculated by searching the specified srcdirs for a directory named progname. special progname objdir pathname Set the obj directory for progname. This is normally calculated by looking for a directory named ``obj'' under the srcdir, and if that is not found, the srcdir itself becomes the objdir. Note: This option only takes effect if the -o option to use existing object files is also specified. special progname objs object-file-name ... Set the list of object files for program progname. This is normally calculated by constructing a temporary makefile that includes ``srcdir / Makefile'' and outputs the value of $(OBJS). Multiple objs lines can be specified for given progname. special progname objpaths full-pathname-to-object-file ... Sets the pathnames of the object files for program progname. This is normally calculated by prepending the objdir pathname to each file in the objs list. Multiple objpaths lines can be specified for given progname. Only the objpaths parameter is actually needed by crunchgen but it is calculated from objdir and objs, which are in turn calculated from srcdir, so is sometimes convenient to specify the earlier parameters and let crunchgen calculate forward from there if it can. The makefile produced by crunchgen contains an optional objs target that will build the object files for each component program by running make inside that program's source directory. For this to work the srcdir and objs parameters must also be valid. If they are not valid for a particular program, that program is skipped in the objs target. ENVIRONMENT
MAKEOBJDIRPREFIX If the environment variable MAKEOBJDIRPREFIX is set, the object directory will be prefixed with the path contained in this environment variable. Note: This variable is only used if the -o option to use existing object files is also specified. MACHINE If the environment variable MACHINE is set, it is used as the name of the machine type, when accessing object directories of the form obj.MACHINE. If it is not set, it defaults to the machine type returned by uname(3). Note: This option is only used if the -o option to use existing object files is also specified. MAKE If the environment variable MAKE is set, it is used as the name of the make(1) executable to be called. If this environ- ment variable is not set, crunchgen defaults to ``make''. EXAMPLES
Here is an example crunchgen input conf file, named ``kcopy.conf'': srcdirs /usr/src/bin /usr/src/sbin progs test cp echo sh fsck halt init mount umount myinstall ln test [ # test can be invoked via [ ln sh -sh # init invokes the shell with "-sh" in argv[0] special myprog objpaths /homes/leroy/src/myinstall.o # no sources libs -lutil -lcrypt This conf file specifies a small crunched binary consisting of some basic system utilities plus a home-grown install program ``myinstall'', for which no source directory is specified, but its object file is specified directly with the special line. The crunched binary ``kcopy'' can be built as follows: % crunchgen -m Makefile kcopy.conf # gen Makefile and kcopy.c % make objs # build the component programs' .o files % make # build the crunched binary kcopy % kcopy sh # test that this invokes a sh shell $ # it works! At this point the binary ``kcopy'' can be copied onto an install floppy and hard-linked to the names of the component programs. SEE ALSO
crunchide(1), make(1) AUTHORS
crunchgen was written by James da Silva <jds@cs.umd.edu>. Copyright (c) 1994 University of Maryland. All Rights Reserved. BUGS
While crunchgen takes care to eliminate link conflicts between the component programs of a crunched binary, conflicts are still possible between the libraries that are linked in. Some shuffling in the order of libraries may be required, and in some rare cases two libraries may have an unresolvable conflict and thus cannot be crunched together. Some versions of the BSD build environment do not by default build the intermediate object file for single-source file programs. The ``make objs'' target must then be used to get those object files built, or some other arrangements made. If a program directory being searched for is found, but contains no objects, other directories are not searched. This causes the following directive to fail: srcdirs /usr/src/usr.bin /usr/src/usr.bin/less progs less gzip as the /usr/src/usr.bin/less directory will be found with the /usr/src/usr.bin srcdirs entry, and as it does not contain the require objects, crunchgen fails to find objects for the less program. To avoid this problem, list specific srcdirs first, and the more general ones later, for e.g.: srcdirs /usr/src/usr.bin/less /usr/src/usr.bin progs less gzip will not have the above problem. BSD
October 18, 2006 BSD
All times are GMT -4. The time now is 04:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy