Skip to content

Instantly share code, notes, and snippets.

@andlrc
Created March 21, 2019 10:36
Show Gist options
  • Save andlrc/43e880e5321d95c389d05343ab2aad9d to your computer and use it in GitHub Desktop.
Save andlrc/43e880e5321d95c389d05343ab2aad9d to your computer and use it in GitHub Desktop.
Compilation rules for ILE RPG programs
# NAME
# rpgle.mk - compilation rules for ILE RPG programs
#
# SYNOPSIS
# LIBL = XXX YYY
# OUTLIB = XXX
# PREFIX = dist/
# CLEANPREFIX = clean/
#
# include rpgle.mk
#
# # service program creation
# dist/my1.mod: myhdr.rpgleinc
# dist/my2.mod:
# dist/my.srvpgm: dist/my1.mod dist/my2.mod
#
# # program creation
# dist/mypgm.mod: myhdr.rpgleinc
# dist/mypgm.pgm: dist/my.bnddir
#
# # clean
# clean: clean/my1.mod clean/my2.mod clean/my.srvpgm \
# clean/my.bnddir clean/my.srvsrc \
# clean/mypgm.mod clean/mypgm.pgm
#
# DESCRIPTION
# See PROGRAMS, "SERVICE PROGRAMS", MODULES, and "BINDING DIRECTORIES"
#
# PROGRAMS
# A program is created with the .pgm rule, an implicit .mod file with the
# same basename as the .pgm needs to exists, see MODULES.
#
# Other dependencies can be specified. I.e. binding directories
#
# SERVICE PROGRAMS
# A service program is created with the .srvpgm rule, all .mod (See
# MODULES) prerequisites are used to create the service program
#
# For each service program a .binder file with the same name as the
# service program needs to be created with the program exports
#
# Other dependencies can be specified. I.e. binding directories
#
# MODULES
# A module is created with the .mod rule, a .rpgle file with the same
# basename as the .mod needs to exists
#
# Other dependencies can be specified. I.e. headers
#
# BINDING DIRECTORIES
# A binding directory is created with the .bnddir rule
#
# ENVIRONMENT VARIABLES
# LIBL the compile library list
# OUTLIB the destination library
# PREFIX the directory used to store temporary files, default is dist/
# CLEANPREFIX the prefix used to create clean rules, default is clean/
# SYSTEM used as the build command, default is system
# SYSTEM_UP used as the build command when a prerequisite needs
# upload, default is system
#
# AUTHOR
# Andreas Louv <andreas@louv.dk>
ifndef LIBL
$(error LIBL is not defined)
endif
ifndef OUTLIB
$(error OUTLIB is not defined)
endif
ifndef PREFIX
PREFIX = dist/$(OUTLIB)-
$(info PREFIX is not defined, using the default: '$(PREFIX)')
endif
ifndef CLEANPREFIX
CLEANPREFIX = clean/$(OUTLIB)-
$(info CLEANPREFIX is not defined, using the default: '$(CLEANPREFIX)')
endif
ifndef SYSTEM
SYSTEM = system
SHELL = qsh
reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
SETLIBL = for lib in $(call reverse,$(LIBL)); do liblist -a $$lib; done;
$(info SYSTEM is not defined, using the default: '$(SYSTEM)')
endif
ifndef SYSTEM_UP
SYSTEM_UP = system
$(info SYSTEM_UP is not defined, using the default: '$(SYSTEM_UP)')
endif
TOUCH_FILE = echo "-- AUTO GENERATED BY make: $$(date) --" > "$@"
.SECONDARY:
slice = $(shell echo "$(1)" | sed 's/\(.\{$(2)\}\).*/\1/')
# Modules
$(PREFIX)%.mod: %.rpgle
@echo "===> CRTSRCPF FILE($(OUTLIB)/QMAKSRC) RCDLEN(240) TEXT('rpgle.mk - Build file')"
@$(SYSTEM) -q "CRTSRCPF FILE($(OUTLIB)/QMAKSRC) RCDLEN(240) TEXT('rpgle.mk - Build file')" ||:
@echo "===> CPYFRMSTMF FROMSTMF('$<') TOMBR('/QSYS.LIB/$(OUTLIB).LIB/QMAKSRC.FILE/$(call slice,$*,10).MBR') MBROPT(*REPLACE)"
@$(SYSTEM_UP) "CPYFRMSTMF FROMSTMF('$<') TOMBR('/QSYS.LIB/$(OUTLIB).LIB/QMAKSRC.FILE/$(call slice,$*,10).MBR') MBROPT(*REPLACE)"
@echo "===> CRTRPGMOD $(RPGFLAGS) MODULE($(OUTLIB)/$(call slice,$*,10)) SRCFILE($(OUTLIB)/QMAKSRC)"
@$(SETLIBL) if ! $(SYSTEM) "CRTRPGMOD $(RPGFLAGS) MODULE($(OUTLIB)/$(call slice,$*,10)) SRCFILE($(OUTLIB)/QMAKSRC)" > errors.txt; \
then \
sed 's~^[[:space:]]*\*RNF[0-9]\{4\} \([12345]0\) .\{6\} \([0-9]\{4\}\)00 \(.*\)~$<:\2:\1 \3~p;d' errors.txt; \
exit 1; \
fi
@$(TOUCH_FILE)
$(CLEANPREFIX)%.mod:
@echo "\$$ rm $(PREFIX)$*.mod"
@rm $(PREFIX)$*.mod 2>/dev/null ||:
@echo "===> DLTOBJ OBJ($(OUTLIB)/$(call slice,$*,10)) OBJTYPE(*MODULE)"
@$(SYSTEM_UP) -q "DLTOBJ OBJ($(OUTLIB)/$(call slice,$*,10)) OBJTYPE(*MODULE)" ||:
# Programs
$(PREFIX)%.pgm: $(PREFIX)%.mod
@echo "===> CRTPGM PGM($(OUTLIB)/$(call slice,$*,10))"
@$(SETLIBL) $(SYSTEM) "CRTPGM PGM($(OUTLIB)/$(call slice,$*,10))"
@$(TOUCH_FILE)
$(CLEANPREFIX)%.pgm:
@echo "\$$ rm $(PREFIX)$*.pgm"
@rm $(PREFIX)$*.pgm 2>/dev/null ||:
@echo "===> DLTOBJ OBJ($(OUTLIB)/$(call slice,$*,10)) OBJTYPE(*PGM)"
@$(SYSTEM_UP) -q "DLTOBJ OBJ($(OUTLIB)/$(call slice,$*,10)) OBJTYPE(*PGM)" ||:
# Service Programs
$(PREFIX)%.srvpgm: $(PREFIX)%.srvsrc
@echo "===> CRTSRVPGM SRVPGM($(OUTLIB)/$(call slice,$*,10)) MODULE($(foreach module,$(patsubst $(PREFIX)%.mod,%,$(filter %.mod,$^)),$(OUTLIB)/$(call slice,$(module),10)))"
@$(SETLIBL) $(SYSTEM) "CRTSRVPGM SRVPGM($(OUTLIB)/$(call slice,$*,10)) MODULE($(foreach module,$(patsubst $(PREFIX)%.mod,%,$(filter %.mod,$^)),$(OUTLIB)/$(call slice,$(module),10)))"
@$(TOUCH_FILE)
$(CLEANPREFIX)%.srvpgm:
@echo "\$$ rm $(PREFIX)$*.srvpgm"
@rm $(PREFIX)$*.srvpgm 2>/dev/null ||:
@echo "===> DLTOBJ OBJ($(OUTLIB)/$(call slice,$*,10)) OBJTYPE(*SRVPGM)"
@$(SYSTEM_UP) -q "DLTOBJ OBJ($(OUTLIB)/$(call slice,$*,10)) OBJTYPE(*SRVPGM)" ||:
# Binding Directories
$(PREFIX)%.bnddir: $(PREFIX)%.srvpgm
@echo "===> CRTBNDDIR BNDDIR($(OUTLIB)/$(call slice,$*,10))"
@$(SYSTEM) -q "CRTBNDDIR BNDDIR($(OUTLIB)/$(call slice,$*,10))" ||:
@echo "===> ADDBNDDIRE BNDDIR($(OUTLIB)/$(call slice,$*,10)) OBJ($(patsubst $(PREFIX)%.bnddir,(*LIBL/% *SRVPGM *IMMED),$@))"
@$(SYSTEM) "ADDBNDDIRE BNDDIR($(OUTLIB)/$(call slice,$*,10)) OBJ($(patsubst $(PREFIX)%.bnddir,(*LIBL/% *SRVPGM *IMMED),$@))" ||:
@$(TOUCH_FILE)
$(CLEANPREFIX)%.bnddir:
@echo "\$$ rm $(PREFIX)$*.bnddir"
@rm $(PREFIX)$*.bnddir 2>/dev/null ||:
@echo "===> DLTOBJ OBJ($(OUTLIB)/$(call slice,$*,10)) OBJTYPE(*BNDDIR)"
@$(SYSTEM_UP) -q "DLTOBJ OBJ($(OUTLIB)/$(call slice,$*,10)) OBJTYPE(*BNDDIR)" ||:
# Binder Language
$(PREFIX)%.srvsrc: %.binder
@echo "===> CRTSRCPF FILE($(OUTLIB)/QSRVSRC) RCDLEN(240) TEXT('rpgle.mk - Binder Language')"
@$(SYSTEM) -q "CRTSRCPF FILE($(OUTLIB)/QSRVSRC) RCDLEN(240) TEXT('rpgle.mk - Binder Language')" ||:
@echo "===> CPYFRMSTMF FROMSTMF('$<') TOMBR('/QSYS.LIB/$(OUTLIB).LIB/QSRVSRC.FILE/$(call slice,$*,10).MBR') MBROPT(*REPLACE)"
@$(SYSTEM_UP) "CPYFRMSTMF FROMSTMF('$<') TOMBR('/QSYS.LIB/$(OUTLIB).LIB/QSRVSRC.FILE/$(call slice,$*,10).MBR') MBROPT(*REPLACE)"
@$(TOUCH_FILE)
$(CLEANPREFIX)%.srvsrc:
@echo "\$$ rm $(PREFIX)$*.srvsrc"
@rm $(PREFIX)$*.srvsrc 2>/dev/null ||:
@echo "===> RMVM FILE($(OUTLIB)/QSRVSRC) MBR($(call slice,$*,10))"
@$(SYSTEM_UP) -q "RMVM FILE($(OUTLIB)/QSRVSRC) MBR($(call slice,$*,10))" ||:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment